Page MenuHomeFreeBSD

libkern: avoid local var in order_base_2()
ClosedPublic

Authored by dougm on Sep 27 2024, 9:58 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Nov 18, 8:12 PM
Unknown Object (File)
Mon, Nov 18, 2:50 PM
Unknown Object (File)
Sat, Nov 16, 12:51 PM
Unknown Object (File)
Fri, Nov 1, 2:15 PM
Unknown Object (File)
Thu, Oct 31, 9:42 PM
Unknown Object (File)
Oct 22 2024, 4:04 PM
Unknown Object (File)
Oct 16 2024, 11:58 AM
Unknown Object (File)
Oct 12 2024, 4:38 PM
Subscribers

Details

Summary

order_base_2(n) is implemented with a variable, which keeps it from being used at file scope. Implement it instead as ilog2(2*n-1).

This will change the behavior of the macro for most values with high bit set. So, for 32-bit unsigned ints greater than 0x80000000, order_base_2(n) will essentially ignore the high order bit. It seems that many uses of order_base_2 are in roundup_pow_of_two, and that already didn't work for cases when the high order bit was set (1<<32 is not defined, and is often computed as 1).

I don't think that this macro is used in cases where this change matters.

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

dougm requested review of this revision.Sep 27 2024, 9:58 PM
dougm created this revision.
This revision is now accepted and ready to land.Sep 27 2024, 10:27 PM
This revision was automatically updated to reflect the committed changes.