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
F110096594: D46826.diff
Thu, Feb 13, 2:02 PM
Unknown Object (File)
Mon, Feb 10, 12:50 PM
Unknown Object (File)
Thu, Feb 6, 6:36 PM
Unknown Object (File)
Mon, Jan 20, 12:25 PM
Unknown Object (File)
Fri, Jan 17, 3:40 PM
Unknown Object (File)
Jan 9 2025, 1:28 AM
Unknown Object (File)
Dec 5 2024, 2:21 AM
Unknown Object (File)
Nov 18 2024, 8:12 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