Skip to content

Commit

Permalink
Avoid direct calls to zend_cpu_supports()
Browse files Browse the repository at this point in the history
While the use of zend_cpu_supports_*() is only strictly necessary
inside ifunc resolvers, where the cpu state has not been initialized
yet, we should prefer the compiler builtins in all cases.
  • Loading branch information
nikic committed Nov 27, 2020
1 parent f35b194 commit 2772f7c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ext/opcache/jit/zend_jit_x86.dasc
Original file line number Diff line number Diff line change
Expand Up @@ -2849,12 +2849,12 @@ extern char *_tls_end;

static int zend_jit_setup(void)
{
if (!zend_cpu_supports(ZEND_CPU_FEATURE_SSE2)) {
if (!zend_cpu_supports_sse2()) {
zend_error(E_CORE_ERROR, "CPU doesn't support SSE2");
return FAILURE;
}
allowed_opt_flags = 0;
if (zend_cpu_supports(ZEND_CPU_FEATURE_AVX)) {
if (zend_cpu_supports_avx()) {
allowed_opt_flags |= ZEND_JIT_CPU_AVX;
}

Expand Down
2 changes: 1 addition & 1 deletion ext/standard/crc32_x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ size_t crc32_x86_simd_update(X86_CRC32_TYPE type, uint32_t *crc, const unsigned
/* {{{ PHP_MINIT_FUNCTION */
PHP_MINIT_FUNCTION(crc32_x86_intrin)
{
if (zend_cpu_supports(ZEND_CPU_FEATURE_SSE42) && zend_cpu_supports(ZEND_CPU_FEATURE_PCLMULQDQ)) {
if (zend_cpu_supports_sse42() && zend_cpu_supports_pclmul()) {
crc32_x86_simd_ptr = crc32_sse42_pclmul_update;
}
return SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -3615,7 +3615,7 @@ PHPAPI void php_stripslashes(zend_string *str) {
/* {{{ PHP_MINIT_FUNCTION */
PHP_MINIT_FUNCTION(string_intrin)
{
if (zend_cpu_supports(ZEND_CPU_FEATURE_SSE42)) {
if (zend_cpu_supports_sse42()) {
php_addslashes_ptr = php_addslashes_sse42;
php_stripslashes_ptr = php_stripslashes_sse42;
} else {
Expand Down

0 comments on commit 2772f7c

Please sign in to comment.