• The Hidden Cost of Misalignment

    But pack(1) costs more than you think. It destroys the compiler’s ability to generate efficient code for every field access, including fields that are perfectly aligned.

    On RISC-V, a single 32-bit store to an aligned field in a pack(1) struct compiles to 7 instructions instead of 1!

    In this post, we show how to fix using the packed and aligned attributes, and how to avoid byte-decomposition even as the struct grows in the future.