3 ms·
In the case of strlen, SSE goes a few cycles slower for n<8, gains a slight advantage over SWAR for n>8, and starts going ~twice as fast for n>255. Benchmarks:
by jart 5y ago
In the case of strlen, SSE goes a few cycles slower for n<8, gains a slight advantage over SWAR for n>8, and starts going ~twice as fast for n>255. Benchmarks: https://justine.lol/swarsimd.txt https://justine.lol/swarsimd.txt The difference is probably more pronounced in functions that do block copying like https://github.com/jart/cosmopolitan/blob/master/libc/str/stpcpy.c https://github.com/jart/cosmopolitan/blob/master/libc/str/st... (which actually uses the ANSITRINSICS library). For more complicated functions like this: https://github.com/jart/cosmopolitan/blob/b3838173ecbb67fae548008ae9a24ce7289fed1c/libc/str/tprecode8to16.c#L27-L44 https://github.com/jart/cosmopolitan/blob/b3838173ecbb67fae5... SIMD has the advantage that figuring out how to do the SWAR arithmetic correctly might be more difficult than figuring out how to use the hardware API. It goes without saying that the most compelling benefits of SSE are the instructions like PMADDUBSW which can be used to great effect for signal decimation https://github.com/jart/cosmopolitan/blob/b3838173ecbb67fae548008ae9a24ce7289fed1c/dsp/scale/cdecimate2xuint8x8.c#L41-L98 https://github.com/jart/cosmopolitan/blob/b3838173ecbb67fae5... assuming you use The Perfect Kernel {-1, -3, 3, 17, 17, 3, -3, -1} http://www.johncostella.com/magic/ http://www.johncostella.com/magic/ or PADDSW which can mix audio samples real fast doing saturating arithmetic. You can't SWAR that. Another great example is carryless multiplication instructions which literally make CRC32 computation go 54x faster.