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)
Thu, Dec 5, 4:50 PM
Unknown Object (File)
Sat, Nov 30, 5:43 PM
Unknown Object (File)
Nov 12 2024, 9:18 PM
Unknown Object (File)
Nov 12 2024, 4:33 PM
Unknown Object (File)
Nov 12 2024, 4:24 AM
Unknown Object (File)
Nov 9 2024, 5:36 PM
Unknown Object (File)
Oct 30 2024, 2:15 AM
Unknown Object (File)
Oct 29 2024, 10:07 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

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

So why not use _Generic ?

subr_blist.c
224 ↗(On Diff #57283)

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 ↗(On Diff #57283)

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 ↗(On Diff #57283)

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 ?