]> Git Repo - linux.git/commitdiff
uapi: Define GENMASK_U128
authorAnshuman Khandual <[email protected]>
Thu, 22 Aug 2024 04:48:52 +0000 (10:18 +0530)
committerYury Norov <[email protected]>
Wed, 28 Aug 2024 13:53:58 +0000 (06:53 -0700)
This adds GENMASK_U128() and __GENMASK_U128() macros using __BITS_PER_U128
and __int128 data types. These macros will be used in providing support for
generating 128 bit masks.

The macros wouldn't work in all assembler flavors for reasons described
in the comments on top of declarations. Enforce it for more by adding
!__ASSEMBLY__ guard.

Cc: Yury Norov <[email protected]>
Cc: Rasmus Villemoes <[email protected]>
Cc: Arnd Bergmann <[email protected]>>
Cc: [email protected]
Cc: [email protected]
Reviewed-by: Arnd Bergmann <[email protected]>
Signed-off-by: Anshuman Khandual <[email protected]>
Signed-off-by: Yury Norov <[email protected]>
include/linux/bits.h
include/uapi/linux/bits.h
include/uapi/linux/const.h

index 0eb24d21aac2142cc94b4489ccd786df58a06400..60044b6088172b3f26aa3f17cdaede9786863dae 100644 (file)
 #define GENMASK_ULL(h, l) \
        (GENMASK_INPUT_CHECK(h, l) + __GENMASK_ULL(h, l))
 
+#if !defined(__ASSEMBLY__)
+/*
+ * Missing asm support
+ *
+ * __GENMASK_U128() depends on _BIT128() which would not work
+ * in the asm code, as it shifts an 'unsigned __init128' data
+ * type instead of direct representation of 128 bit constants
+ * such as long and unsigned long. The fundamental problem is
+ * that a 128 bit constant will get silently truncated by the
+ * gcc compiler.
+ */
+#define GENMASK_U128(h, l) \
+       (GENMASK_INPUT_CHECK(h, l) + __GENMASK_U128(h, l))
+#endif
+
 #endif /* __LINUX_BITS_H */
index 3c2a101986a314f6abdc486cfcda4c109017183f..5ee30f882736cbd1bc7b3c1e5236858db44015d7 100644 (file)
@@ -12,4 +12,7 @@
         (((~_ULL(0)) - (_ULL(1) << (l)) + 1) & \
          (~_ULL(0) >> (__BITS_PER_LONG_LONG - 1 - (h))))
 
+#define __GENMASK_U128(h, l) \
+       ((_BIT128((h)) << 1) - (_BIT128(l)))
+
 #endif /* _UAPI_LINUX_BITS_H */
index a429381e7ca507fe7f4d86f4e7fa229cdcda078b..e16be0d37746e14b9eedcdb38be7d11f29b5113a 100644 (file)
 #define _BITUL(x)      (_UL(1) << (x))
 #define _BITULL(x)     (_ULL(1) << (x))
 
+#if !defined(__ASSEMBLY__)
+/*
+ * Missing asm support
+ *
+ * __BIT128() would not work in the asm code, as it shifts an
+ * 'unsigned __init128' data type as direct representation of
+ * 128 bit constants is not supported in the gcc compiler, as
+ * they get silently truncated.
+ *
+ * TODO: Please revisit this implementation when gcc compiler
+ * starts representing 128 bit constants directly like long
+ * and unsigned long etc. Subsequently drop the comment for
+ * GENMASK_U128() which would then start supporting asm code.
+ */
+#define _BIT128(x)     ((unsigned __int128)(1) << (x))
+#endif
+
 #define __ALIGN_KERNEL(x, a)           __ALIGN_KERNEL_MASK(x, (__typeof__(x))(a) - 1)
 #define __ALIGN_KERNEL_MASK(x, mask)   (((x) + (mask)) & ~(mask))
 
This page took 0.07606 seconds and 4 git commands to generate.