2929#include "zend_enum.h"
3030#include "zend_property_hooks.h"
3131#include "zend_lazy_objects.h"
32+ #include "zend_bitset.h"
3233
3334#ifdef ZEND_INTRIN_SSE4_2_NATIVE
3435# include <nmmintrin.h>
@@ -500,7 +501,7 @@ zend_result php_json_escape_string(
500501
501502 int input_range_mask = _mm_movemask_epi8 (input_range );
502503 if (input_range_mask != 0 ) {
503- max_shift = __builtin_ctz (input_range_mask );
504+ max_shift = zend_ulong_ntz (input_range_mask );
504505 }
505506
506507#ifdef ZEND_INTRIN_SSE4_2_NATIVE /* TODO: resolver support */
@@ -527,16 +528,16 @@ zend_result php_json_escape_string(
527528#endif
528529 if (mask != 0 ) {
529530 if (max_shift < 16 ) {
530- int shift = __builtin_ctz (mask ); /* first offending character */
531+ int shift = zend_ulong_ntz (mask ); /* first offending character */
531532 pos += MIN (max_shift , shift );
532533 len -= MIN (max_shift , shift );
533534 break ;
534535 }
535- int shift = __builtin_clz (mask ) - 16 ; /* skips over everything */
536+ int shift = zend_ulong_nlz (mask ) - 16 - ( SIZEOF_ZEND_LONG == 8 ? 32 : 0 ) ; /* skips over everything */
536537 do {
537538 /* Note that we shift the input forward, so we have to shift the mask as well,
538539 * beyond the to-be-escaped character */
539- int len = __builtin_ctz (mask );
540+ int len = zend_ulong_ntz (mask );
540541 mask >>= len + 1 ;
541542
542543 smart_str_appendl (buf , s , len + pos );
0 commit comments