ilog2(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– 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 big n is, you get the matching optimised flavour. sized up correctly, every time 🧚

πŸ’œ SEE ALSO πŸ’œ


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