From 290944af9029ea64c9c4d2e4c96c89ebb09df960 Mon Sep 17 00:00:00 2001 From: "antares0982@gmail.com" Date: Wed, 1 May 2024 16:59:13 +0800 Subject: [PATCH] fix: use avx2 instead of avx512 [skip ci] --- CMakeLists.txt | 2 +- src/str.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4504e55..67033b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ file(GLOB_RECURSE DEPS_CPP_FILES ${DEPS_PATH}/*.cpp) add_library(cjson SHARED ${SRC_C_FILES} ${DEPS_CPP_FILES}) if (NOT MSVC) - target_compile_options(cjson PUBLIC -march=native) + target_compile_options(cjson PUBLIC -march=native -mavx2) endif (NOT MSVC) if (CMAKE_BUILD_TYPE STREQUAL "Release") diff --git a/src/str.c b/src/str.c index f4e6478..9a9ef14 100644 --- a/src/str.c +++ b/src/str.c @@ -4,7 +4,7 @@ // #include // SSE2 #include // AVX - +#include #define CHECK_NOT_LATIN1_2BYTES(a, b) (((a & 0b00011111) << 6 | (b & 0b00111111)) > 0xFF) @@ -44,7 +44,7 @@ int get_utf8_kind(const unsigned char *buf, size_t len) { // check unicode escape \uXXXX // unicode starting at even position - __mmask32 result = _mm256_cmpeq_epu8_mask(in, unicode_mask1); + uint32_t result = _mm256_movemask_epi8(_mm256_cmpeq_epi8(in, unicode_mask1)); if ((result & (result >> 1)) != 0) { for (int ii = 0; ii < 32 - 1; ii += 2) { if (buf[i + ii] == '\\' && buf[i + ii + 1] == 'u' && (i + ii - 1 < 0 || buf[i + ii - 1] != '\\')) { @@ -62,7 +62,7 @@ int get_utf8_kind(const unsigned char *buf, size_t len) { } // unicode starting at odd position - result = (_mm256_cmpeq_epu8_mask(in, unicode_mask2) >> 1) & 0b1111111111111111111111111111111; + result = _mm256_movemask_epi8(_mm256_cmpeq_epi8(in, unicode_mask2)) & 0b01111111111111111111111111111110; if ((result & (result >> 1)) != 0) { for (int ii = 1; ii < 32 - 2; ii += 2) { if (buf[i + ii] == '\\' && buf[i + ii + 1] == 'u' && (i + ii - 1 < 0 || buf[i + ii - 1] != '\\')) {