Compare commits

...

4 Commits

Author SHA1 Message Date
0c2af46a79 Start bench at a stride of 128 2025-06-05 15:45:44 -04:00
35c3e14586 Remove -mavx 2025-06-05 15:38:24 -04:00
d60777002f Function multiversioning for n_string2 2025-06-05 15:36:12 -04:00
f7871915e9 Update simd.h 2025-06-05 15:34:10 -04:00
4 changed files with 2176 additions and 606 deletions

View File

@@ -84,9 +84,6 @@ check_cxx_source_compiles("int main(){}" HAS_VERSION_SCRIPT FAIL_REGEX
"warning:")
cmake_pop_check_state()
if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
add_compile_options(-mavx)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
add_link_options(LINKER:--gc-sections)
endif()

View File

@@ -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 <class V>
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<int8_t, kStride>;
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<simd<int8_t, 64, sse::Simd_x86_SSE>>(Parser3 *, char *, char *);
template __attribute__((target("avx2"))) WeaselJsonStatus
n_string2_impl<simd<int8_t, 64, sse::Simd_x86_AVX2>>(Parser3 *, char *, char *);
__attribute__((target("default"))) inline PRESERVE_NONE WeaselJsonStatus
n_string2(Parser3 *self, char *buf, char *bufEnd) {
MUSTTAIL return n_string2_impl<simd<int8_t, 64, sse::Simd_x86_SSE>>(self, buf,
bufEnd);
}
__attribute__((target("avx2"))) inline PRESERVE_NONE WeaselJsonStatus
n_string2(Parser3 *self, char *buf, char *bufEnd) {
MUSTTAIL return n_string2_impl<simd<int8_t, 64, sse::Simd_x86_AVX2>>(
self, buf, bufEnd);
}
inline PRESERVE_NONE WeaselJsonStatus n_string_following_escape(Parser3 *self,
char *buf,
char *bufEnd) {

2748
src/simd.h

File diff suppressed because it is too large Load Diff

View File

@@ -262,7 +262,7 @@ TEST_CASE("bench3") {
bench.batch(json.size());
bench.unit("byte");
auto *parser = WeaselJsonParser_create(1024, &c, nullptr);
for (size_t stride = 1; stride <= json.size(); stride *= 2) {
for (size_t stride = 128; stride <= json.size(); stride *= 2) {
bench.run("parser3 (stride: " + std::to_string(stride) + ")", [&]() {
auto copy = json;
WeaselJsonParser_reset(parser);