Skip to content

Commit e50b5df

Browse files
committed
Dont do popcount in sse2 path either
1 parent 56c34a4 commit e50b5df

File tree

2 files changed

+10
-35
lines changed

2 files changed

+10
-35
lines changed

ext/json/ext/generator/generator.c

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ typedef struct _search_state {
115115
#ifdef ENABLE_SIMD
116116
const char *chunk_base;
117117
const char *chunk_end;
118-
uint8_t has_matches;
118+
bool has_matches;
119119

120120
#ifdef HAVE_SIMD_NEON
121121
uint64_t matches_mask;
@@ -223,11 +223,8 @@ static inline FORCE_INLINE void escape_UTF8_char_basic(search_state *search)
223223
*/
224224
static inline void convert_UTF8_to_JSON(search_state *search)
225225
{
226-
unsigned char num_chars = 0;
227-
while ((num_chars = search_escape_basic_impl(search))) {
228-
do {
229-
escape_UTF8_char_basic(search);
230-
} while (--num_chars);
226+
while (search_escape_basic_impl(search)) {
227+
escape_UTF8_char_basic(search);
231228
}
232229
}
233230

@@ -344,7 +341,7 @@ static inline unsigned char search_escape_basic_neon(search_state *search)
344341
} else {
345342
// neon_next_match will only advance search->ptr up to the last matching character.
346343
// Skip over any characters in the last chunk that occur after the last match.
347-
search->has_matches = 0;
344+
search->has_matches = false;
348345
search->ptr = search->chunk_end;
349346
}
350347
}
@@ -398,7 +395,7 @@ static inline unsigned char search_escape_basic_neon(search_state *search)
398395
continue;
399396
}
400397
search->matches_mask = mask;
401-
search->has_matches = 1;
398+
search->has_matches = true;
402399
search->chunk_base = search->ptr;
403400
search->chunk_end = search->ptr + sizeof(uint8x16_t);
404401
return neon_next_match(search);
@@ -422,7 +419,7 @@ static inline unsigned char search_escape_basic_neon(search_state *search)
422419
}
423420

424421
search->matches_mask = neon_match_mask(needs_escape);
425-
search->has_matches = 1;
422+
search->has_matches = true;
426423
search->chunk_end = search->end;
427424
search->chunk_base = search->ptr;
428425
return neon_next_match(search);
@@ -490,7 +487,7 @@ static inline TARGET_SSE2 FORCE_INLINE unsigned char search_escape_basic_sse2(se
490487
} else {
491488
// sse2_next_match will only advance search->ptr up to the last matching character.
492489
// Skip over any characters in the last chunk that occur after the last match.
493-
search->has_matches = 0;
490+
search->has_matches = false;
494491
if (RB_UNLIKELY(search->chunk_base + sizeof(__m128i) >= search->end)) {
495492
search->ptr = search->end;
496493
} else {
@@ -510,11 +507,7 @@ static inline TARGET_SSE2 FORCE_INLINE unsigned char search_escape_basic_sse2(se
510507
continue;
511508
}
512509

513-
if (popcount32(needs_escape_mask) >= sizeof(__m128i)/2) {
514-
return sizeof(__m128i);
515-
}
516-
517-
search->has_matches = 1;
510+
search->has_matches = true;
518511
search->matches_mask = needs_escape_mask;
519512
search->chunk_base = search->ptr;
520513
return sse2_next_match(search);
@@ -539,11 +532,7 @@ static inline TARGET_SSE2 FORCE_INLINE unsigned char search_escape_basic_sse2(se
539532
return 0;
540533
}
541534

542-
if (popcount32(needs_escape_mask) >= sizeof(__m128i)/2) {
543-
return remaining;
544-
}
545-
546-
search->has_matches = 1;
535+
search->has_matches = true;
547536
search->matches_mask = needs_escape_mask;
548537
search->chunk_base = search->ptr;
549538
return sse2_next_match(search);
@@ -1310,7 +1299,7 @@ static void generate_json_string(FBuffer *buffer, struct generate_json_data *dat
13101299

13111300
#ifdef ENABLE_SIMD
13121301
search.matches_mask = 0;
1313-
search.has_matches = 0;
1302+
search.has_matches = false;
13141303
search.chunk_base = NULL;
13151304
#endif /* ENABLE_SIMD */
13161305

ext/json/ext/generator/simd.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,6 @@ static inline int trailing_zeros(int input) {
4848
#endif
4949
}
5050

51-
uint32_t popcount32(uint32_t x) {
52-
#if defined(__GNUC__) || defined(__clang__)
53-
return __builtin_popcount(x);
54-
#elif defined(__ARM_NEON)
55-
#include <arm_neon.h>
56-
return vaddv_u8(vcnt_u8(vcreate_u8((uint64_t)x))) & 0xFF;
57-
#else
58-
x = x - ((x >> 1) & 0x55555555);
59-
x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
60-
x = (x + (x >> 4)) & 0x0F0F0F0F;
61-
return (x * 0x01010101) >> 24;
62-
#endif
63-
}
64-
6551
#define SIMD_MINIMUM_THRESHOLD 6
6652

6753
#if defined(__ARM_NEON) || defined(__ARM_NEON__) || defined(__aarch64__) || defined(_M_ARM64)

0 commit comments

Comments
 (0)