Skip to contentSkip to conversation

Is __ffs64 supposed to be zero based?

DISCUSSION Ben Greear 2 participants 3 messages Nov 6, 2013

lore
Share & tools
lore

Ben Greear

author
#0 lore raw

Similarly named methods elsewhere seem to indicate it is supposed to be ones-based counting (ie, bit (1<<0) would be considred 'bit 1'.

Thanks,
Ben

Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com
#1 lore raw
Quoted 2 lines · Ben Greear

Similarly named methods elsewhere seem to indicate it is supposed to be ones-based counting (ie, bit (1<<0) would be considred 'bit 1'.

ffs() is defined to use one-based counting:
<http://pubs.opengroup.org/onlinepubs/9699919799/functions/ffs.html>

__ffs() uses zero-based counting. On gcc, it's likely to be implemented with__builtin_ctz*(), whose documentation says:
| Returns the number of trailing 0-bits in x, starting at the least | significant bit position.

Regards,
Clemens

author
#2 lore raw
Quoted 11 lines · Clemens Ladisch
Quoted 2 lines · Ben Greear

Similarly named methods elsewhere seem to indicate it is supposed to be ones-based counting (ie, bit (1<<0) would be considred 'bit 1'.

ffs() is defined to use one-based counting:
<http://pubs.opengroup.org/onlinepubs/9699919799/functions/ffs.html>

__ffs() uses zero-based counting. On gcc, it's likely to be implemented with__builtin_ctz*(), whose documentation says:
| Returns the number of trailing 0-bits in x, starting at the least | significant bit position.

Thanks for the information!

Ben

Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com