Skip to content

Commit 152adba

Browse files
committed
Make stripslashes() only dependent on SSE2 configuration.
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] php#10313 (comment)
1 parent 9f02a11 commit 152adba

File tree

1 file changed

+2
-33
lines changed

1 file changed

+2
-33
lines changed

ext/standard/string.c

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3472,15 +3472,10 @@ PHPAPI zend_string *php_addcslashes(zend_string *str, const char *what, size_t w
34723472
ZEND_INTRIN_SSE4_2_FUNC_DECL(zend_string *php_addslashes_sse42(zend_string *str));
34733473
zend_string *php_addslashes_default(zend_string *str);
34743474

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

34823478
typedef zend_string *(*php_addslashes_func_t)(zend_string *);
3483-
typedef void (*php_stripslashes_func_t)(zend_string *);
34843479

34853480
ZEND_NO_SANITIZE_ADDRESS
34863481
ZEND_ATTRIBUTE_UNUSED /* clang mistakenly warns about this */
@@ -3490,36 +3485,21 @@ static php_addslashes_func_t resolve_addslashes(void) {
34903485
}
34913486
return php_addslashes_default;
34923487
}
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-
}
35023488
# else /* ZEND_INTRIN_SSE4_2_FUNC_PTR */
35033489

35043490
static zend_string *(*php_addslashes_ptr)(zend_string *str) = NULL;
3505-
static void (*php_stripslashes_ptr)(zend_string *str) = NULL;
35063491

35073492
PHPAPI zend_string *php_addslashes(zend_string *str) {
35083493
return php_addslashes_ptr(str);
35093494
}
3510-
PHPAPI void php_stripslashes(zend_string *str) {
3511-
php_stripslashes_ptr(str);
3512-
}
35133495

35143496
/* {{{ PHP_MINIT_FUNCTION */
35153497
PHP_MINIT_FUNCTION(string_intrin)
35163498
{
35173499
if (zend_cpu_supports_sse42()) {
35183500
php_addslashes_ptr = php_addslashes_sse42;
3519-
php_stripslashes_ptr = php_stripslashes_sse42;
35203501
} else {
35213502
php_addslashes_ptr = php_addslashes_default;
3522-
php_stripslashes_ptr = php_stripslashes_default;
35233503
}
35243504
return SUCCESS;
35253505
}
@@ -3872,12 +3852,8 @@ static zend_always_inline char *php_stripslashes_impl(const char *str, char *out
38723852
return out;
38733853
}
38743854

3875-
#if defined(ZEND_INTRIN_SSE4_2_NATIVE) || defined(ZEND_INTRIN_SSE4_2_RESOLVER)
3876-
# ifdef ZEND_INTRIN_SSE4_2_NATIVE
3855+
#ifdef __SSE2__
38773856
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
38813857
{
38823858
const char *s = ZSTR_VAL(str);
38833859
char *t = ZSTR_VAL(str);
@@ -3928,22 +3904,15 @@ void php_stripslashes_sse42(zend_string *str)
39283904
ZSTR_VAL(str)[ZSTR_LEN(str)] = '\0';
39293905
}
39303906
}
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
3907+
#else
39373908
PHPAPI void php_stripslashes(zend_string *str)
3938-
# endif
39393909
{
39403910
const char *t = php_stripslashes_impl(ZSTR_VAL(str), ZSTR_VAL(str), ZSTR_LEN(str));
39413911
if (t != (ZSTR_VAL(str) + ZSTR_LEN(str))) {
39423912
ZSTR_LEN(str) = t - ZSTR_VAL(str);
39433913
ZSTR_VAL(str)[ZSTR_LEN(str)] = '\0';
39443914
}
39453915
}
3946-
/* }}} */
39473916
#endif
39483917
/* }}} */
39493918

0 commit comments

Comments
 (0)