Created
July 4, 2024 03:24
-
-
Save cyb70289/745a738096ab501e6334cdb0d5c35fcd to your computer and use it in GitHub Desktop.
optimize skipstring with sve2 match
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/cmake/set_arch_flags.cmake b/cmake/set_arch_flags.cmake | |
index 538ddfe..6dc7754 100644 | |
--- a/cmake/set_arch_flags.cmake | |
+++ b/cmake/set_arch_flags.cmake | |
@@ -2,8 +2,8 @@ function(set_arch_flags target arch) | |
message(STATUS "Setting architecture flags for ${arch}") | |
if(arch MATCHES "x86_64") | |
target_compile_options(${target} PRIVATE -mavx2 -mpclmul -mbmi -mlzcnt) | |
- elseif(arch MATCHES "arm") | |
- target_compile_options(${target} PRIVATE -march=armv8-a) | |
+ elseif(arch MATCHES "arm|aarch64") | |
+ target_compile_options(${target} PRIVATE -march=armv8.5-a+sve2 -msve-vector-bits=128) | |
else() | |
message(FATAL_ERROR "Unsupported architecture: ${arch}") | |
endif() | |
diff --git a/include/sonic/internal/arch/neon/skip.h b/include/sonic/internal/arch/neon/skip.h | |
index 8be0926..f048b68 100644 | |
--- a/include/sonic/internal/arch/neon/skip.h | |
+++ b/include/sonic/internal/arch/neon/skip.h | |
@@ -26,6 +26,10 @@ | |
#include "sonic/macro.h" | |
#include "unicode.h" | |
+#include <arm_sve.h> | |
+typedef svuint8_t svuint8x16_t __attribute__((arm_sve_vector_bits(128))); | |
+typedef svbool_t svbool8x16_t __attribute__((arm_sve_vector_bits(128))); | |
+ | |
namespace sonic_json { | |
namespace internal { | |
namespace neon { | |
@@ -79,6 +83,37 @@ sonic_force_inline int SkipString(const uint8_t *data, size_t &pos, | |
const static int kEscaped = 2; | |
const static int kNormal = 1; | |
const static int kUnclosed = 0; | |
+#if 1 | |
+ int ret = kNormal; | |
+ const svbool8x16_t ptrue = svptrue_b8(); | |
+ const uint8_t needle_array[] = R"(\""""""""""""""")"; | |
+ const svuint8x16_t needle = svld1(ptrue, needle_array); | |
+ while (pos + VEC_LEN <= len) { | |
+ const svuint8x16_t v = svld1(ptrue, data + pos); | |
+ const svbool8x16_t mask = svmatch_u8(ptrue, v, needle); | |
+ if (!svptest_any(mask, mask)) { | |
+ pos += VEC_LEN; | |
+ continue; | |
+ } | |
+ for (int i = 0; i < VEC_LEN; ++i) { | |
+ if (data[pos + i] == '"') { | |
+ pos += i + 1; | |
+ return ret; | |
+ } else if (data[pos + i] == '\\') { | |
+ ret = kEscaped; | |
+ pos += i + 2; | |
+ while (pos < len) { | |
+ if (data[pos] == '\\') { | |
+ pos += 2; | |
+ } else { | |
+ i = VEC_LEN; | |
+ break; | |
+ } | |
+ } | |
+ } | |
+ } | |
+ } | |
+#else | |
uint64_t quote_bits = 0; | |
uint64_t bs_bits = 0; | |
int ret = kNormal; | |
@@ -105,6 +140,7 @@ sonic_force_inline int SkipString(const uint8_t *data, size_t &pos, | |
pos += VEC_LEN; | |
} | |
} | |
+#endif | |
while (pos < len) { | |
if (data[pos] == '\\') { | |
if (pos + 1 >= len) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment