libroot: Replace custom ffs implementation with musl's.

It already has a per-arch implementation or a fallback in
musl's own arch_atomic.h, which we already imported so we
might as well leverage it.
This commit is contained in:
Augustin Cavalier 2022-06-09 16:04:11 -04:00
parent 2b609f8f66
commit 092b6d4a98
4 changed files with 8 additions and 25 deletions

View File

@ -2,6 +2,7 @@ SubDir HAIKU_TOP src system libroot posix musl misc ;
SubDirSysHdrs [ FDirName $(SUBDIR) .. include ] ;
UseHeaders [ FDirName $(SUBDIR) .. internal ] ;
UseHeaders [ FDirName $(SUBDIR) .. arch $(TARGET_KERNEL_ARCH_DIR) ] ;
local architectureObject ;
for architectureObject in [ MultiArchSubDirSetup ] {
@ -10,6 +11,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
MergeObject <$(architecture)>posix_musl_misc.o :
a64l.c
ffs.c
;
}
}

View File

@ -0,0 +1,6 @@
#include "atomic.h"
int ffs(int i)
{
return i ? a_ctz_l(i)+1 : 0;
}

View File

@ -20,7 +20,6 @@ for architectureObject in [ MultiArchSubDirSetup ] {
bcmp.c
bcopy.c
bzero.c
ffs.cpp
memccpy.c
memchr.c
memcmp.c

View File

@ -1,24 +0,0 @@
/*
* Copyright 2020, Adrien Destugues <pulkomandy@pulkomandy.tk>.
* Distributed under the terms of the MIT License.
*/
// find first (least significant) set bit
extern "C" int
ffs(int value)
{
#ifdef __riscv
// TODO: As of this writing, gcc 8.x seems
// to have an issue with infinite recursion.
// Re-examine in future GCC updates
int bit;
if (value == 0)
return 0;
for (bit = 1; !(value & 1); bit++)
value >>= 1;
return bit;
#else
return __builtin_ffs(value);
#endif
}