]> git.itanic.dy.fi Git - linux-stable/commit
x86/asm/bitops: Use __builtin_clz{l|ll} to evaluate constant expressions
authorNick Desaulniers <ndesaulniers@google.com>
Mon, 28 Aug 2023 18:53:57 +0000 (11:53 -0700)
committerIngo Molnar <mingo@kernel.org>
Wed, 6 Sep 2023 22:05:50 +0000 (00:05 +0200)
commit3dae5c43badf285e22f6d88388e8a232a83bdfec
tree82670ebc99ec4553ca8b2b3d2e4d04271761f898
parent4accdb9895349026d85e526036ff28c07921d7cf
x86/asm/bitops: Use __builtin_clz{l|ll} to evaluate constant expressions

Micro-optimize the bitops code some more, similar to commits:

  fdb6649ab7c1 ("x86/asm/bitops: Use __builtin_ctzl() to evaluate constant expressions")
  2fcff790dcb4 ("powerpc: Use builtin functions for fls()/__fls()/fls64()")

From a recent discussion, I noticed that x86 is lacking an optimization
that appears in arch/powerpc/include/asm/bitops.h related to constant
folding.  If you add a BUILD_BUG_ON(__builtin_constant_p(param)) to
these functions, you'll find that there were cases where the use of
inline asm pessimized the compiler's ability to perform constant folding
resulting in runtime calculation of a value that could have been
computed at compile time.

Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20230828-x86_fls-v1-1-e6a31b9f79c3@google.com
arch/x86/include/asm/bitops.h