r/programming • • Jul 23 '26

Everyone Should Know SIMD

https://mitchellh.com/writing/everyone-should-know-simd
413 Upvotes

82 comments sorted by

View all comments

Show parent comment

1

u/The_Northern_Light Jul 26 '26

Unaligned access isn’t as big of a deal today (equally as fast on some platforms), and floating point commutativity can be controlled by compiler flags.

I’ve also definitely seen compilers generate a clean-up loop for the leftovers caused by arbitrary array lengths.

3

u/tanner-gooding Jul 27 '26

Unaligned access is still a fairly big deal today, especially for large payloads, and is only equally fast for the accesses that don't split a cache line.

If you do split a cache line, you still incur at least a 1-cycle penalty on loads (sometimes 2) and stores tend to be quite a bit more expensive. -- Unaligned accesses may then also lose out on atomicity guarantees, which can impact multithreading.

So V128 incurs a penalty every 4 accesses, V256 every 2, and V512 every access. If you have multiple inputs or destinations, it can be even more regular or higher cost.

Page splits are then even more expensive, but that's typically every 4k bytes, so tends to get lost in the noise.