]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
string: Use builtins for ffs and ffsll
authorAdhemerval Zanella Netto <adhemerval.zanella@linaro.org>
Fri, 25 Aug 2023 16:30:58 +0000 (13:30 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 1 Feb 2024 12:31:33 +0000 (09:31 -0300)
It allows to remove a lot of arch-specific implementations.

Checked on x86_64, aarch64, powerpc64.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
28 files changed:
string/ffs.c
string/ffsll.c
sysdeps/aarch64/math-use-builtins-ffs.h [new file with mode: 0644]
sysdeps/alpha/alphaev67/ffs.S [deleted file]
sysdeps/alpha/alphaev67/ffsll.S [deleted file]
sysdeps/alpha/ffs.S [deleted file]
sysdeps/alpha/ffsll.S [deleted file]
sysdeps/alpha/math-use-builtins-ffs.h [new file with mode: 0644]
sysdeps/arc/math-use-builtins-ffs.h [new file with mode: 0644]
sysdeps/arm/armv6t2/ffs.S [deleted file]
sysdeps/arm/armv6t2/ffsll.S [deleted file]
sysdeps/arm/armv6t2/math-use-builtins-ffs.h [new file with mode: 0644]
sysdeps/generic/math-use-builtins-ffs.h [new file with mode: 0644]
sysdeps/generic/math-use-builtins.h
sysdeps/i386/ffs.c [deleted file]
sysdeps/i386/i686/ffs.c [deleted file]
sysdeps/i386/math-use-builtins-ffs.h [new file with mode: 0644]
sysdeps/ia64/math-use-builtins-ffs.h [new file with mode: 0644]
sysdeps/m68k/ffs.c [deleted file]
sysdeps/m68k/math-use-builtins-ffs.h [new file with mode: 0644]
sysdeps/powerpc/ffs.c [deleted file]
sysdeps/powerpc/math-use-builtins-ffs.h [new file with mode: 0644]
sysdeps/powerpc/powerpc64/ffsll.c [deleted file]
sysdeps/s390/ffs.c [deleted file]
sysdeps/x86_64/ffs.c [deleted file]
sysdeps/x86_64/ffsll.c [deleted file]
sysdeps/x86_64/math-use-builtins-ffs.h [new file with mode: 0644]
sysdeps/x86_64/x32/ffs.c [deleted file]

index 6a05ef83863da487120bcf89c8a4bfe5475ed569..760c2bdd8d3e6b0483d2680d6d1523d602271b73 100644 (file)
 #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)
index 7d16250026524a83156eb59ba3503bdb2769ddbd..0ec39a0c5661652ad326e934f4d0d3b20e94ba42 100644 (file)
 #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
diff --git a/sysdeps/aarch64/math-use-builtins-ffs.h b/sysdeps/aarch64/math-use-builtins-ffs.h
new file mode 100644 (file)
index 0000000..a83bb15
--- /dev/null
@@ -0,0 +1,2 @@
+#define USE_FFS_BUILTIN   1
+#define USE_FFSLL_BUILTIN 1
diff --git a/sysdeps/alpha/alphaev67/ffs.S b/sysdeps/alpha/alphaev67/ffs.S
deleted file mode 100644 (file)
index 0b5e677..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/* Copyright (C) 2000-2024 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library.  If not, see
-   <https://www.gnu.org/licenses/>.  */
-
-/* Finds the first bit set in an integer.  */
-
-#include <sysdep.h>
-
-       .arch ev6
-       .set noreorder
-       .set noat
-
-
-ENTRY(__ffs)
-#ifdef PROF
-       ldgp    gp, 0(pv)
-       lda     AT, _mcount
-       jsr     AT, (AT), _mcount
-       .prologue 1
-#else
-       .prologue 0
-#endif
-
-       zap     $16, 0xF0, $16
-       cttz    $16, $0
-       addq    $0, 1, $0
-       cmoveq  $16, 0, $0
-
-       nop
-       nop
-       nop
-       ret
-
-END(__ffs)
-
-weak_alias (__ffs, ffs)
-libc_hidden_def (__ffs)
-libc_hidden_builtin_def (ffs)
diff --git a/sysdeps/alpha/alphaev67/ffsll.S b/sysdeps/alpha/alphaev67/ffsll.S
deleted file mode 100644 (file)
index 56e26d1..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/* Copyright (C) 2000-2024 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library.  If not, see
-   <https://www.gnu.org/licenses/>.  */
-
-/* Finds the first bit set in a long.  */
-
-#include <sysdep.h>
-
-       .arch ev6
-       .set noreorder
-       .set noat
-
-ENTRY(ffsl)
-#ifdef PROF
-       ldgp    gp, 0(pv)
-       lda     AT, _mcount
-       jsr     AT, (AT), _mcount
-       .prologue 1
-#else
-       .prologue 0
-#endif
-
-       cttz    $16, $0
-       addq    $0, 1, $0
-       cmoveq  $16, 0, $0
-       ret
-
-END(ffsl)
-
-weak_extern (ffsl)
-weak_alias (ffsl, ffsll)
diff --git a/sysdeps/alpha/ffs.S b/sysdeps/alpha/ffs.S
deleted file mode 100644 (file)
index 350d9dd..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-/* Copyright (C) 1996-2024 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library.  If not, see
-   <https://www.gnu.org/licenses/>.  */
-
-/* Finds the first bit set in an integer.  Optimized for the Alpha
-   architecture.  */
-
-#include <sysdep.h>
-
-       .set noreorder
-       .set noat
-
-
-ENTRY(__ffs)
-#ifdef PROF
-       ldgp    gp, 0(pv)
-       lda     AT, _mcount
-       jsr     AT, (AT), _mcount
-       .prologue 1
-       zap     $16, 0xF0, $16
-       br      $ffsl..ng
-#else
-       .prologue 0
-       zap     $16, 0xF0, $16
-       # FALLTHRU
-#endif
-END(__ffs)
-
-       .align 4
-ENTRY(ffsl)
-#ifdef PROF
-       ldgp    gp, 0(pv)
-       lda     AT, _mcount
-       jsr     AT, (AT), _mcount
-       .prologue 1
-$ffsl..ng:
-#else
-       .prologue 0
-#endif
-       not     $16, $1         # e0    :
-       ldi     $2, -1          # .. e1 :
-       cmpbge  $1, $2, $3      # e0    : bit N == 1 for byte N == 0
-       clr     $0              # .. e1 :
-       addq    $3, 1, $4       # e0    :
-       bic     $4, $3, $3      # e1    : bit N == 1 for first byte N != 0
-       and     $3, 0xF0, $4    # e0    :
-       and     $3, 0xCC, $5    # .. e1 :
-       and     $3, 0xAA, $6    # e0    :
-       cmovne  $4, 4, $0       # .. e1 :
-       cmovne  $5, 2, $5       # e0    :
-       cmovne  $6, 1, $6       # .. e1 :
-       addl    $0, $5, $0      # e0    :
-       addl    $0, $6, $0      # e1    : $0 == N
-       extbl   $16, $0, $1     # e0    : $1 == byte N
-       ldi     $2, 1           # .. e1 :
-       negq    $1, $3          # e0    :
-       and     $3, $1, $3      # e1    : bit N == least bit set of byte N
-       and     $3, 0xF0, $4    # e0    :
-       and     $3, 0xCC, $5    # .. e1 :
-       and     $3, 0xAA, $6    # e0    :
-       cmovne  $4, 5, $2       # .. e1 :
-       cmovne  $5, 2, $5       # e0    :
-       cmovne  $6, 1, $6       # .. e1 :
-       s8addl  $0, $2, $0      # e0    : mult byte ofs by 8 and sum
-       addl    $5, $6, $5      # .. e1 :
-       addl    $0, $5, $0      # e0    :
-       nop                     # .. e1 :
-       cmoveq  $16, 0, $0      # e0    : trap input == 0 case.
-       ret                     # .. e1 : 18
-
-END(ffsl)
-
-weak_alias (__ffs, ffs)
-libc_hidden_def (__ffs)
-libc_hidden_builtin_def (ffs)
-weak_extern (ffsl)
-weak_alias (ffsl, ffsll)
diff --git a/sysdeps/alpha/ffsll.S b/sysdeps/alpha/ffsll.S
deleted file mode 100644 (file)
index b2f46d8..0000000
+++ /dev/null
@@ -1 +0,0 @@
-/* This function is defined in ffs.S.  */
diff --git a/sysdeps/alpha/math-use-builtins-ffs.h b/sysdeps/alpha/math-use-builtins-ffs.h
new file mode 100644 (file)
index 0000000..9925e37
--- /dev/null
@@ -0,0 +1,7 @@
+#ifdef __alpha_cix__
+# define USE_FFS_BUILTIN   1
+# define USE_FFSLL_BUILTIN 1
+#else
+# define USE_FFS_BUILTIN   0
+# define USE_FFSLL_BUILTIN 0
+#endif
diff --git a/sysdeps/arc/math-use-builtins-ffs.h b/sysdeps/arc/math-use-builtins-ffs.h
new file mode 100644 (file)
index 0000000..c0f108c
--- /dev/null
@@ -0,0 +1,2 @@
+#define USE_FFS_BUILTIN   1
+#define USE_FFSLL_BUILTIN 0
diff --git a/sysdeps/arm/armv6t2/ffs.S b/sysdeps/arm/armv6t2/ffs.S
deleted file mode 100644 (file)
index 57df60f..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/* ffs -- find first set bit in an int, from least significant end.
-   Copyright (C) 2013-2024 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library.  If not, see
-   <https://www.gnu.org/licenses/>.  */
-
-#include <sysdep.h>
-
-       .syntax unified
-       .text
-
-ENTRY (__ffs)
-       cmp     r0, #0
-       rbit    r0, r0
-       itt     ne
-       clzne   r0, r0
-       addne   r0, r0, #1
-       bx      lr
-END (__ffs)
-
-weak_alias (__ffs, ffs)
-weak_alias (__ffs, ffsl)
-libc_hidden_def (__ffs)
-libc_hidden_builtin_def (ffs)
diff --git a/sysdeps/arm/armv6t2/ffsll.S b/sysdeps/arm/armv6t2/ffsll.S
deleted file mode 100644 (file)
index bd51c38..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/* ffsll -- find first set bit in a long long, from least significant end.
-   Copyright (C) 2013-2024 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library.  If not, see
-   <https://www.gnu.org/licenses/>.  */
-
-#include <sysdep.h>
-
-       .syntax unified
-       .text
-
-ENTRY (ffsll)
-       @ If low part is 0, operate on the high part.  Ensure that the
-       @ word on which we operate is in r0.  Set r2 to the bit offset
-       @ of the word being considered.  Set the flags for the word
-       @ being operated on.
-#ifdef __ARMEL__
-       cmp     r0, #0
-       itee    ne
-       movne   r2, #0
-       moveq   r2, #32
-       movseq  r0, r1
-#else
-       cmp     r1, #0
-       ittee   ne
-       movne   r2, #0
-       movne   r0, r1
-       moveq   r2, #32
-       cmpeq   r0, #0
-#endif
-       @ Perform the ffs on r0.
-       rbit    r0, r0
-       ittt    ne
-       clzne   r0, r0
-       addne   r2, r2, #1
-       addne   r0, r0, r2
-       bx      lr
-END (ffsll)
diff --git a/sysdeps/arm/armv6t2/math-use-builtins-ffs.h b/sysdeps/arm/armv6t2/math-use-builtins-ffs.h
new file mode 100644 (file)
index 0000000..c0f108c
--- /dev/null
@@ -0,0 +1,2 @@
+#define USE_FFS_BUILTIN   1
+#define USE_FFSLL_BUILTIN 0
diff --git a/sysdeps/generic/math-use-builtins-ffs.h b/sysdeps/generic/math-use-builtins-ffs.h
new file mode 100644 (file)
index 0000000..add8537
--- /dev/null
@@ -0,0 +1,2 @@
+#define USE_FFS_BUILTIN   0
+#define USE_FFSLL_BUILTIN 0
index 2352104c85952676a5000a54592bba5c3cb4a37e..63728e0cc629ff013a3254e074018035d2a231f5 100644 (file)
@@ -40,5 +40,6 @@
 #include <math-use-builtins-lrint.h>
 #include <math-use-builtins-llrint.h>
 #include <math-use-builtins-logb.h>
+#include <math-use-builtins-ffs.h>
 
 #endif /* MATH_USE_BUILTINS_H  */
diff --git a/sysdeps/i386/ffs.c b/sysdeps/i386/ffs.c
deleted file mode 100644 (file)
index 587d80d..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/* ffs -- find first set bit in a word, counted from least significant end.
-   For Intel 80x86, x>=3.
-   This file is part of the GNU C Library.
-   Copyright (C) 1991-2024 Free Software Foundation, Inc.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <https://www.gnu.org/licenses/>.  */
-
-#define ffsl __something_else
-#include <string.h>
-
-#undef ffs
-
-#ifdef __GNUC__
-
-int
-__ffs (int x)
-{
-  int cnt;
-  int tmp;
-
-  asm ("xorl %0,%0\n"          /* Set CNT to zero.  */
-       "bsfl %2,%1\n"          /* Count low bits in X and store in %1.  */
-       "jz 1f\n"               /* Jump if OK, i.e. X was non-zero.  */
-       "leal 1(%1),%0\n"       /* Return bsfl-result plus one on %0.  */
-       "1:" : "=&a" (cnt), "=r" (tmp) : "rm" (x));
-
-  return cnt;
-}
-weak_alias (__ffs, ffs)
-libc_hidden_def (__ffs)
-libc_hidden_builtin_def (ffs)
-#undef ffsl
-weak_alias (__ffs, ffsl)
-
-#else
-#include <string/ffs.c>
-#endif
diff --git a/sysdeps/i386/i686/ffs.c b/sysdeps/i386/i686/ffs.c
deleted file mode 100644 (file)
index 6712730..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/* ffs -- find first set bit in a word, counted from least significant end.
-   For Intel 80x86, x>=6.
-   This file is part of the GNU C Library.
-   Copyright (C) 1991-2024 Free Software Foundation, Inc.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <https://www.gnu.org/licenses/>.  */
-
-#define ffsl __something_else
-#include <string.h>
-
-#undef ffs
-
-#ifdef __GNUC__
-
-int
-__ffs (int x)
-{
-  int cnt;
-  int tmp;
-
-  asm ("bsfl %2,%0\n"          /* Count low bits in X and store in %1.  */
-       "cmovel %1,%0\n"                /* If number was zero, use -1 as result.  */
-       : "=&r" (cnt), "=r" (tmp) : "rm" (x), "1" (-1));
-
-  return cnt + 1;
-}
-weak_alias (__ffs, ffs)
-libc_hidden_def (__ffs)
-libc_hidden_builtin_def (ffs)
-#undef ffsl
-weak_alias (__ffs, ffsl)
-
-#else
-#include <string/ffs.c>
-#endif
diff --git a/sysdeps/i386/math-use-builtins-ffs.h b/sysdeps/i386/math-use-builtins-ffs.h
new file mode 100644 (file)
index 0000000..c0f108c
--- /dev/null
@@ -0,0 +1,2 @@
+#define USE_FFS_BUILTIN   1
+#define USE_FFSLL_BUILTIN 0
diff --git a/sysdeps/ia64/math-use-builtins-ffs.h b/sysdeps/ia64/math-use-builtins-ffs.h
new file mode 100644 (file)
index 0000000..a83bb15
--- /dev/null
@@ -0,0 +1,2 @@
+#define USE_FFS_BUILTIN   1
+#define USE_FFSLL_BUILTIN 1
diff --git a/sysdeps/m68k/ffs.c b/sysdeps/m68k/ffs.c
deleted file mode 100644 (file)
index 496ceb8..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/* ffs -- find first set bit in a word, counted from least significant end.
-   For mc68020, mc68030, mc68040.
-   This file is part of the GNU C Library.
-   Copyright (C) 1991-2024 Free Software Foundation, Inc.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library.  If not, see
-   <https://www.gnu.org/licenses/>.  */
-
-#define ffsl __something_else
-#include <string.h>
-
-#undef ffs
-
-#if    defined (__GNUC__) && defined (__mc68020__)
-
-int
-__ffs (int x)
-{
-  int cnt;
-
-  asm ("bfffo %1{#0:#0},%0" : "=d" (cnt) : "dm" (x & -x));
-
-  return 32 - cnt;
-}
-weak_alias (__ffs, ffs)
-libc_hidden_def (__ffs)
-libc_hidden_builtin_def (ffs)
-#undef ffsl
-weak_alias (__ffs, ffsl)
-
-#else
-
-#include <string/ffs.c>
-
-#endif
diff --git a/sysdeps/m68k/math-use-builtins-ffs.h b/sysdeps/m68k/math-use-builtins-ffs.h
new file mode 100644 (file)
index 0000000..4e1d994
--- /dev/null
@@ -0,0 +1,7 @@
+#if defined __mc68020__ || defined __mc68030__ || defined __mc68040__ \
+    || defined __mc68060__
+# define USE_FFS_BUILTIN  1
+#else
+# define USE_FFS_BUILTIN  0
+#endif
+#define USE_FFSLL_BUILTIN 0
diff --git a/sysdeps/powerpc/ffs.c b/sysdeps/powerpc/ffs.c
deleted file mode 100644 (file)
index 9614d48..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/* Find first set bit in a word, counted from least significant end.
-   For PowerPC.
-   Copyright (C) 1991-2024 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <https://www.gnu.org/licenses/>.  */
-
-#define ffsl __something_else
-#include <limits.h>
-#include <string.h>
-
-#undef ffs
-
-#ifdef         __GNUC__
-
-int
-__ffs (int x)
-{
-  int cnt;
-
-  asm ("cntlzw %0,%1" : "=r" (cnt) : "r" (x & -x));
-  return 32 - cnt;
-}
-weak_alias (__ffs, ffs)
-libc_hidden_def (__ffs)
-libc_hidden_builtin_def (ffs)
-#if ULONG_MAX == UINT_MAX
-#undef ffsl
-weak_alias (__ffs, ffsl)
-#endif
-
-#else
-#include <string/ffs.c>
-#endif
diff --git a/sysdeps/powerpc/math-use-builtins-ffs.h b/sysdeps/powerpc/math-use-builtins-ffs.h
new file mode 100644 (file)
index 0000000..7b1d401
--- /dev/null
@@ -0,0 +1,6 @@
+#define USE_FFS_BUILTIN    1
+#ifdef __powerpc64__
+# define USE_FFSLL_BUILTIN 1
+#else
+# define USE_FFSLL_BUILTIN 0
+#endif
diff --git a/sysdeps/powerpc/powerpc64/ffsll.c b/sysdeps/powerpc/powerpc64/ffsll.c
deleted file mode 100644 (file)
index a8f0c30..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/* Find first set bit in a word, counted from least significant end.
-   For PowerPC.
-   Copyright (C) 1991-2024 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <https://www.gnu.org/licenses/>.  */
-
-#define ffsl __something_else
-#include <limits.h>
-#include <string.h>
-
-#undef ffs
-
-int
-__ffsll (long long int x)
-{
-  int cnt;
-
-  asm ("cntlzd %0,%1" : "=r" (cnt) : "r" (x & -x));
-  return 64 - cnt;
-}
-weak_alias (__ffsll, ffsll)
-#undef ffsl
-weak_alias (__ffsll, ffsl)
diff --git a/sysdeps/s390/ffs.c b/sysdeps/s390/ffs.c
deleted file mode 100644 (file)
index 027e0ce..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/* ffs -- find first set bit in a word, counted from least significant end.
-   S/390 version.
-   Copyright (C) 2000-2024 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <https://www.gnu.org/licenses/>.  */
-
-#include <limits.h>
-#define ffsl __something_else
-#include <string.h>
-
-#undef ffs
-
-/* ffs: find first bit set. This is defined the same way as
-   the libc and compiler builtin ffs routines, therefore
-   differs in spirit from the above ffz (man ffs).  */
-
-int
-__ffs (int x)
-{
-       int r;
-
-       if (x == 0)
-         return 0;
-       __asm__("    lr   %%r1,%1\n"
-               "    sr   %0,%0\n"
-               "    tml  %%r1,0xFFFF\n"
-               "    jnz  0f\n"
-               "    ahi  %0,16\n"
-               "    srl  %%r1,16\n"
-               "0:  tml  %%r1,0x00FF\n"
-               "    jnz  1f\n"
-               "    ahi  %0,8\n"
-               "    srl  %%r1,8\n"
-               "1:  tml  %%r1,0x000F\n"
-               "    jnz  2f\n"
-               "    ahi  %0,4\n"
-               "    srl  %%r1,4\n"
-               "2:  tml  %%r1,0x0003\n"
-               "    jnz  3f\n"
-               "    ahi  %0,2\n"
-               "    srl  %%r1,2\n"
-               "3:  tml  %%r1,0x0001\n"
-               "    jnz  4f\n"
-               "    ahi  %0,1\n"
-               "4:"
-               : "=&d" (r) : "d" (x) : "cc", "1" );
-       return r+1;
-}
-
-weak_alias (__ffs, ffs)
-libc_hidden_def (__ffs)
-libc_hidden_builtin_def (ffs)
-#if ULONG_MAX == UINT_MAX
-#undef ffsl
-weak_alias (__ffs, ffsl)
-#endif
diff --git a/sysdeps/x86_64/ffs.c b/sysdeps/x86_64/ffs.c
deleted file mode 100644 (file)
index a049e87..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/* ffs -- find first set bit in a word, counted from least significant end.
-   For AMD x86-64.
-   This file is part of the GNU C Library.
-   Copyright (C) 1991-2024 Free Software Foundation, Inc.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <https://www.gnu.org/licenses/>.  */
-
-#include <string.h>
-
-#undef ffs
-
-int
-__ffs (int x)
-{
-  int cnt;
-  int tmp;
-
-  asm ("bsfl %2,%0\n"          /* Count low bits in X and store in %1.  */
-       "cmovel %1,%0\n"                /* If number was zero, use -1 as result.  */
-       : "=&r" (cnt), "=r" (tmp) : "rm" (x), "1" (-1));
-
-  return cnt + 1;
-}
-weak_alias (__ffs, ffs)
-libc_hidden_def (__ffs)
-libc_hidden_builtin_def (ffs)
diff --git a/sysdeps/x86_64/ffsll.c b/sysdeps/x86_64/ffsll.c
deleted file mode 100644 (file)
index 2844428..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/* ffsll -- find first set bit in a word, counted from least significant end.
-   For AMD x86-64.
-   This file is part of the GNU C Library.
-   Copyright (C) 1991-2024 Free Software Foundation, Inc.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <https://www.gnu.org/licenses/>.  */
-
-#define ffsl __something_else
-#include <string.h>
-
-#undef ffsll
-
-int
-ffsll (long long int x)
-{
-  long long int cnt;
-
-  asm ("mov $-1,%k0\n" /* Initialize cnt to -1.  */
-       "bsf %1,%0\n"   /* Count low bits in x and store in cnt.  */
-       "inc %k0\n"     /* Increment cnt by 1.  */
-       : "=&r" (cnt) : "r" (x));
-
-  return cnt;
-}
-
-#ifndef __ILP32__
-#undef ffsl
-weak_alias (ffsll, ffsl)
-#endif
diff --git a/sysdeps/x86_64/math-use-builtins-ffs.h b/sysdeps/x86_64/math-use-builtins-ffs.h
new file mode 100644 (file)
index 0000000..a83bb15
--- /dev/null
@@ -0,0 +1,2 @@
+#define USE_FFS_BUILTIN   1
+#define USE_FFSLL_BUILTIN 1
diff --git a/sysdeps/x86_64/x32/ffs.c b/sysdeps/x86_64/x32/ffs.c
deleted file mode 100644 (file)
index fa7de8b..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-#define ffsl __something_else
-#include <sysdeps/x86_64/ffs.c>
-#undef ffsl
-weak_alias (__ffs, ffsl)