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
F133810092: D46826.id143829.diff
Tue, Oct 28, 2:49 PM
F133772051: D46826.diff
Tue, Oct 28, 7:17 AM
Unknown Object (File)
Sat, Oct 18, 6:35 AM
Unknown Object (File)
Sat, Oct 18, 6:35 AM
Unknown Object (File)
Sat, Oct 18, 6:35 AM
Unknown Object (File)
Fri, Oct 17, 7:44 PM
Unknown Object (File)
Tue, Oct 7, 3:29 PM
Unknown Object (File)
Tue, Oct 7, 7:38 AM
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