about summary refs log tree commit diff
path: root/string
diff options
context:
space:
mode:
Diffstat (limited to 'string')
-rw-r--r--string/ffs.c6
-rw-r--r--string/ffsll.c10
2 files changed, 13 insertions, 3 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)
diff --git a/string/ffsll.c b/string/ffsll.c
index 7d16250026..0ec39a0c56 100644
--- a/string/ffsll.c
+++ b/string/ffsll.c
@@ -18,20 +18,26 @@
 #include <limits.h>
 #define ffsl __something_else
 #include <string.h>
-
 #undef	ffsll
+#include <math-use-builtins.h>
+#include <libc-diag.h>
 
 /* Find the first bit set in I.  */
 int
-ffsll (long long int i)
+__ffsll (long long int i)
 {
+#if USE_FFSLL_BUILTIN
+  return __builtin_ffsll (i);
+#else
   unsigned long long int x = i & -i;
 
   if (x <= 0xffffffff)
     return ffs (i);
   else
     return 32 + ffs (i >> 32);
+#endif
 }
+weak_alias (__ffsll, ffsll)
 
 #if ULONG_MAX != UINT_MAX
 #undef ffsl