lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250301142409.2513835-19-visitorckw@gmail.com>
Date: Sat,  1 Mar 2025 22:24:09 +0800
From: Kuan-Wei Chiu <visitorckw@...il.com>
To: tglx@...utronix.de,
	mingo@...hat.com,
	bp@...en8.de,
	dave.hansen@...ux.intel.com,
	x86@...nel.org,
	jk@...abs.org,
	joel@....id.au,
	eajames@...ux.ibm.com,
	andrzej.hajda@...el.com,
	neil.armstrong@...aro.org,
	rfoss@...nel.org,
	maarten.lankhorst@...ux.intel.com,
	mripard@...nel.org,
	tzimmermann@...e.de,
	airlied@...il.com,
	simona@...ll.ch,
	dmitry.torokhov@...il.com,
	mchehab@...nel.org,
	awalls@...metrocast.net,
	hverkuil@...all.nl,
	miquel.raynal@...tlin.com,
	richard@....at,
	vigneshr@...com,
	louis.peens@...igine.com,
	andrew+netdev@...n.ch,
	davem@...emloft.net,
	edumazet@...gle.com,
	pabeni@...hat.com,
	parthiban.veerasooran@...rochip.com,
	arend.vanspriel@...adcom.com,
	johannes@...solutions.net,
	gregkh@...uxfoundation.org,
	jirislaby@...nel.org,
	yury.norov@...il.com,
	akpm@...ux-foundation.org
Cc: hpa@...or.com,
	alistair@...ple.id.au,
	linux@...musvillemoes.dk,
	Laurent.pinchart@...asonboard.com,
	jonas@...boo.se,
	jernej.skrabec@...il.com,
	kuba@...nel.org,
	linux-kernel@...r.kernel.org,
	linux-fsi@...ts.ozlabs.org,
	dri-devel@...ts.freedesktop.org,
	linux-input@...r.kernel.org,
	linux-media@...r.kernel.org,
	linux-mtd@...ts.infradead.org,
	oss-drivers@...igine.com,
	netdev@...r.kernel.org,
	linux-wireless@...r.kernel.org,
	brcm80211@...ts.linux.dev,
	brcm80211-dev-list.pdl@...adcom.com,
	linux-serial@...r.kernel.org,
	bpf@...r.kernel.org,
	jserv@...s.ncku.edu.tw,
	david.laight.linux@...il.com,
	andrew.cooper3@...rix.com,
	Kuan-Wei Chiu <visitorckw@...il.com>,
	Yu-Chun Lin <eleanor15x@...il.com>
Subject: [PATCH v2 18/18] bitops: Add parity() macro for automatic type-based selection

Introduce the parity() macro, which selects the appropriate parity
function (parity8(), parity16(), parity32(), or parity64()) based on
the size of the input type. This improves usability by allowing a
generic parity calculation without requiring explicit function
selection.

If the input type does not match the supported sizes, BUILD_BUG() is
triggered to catch invalid usage at compile time.

Co-developed-by: Yu-Chun Lin <eleanor15x@...il.com>
Signed-off-by: Yu-Chun Lin <eleanor15x@...il.com>
Signed-off-by: Kuan-Wei Chiu <visitorckw@...il.com>
---
Place this patch last in the series to avoid compilation errors.

 include/linux/bitops.h | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index 41e9e7fb894b..fa4e45741dff 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -339,6 +339,28 @@ static inline __attribute_const__ int parity64(u64 val)
 	return __builtin_constant_p(val) ? _parity_const(val) : _parity64(val);
 }
 
+#define parity(val)			\
+({					\
+	int __ret;			\
+	switch (BITS_PER_TYPE(val)) {	\
+	case 64:			\
+		__ret = parity64(val);	\
+		break;			\
+	case 32:			\
+		__ret = parity32(val);	\
+		break;			\
+	case 16:			\
+		__ret = parity16(val);	\
+		break;			\
+	case 8:				\
+		__ret = parity8(val);	\
+		break;			\
+	default:			\
+		BUILD_BUG();		\
+	}				\
+	__ret;				\
+})
+
 /**
  * __ffs64 - find first set bit in a 64 bit word
  * @word: The 64 bit word
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