[PATCH v3 07/16] lib/bch: Replace open-coded parity calculation with parity32()
Kuan-Wei Chiu <[email protected]>
| Newsgroups | dev.linux.lists.brcm80211,org.freedesktop.lists.dri-devel,org.infradead.lists.linux-mtd,org.kernel.vger.bpf,org.kernel.vger.linux-input,org.kernel.vger.linux-kernel,org.kernel.vger.linux-media,org.kernel.vger.linux-serial,org.kernel.vger.linux-wireless,org.kernel.vger.netdev |
|---|---|
| Message-ID | <[email protected]> |
Refactor parity calculations to use the standard parity32() helper. This change eliminates redundant implementations and improves code efficiency. Co-developed-by: Yu-Chun Lin <[email protected]> Signed-off-by: Yu-Chun Lin <[email protected]> Signed-off-by: Kuan-Wei Chiu <[email protected]> --- Changes in v3: - Change parity32(mask) to !!parity32(mask). lib/bch.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/lib/bch.c b/lib/bch.c index 1c0cb07cdfeb..6c29122c0982 100644 --- a/lib/bch.c +++ b/lib/bch.c @@ -311,18 +311,6 @@ static inline int deg(unsigned int poly) return fls(poly)-1; } -static inline int parity(unsigned int x) -{ - /* - * public domain code snippet, lifted from - * http://www-graphics.stanford.edu/~seander/bithacks.html - */ - x ^= x >> 1; - x ^= x >> 2; - x = (x & 0x11111111U) * 0x11111111U; - return (x >> 28) & 1; -} - /* Galois field basic operations: multiply, divide, inverse, etc. */ static inline unsigned int gf_mul(struct bch_control *bch, unsigned int a, @@ -524,7 +512,7 @@ static int solve_linear_system(struct bch_control *bch, unsigned int *rows, tmp = 0; for (r = m-1; r >= 0; r--) { mask = rows[r] & (tmp|1); - tmp |= parity(mask) << (m-r); + tmp |= !!parity32(mask) << (m-r); } sol[p] = tmp >> 1; } -- 2.34.1