+ lib-bchc-use-__builtin_parity-when-available.patch added to mm-nonmm-unstable branch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The patch titled
     Subject: lib/bch.c: use __builtin_parity() when available
has been added to the -mm mm-nonmm-unstable branch.  Its filename is
     lib-bchc-use-__builtin_parity-when-available.patch

This patch will shortly appear at
     https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/lib-bchc-use-__builtin_parity-when-available.patch

This patch will later appear in the mm-nonmm-unstable branch at
    git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next via the mm-everything
branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there every 2-3 working days

------------------------------------------------------
From: Uros Bizjak <ubizjak@xxxxxxxxx>
Subject: lib/bch.c: use __builtin_parity() when available
Date: Wed, 29 Jan 2025 21:57:31 +0100

Compilers (GCC and clang) provide optimized __builtin_parity() function
that returns the parity of X, i.e.  the number of 1-bits in X modulo 2.

Use __builtin_parity() built-in function to optimize parity(). This
improves generated code on x86_64 from:

	movl    %edi, %edx
	shrl    %edx
	xorl    %edi, %edx
	movl    %edx, %eax
	shrl    $2, %eax
	xorl    %edx, %eax
	andl    $286331153, %eax
	imull   $286331153, %eax, %eax
	shrl    $28, %eax
	andl    $1, %eax

to an optimized:

	movl    %edi, %ecx
	shrl    $16, %ecx
	xorl    %edi, %ecx
	xorl    %eax, %eax
	xorb    %ch, %cl
	setnp   %al

Please note SETNP instruction that exercises hardware parity
calculation of x86 processors. When POPCNT instruction is
available, the generated code gets optimized even further:

	popcntl %edi, %eax
	andl    $1, %eax

Compile-tested only.

Link: https://lkml.kernel.org/r/20250129205746.10963-1-ubizjak@xxxxxxxxx
Signed-off-by: Uros Bizjak <ubizjak@xxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---

 lib/bch.c |    4 ++++
 1 file changed, 4 insertions(+)

--- a/lib/bch.c~lib-bchc-use-__builtin_parity-when-available
+++ a/lib/bch.c
@@ -313,6 +313,9 @@ static inline int deg(unsigned int poly)
 
 static inline int parity(unsigned int x)
 {
+#if __has_builtin(__builtin_parity)
+	return __builtin_parity(x);
+#else
 	/*
 	 * public domain code snippet, lifted from
 	 * http://www-graphics.stanford.edu/~seander/bithacks.html
@@ -321,6 +324,7 @@ static inline int parity(unsigned int x)
 	x ^= x >> 2;
 	x = (x & 0x11111111U) * 0x11111111U;
 	return (x >> 28) & 1;
+#endif
 }
 
 /* Galois field basic operations: multiply, divide, inverse, etc. */
_

Patches currently in -mm which might be from ubizjak@xxxxxxxxx are

x86-kgdb-use-is_err_pcpu-macro.patch
compilerh-introduce-typeof_unqual-macro.patch
percpu-use-typeof_unqual-in-variable-declarations.patch
percpu-use-typeof_unqual-in-_cpu_ptr-accessors.patch
percpu-repurpose-__percpu-tag-as-a-named-address-space-qualifier.patch
percpu-x86-enable-strict-percpu-checks-via-named-as-qualifiers.patch
lib-bchc-use-__builtin_parity-when-available.patch





[Index of Archives]     [Kernel Archive]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]

  Powered by Linux