aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathieu Poirier <mathieu.poirier@linaro.org>2014-12-09 14:38:21 -0700
committerMathieu Poirier <mathieu.poirier@linaro.org>2014-12-22 10:49:12 -0700
commitbfab9062c7be44b3a255d478bda5d4a7a3dba7e2 (patch)
tree84a02dbf8602a2fe926131b0d34deb53a36adc44
parent54d37488baccb0b31610458ac9833591b76de1e4 (diff)
bitops: Introduce a more generic BITMASK macro
This patch is back-porting the generic _portion_ of 10ef6b0dffe404bcc54e94cb2ca1a5b18445a66b to 3.10 Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
-rw-r--r--include/linux/bitops.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index a3b6b82108b9..bd0c4598d03b 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -10,6 +10,14 @@
#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
#endif
+/*
+ * Create a contiguous bitmask starting at bit position @l and ending at
+ * position @h. For example
+ * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
+ */
+#define GENMASK(h, l) (((U32_C(1) << ((h) - (l) + 1)) - 1) << (l))
+#define GENMASK_ULL(h, l) (((U64_C(1) << ((h) - (l) + 1)) - 1) << (l))
+
extern unsigned int __sw_hweight8(unsigned int w);
extern unsigned int __sw_hweight16(unsigned int w);
extern unsigned int __sw_hweight32(unsigned int w);