summaryrefslogtreecommitdiff
path: root/include/asm-generic/bitops/builtin-ffs.h
diff options
context:
space:
mode:
authorSean Anderson <sean.anderson@seco.com>2023-07-31 17:27:33 -0400
committerTom Rini <trini@konsulko.com>2023-08-17 16:39:20 -0400
commit726a802fdaf1ffb4ca95ebf6910a738781137ef5 (patch)
tree7d2df62ee83092d7b8b6032f48a980b2a212df8c /include/asm-generic/bitops/builtin-ffs.h
parent14ba0a8bbc342a677982acc787ae542b84ed7993 (diff)
arm: Use builtins for ffs/fls
Since ARMv5, the clz instruction allows for efficient implementation of ffs/fls with builtins. Until ARMv7 (with Thumb-2), this instruction is only available in ARM mode. LTO makes it difficult to force specific functions to be in ARM mode, as it is effectively a form of very aggressive inlining. To work around this, fls/ffs are implemented in assembly for ARMv5 and ARMv6 when compiling U-Boot in Thumb mode. Overall, this saves around 75 bytes per call. This code is synced with v5.15 of the Linux kernel. Signed-off-by: Sean Anderson <sean.anderson@seco.com> Reviewed-by: Tom Rini <trini@konsulko.com>
Diffstat (limited to 'include/asm-generic/bitops/builtin-ffs.h')
-rw-r--r--include/asm-generic/bitops/builtin-ffs.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/include/asm-generic/bitops/builtin-ffs.h b/include/asm-generic/bitops/builtin-ffs.h
new file mode 100644
index 00000000000..7b129329046
--- /dev/null
+++ b/include/asm-generic/bitops/builtin-ffs.h
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_GENERIC_BITOPS_BUILTIN_FFS_H_
+#define _ASM_GENERIC_BITOPS_BUILTIN_FFS_H_
+
+/**
+ * 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 ffz (man ffs).
+ */
+#define ffs(x) __builtin_ffs(x)
+
+#endif