[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250223164217.2139331-2-visitorckw@gmail.com>
Date: Mon, 24 Feb 2025 00:42:01 +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,
Kuan-Wei Chiu <visitorckw@...il.com>,
Yu-Chun Lin <eleanor15x@...il.com>
Subject: [PATCH 01/17] bitops: Add generic parity calculation for u32
Several parts of the kernel open-code parity calculations using
different methods. Add a generic parity32() helper implemented with the
same efficient approach as parity8().
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>
---
include/linux/bitops.h | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index c1cb53cf2f0f..fb13dedad7aa 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -260,6 +260,27 @@ static inline int parity8(u8 val)
return (0x6996 >> (val & 0xf)) & 1;
}
+/**
+ * parity32 - get the parity of an u32 value
+ * @value: the value to be examined
+ *
+ * Determine the parity of the u32 argument.
+ *
+ * Returns:
+ * 0 for even parity, 1 for odd parity
+ */
+static inline int parity32(u32 val)
+{
+ /*
+ * One explanation of this algorithm:
+ * https://funloop.org/codex/problem/parity/README.html
+ */
+ val ^= val >> 16;
+ val ^= val >> 8;
+ val ^= val >> 4;
+ return (0x6996 >> (val & 0xf)) & 1;
+}
+
/**
* __ffs64 - find first set bit in a 64 bit word
* @word: The 64 bit word
--
2.34.1
Powered by blists - more mailing lists