mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Denis Orlov <denorl2009@gmail.com>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>,
	Denis Orlov <denorl2009@gmail.com>
Subject: [PATCH 3/3] include: bitops: import more BITS_TO_* defines from linux
Date: Fri,  9 Jun 2023 07:54:09 +0300	[thread overview]
Message-ID: <20230609045829.2225-4-denorl2009@gmail.com> (raw)
In-Reply-To: <20230609045829.2225-1-denorl2009@gmail.com>

Those seem quite useful, e.g. when defining bitmasks.

Signed-off-by: Denis Orlov <denorl2009@gmail.com>
---
 include/linux/bitops.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index d9a5a81a9c..a5f6ac6545 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -14,7 +14,11 @@
 #define BIT_ULL_MASK(nr)	(ULL(1) << ((nr) % BITS_PER_LONG_LONG))
 #define BIT_ULL_WORD(nr)	((nr) / BITS_PER_LONG_LONG)
 #define BITS_PER_BYTE		8
-#define BITS_TO_LONGS(nr)	DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
+#define BITS_PER_TYPE(type)	(sizeof(type) * BITS_PER_BYTE)
+#define BITS_TO_LONGS(nr)	DIV_ROUND_UP(nr, BITS_PER_TYPE(long))
+#define BITS_TO_U64(nr)		DIV_ROUND_UP(nr, BITS_PER_TYPE(u64))
+#define BITS_TO_U32(nr)		DIV_ROUND_UP(nr, BITS_PER_TYPE(u32))
+#define BITS_TO_BYTES(nr)	DIV_ROUND_UP(nr, BITS_PER_TYPE(char))
 #endif
 
 /*
-- 
2.41.0




  parent reply	other threads:[~2023-06-09  5:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-09  4:54 [PATCH 0/3] include: bitops/const: partial update from Linux Denis Orlov
2023-06-09  4:54 ` [PATCH 1/3] include: const: make UL/ULL() macros commonly available Denis Orlov
2023-06-09  4:54 ` [PATCH 2/3] include: bitops: allow BIT* macros to be used in assembly code Denis Orlov
2023-06-09  4:54 ` Denis Orlov [this message]
2023-06-09  6:30 ` [PATCH 0/3] include: bitops/const: partial update from Linux Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230609045829.2225-4-denorl2009@gmail.com \
    --to=denorl2009@gmail.com \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox