Skip to contentSkip to conversation

hexagon: bitops: use the compiler builtins for ffs(), fls() and ffz()

PATCH In review Tzu-Ching Yang 4 participants 7 messages Nov 17 – Nov 19

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

PATCH 1/1 hexagon: bitops: use the compiler builtins for ffs(), fls() and ffz()

The hexagon inline asm for ffs(), __ffs(), fls(), __fls() and ffz() is not needed: Clang, the only compiler that builds hexagon kernels, emits the same ct0, cl0 and ct1 instructions for the compiler builtins, and unlike the asm, the builtins fold constant arguments. The asm dates from the 2011 port (a86a7ce30ac0, "Hexagon: Add bitops support"), before the builtin-based asm-generic helpers existed (048fa2df92c3, "generic: Implement generic ffs/fls using __builtin_* functions").

Replace the asm with the asm-generic builtin helpers, and ffz() with the generic __ffs(~x), as arm64 does.

ffs(0) and fls(0) still return 0. __ffs() and __fls() now return unsigned int, which is as wide as unsigned long on hexagon, and ffz() returns unsigned int instead of long. __ffs(0), __fls(0) and ffz(~0) remain undefined.

With Clang 17 to 23, the functions of a defconfig vmlinux shrink by 1972 to 6068 bytes in total (scripts/bloat-o-meter -t). One helper in lib/find_bit.c gets worse: _find_last_bit() executes one instruction more per call that finds a bit, because LLVM rewrites 31 - clz as 31 ^ clz once it knows clz < 32, and the hexagon backend keeps the xor, which needs the 31 in a register, instead of sub(#31, Rs) [1]. A few 1 << ffz() sites also grow by a few instructions, as LLVM rewrites that expression too [2]. __find_nth_bit() executes two fewer, and the other helpers that find_bit_benchmark calls the same number.

---
I have no hexagon hardware, and mainline does not boot in QEMU yet. On Brian's out-of-tree bcain/hexagon-qemu-virt branch (dc370baa041d, v7.3-rc1 plus 24 patches) with this patch on top, qemu_defconfig plus the ffs and bitops KUnit tests and find_bit_benchmark, built with Clang 17 and 23, boots under qemu-system-hexagon from qualcomm/qemu hex-next with -M virt,hvm=on (and under -M qcs6490-cdsp with the prebuilt H2 hypervisor); the KUnit tests pass before and after, with the same .config on both sides. Under -M virt,hvm=on, with a TCG plugin that writes the same bitmaps into both kernels before each test and counts the executed instructions without interrupts, find_bit_benchmark's find_last_bit executes one instruction more per iteration, bitmap_find_next_zero_area_off 36 more on the random bitmap through its find_last_bit() calls, find_nth_bit and test_bitops' fns() two fewer, and the other tests the same.

Under qemu-hexagon (user mode), the old and new helpers return the same values for every defined 32-bit input, and fls64() and __ffs64() for selected 64-bit inputs, with Clang 17 to 23 at -O2 and -Os.

defconfig (also with the KUnit tests and find_bit_benchmark, with -Os and with -mv73) and allmodconfig were built with Clang 17 to 23 before and after, with the same .config on both sides: same W=1 warnings, no calls to __ctzsi2(), __clzsi2() or ffs(), and a smaller bloat-o-meter -t total in every defconfig-based vmlinux. allmodconfig does not link with Clang 17 and 18, before or after: ld.lld before 19.1.5 rejects the calls in head.S as out of range.

Instructions of each helper in a test function that only returns its result (return included), built with the kernel's flags by Clang 17 to 22 at -O2 and -Os; Clang 23 adds an allocframe to both rows:

ffs __ffs fls __fls ffz

  asm         6      3    4      4    3
  builtin     5      2    3      3    2

The instruction saved is the copy of the result to r0: the asm's early-clobber output ("=&r") cannot share the argument's register.

In packets, only ffs() takes one more than the asm (4 -> 5): with df5e4db805d5 ("hexagon: disable the LLVM packetizer") applied, each instruction of the builtin version gets a packet of its own, while the asm is bundled by hand. Without that workaround, which linux-next does not have yet, ffs() goes from 6 instructions in 3 packets to 5 in 2.

Against the bcain/hexagon-fixes branch of bcain/linux.git (0304683b4c43); also applies to next-20261113 and to bitmap-for-next.

 arch/hexagon/include/asm/bitops.h | 100 ++----------------------------
 1 file changed, 5 insertions(+), 95 deletions(-)
arch/hexagon/include/asm/bitops.h +5 -95
index b23cb13833af..975328172b7c 100644
@@ -194,101 +194,11 @@ arch_test_bit_acquire(unsigned long nr, const volatile unsigned long *addr)
 	return retval;
 }
 
-/*
- * ffz - find first zero in word.
- * @word: The word to search
- *
- * Undefined if no zero exists, so code should check against ~0UL first.
- */
-static inline long __attribute_const__ ffz(int x)
-{
-	int r;
-
-	asm("%0 = ct1(%1);\n"
-		: "=&r" (r)
-		: "r" (x));
-	return r;
-}
-
-/*
- * fls - find last (most-significant) bit set
- * @x: the word to search
- *
- * This is defined the same way as ffs.
- * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
- */
-static inline __attribute_const__ int fls(unsigned int x)
-{
-	int r;
-
-	asm("{ %0 = cl0(%1);}\n"
-		"%0 = sub(#32,%0);\n"
-		: "=&r" (r)
-		: "r" (x)
-		: "p0");
-
-	return r;
-}
-
-/*
- * ffs - find first bit set
- * @x: the word to search
- *
- * This is defined the same way as
- * the libc and compiler builtin ffs routines, therefore
- * differs in spirit from the above ffz (man ffs).
- */
-static inline __attribute_const__ int ffs(int x)
-{
-	int r;
-
-	asm("{ P0 = cmp.eq(%1,#0); %0 = ct0(%1);}\n"
-		"{ if (P0) %0 = #0; if (!P0) %0 = add(%0,#1);}\n"
-		: "=&r" (r)
-		: "r" (x)
-		: "p0");
-
-	return r;
-}
-
-/*
- * __ffs - find first bit in word.
- * @word: The word to search
- *
- * Undefined if no bit exists, so code should check against 0 first.
- *
- * bits_per_long assumed to be 32
- * numbering starts at 0 I think (instead of 1 like ffs)
- */
-static inline __attribute_const__ unsigned long __ffs(unsigned long word)
-{
-	int num;
-
-	asm("%0 = ct0(%1);\n"
-		: "=&r" (num)
-		: "r" (word));
-
-	return num;
-}
-
-/*
- * __fls - find last (most-significant) set bit in a long word
- * @word: the word to search
- *
- * Undefined if no set bit exists, so code should check against 0 first.
- * bits_per_long assumed to be 32
- */
-static inline __attribute_const__ unsigned long __fls(unsigned long word)
-{
-	int num;
-
-	asm("%0 = cl0(%1);\n"
-		"%0 = sub(#31,%0);\n"
-		: "=&r" (num)
-		: "r" (word));
-
-	return num;
-}
+#include <asm-generic/bitops/builtin-__ffs.h>
+#include <asm-generic/bitops/builtin-ffs.h>
+#include <asm-generic/bitops/builtin-__fls.h>
+#include <asm-generic/bitops/builtin-fls.h>
+#include <asm-generic/bitops/ffz.h>
 
 #include <asm-generic/bitops/lock.h>
 #include <asm-generic/bitops/non-instrumented-non-atomic.h>

base-commit: 0304683b4c43048082483e9445fdd0691d088431

Signature · 1 line
2.34.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 26 lines · Tzu-Ching Yang

The hexagon inline asm for ffs(), __ffs(), fls(), __fls() and ffz() is not needed: Clang, the only compiler that builds hexagon kernels, emits the same ct0, cl0 and ct1 instructions for the compiler builtins, and unlike the asm, the builtins fold constant arguments. The asm dates from the 2011 port (a86a7ce30ac0, "Hexagon: Add bitops support"), before the builtin-based asm-generic helpers existed (048fa2df92c3, "generic: Implement generic ffs/fls using __builtin_* functions").

Replace the asm with the asm-generic builtin helpers, and ffz() with the generic __ffs(~x), as arm64 does.

ffs(0) and fls(0) still return 0. __ffs() and __fls() now return unsigned int, which is as wide as unsigned long on hexagon, and ffz() returns unsigned int instead of long. __ffs(0), __fls(0) and ffz(~0) remain undefined.

