Page MenuHomeFreeBSD

Make bitpos() handle arguments with many set bits
ClosedPublic

Authored by dougm on May 10 2019, 6:56 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Oct 20, 2:32 AM
Unknown Object (File)
Thu, Oct 16, 12:01 AM
Unknown Object (File)
Thu, Oct 16, 12:01 AM
Unknown Object (File)
Thu, Oct 16, 12:01 AM
Unknown Object (File)
Thu, Oct 16, 12:01 AM
Unknown Object (File)
Thu, Oct 16, 12:01 AM
Unknown Object (File)
Wed, Oct 15, 1:30 PM
Unknown Object (File)
Thu, Oct 9, 2:04 PM
Subscribers

Details

Summary

When bitpos can't be implemented with an inline ffs* instruction, change the binary search so that it does not depend on a single bit only being set in the bitmask. Use bitpos more generally, and avoid some clearing of bits to accommodate its current behavior.

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

So why not use _Generic ?

subr_blist.c
224

Is this case ever occur ? I believe daddr_t is always 64bit.
For this argument, you might actually add 'long'.

Apply _Generic instead of switch. Not previously acquainted with that construct.

subr_blist.c
224

Where I'm testing, long long and long have the same size and the switch led to a compilation error.

Alan has suggested that someday he hopes to use a 32-bit daddr_t for 32-bit machines, which is why I bother sticking the int case in there.

subr_blist.c
224

Did you tested with switch, or with _Generic. I would expect that you can use long with generic, since all three types 'long long', 'long' and 'int' are different, even if some of them have identical representation.

Add a 'long' case to the _Generic for bitpos, which compiles successfully.

This revision is now accepted and ready to land.May 10 2019, 10:46 PM
This revision was automatically updated to reflect the committed changes.

_Generic broke several builds. I'll prepare a patch to undo it, in case you don't have a better solution to offer.

_Generic broke several builds. I'll prepare a patch to undo it, in case you don't have a better solution to offer.

If you intend reverting the commit, you got the implicit approval.

Can you point me to the reports ?