@@ -7,45 +7,45 @@ typedef enum {
7
7
#ifdef JSON_ENABLE_SIMD
8
8
9
9
#ifdef __clang__
10
- # if __has_builtin (__builtin_ctzll )
11
- # define HAVE_BUILTIN_CTZLL 1
12
- # else
13
- # define HAVE_BUILTIN_CTZLL 0
14
- # endif
10
+ # if __has_builtin (__builtin_ctzll )
11
+ # define HAVE_BUILTIN_CTZLL 1
12
+ # else
13
+ # define HAVE_BUILTIN_CTZLL 0
14
+ # endif
15
15
#elif defined(__GNUC__ ) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3 ))
16
- # define HAVE_BUILTIN_CTZLL 1
16
+ # define HAVE_BUILTIN_CTZLL 1
17
17
#else
18
- # define HAVE_BUILTIN_CTZLL 0
18
+ # define HAVE_BUILTIN_CTZLL 0
19
19
#endif
20
20
21
21
static inline uint32_t trailing_zeros64 (uint64_t input )
22
22
{
23
23
#if HAVE_BUILTIN_CTZLL
24
- return __builtin_ctzll (input );
24
+ return __builtin_ctzll (input );
25
25
#else
26
- uint32_t trailing_zeros = 0 ;
27
- uint64_t temp = input ;
28
- while ((temp & 1 ) == 0 && temp > 0 ) {
29
- trailing_zeros ++ ;
30
- temp >>= 1 ;
31
- }
32
- return trailing_zeros ;
26
+ uint32_t trailing_zeros = 0 ;
27
+ uint64_t temp = input ;
28
+ while ((temp & 1 ) == 0 && temp > 0 ) {
29
+ trailing_zeros ++ ;
30
+ temp >>= 1 ;
31
+ }
32
+ return trailing_zeros ;
33
33
#endif
34
34
}
35
35
36
36
static inline int trailing_zeros (int input )
37
37
{
38
- #if HAVE_BUILTIN_CTZLL
38
+ #if HAVE_BUILTIN_CTZLL
39
39
return __builtin_ctz (input );
40
- #else
40
+ #else
41
41
int trailing_zeros = 0 ;
42
42
int temp = input ;
43
43
while ((temp & 1 ) == 0 && temp > 0 ) {
44
- trailing_zeros ++ ;
45
- temp >>= 1 ;
44
+ trailing_zeros ++ ;
45
+ temp >>= 1 ;
46
46
}
47
47
return trailing_zeros ;
48
- #endif
48
+ #endif
49
49
}
50
50
51
51
#if (defined(__GNUC__ ) || defined(__clang__ ))
@@ -79,38 +79,38 @@ static inline FORCE_INLINE uint64_t neon_match_mask(uint8x16_t matches)
79
79
80
80
static inline FORCE_INLINE uint64_t compute_chunk_mask_neon (const char * ptr )
81
81
{
82
- uint8x16_t chunk = vld1q_u8 ((const unsigned char * )ptr );
82
+ uint8x16_t chunk = vld1q_u8 ((const unsigned char * )ptr );
83
83
84
- // Trick: c < 32 || c == 34 can be factored as c ^ 2 < 33
85
- // https://lemire.me/blog/2025/04/13/detect-control-characters-quotes-and-backslashes-efficiently-using-swar/
86
- const uint8x16_t too_low_or_dbl_quote = vcltq_u8 (veorq_u8 (chunk , vdupq_n_u8 (2 )), vdupq_n_u8 (33 ));
84
+ // Trick: c < 32 || c == 34 can be factored as c ^ 2 < 33
85
+ // https://lemire.me/blog/2025/04/13/detect-control-characters-quotes-and-backslashes-efficiently-using-swar/
86
+ const uint8x16_t too_low_or_dbl_quote = vcltq_u8 (veorq_u8 (chunk , vdupq_n_u8 (2 )), vdupq_n_u8 (33 ));
87
87
88
- uint8x16_t has_backslash = vceqq_u8 (chunk , vdupq_n_u8 ('\\' ));
89
- uint8x16_t needs_escape = vorrq_u8 (too_low_or_dbl_quote , has_backslash );
90
- return neon_match_mask (needs_escape );
88
+ uint8x16_t has_backslash = vceqq_u8 (chunk , vdupq_n_u8 ('\\' ));
89
+ uint8x16_t needs_escape = vorrq_u8 (too_low_or_dbl_quote , has_backslash );
90
+ return neon_match_mask (needs_escape );
91
91
}
92
92
93
93
static inline FORCE_INLINE int string_scan_simd_neon (const char * * ptr , const char * end , uint64_t * mask )
94
94
{
95
95
while (* ptr + sizeof (uint8x16_t ) <= end ) {
96
- uint64_t chunk_mask = compute_chunk_mask_neon (* ptr );
97
- if (chunk_mask ) {
98
- * mask = chunk_mask ;
99
- return 1 ;
100
- }
101
- * ptr += sizeof (uint8x16_t );
96
+ uint64_t chunk_mask = compute_chunk_mask_neon (* ptr );
97
+ if (chunk_mask ) {
98
+ * mask = chunk_mask ;
99
+ return 1 ;
100
+ }
101
+ * ptr += sizeof (uint8x16_t );
102
102
}
103
103
return 0 ;
104
104
}
105
105
106
106
static inline uint8x16x4_t load_uint8x16_4 (const unsigned char * table )
107
107
{
108
- uint8x16x4_t tab ;
109
- tab .val [0 ] = vld1q_u8 (table );
110
- tab .val [1 ] = vld1q_u8 (table + 16 );
111
- tab .val [2 ] = vld1q_u8 (table + 32 );
112
- tab .val [3 ] = vld1q_u8 (table + 48 );
113
- return tab ;
108
+ uint8x16x4_t tab ;
109
+ tab .val [0 ] = vld1q_u8 (table );
110
+ tab .val [1 ] = vld1q_u8 (table + 16 );
111
+ tab .val [2 ] = vld1q_u8 (table + 32 );
112
+ tab .val [3 ] = vld1q_u8 (table + 48 );
113
+ return tab ;
114
114
}
115
115
116
116
#endif /* ARM Neon Support.*/
@@ -151,12 +151,12 @@ static inline TARGET_SSE2 FORCE_INLINE int compute_chunk_mask_sse2(const char *p
151
151
static inline TARGET_SSE2 FORCE_INLINE int string_scan_simd_sse2 (const char * * ptr , const char * end , int * mask )
152
152
{
153
153
while (* ptr + sizeof (__m128i ) <= end ) {
154
- int chunk_mask = compute_chunk_mask_sse2 (* ptr );
155
- if (chunk_mask ) {
156
- * mask = chunk_mask ;
157
- return 1 ;
158
- }
159
- * ptr += sizeof (__m128i );
154
+ int chunk_mask = compute_chunk_mask_sse2 (* ptr );
155
+ if (chunk_mask ) {
156
+ * mask = chunk_mask ;
157
+ return 1 ;
158
+ }
159
+ * ptr += sizeof (__m128i );
160
160
}
161
161
162
162
return 0 ;
0 commit comments