diff options
author | Denis Orlov <denorl2009@gmail.com> | 2023-06-09 07:54:09 +0300 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2023-06-09 08:30:16 +0200 |
commit | 87199b07faae7869cd34cb7ec5fbfdbebd7b0000 (patch) | |
tree | 9098a7d646b7bf086e042db1bd8139ddc16d6295 /include/linux/bitops.h | |
parent | da3c0d73dc6ac76cb038bf5221dc080a038859f3 (diff) | |
download | barebox-87199b07faae7869cd34cb7ec5fbfdbebd7b0000.tar.gz barebox-87199b07faae7869cd34cb7ec5fbfdbebd7b0000.tar.xz |
include: bitops: import more BITS_TO_* defines from linux
Those seem quite useful, e.g. when defining bitmasks.
Signed-off-by: Denis Orlov <denorl2009@gmail.com>
Link: https://lore.barebox.org/20230609045829.2225-4-denorl2009@gmail.com
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include/linux/bitops.h')
-rw-r--r-- | include/linux/bitops.h | 6 |
1 files changed, 5 insertions, 1 deletions
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 /* |