Skip to content
This repository has been archived by the owner on May 25, 2024. It is now read-only.

Commit

Permalink
fix: use avx2 instead of avx512
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
Antares0982 committed May 1, 2024
1 parent a52efd7 commit 290944a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions src/str.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// #include <emmintrin.h> // SSE2
#include <immintrin.h> // AVX

#include <stdint.h>
#define CHECK_NOT_LATIN1_2BYTES(a, b) (((a & 0b00011111) << 6 | (b & 0b00111111)) > 0xFF)


Expand Down Expand Up @@ -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] != '\\')) {
Expand All @@ -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] != '\\')) {
Expand Down

0 comments on commit 290944a

Please sign in to comment.