STRUCT REGBIT(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… struct regbit(9) β€” Kernel API Manual, bestie edition πŸŽ€

okay so bestie, welcome to the glow-up of the struct regbit manpage, from the Kernel API Manual. this one's short but she's iconic β€” a whole tiny struct that exists to pack one single bit into as few bytes as possible. main character energy fr fr ✨


πŸ¦‹ NAME πŸ¦‹

struct regbit β€” describe one bit in a register πŸ’«

like, literally just one bit. one. tiny. bit. and this struct is the whole personality ✨


🌸 SYNOPSIS 🌸

struct regbit {
    u16 bit:5;
    u16 reg:11;
 };

that's her!! that's the whole struct!! and yes the original has that little space before the closing }; β€” keeping it exactly as it is, character for character, because we respect the source πŸ’…


πŸŽ€ Members πŸŽ€

  • bit β€” which bit (0 to 31) in the register 🧚 lowkey the whole point of the struct ngl
  • reg β€” offset of register relative to base address, expressed in units of 32-bit words (not bytes), ⚠️ not bytes ⚠️ β€” this is the detail everyone gets wrong, iykyk

πŸ”₯ Description πŸ”₯

so the whole point of this structure is that it's used to compactly encode the location of a single bit in a register 🫢 like, she's not here to be spacious, she's here to be snatched.

here's the math bestie, and it's giving bit-budget: five bits are needed to encode the bit number. and with the uint16_t data type, that leaves 11 bits to encode a register offset up to 2047 πŸ‘‘

and because registers are aligned on 32-bit boundaries, the offset gets specified in 32-bit words rather than bytes πŸ’– which means you can encode an offset up to 0x1FFC (8188) bytes. yes both numbers. no we're not rounding. we don't do that here 🌈

and the helper macro RB takes care of converting the register offset from bytes to 32-bit words for you, because she's a queen and she handles the messy part πŸ’…βœ¨


⭐ SEE ALSO ⭐

  • Kernel file ./drivers/clk/renesas/r9a06g032-clocks.c struct r9a06g032_gate(9), struct r9a06g032_clkdesc(9) πŸ¦‹

go read those next, bestie, they're in the same friend group πŸ’œ


ngl this struct is tiny but she ate. packing a bit number AND a register offset into 16 bits? obsessed. πŸ“

and that's the page!! 🌸 sign-off time: this one lives over at ./drivers/clk/renesas, dated October 2026 β€” so she's fresh, she's Reneasas-adjacent, and she's ready for you. mwah πŸ’‹πŸŽ€πŸ’–

πŸ“¦ where this page comes from