Hacker News new | ask | show | jobs
by simonask 25 days ago
String search algorithms would be one example, where a 64-bit register can be used as a “vector” containing 8x1 bytes.
1 comments

Where is the part about unaligned pointers?
Strings typically consist of UTF-8 bytes, and any old `char*` pair has no alignment guarantees.
That's true, and that's why your typical string vector code has a prelude and a postlude to do the incomplete chunks at the ends. Between the ends, it's processing larger self-aligned chunks.
If you're aware of that technique, why were you asking about use cases for unaligned loads?
I'm saying that string search algorithms are _not_ a legitimate use case for unaligned loads.
You didn’t really say that, but feel free to share any reasons you might have to think so.

I don’t see any reason why it wouldn’t be perfectly fine on recent hardware, where unaligned loads are just as fast, and the cache pressure is identical for a linear search algorithm.