ilog2(9)
π ilog2(9) β the Kernel API Manual, bestie edition π
okay so real talk, we're in the Kernel API Manual today and the star of the show is ilog2. yes she's a function-ish macro thing. yes she's iconic. let's get into it πΈ
β¨ NAME β¨
ilog2 β log of base 2 of 32-bit or a 64-bit unsigned value, and @n is the parameter π
π¦ SYNOPSIS π¦
ilog2 (n );
that's it. that's the whole vibe. one argument, one dream π
π ARGUMENTS π
nβ literally labeled-- undescribed --in the docs π like the manual writers simply did not elaborate. that's the entire description. we move.
π₯ DESCRIPTION π₯
it's a constant-capable log of base 2 calculation β¨ "constant-capable" meaning she can do her thing at compile time, which is the whole point and honestly kind of a slay.
- this can be used to initialise global variables from constant data β hence the massive ternary operator construction π (yes the giant ternary is on purpose. no she will not be apologising for it.)
- selects the appropriately-sized optimised version depending on
sizeof(n)β so depending on how bignis, you get the matching optimised flavour. sized up correctly, every time π§
π SEE ALSO π
- Kernel file
./tools/include/linux/log2.h roundup_pow_of_two(9)rounddown_pow_of_two(9)
ngl if you're confused, just read it again β she's constant-capable, she picks the optimised version based on sizeof(n), and the ternary monster is intentional. no cap π
and that's the whole page bestie!! sign-off time: this one lives out of ./tools/include/linux and the docs are dated October 2026, so yeah, she's fresh π mwah, go log some base 2 ππ«Ά
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms