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:
parent
2b609f8f66
commit
092b6d4a98
@ -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
|
||||
;
|
||||
}
|
||||
}
|
||||
|
6
src/system/libroot/posix/musl/misc/ffs.c
Normal file
6
src/system/libroot/posix/musl/misc/ffs.c
Normal file
@ -0,0 +1,6 @@
|
||||
#include "atomic.h"
|
||||
|
||||
int ffs(int i)
|
||||
{
|
||||
return i ? a_ctz_l(i)+1 : 0;
|
||||
}
|
@ -20,7 +20,6 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
||||
bcmp.c
|
||||
bcopy.c
|
||||
bzero.c
|
||||
ffs.cpp
|
||||
memccpy.c
|
||||
memchr.c
|
||||
memcmp.c
|
||||
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user