Skip to contentSkip to conversation

x86/bitops: Implement variable_ffz() as variable__ffs(~word)

PATCH Applied Uros Bizjak 2 participants 2 messages Mar 27, 2025 – Mar 28, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/bitops: Implement variable_ffz() as variable__ffs(~word)

Find first zero (FFZ) can be implemented by negating the input and using find first set (FFS).

No functional changes intended.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Dave Hansen <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/include/asm/bitops.h | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
arch/x86/include/asm/bitops.h +1 -4
index bbaf75ea6703..eebbc8889e70 100644
@@ -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);
 }
 
 /**
Signature · 1 line
2.49.0
merge bot Applied
#1 lore raw

[tip: x86/asm] x86/bitops: Simplify variable_ffz() as variable__ffs(~word)

The following commit has been merged into the x86/asm branch of tip:

The following commit has been merged into the x86/asm branch of tip:

Commit-ID:     e29c5d0e5dc35ed8b8920b573925d8aa2f8bafb0
Gitweb:        https://git.kernel.org/tip/e29c5d0e5dc35ed8b8920b573925d8aa2f8bafb0
Author:        Uros Bizjak <[email protected]>
AuthorDate:    Thu, 27 Mar 2025 10:56:28 +01:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Fri, 28 Mar 2025 23:24:16 +01:00

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. ]

---
 arch/x86/include/asm/bitops.h | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
arch/x86/include/asm/bitops.h +1 -4
index bbaf75e..eebbc88 100644
@@ -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);
 }
 
 /**