bitops: Introduce a more generic BITMASK macro
authorMathieu Poirier <mathieu.poirier@linaro.org>
Tue, 9 Dec 2014 21:38:21 +0000 (14:38 -0700)
committerMathieu Poirier <mathieu.poirier@linaro.org>
Mon, 22 Dec 2014 17:49:12 +0000 (10:49 -0700)
This patch is back-porting the generic _portion_ of
10ef6b0dffe404bcc54e94cb2ca1a5b18445a66b to 3.10

Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
include/linux/bitops.h

index a3b6b82108b9ad239dd1dda1abe6c8e3f585d3b3..bd0c4598d03b8b815f80c6bf8df984179701dc35 100644 (file)
 #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);