@@ -7,45 +7,45 @@ typedef enum {
77#ifdef JSON_ENABLE_SIMD
88
99#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
1515#elif defined(__GNUC__ ) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3 ))
16- # define HAVE_BUILTIN_CTZLL 1
16+ # define HAVE_BUILTIN_CTZLL 1
1717#else
18- # define HAVE_BUILTIN_CTZLL 0
18+ # define HAVE_BUILTIN_CTZLL 0
1919#endif
2020
2121static inline uint32_t trailing_zeros64 (uint64_t input )
2222{
2323#if HAVE_BUILTIN_CTZLL
24- return __builtin_ctzll (input );
24+ return __builtin_ctzll (input );
2525#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 ;
3333#endif
3434}
3535
3636static inline int trailing_zeros (int input )
3737{
38- #if HAVE_BUILTIN_CTZLL
38+ #if HAVE_BUILTIN_CTZLL
3939 return __builtin_ctz (input );
40- #else
40+ #else
4141 int trailing_zeros = 0 ;
4242 int temp = input ;
4343 while ((temp & 1 ) == 0 && temp > 0 ) {
44- trailing_zeros ++ ;
45- temp >>= 1 ;
44+ trailing_zeros ++ ;
45+ temp >>= 1 ;
4646 }
4747 return trailing_zeros ;
48- #endif
48+ #endif
4949}
5050
5151#if (defined(__GNUC__ ) || defined(__clang__ ))
@@ -79,38 +79,38 @@ static inline FORCE_INLINE uint64_t neon_match_mask(uint8x16_t matches)
7979
8080static inline FORCE_INLINE uint64_t compute_chunk_mask_neon (const char * ptr )
8181{
82- uint8x16_t chunk = vld1q_u8 ((const unsigned char * )ptr );
82+ uint8x16_t chunk = vld1q_u8 ((const unsigned char * )ptr );
8383
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 ));
8787
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 );
9191}
9292
9393static inline FORCE_INLINE int string_scan_simd_neon (const char * * ptr , const char * end , uint64_t * mask )
9494{
9595 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 );
102102 }
103103 return 0 ;
104104}
105105
106106static inline uint8x16x4_t load_uint8x16_4 (const unsigned char * table )
107107{
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 ;
114114}
115115
116116#endif /* ARM Neon Support.*/
@@ -151,12 +151,12 @@ static inline TARGET_SSE2 FORCE_INLINE int compute_chunk_mask_sse2(const char *p
151151static inline TARGET_SSE2 FORCE_INLINE int string_scan_simd_sse2 (const char * * ptr , const char * end , int * mask )
152152{
153153 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 );
160160 }
161161
162162 return 0 ;
0 commit comments