3 ms·
I know the post only uses SIMD as an attempt to do bitmask lookup for each byte, but a good alternative use of SIMD is for parallel data processing, i.e. operat
by ww520 2y ago
I know the post only uses SIMD as an attempt to do bitmask lookup for each byte, but a good alternative use of SIMD is for parallel data processing, i.e. operating on more than one character. Being able to identify a range of characters making up the identifier is much faster than checking one character at a time, especially for avoiding branching.
Did a bit of xmas hacking to come up with the function to find identifiers in parallel in 32-byte chunks. I used Zig since it makes vector/SIMD programming easy.
The code is in: https://github.com/williamw520/misc_zig/blob/main/identifier.zig https://github.com/williamw520/misc_zig/blob/main/identifier...
The generated code of the nextBitmask32() function has about 38 instructions. https://godbolt.org/z/7ME3sW55e https://godbolt.org/z/7ME3sW55e
That's 38 instructions for processing every 32 bytes. With no branching!
- deleted 2y ago[deleted]
- ww520 2y agoSlightly optimized code to get down to 32 asm instructions. https://godbolt.org/z/ccE3r1bjc https://godbolt.org/z/ccE3r1bjc
- teo_zero 2y agoGodbolt shows 40 asm instructions, or am I misreading it?
- ww520 2y agoAhh ok. The above link used whatever the latest trunk of the zig compiler to generate code. Looks like the current trunk has regressed just now and produces more instructions. The link below uses the previous stable version and produces fewer instructions. https://godbolt.org/z/Ez4YGbdqn https://godbolt.org/z/Ez4YGbdqn