[PATCH v2] string: Use builtins for ffs and ffsll

Richard Henderson richard.henderson@linaro.org
Sat Aug 26 19:02:38 GMT 2023


On 8/26/23 05:31, Wilco Dijkstra wrote:
> Hi Adhemerval,
> 
>> I did analyze it and for 32 bits targets that do define USE_FFSLL_BUILTIN
>> to 1 (armv6t2, arc, i386, m68k/mc68020, and powerpc) gcc will lower ffs to
>> __builin_ffs. For instance:
> 
> But there is no point in ever defining USE_FFSLL_BUILTIN 0 - if a target can
> inline a 32-bit ffs, it will also inline 64-bit ffs.

s/will/should/.

With gcc version 12.3.0 (Ubuntu 12.3.0-1ubuntu1~22.04) arm-linux-gnueabihf-gcc,

int f(long int x) { return __builtin_ffsl(x); }
int g(long long int x) { return __builtin_ffsll(x); }

The compiler only inlines f.

That said, it is reasonable to call this a missed optimization and fix the compiler.


r~


More information about the Libc-alpha mailing list