From: Uros Bizjak Date: Thu, 27 Mar 2025 09:56:28 +0000 (+0100) Subject: x86/bitops: Simplify variable_ffz() as variable__ffs(~word) X-Git-Tag: v6.16-rc1~195^2~32^2~16 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e29c5d0e5dc35ed8b8920b573925d8aa2f8bafb0;p=thirdparty%2Fkernel%2Flinux.git x86/bitops: Simplify variable_ffz() as variable__ffs(~word) Find first zero (FFZ) can be implemented by negating the input and using find first set (FFS). Before/after code generation comparison on ffz()-using kernel code shows that code generation has not changed: # kernel/signal.o: text data bss dec hex filename 42121 3472 8 45601 b221 signal.o.before 42121 3472 8 45601 b221 signal.o.after md5: ce4c31e1bce96af19b62a5f9659842f1 signal.o.before.asm ce4c31e1bce96af19b62a5f9659842f1 signal.o.after.asm [ mingo: Added code generation check. ] Signed-off-by: Uros Bizjak Signed-off-by: Ingo Molnar Cc: Brian Gerst Cc: Juergen Gross Cc: H. Peter Anvin Cc: Josh Poimboeuf Link: https://lore.kernel.org/r/20250327095641.131483-1-ubizjak@gmail.com --- diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h index bbaf75ea6703b..eebbc8889e70f 100644 --- a/arch/x86/include/asm/bitops.h +++ b/arch/x86/include/asm/bitops.h @@ -267,10 +267,7 @@ static __always_inline unsigned long variable__ffs(unsigned long word) static __always_inline unsigned long variable_ffz(unsigned long word) { - asm("tzcnt %1,%0" - : "=r" (word) - : "r" (~word)); - return word; + return variable__ffs(~word); } /**