From d60777002f23d7b681a3701b57a2e966875f2e61 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Thu, 5 Jun 2025 15:36:12 -0400 Subject: [PATCH] Function multiversioning for n_string2 --- src/parser3.h | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/parser3.h b/src/parser3.h index b987eb3..d78f6da 100644 --- a/src/parser3.h +++ b/src/parser3.h @@ -396,27 +396,26 @@ inline PRESERVE_NONE WeaselJsonStatus n_string(Parser3 *self, char *buf, MUSTTAIL return Parser3::keepGoing(self, buf, bufEnd); } -inline PRESERVE_NONE WeaselJsonStatus n_string2(Parser3 *self, char *buf, - char *bufEnd) { +template +PRESERVE_NONE WeaselJsonStatus n_string2_impl(Parser3 *self, char *buf, + char *bufEnd) { const auto before = buf; // Advance buf to the first "non-normal" character for (;;) { - constexpr int kStride = 64; - if (bufEnd - buf < kStride) [[unlikely]] { + if (bufEnd - buf < V::lanes) [[unlikely]] { while (buf != bufEnd && tables.stringByteMeaning[uint8_t(*buf)] == Tables::NORMAL) { ++buf; } break; } - using V = simd; auto v = V{(int8_t *)buf}; int normal = (v != V::splat('"') & v != V::splat('\\') & v >= V::splat(0x20)) .count_leading_nonzero_lanes(); buf += normal; - if (normal < kStride) { + if (normal < V::lanes) { break; } } @@ -485,6 +484,24 @@ inline PRESERVE_NONE WeaselJsonStatus n_string2(Parser3 *self, char *buf, } } +template WeaselJsonStatus +n_string2_impl>(Parser3 *, char *, char *); + +template __attribute__((target("avx2"))) WeaselJsonStatus +n_string2_impl>(Parser3 *, char *, char *); + +__attribute__((target("default"))) inline PRESERVE_NONE WeaselJsonStatus +n_string2(Parser3 *self, char *buf, char *bufEnd) { + MUSTTAIL return n_string2_impl>(self, buf, + bufEnd); +} + +__attribute__((target("avx2"))) inline PRESERVE_NONE WeaselJsonStatus +n_string2(Parser3 *self, char *buf, char *bufEnd) { + MUSTTAIL return n_string2_impl>( + self, buf, bufEnd); +} + inline PRESERVE_NONE WeaselJsonStatus n_string_following_escape(Parser3 *self, char *buf, char *bufEnd) {