Repository navigation
Provide SWAR memcmp implementation when SIMD not enabled - #910
Conversation
alexcrichton
left a comment
There was a problem hiding this comment.
Thanks! Would you be up for adding a benchmark to this repository itself to perhaps assist others when this is changed in the future? There are no benchmarks at this time in wasi-libc, but I'd be surprised if there was no mostly-works-out-the-box style project that works with benchmarking and CMake
Without SIMD, memcmp compares one byte per iteration. Add a path for n >= 8 that compares 8-byte words and locates the first differing byte with ctz on their XOR. Calls shorter than 8 bytes go straight to the existing byte loop. ns per call, old loop -> new, Clang trunk at -O3, AMD EPYC 7B13: n first difference Wasmtime 50 V8 (Node 22) 4 none 4.2 -> 3.5 4.3 -> 4.1 8 byte 0 2.2 -> 2.2 3.2 -> 3.2 8 none 6.6 -> 3.2 7.5 -> 3.6 16 none 12.6 -> 4.4 11.2 -> 4.2 64 byte 0 2.2 -> 2.2 3.2 -> 3.2 64 none 46.9 -> 11.9 33.2 -> 8.3 1024 none 642 -> 167 502 -> 89 The function grows from 74->311 bytes at -O3 and from 66->185 at -Oz.
6e5c77f to
13f48f9
Compare
okay did a quick search and most i found either require libc++ (google benchmark) or don't support wasi/high-precision (ubench.h). generated #911 which looks pretty reasonable. would that work? for reference, the two outputs would look like this. #911 (main+benchmark): and #910 (this pr): |
alexcrichton
left a comment
There was a problem hiding this comment.
Thanks! I'll review the other PR for benchmarking
Without SIMD, memcmp compares one byte per iteration. Add a path for
n >= 8 that compares 8-byte words and locates the first differing byte
with ctz on their XOR. Calls shorter than 8 bytes go straight to the
existing byte loop.
ns per call, old loop -> new, Clang trunk at -O3, AMD EPYC 7B13:
The function grows from 74->283 bytes at -O3 and from 66->159 at -Oz.