With Clang 17 to 23, the functions of a defconfig vmlinux shrink by 1972 to 6068 bytes in total (scripts/bloat-o-meter -t). One helper in lib/find_bit.c gets worse: _find_last_bit() executes one instruction more per call that finds a bit, because LLVM rewrites 31 - clz as 31 ^ clz once it knows clz < 32, and the hexagon backend keeps the xor, which needs the 31 in a register, instead of sub(#31, Rs) [1]. A few 1 << ffz() sites also grow by a few instructions, as LLVM rewrites that expression too [2]. __find_nth_bit() executes two fewer, and the other helpers that find_bit_benchmark calls the same number.

Quoted 6 lines

Link:
https://lore.kernel.org/all/[email protected]/

LGTM,

Reviewed-by on v1 1/1
#2 lore raw
In reply to Tzu-Ching Yang
Quoted 26 lines · Tzu-Ching Yang

The hexagon inline asm for ffs(), __ffs(), fls(), __fls() and ffz() is not needed: Clang, the only compiler that builds hexagon kernels, emits the same ct0, cl0 and ct1 instructions for the compiler builtins, and unlike the asm, the builtins fold constant arguments. The asm dates from the 2011 port (a86a7ce30ac0, "Hexagon: Add bitops support"), before the builtin-based asm-generic helpers existed (048fa2df92c3, "generic: Implement generic ffs/fls using __builtin_* functions").

Replace the asm with the asm-generic builtin helpers, and ffz() with the generic __ffs(~x), as arm64 does.

ffs(0) and fls(0) still return 0. __ffs() and __fls() now return unsigned int, which is as wide as unsigned long on hexagon, and ffz() returns unsigned int instead of long. __ffs(0), __fls(0) and ffz(~0) remain undefined.

With Clang 17 to 23, the functions of a defconfig vmlinux shrink by 1972 to 6068 bytes in total (scripts/bloat-o-meter -t). One helper in lib/find_bit.c gets worse: _find_last_bit() executes one instruction more per call that finds a bit, because LLVM rewrites 31 - clz as 31 ^ clz once it knows clz < 32, and the hexagon backend keeps the xor, which needs the 31 in a register, instead of sub(#31, Rs) [1]. A few 1 << ffz() sites also grow by a few instructions, as LLVM rewrites that expression too [2]. __find_nth_bit() executes two fewer, and the other helpers that find_bit_benchmark calls the same number.

Quoted 5 lines

Would you like me to move it with the other bitops material, or leave it to Brian?

Quoted 167 lines

---
I have no hexagon hardware, and mainline does not boot in QEMU yet. On Brian's out-of-tree bcain/hexagon-qemu-virt branch (dc370baa041d, v7.3-rc1 plus 24 patches) with this patch on top, qemu_defconfig plus the ffs and bitops KUnit tests and find_bit_benchmark, built with Clang 17 and 23, boots under qemu-system-hexagon from qualcomm/qemu hex-next with -M virt,hvm=on (and under -M qcs6490-cdsp with the prebuilt H2 hypervisor); the KUnit tests pass before and after, with the same .config on both sides. Under -M virt,hvm=on, with a TCG plugin that writes the same bitmaps into both kernels before each test and counts the executed instructions without interrupts, find_bit_benchmark's find_last_bit executes one instruction more per iteration, bitmap_find_next_zero_area_off 36 more on the random bitmap through its find_last_bit() calls, find_nth_bit and test_bitops' fns() two fewer, and the other tests the same.

Under qemu-hexagon (user mode), the old and new helpers return the same values for every defined 32-bit input, and fls64() and __ffs64() for selected 64-bit inputs, with Clang 17 to 23 at -O2 and -Os.

defconfig (also with the KUnit tests and find_bit_benchmark, with -Os and with -mv73) and allmodconfig were built with Clang 17 to 23 before and after, with the same .config on both sides: same W=1 warnings, no calls to __ctzsi2(), __clzsi2() or ffs(), and a smaller bloat-o-meter -t total in every defconfig-based vmlinux. allmodconfig does not link with Clang 17 and 18, before or after: ld.lld before 19.1.5 rejects the calls in head.S as out of range.

Instructions of each helper in a test function that only returns its result (return included), built with the kernel's flags by Clang 17 to 22 at -O2 and -Os; Clang 23 adds an allocframe to both rows:

ffs __ffs fls __fls ffz

  asm         6      3    4      4    3
  builtin     5      2    3      3    2

The instruction saved is the copy of the result to r0: the asm's early-clobber output ("=&r") cannot share the argument's register.

In packets, only ffs() takes one more than the asm (4 -> 5): with df5e4db805d5 ("hexagon: disable the LLVM packetizer") applied, each instruction of the builtin version gets a packet of its own, while the asm is bundled by hand. Without that workaround, which linux-next does not have yet, ffs() goes from 6 instructions in 3 packets to 5 in 2.

Against the bcain/hexagon-fixes branch of bcain/linux.git (0304683b4c43); also applies to next-20261113 and to bitmap-for-next.

 arch/hexagon/include/asm/bitops.h | 100 ++----------------------------
 1 file changed, 5 insertions(+), 95 deletions(-)
arch/hexagon/include/asm/bitops.h +5 -95
index b23cb13833af..975328172b7c 100644
@@ -194,101 +194,11 @@ arch_test_bit_acquire(unsigned long nr, const volatile unsigned long *addr)
 	return retval;
 }
 
-/*
- * ffz - find first zero in word.
- * @word: The word to search
- *
- * Undefined if no zero exists, so code should check against ~0UL first.
- */
-static inline long __attribute_const__ ffz(int x)
-{
-	int r;
-
-	asm("%0 = ct1(%1);\n"
-		: "=&r" (r)
-		: "r" (x));
-	return r;
-}
-
-/*
- * fls - find last (most-significant) bit set
- * @x: the word to search
- *
- * This is defined the same way as ffs.
- * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
- */
-static inline __attribute_const__ int fls(unsigned int x)
-{
-	int r;
-
-	asm("{ %0 = cl0(%1);}\n"
-		"%0 = sub(#32,%0);\n"
-		: "=&r" (r)
-		: "r" (x)
-		: "p0");
-
-	return r;
-}
-
-/*
- * ffs - find first bit set
- * @x: the word to search
- *
- * This is defined the same way as
- * the libc and compiler builtin ffs routines, therefore
- * differs in spirit from the above ffz (man ffs).
- */
-static inline __attribute_const__ int ffs(int x)
-{
-	int r;
-
-	asm("{ P0 = cmp.eq(%1,#0); %0 = ct0(%1);}\n"
-		"{ if (P0) %0 = #0; if (!P0) %0 = add(%0,#1);}\n"
-		: "=&r" (r)
-		: "r" (x)
-		: "p0");
-
-	return r;
-}
-
-/*
- * __ffs - find first bit in word.
- * @word: The word to search
- *
- * Undefined if no bit exists, so code should check against 0 first.
- *
- * bits_per_long assumed to be 32
- * numbering starts at 0 I think (instead of 1 like ffs)
- */
-static inline __attribute_const__ unsigned long __ffs(unsigned long word)
-{
-	int num;
-
-	asm("%0 = ct0(%1);\n"
-		: "=&r" (num)
-		: "r" (word));
-
-	return num;
-}
-
-/*
- * __fls - find last (most-significant) set bit in a long word
- * @word: the word to search
- *
- * Undefined if no set bit exists, so code should check against 0 first.
- * bits_per_long assumed to be 32
- */
-static inline __attribute_const__ unsigned long __fls(unsigned long word)
-{
-	int num;
-
-	asm("%0 = cl0(%1);\n"
-		"%0 = sub(#31,%0);\n"
-		: "=&r" (num)
-		: "r" (word));
-
-	return num;
-}
+#include <asm-generic/bitops/builtin-__ffs.h>
+#include <asm-generic/bitops/builtin-ffs.h>
+#include <asm-generic/bitops/builtin-__fls.h>
+#include <asm-generic/bitops/builtin-fls.h>
+#include <asm-generic/bitops/ffz.h>
 
 #include <asm-generic/bitops/lock.h>
 #include <asm-generic/bitops/non-instrumented-non-atomic.h>

base-commit: 0304683b4c43048082483e9445fdd0691d088431

Signature · 1 line
2.34.1
#3 lore raw
Quoted 4 lines · Yury Norov

Would you like me to move it with the other bitops material, or leave it to Brian?

Thanks for the review.

Either way is fine with me. If Brian has no objection, please take it with the other bitops patches.

Brian, would that be OK with you?

Thanks,
Tzu-Ching

maintainer
#4 lore raw
Quoted 11 lines · Tzu-Ching Yang
Quoted 4 lines · Yury Norov

Would you like me to move it with the other bitops material, or leave it to Brian?

Thanks for the review.

Either way is fine with me. If Brian has no objection, please take it with the other bitops patches.

Brian, would that be OK with you?

Sure - sounds good to me.

Quoted 3 lines

Thanks,
Tzu-Ching

#5 lore raw
Quoted 7 lines · Brian Cain
Quoted 5 lines · Tzu-Ching Yang
Quoted 4 lines · Yury Norov

Would you like me to move it with the other bitops material, or leave it to Brian?

Quoted 8 lines
Quoted 6 lines

Thanks for the review.

Either way is fine with me. If Brian has no objection, please take it with the other bitops patches.

Brian, would that be OK with you?

Sure - sounds good to me.

OK, added in bitmap-for-next.

Thanks,
Yury

maintainer Reviewed-by on v1 1/1
#6 lore raw
In reply to Tzu-Ching Yang
Quoted 77 lines · Tzu-Ching Yang

The hexagon inline asm for ffs(), __ffs(), fls(), __fls() and ffz() is not needed: Clang, the only compiler that builds hexagon kernels, emits the same ct0, cl0 and ct1 instructions for the compiler builtins, and unlike the asm, the builtins fold constant arguments. The asm dates from the 2011 port (a86a7ce30ac0, "Hexagon: Add bitops support"), before the builtin-based asm-generic helpers existed (048fa2df92c3, "generic: Implement generic ffs/fls using __builtin_* functions").

Replace the asm with the asm-generic builtin helpers, and ffz() with the generic __ffs(~x), as arm64 does.

ffs(0) and fls(0) still return 0. __ffs() and __fls() now return unsigned int, which is as wide as unsigned long on hexagon, and ffz() returns unsigned int instead of long. __ffs(0), __fls(0) and ffz(~0) remain undefined.

With Clang 17 to 23, the functions of a defconfig vmlinux shrink by 1972 to 6068 bytes in total (scripts/bloat-o-meter -t). One helper in lib/find_bit.c gets worse: _find_last_bit() executes one instruction more per call that finds a bit, because LLVM rewrites 31 - clz as 31 ^ clz once it knows clz < 32, and the hexagon backend keeps the xor, which needs the 31 in a register, instead of sub(#31, Rs) [1]. A few 1 << ffz() sites also grow by a few instructions, as LLVM rewrites that expression too [2]. __find_nth_bit() executes two fewer, and the other helpers that find_bit_benchmark calls the same number.

---
I have no hexagon hardware, and mainline does not boot in QEMU yet. On Brian's out-of-tree bcain/hexagon-qemu-virt branch (dc370baa041d, v7.3-rc1 plus 24 patches) with this patch on top, qemu_defconfig plus the ffs and bitops KUnit tests and find_bit_benchmark, built with Clang 17 and 23, boots under qemu-system-hexagon from qualcomm/qemu hex-next with -M virt,hvm=on (and under -M qcs6490-cdsp with the prebuilt H2 hypervisor); the KUnit tests pass before and after, with the same .config on both sides. Under -M virt,hvm=on, with a TCG plugin that writes the same bitmaps into both kernels before each test and counts the executed instructions without interrupts, find_bit_benchmark's find_last_bit executes one instruction more per iteration, bitmap_find_next_zero_area_off 36 more on the random bitmap through its find_last_bit() calls, find_nth_bit and test_bitops' fns() two fewer, and the other tests the same.

Under qemu-hexagon (user mode), the old and new helpers return the same values for every defined 32-bit input, and fls64() and __ffs64() for selected 64-bit inputs, with Clang 17 to 23 at -O2 and -Os.

defconfig (also with the KUnit tests and find_bit_benchmark, with -Os and with -mv73) and allmodconfig were built with Clang 17 to 23 before and after, with the same .config on both sides: same W=1 warnings, no calls to __ctzsi2(), __clzsi2() or ffs(), and a smaller bloat-o-meter -t total in every defconfig-based vmlinux. allmodconfig does not link with Clang 17 and 18, before or after: ld.lld before 19.1.5 rejects the calls in head.S as out of range.

Instructions of each helper in a test function that only returns its result (return included), built with the kernel's flags by Clang 17 to 22 at -O2 and -Os; Clang 23 adds an allocframe to both rows:

ffs __ffs fls __fls ffz

   asm         6      3    4      4    3
   builtin     5      2    3      3    2

The instruction saved is the copy of the result to r0: the asm's early-clobber output ("=&r") cannot share the argument's register.

In packets, only ffs() takes one more than the asm (4 -> 5): with df5e4db805d5 ("hexagon: disable the LLVM packetizer") applied, each instruction of the builtin version gets a packet of its own, while the asm is bundled by hand. Without that workaround, which linux-next does not have yet, ffs() goes from 6 instructions in 3 packets to 5 in 2.

Quoted 5 lines

Against the bcain/hexagon-fixes branch of bcain/linux.git (0304683b4c43); also applies to next-20261113 and to bitmap-for-next.

  arch/hexagon/include/asm/bitops.h | 100 ++----------------------------
  1 file changed, 5 insertions(+), 95 deletions(-)

Thanks for giving QEMU a try - we're in pretty decent shape for the 11.2 release.  One caveat is that the built-in h2 in 11.2 doesn't forward the DTB address, so that can be a bit inconvenient.  Use my h2 fork with upstream QEMU or -- like you've already found, use the QEMU fork that has h2 built from my fork or the built-in HVM.

Quoted 113 lines
arch/hexagon/include/asm/bitops.h +5 -95
index b23cb13833af..975328172b7c 100644
@@ -194,101 +194,11 @@ arch_test_bit_acquire(unsigned long nr, const volatile unsigned long *addr)
  	return retval;
  }
 
-/*
- * ffz - find first zero in word.
- * @word: The word to search
- *
- * Undefined if no zero exists, so code should check against ~0UL first.
- */
-static inline long __attribute_const__ ffz(int x)
-{
-	int r;
-
-	asm("%0 = ct1(%1);\n"
-		: "=&r" (r)
-		: "r" (x));
-	return r;
-}
-
-/*
- * fls - find last (most-significant) bit set
- * @x: the word to search
- *
- * This is defined the same way as ffs.
- * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
- */
-static inline __attribute_const__ int fls(unsigned int x)
-{
-	int r;
-
-	asm("{ %0 = cl0(%1);}\n"
-		"%0 = sub(#32,%0);\n"
-		: "=&r" (r)
-		: "r" (x)
-		: "p0");
-
-	return r;
-}
-
-/*
- * ffs - find first bit set
- * @x: the word to search
- *
- * This is defined the same way as
- * the libc and compiler builtin ffs routines, therefore
- * differs in spirit from the above ffz (man ffs).
- */
-static inline __attribute_const__ int ffs(int x)
-{
-	int r;
-
-	asm("{ P0 = cmp.eq(%1,#0); %0 = ct0(%1);}\n"
-		"{ if (P0) %0 = #0; if (!P0) %0 = add(%0,#1);}\n"
-		: "=&r" (r)
-		: "r" (x)
-		: "p0");
-
-	return r;
-}
-
-/*
- * __ffs - find first bit in word.
- * @word: The word to search
- *
- * Undefined if no bit exists, so code should check against 0 first.
- *
- * bits_per_long assumed to be 32
- * numbering starts at 0 I think (instead of 1 like ffs)
- */
-static inline __attribute_const__ unsigned long __ffs(unsigned long word)
-{
-	int num;
-
-	asm("%0 = ct0(%1);\n"
-		: "=&r" (num)
-		: "r" (word));
-
-	return num;
-}
-
-/*
- * __fls - find last (most-significant) set bit in a long word
- * @word: the word to search
- *
- * Undefined if no set bit exists, so code should check against 0 first.
- * bits_per_long assumed to be 32
- */
-static inline __attribute_const__ unsigned long __fls(unsigned long word)
-{
-	int num;
-
-	asm("%0 = cl0(%1);\n"
-		"%0 = sub(#31,%0);\n"
-		: "=&r" (num)
-		: "r" (word));
-
-	return num;
-}
+#include <asm-generic/bitops/builtin-__ffs.h>
+#include <asm-generic/bitops/builtin-ffs.h>
+#include <asm-generic/bitops/builtin-__fls.h>
+#include <asm-generic/bitops/builtin-fls.h>
+#include <asm-generic/bitops/ffz.h>
 
  #include <asm-generic/bitops/lock.h>
  #include <asm-generic/bitops/non-instrumented-non-atomic.h>

base-commit: 0304683b4c43048082483e9445fdd0691d088431