]> xenbits.xensource.com Git - xen.git/commitdiff
xen/bitops: Introduce GENMASK to generate mask
authorJulien Grall <julien.grall@arm.com>
Fri, 22 Apr 2016 15:58:32 +0000 (16:58 +0100)
committerStefano Stabellini <sstabellini@kernel.org>
Wed, 27 Apr 2016 15:44:20 +0000 (16:44 +0100)
The code has been imported from the header include/linux/bitops.h in
Linux v4.6-rc3.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
xen/include/xen/bitops.h

index cb56f247ab3154fe9540345553ca258c53c5f13f..bd0883ab220717451081f702f05d700d3895b3d4 100644 (file)
@@ -2,6 +2,14 @@
 #define _LINUX_BITOPS_H
 #include <asm/types.h>
 
+/*
+ * Create a contiguous bitmask starting at bit position @l and ending at
+ * position @h. For example
+ * GENMASK(30, 21) gives us the 32bit vector 0x01fe00000.
+ */
+#define GENMASK(h, l) \
+    (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
+
 /*
  * ffs: find first bit set. This is defined the same way as
  * the libc and compiler builtin ffs routines, therefore