In the short thread I wrote this morning I dropped a comment about always being ...
Gabriele Svelto @gabrielesvelto@mas.to
In the short thread I wrote this morning I dropped a comment about always being able to do an unaligned 16-bit write on x86 (and ARM64). That kind of handwaves away just how complex that is in hardware. Because memory accesses that aren't aligned on natural boundaries are *ridiculously hard*.
Think about it for a sec. If it falls within a cacheline at minimum you'll have to shift and mask data around, depending on how the physical layout of your L1.
But what if it partially overlaps with another access to the same location? And what if it straddles two cache-lines? What if the second cache-line is not in the L1 and needs to be fetched from memory (without ejecting the other!). What if it's owned by another core? And what if the access straddles two pages? And maybe one has different access rights. Or has been swapped out.
Making that operation fast and giving it the appearance of being mostly atomic requires incredibly complex machinery that naturally-aligned accesses don't need.