aboutsummaryrefslogtreecommitdiff
path: root/string/ffs.c
diff options
context:
space:
mode:
authorAdhemerval Zanella Netto <adhemerval.zanella@linaro.org>2023-08-25 13:30:58 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2024-02-01 09:31:33 -0300
commitae4b8d6a0e0dc502e3d8307474a2e5691b7434da (patch)
tree8e8d958ebb90b9edec3847a53364edb32a2314a3 /string/ffs.c
parent26d01172f5c3f3b912ecf21ebb911eb5351bba4d (diff)
downloadglibc-ae4b8d6a0e0dc502e3d8307474a2e5691b7434da.tar
glibc-ae4b8d6a0e0dc502e3d8307474a2e5691b7434da.tar.gz
glibc-ae4b8d6a0e0dc502e3d8307474a2e5691b7434da.tar.bz2
glibc-ae4b8d6a0e0dc502e3d8307474a2e5691b7434da.zip
string: Use builtins for ffs and ffsll
It allows to remove a lot of arch-specific implementations. Checked on x86_64, aarch64, powerpc64. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'string/ffs.c')
-rw-r--r--string/ffs.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/string/ffs.c b/string/ffs.c
index 6a05ef8386..760c2bdd8d 100644
--- a/string/ffs.c
+++ b/string/ffs.c
@@ -18,13 +18,16 @@
#include <limits.h>
#define ffsl __something_else
#include <string.h>
-
#undef ffs
+#include <math-use-builtins.h>
/* Find the first bit set in I. */
int
__ffs (int i)
{
+#if USE_FFS_BUILTIN
+ return __builtin_ffs (i);
+#else
static const unsigned char table[] =
{
0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
@@ -42,6 +45,7 @@ __ffs (int i)
a = x <= 0xffff ? (x <= 0xff ? 0 : 8) : (x <= 0xffffff ? 16 : 24);
return table[x >> a] + a;
+#endif
}
weak_alias (__ffs, ffs)
libc_hidden_def (__ffs)