Skip to content

Commit 2b55dee

Browse files
authored
Make stripslashes() only dependent on SSE2 configuration. (#10408)
Alex Dowad noticed[1] that the SIMD stripslashes implementation actually only depended on SSE2, and not on SSE4.2 instructions. Remove the checking for SSE4.2 and only check for SSE2. This also greatly simplifies the supporting code. [1] #10313 (comment)
1 parent 670f1aa commit 2b55dee

File tree

1 file changed

+3
-33
lines changed

1 file changed

+3
-33
lines changed

ext/standard/string.c

+3-33
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848

4949
#ifdef __SSE2__
5050
#include <emmintrin.h>
51+
#include "Zend/zend_bitset.h"
5152
#endif
5253

5354
/* this is read-only, so it's ok */
@@ -3472,15 +3473,10 @@ PHPAPI zend_string *php_addcslashes(zend_string *str, const char *what, size_t w
34723473
ZEND_INTRIN_SSE4_2_FUNC_DECL(zend_string *php_addslashes_sse42(zend_string *str));
34733474
zend_string *php_addslashes_default(zend_string *str);
34743475

3475-
ZEND_INTRIN_SSE4_2_FUNC_DECL(void php_stripslashes_sse42(zend_string *str));
3476-
void php_stripslashes_default(zend_string *str);
3477-
34783476
# ifdef ZEND_INTRIN_SSE4_2_FUNC_PROTO
34793477
PHPAPI zend_string *php_addslashes(zend_string *str) __attribute__((ifunc("resolve_addslashes")));
3480-
PHPAPI void php_stripslashes(zend_string *str) __attribute__((ifunc("resolve_stripslashes")));
34813478

34823479
typedef zend_string *(*php_addslashes_func_t)(zend_string *);
3483-
typedef void (*php_stripslashes_func_t)(zend_string *);
34843480

34853481
ZEND_NO_SANITIZE_ADDRESS
34863482
ZEND_ATTRIBUTE_UNUSED /* clang mistakenly warns about this */
@@ -3490,36 +3486,21 @@ static php_addslashes_func_t resolve_addslashes(void) {
34903486
}
34913487
return php_addslashes_default;
34923488
}
3493-
3494-
ZEND_NO_SANITIZE_ADDRESS
3495-
ZEND_ATTRIBUTE_UNUSED /* clang mistakenly warns about this */
3496-
static php_stripslashes_func_t resolve_stripslashes(void) {
3497-
if (zend_cpu_supports_sse42()) {
3498-
return php_stripslashes_sse42;
3499-
}
3500-
return php_stripslashes_default;
3501-
}
35023489
# else /* ZEND_INTRIN_SSE4_2_FUNC_PTR */
35033490

35043491
static zend_string *(*php_addslashes_ptr)(zend_string *str) = NULL;
3505-
static void (*php_stripslashes_ptr)(zend_string *str) = NULL;
35063492

35073493
PHPAPI zend_string *php_addslashes(zend_string *str) {
35083494
return php_addslashes_ptr(str);
35093495
}
3510-
PHPAPI void php_stripslashes(zend_string *str) {
3511-
php_stripslashes_ptr(str);
3512-
}
35133496

35143497
/* {{{ PHP_MINIT_FUNCTION */
35153498
PHP_MINIT_FUNCTION(string_intrin)
35163499
{
35173500
if (zend_cpu_supports_sse42()) {
35183501
php_addslashes_ptr = php_addslashes_sse42;
3519-
php_stripslashes_ptr = php_stripslashes_sse42;
35203502
} else {
35213503
php_addslashes_ptr = php_addslashes_default;
3522-
php_stripslashes_ptr = php_stripslashes_default;
35233504
}
35243505
return SUCCESS;
35253506
}
@@ -3872,12 +3853,8 @@ static zend_always_inline char *php_stripslashes_impl(const char *str, char *out
38723853
return out;
38733854
}
38743855

3875-
#if defined(ZEND_INTRIN_SSE4_2_NATIVE) || defined(ZEND_INTRIN_SSE4_2_RESOLVER)
3876-
# ifdef ZEND_INTRIN_SSE4_2_NATIVE
3856+
#ifdef __SSE2__
38773857
PHPAPI void php_stripslashes(zend_string *str)
3878-
# elif defined(ZEND_INTRIN_SSE4_2_RESOLVER)
3879-
void php_stripslashes_sse42(zend_string *str)
3880-
# endif
38813858
{
38823859
const char *s = ZSTR_VAL(str);
38833860
char *t = ZSTR_VAL(str);
@@ -3928,22 +3905,15 @@ void php_stripslashes_sse42(zend_string *str)
39283905
ZSTR_VAL(str)[ZSTR_LEN(str)] = '\0';
39293906
}
39303907
}
3931-
#endif
3932-
3933-
#ifndef ZEND_INTRIN_SSE4_2_NATIVE
3934-
# ifdef ZEND_INTRIN_SSE4_2_RESOLVER
3935-
void php_stripslashes_default(zend_string *str) /* {{{ */
3936-
# else
3908+
#else
39373909
PHPAPI void php_stripslashes(zend_string *str)
3938-
# endif
39393910
{
39403911
const char *t = php_stripslashes_impl(ZSTR_VAL(str), ZSTR_VAL(str), ZSTR_LEN(str));
39413912
if (t != (ZSTR_VAL(str) + ZSTR_LEN(str))) {
39423913
ZSTR_LEN(str) = t - ZSTR_VAL(str);
39433914
ZSTR_VAL(str)[ZSTR_LEN(str)] = '\0';
39443915
}
39453916
}
3946-
/* }}} */
39473917
#endif
39483918
/* }}} */
39493919

0 commit comments

Comments
 (0)