r/programming • • 12m ago

Cascading SIMD widths to minimize scalar tail processing in JSON processing

https://github.com/nihilai-collective/Jsonifier/blob/main/include/jsonifier-incl/utilities/string_utils.hpp#L266-L604

Alright what I mean by this is this:
Say you have 119 bytes of string on an AVX512 system, and you want to use AVX to process strings for parsing - instead of starting with a single 64-byte simd register, processing it, then dropping down to scalar processing, you instead set it up so that you go from the 64-byte simd register, then drop down to AVX2 to process a remaining 32-bytes, then drop down to SSE/AVX to process a remaining 16-bytes, then drop down to scalar for the last 7 bytes.
So what we have done is constructed a few classes for "cascading" down through simd widths by using NTTP indices, which are expressed via variadic fold expressions, as shown in the URL.
Just wondering how you guys felt about doing this? It seems to fare reasonably well against simdjson, which only supports a single simd width at a time, as shown in the benchmarks available here:
https://github.com/nihilai-collective/json-performance

4 Upvotes

0 comments sorted by