Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Sync ruby/json #13227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/json/generator/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
return 0;
}
SRC
$defs.push("-DENABLE_SIMD")
$defs.push("-DJSON_ENABLE_SIMD")
end
end

Expand All @@ -29,7 +29,7 @@
return 0;
}
SRC
$defs.push("-DENABLE_SIMD")
$defs.push("-DJSON_ENABLE_SIMD")
end

have_header('cpuid.h')
Expand Down
30 changes: 13 additions & 17 deletions ext/json/generator/generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ typedef struct _search_state {
const char *cursor;
FBuffer *buffer;

#ifdef ENABLE_SIMD
#ifdef HAVE_SIMD
const char *chunk_base;
const char *chunk_end;
bool has_matches;
Expand All @@ -124,7 +124,7 @@ typedef struct _search_state {
#else
#error "Unknown SIMD Implementation."
#endif /* HAVE_SIMD_NEON */
#endif /* ENABLE_SIMD */
#endif /* HAVE_SIMD */
} search_state;

#if (defined(__GNUC__ ) || defined(__clang__))
Expand Down Expand Up @@ -189,15 +189,11 @@ static inline FORCE_INLINE void escape_UTF8_char_basic(search_state *search)
case '\r': fbuffer_append(search->buffer, "\\r", 2); break;
case '\t': fbuffer_append(search->buffer, "\\t", 2); break;
default: {
if (ch < ' ') {
const char *hexdig = "0123456789abcdef";
char scratch[6] = { '\\', 'u', '0', '0', 0, 0 };
scratch[4] = hexdig[(ch >> 4) & 0xf];
scratch[5] = hexdig[ch & 0xf];
fbuffer_append(search->buffer, scratch, 6);
} else {
fbuffer_append_char(search->buffer, ch);
}
const char *hexdig = "0123456789abcdef";
char scratch[6] = { '\\', 'u', '0', '0', 0, 0 };
scratch[4] = hexdig[(ch >> 4) & 0xf];
scratch[5] = hexdig[ch & 0xf];
fbuffer_append(search->buffer, scratch, 6);
break;
}
}
Expand Down Expand Up @@ -265,7 +261,7 @@ static inline void escape_UTF8_char(search_state *search, unsigned char ch_len)
search->cursor = (search->ptr += ch_len);
}

#ifdef ENABLE_SIMD
#ifdef HAVE_SIMD

static inline FORCE_INLINE char *copy_remaining_bytes(search_state *search, unsigned long vec_len, unsigned long len)
{
Expand Down Expand Up @@ -537,7 +533,7 @@ static inline TARGET_SSE2 FORCE_INLINE unsigned char search_escape_basic_sse2(se

#endif /* HAVE_SIMD_SSE2 */

#endif /* ENABLE_SIMD */
#endif /* HAVE_SIMD */

static const unsigned char script_safe_escape_table[256] = {
// ASCII Control Characters
Expand Down Expand Up @@ -1302,11 +1298,11 @@ static void generate_json_string(FBuffer *buffer, struct generate_json_data *dat
search.cursor = search.ptr;
search.end = search.ptr + len;

#ifdef ENABLE_SIMD
#ifdef HAVE_SIMD
search.matches_mask = 0;
search.has_matches = false;
search.chunk_base = NULL;
#endif /* ENABLE_SIMD */
#endif /* HAVE_SIMD */

switch(rb_enc_str_coderange(obj)) {
case ENC_CODERANGE_7BIT:
Expand Down Expand Up @@ -2174,7 +2170,7 @@ void Init_generator(void)


switch(find_simd_implementation()) {
#ifdef ENABLE_SIMD
#ifdef HAVE_SIMD
#ifdef HAVE_SIMD_NEON
case SIMD_NEON:
search_escape_basic_impl = search_escape_basic_neon;
Expand All @@ -2185,7 +2181,7 @@ void Init_generator(void)
search_escape_basic_impl = search_escape_basic_sse2;
break;
#endif /* HAVE_SIMD_SSE2 */
#endif /* ENABLE_SIMD */
#endif /* HAVE_SIMD */
default:
search_escape_basic_impl = search_escape_basic;
break;
Expand Down
6 changes: 4 additions & 2 deletions ext/json/generator/simd.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ typedef enum {
SIMD_SSE2
} SIMD_Implementation;

#ifdef ENABLE_SIMD
#ifdef JSON_ENABLE_SIMD

#ifdef __clang__
#if __has_builtin(__builtin_ctzll)
Expand Down Expand Up @@ -56,6 +56,7 @@ static SIMD_Implementation find_simd_implementation(void) {
return SIMD_NEON;
}

#define HAVE_SIMD 1
#define HAVE_SIMD_NEON 1

uint8x16x4_t load_uint8x16_4(const unsigned char *table) {
Expand All @@ -74,6 +75,7 @@ uint8x16x4_t load_uint8x16_4(const unsigned char *table) {
#ifdef HAVE_X86INTRIN_H
#include <x86intrin.h>

#define HAVE_SIMD 1
#define HAVE_SIMD_SSE2 1

#ifdef HAVE_CPUID_H
Expand Down Expand Up @@ -101,7 +103,7 @@ static SIMD_Implementation find_simd_implementation(void) {
#endif /* HAVE_X86INTRIN_H */
#endif /* X86_64 Support */

#endif /* ENABLE_SIMD */
#endif /* JSON_ENABLE_SIMD */

#ifndef FIND_SIMD_IMPLEMENTATION_DEFINED
static SIMD_Implementation find_simd_implementation(void) {
Expand Down
Loading