+#define parity(val) \What do you think about using these inline functions instead of macros?
+({ \
+ u64 __v = (val); \
+ int __ret; \
+ switch (BITS_PER_TYPE(val)) { \
+ case 64: \
+ __v ^= __v >> 32; \
+ fallthrough; \
+ case 32: \
+ __v ^= __v >> 16; \
+ fallthrough; \
+ case 16: \
+ __v ^= __v >> 8; \
+ fallthrough; \
+ case 8: \
+ __v ^= __v >> 4; \
+ __ret = (0x6996 >> (__v & 0xf)) & 1; \
+ break; \
+ default: \
+ BUILD_BUG(); \
+ } \
+ __ret; \
+})
+
+#define parity8(val) parity((u8)(val))
+#define parity32(val) parity((u32)(val))
+#define parity64(val) parity((u64)(val))
Except for parity8(), each function is a single line and follows the
same logic. I find inline functions more readable, and coding-style.rst
also recommends them over macros.