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
F132594324: D46826.id.diff
Sat, Oct 18, 6:35 AM
F132594323: D46826.id143829.diff
Sat, Oct 18, 6:35 AM
F132594322: D46826.id143835.diff
Sat, Oct 18, 6:35 AM
F132540251: D46826.diff
Fri, Oct 17, 7:44 PM
Unknown Object (File)
Tue, Oct 7, 3:29 PM
Unknown Object (File)
Tue, Oct 7, 7:38 AM
Unknown Object (File)
Sun, Sep 21, 10:20 PM
Unknown Object (File)
Sep 14 2025, 6:03 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

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable