mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-28 00:21:52 +03:00
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>
This commit is contained in:
committed by
Adhemerval Zanella
parent
26d01172f5
commit
ae4b8d6a0e
@ -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)
|
||||
|
Reference in New Issue
Block a user