Skip to content

Commit 2b11554

Browse files
committed
Revert "let ci run without max_shift trick to compare perf"
This reverts commit d7f2562.
1 parent d7f2562 commit 2b11554

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

ext/json/json_encoder.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,9 +522,11 @@ zend_result php_json_escape_string(
522522
const __m128i input = _mm_loadu_si128((__m128i *) (s + pos));
523523
const __m128i input_range = _mm_cmplt_epi8(input, _mm_set1_epi8(32));
524524

525+
int max_shift = 16;
526+
525527
int input_range_mask = _mm_movemask_epi8(input_range);
526528
if (input_range_mask != 0) {
527-
break;
529+
max_shift = zend_ulong_ntz(input_range_mask);
528530
}
529531

530532
#ifdef ZEND_INTRIN_SSE4_2_NATIVE
@@ -551,6 +553,12 @@ zend_result php_json_escape_string(
551553
int mask = _mm_movemask_epi8(result_individual_bytes);
552554
#endif
553555
if (mask != 0) {
556+
if (max_shift < 16) {
557+
int shift = zend_ulong_ntz(mask); /* first offending character */
558+
pos += MIN(max_shift, shift);
559+
len -= MIN(max_shift, shift);
560+
break;
561+
}
554562
int shift = zend_ulong_nlz(mask) - 16 - (SIZEOF_ZEND_LONG == 8 ? 32 : 0); /* skips over everything */
555563
do {
556564
/* Note that we shift the input forward, so we have to shift the mask as well,
@@ -571,6 +579,11 @@ zend_result php_json_escape_string(
571579

572580
pos += shift;
573581
} else {
582+
if (max_shift < 16) {
583+
pos += max_shift;
584+
len -= max_shift;
585+
break;
586+
}
574587
pos += sizeof(__m128i);
575588
}
576589

0 commit comments

Comments
 (0)