3434#include "private.h"
3535#include <stdbool.h>
3636#include <stddef.h>
37- #ifdef __SSE2__
38- # include <emmintrin.h>
39- #endif
4037
4138/* Convert strings to bc numbers. Base 10 only.*/
4239static const char * bc_count_digits (const char * str , const char * end )
4340{
4441 /* Process in bulk */
45- #ifdef __SSE2__
46- const __m128i offset = _mm_set1_epi8 ((signed char ) (SCHAR_MIN - '0' ));
42+ #ifdef HAVE_BC_SIMD128_T
43+ const bc_simd_128_t offset = bc_set_8x16 ((signed char ) (SCHAR_MIN - '0' ));
4744 /* we use the less than comparator, so add 1 */
48- const __m128i threshold = _mm_set1_epi8 (SCHAR_MIN + ('9' + 1 - '0' ));
45+ const bc_simd_128_t threshold = bc_set_8x16 (SCHAR_MIN + ('9' + 1 - '0' ));
4946
50- while (str + sizeof (__m128i ) <= end ) {
51- __m128i bytes = _mm_loadu_si128 ((const __m128i * ) str );
47+ while (str + sizeof (bc_simd_128_t ) <= end ) {
48+ bc_simd_128_t bytes = bc_load_u128 ((const bc_simd_128_t * ) str );
5249 /* Wrapping-add the offset to the bytes, such that all bytes below '0' are positive and others are negative.
5350 * More specifically, '0' will be -128 and '9' will be -119. */
54- bytes = _mm_add_epi8 (bytes , offset );
51+ bytes = bc_add_8x16 (bytes , offset );
5552 /* Now mark all bytes that are <= '9', i.e. <= -119, i.e. < -118, i.e. the threshold. */
56- bytes = _mm_cmplt_epi8 (bytes , threshold );
53+ bytes = bc_cmplt_8x16 (bytes , threshold );
5754
58- int mask = _mm_movemask_epi8 (bytes );
55+ int mask = bc_movemask_8x16 (bytes );
5956 if (mask != 0xffff ) {
6057 /* At least one of the bytes is not within range. Move to the first offending byte. */
6158#ifdef PHP_HAVE_BUILTIN_CTZL
@@ -65,7 +62,7 @@ static const char *bc_count_digits(const char *str, const char *end)
6562#endif
6663 }
6764
68- str += sizeof (__m128i );
65+ str += sizeof (bc_simd_128_t );
6966 }
7067#endif
7168
@@ -79,19 +76,19 @@ static const char *bc_count_digits(const char *str, const char *end)
7976static inline const char * bc_skip_zero_reverse (const char * scanner , const char * stop )
8077{
8178 /* Check in bulk */
82- #ifdef __SSE2__
83- const __m128i c_zero_repeat = _mm_set1_epi8 ('0' );
84- while (scanner - sizeof (__m128i ) >= stop ) {
85- scanner -= sizeof (__m128i );
86- __m128i bytes = _mm_loadu_si128 ((const __m128i * ) scanner );
79+ #ifdef HAVE_BC_SIMD128_T
80+ const bc_simd_128_t c_zero_repeat = bc_set_8x16 ('0' );
81+ while (scanner - sizeof (bc_simd_128_t ) >= stop ) {
82+ scanner -= sizeof (bc_simd_128_t );
83+ bc_simd_128_t bytes = bc_load_u128 ((const bc_simd_128_t * ) scanner );
8784 /* Checks if all numeric strings are equal to '0'. */
88- bytes = _mm_cmpeq_epi8 (bytes , c_zero_repeat );
85+ bytes = bc_cmpeq_8x16 (bytes , c_zero_repeat );
8986
90- int mask = _mm_movemask_epi8 (bytes );
87+ int mask = bc_movemask_8x16 (bytes );
9188 /* The probability of having 16 trailing 0s in a row is very low, so we use EXPECTED. */
9289 if (EXPECTED (mask != 0xffff )) {
9390 /* Move the pointer back and check each character in loop. */
94- scanner += sizeof (__m128i );
91+ scanner += sizeof (bc_simd_128_t );
9592 break ;
9693 }
9794 }
0 commit comments