From d7ddf83dde6bd0829d991a6c45aa8baa85705ff9 Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Fri, 5 Jul 2024 15:18:26 +0200 Subject: [PATCH] Autotools: Refactor AVX-512 checks (#14831) * Autotools: Refactor AVX-512 checks - CS synced - checks wrapped in AC_CACHE_CHECK - CPP macros PHP_HAVE_AVX512_SUPPORTS and PHP_HAVE_AVX512_VBMI_SUPPORTS are now either defined to 1 or undefined to avoid manual defining on Windows (previously they should be either 0 or 1) * [skip ci] Add basic macros help texts --- UPGRADING.INTERNALS | 2 + Zend/zend_cpuinfo.h | 4 +- Zend/zend_portability.h | 4 +- build/php.m4 | 94 +++++++++++++++++++++-------------------- 4 files changed, 55 insertions(+), 49 deletions(-) diff --git a/UPGRADING.INTERNALS b/UPGRADING.INTERNALS index 0726a21738e..6470bb26b67 100644 --- a/UPGRADING.INTERNALS +++ b/UPGRADING.INTERNALS @@ -141,6 +141,8 @@ PHP 8.4 INTERNALS UPGRADE NOTES - Symbols PHP_FPM_SYSTEMD, PHP_FPM_USER, and PHP_FPM_GROUP removed. - Symbol PTHREADS has been removed. - Symbol HAVE_STRPTIME_DECL_FAILS has been removed (use HAVE_DECL_STRPTIME). + - Symbols PHP_HAVE_AVX512_SUPPORTS and PHP_HAVE_AVX512_VBMI_SUPPORTS are now + either defined to 1 or undefined. - M4 macro PHP_DEFINE (atomic includes) removed (use AC_DEFINE and config.h). - M4 macro PHP_WITH_SHARED has been removed (use PHP_ARG_WITH). - M4 macro PHP_STRUCT_FLOCK has been removed (use AC_CHECK_TYPES). diff --git a/Zend/zend_cpuinfo.h b/Zend/zend_cpuinfo.h index 9d221c59e54..a854739bcc9 100644 --- a/Zend/zend_cpuinfo.h +++ b/Zend/zend_cpuinfo.h @@ -180,7 +180,7 @@ static inline int zend_cpu_supports_avx2(void) { return __builtin_cpu_supports("avx2"); } -#if PHP_HAVE_AVX512_SUPPORTS +#ifdef PHP_HAVE_AVX512_SUPPORTS ZEND_NO_SANITIZE_ADDRESS static inline int zend_cpu_supports_avx512(void) { #if PHP_HAVE_BUILTIN_CPU_INIT @@ -192,7 +192,7 @@ static inline int zend_cpu_supports_avx512(void) { } #endif -#if PHP_HAVE_AVX512_VBMI_SUPPORTS +#ifdef PHP_HAVE_AVX512_VBMI_SUPPORTS ZEND_NO_SANITIZE_ADDRESS static inline int zend_cpu_supports_avx512_vbmi(void) { #if PHP_HAVE_BUILTIN_CPU_INIT diff --git a/Zend/zend_portability.h b/Zend/zend_portability.h index 4f785d13963..84ca7047492 100644 --- a/Zend/zend_portability.h +++ b/Zend/zend_portability.h @@ -675,7 +675,7 @@ extern "C++" { # define ZEND_INTRIN_AVX2_FUNC_DECL(func) #endif -#if PHP_HAVE_AVX512_SUPPORTS && defined(HAVE_FUNC_ATTRIBUTE_TARGET) || defined(ZEND_WIN32) +#if defined(PHP_HAVE_AVX512_SUPPORTS) && defined(HAVE_FUNC_ATTRIBUTE_TARGET) || defined(ZEND_WIN32) #define ZEND_INTRIN_AVX512_RESOLVER 1 #endif @@ -695,7 +695,7 @@ extern "C++" { # define ZEND_INTRIN_AVX512_FUNC_DECL(func) #endif -#if PHP_HAVE_AVX512_VBMI_SUPPORTS && defined(HAVE_FUNC_ATTRIBUTE_TARGET) +#if defined(PHP_HAVE_AVX512_VBMI_SUPPORTS) && defined(HAVE_FUNC_ATTRIBUTE_TARGET) #define ZEND_INTRIN_AVX512_VBMI_RESOLVER 1 #endif diff --git a/build/php.m4 b/build/php.m4 index f2d326d389d..880db91ae8c 100644 --- a/build/php.m4 +++ b/build/php.m4 @@ -2750,56 +2750,60 @@ AC_DEFUN([PHP_PATCH_CONFIG_HEADERS], [ dnl dnl PHP_CHECK_AVX512_SUPPORTS dnl -AC_DEFUN([PHP_CHECK_AVX512_SUPPORTS], [ - AC_MSG_CHECKING([for avx512 supports in compiler]) - save_CFLAGS="$CFLAGS" - CFLAGS="-mavx512f -mavx512cd -mavx512vl -mavx512dq -mavx512bw $CFLAGS" - - AC_LINK_IFELSE([AC_LANG_SOURCE([[ - #include - int main(void) { - __m512i mask = _mm512_set1_epi32(0x1); - char out[32]; - _mm512_storeu_si512(out, _mm512_shuffle_epi8(mask, mask)); - return 0; - }]])], [ - have_avx512_supports=1 - AC_MSG_RESULT([yes]) - ], [ - have_avx512_supports=0 - AC_MSG_RESULT([no]) - ]) - - CFLAGS="$save_CFLAGS" - - AC_DEFINE_UNQUOTED([PHP_HAVE_AVX512_SUPPORTS], - [$have_avx512_supports], [Whether the compiler supports AVX512]) +dnl Check whether the compiler supports the AVX-512 extensions and define +dnl PHP_HAVE_AVX512_SUPPORTS to 1 if found. Note that this is a compiler check, +dnl not a runtime check where additional adjustments are done in the C code. +dnl +AC_DEFUN([PHP_CHECK_AVX512_SUPPORTS], +[AC_CACHE_CHECK([whether compiler supports AVX-512], +[php_cv_have_avx512], +[save_CFLAGS="$CFLAGS" +CFLAGS="-mavx512f -mavx512cd -mavx512vl -mavx512dq -mavx512bw $CFLAGS" +AC_LINK_IFELSE([AC_LANG_SOURCE([[ + #include + int main(void) { + __m512i mask = _mm512_set1_epi32(0x1); + char out[32]; + _mm512_storeu_si512(out, _mm512_shuffle_epi8(mask, mask)); + return 0; + }]])], + [php_cv_have_avx512=yes], + [php_cv_have_avx512=no]) +CFLAGS="$save_CFLAGS" +]) +AS_VAR_IF([php_cv_have_avx512], [yes], + [AC_DEFINE([PHP_HAVE_AVX512_SUPPORTS], [1], + [Define to 1 if the compiler supports AVX-512.])]) ]) dnl dnl PHP_CHECK_AVX512_VBMI_SUPPORTS dnl -AC_DEFUN([PHP_CHECK_AVX512_VBMI_SUPPORTS], [ - AC_MSG_CHECKING([for avx512 vbmi supports in compiler]) - save_CFLAGS="$CFLAGS" - CFLAGS="-mavx512f -mavx512cd -mavx512vl -mavx512dq -mavx512bw -mavx512vbmi $CFLAGS" - AC_LINK_IFELSE([AC_LANG_SOURCE([[ - #include - int main(void) { - __m512i mask = _mm512_set1_epi32(0x1); - char out[32]; - _mm512_storeu_si512(out, _mm512_permutexvar_epi8(mask, mask)); - return 0; - }]])], [ - have_avx512_vbmi_supports=1 - AC_MSG_RESULT([yes]) - ], [ - have_avx512_vbmi_supports=0 - AC_MSG_RESULT([no]) - ]) - CFLAGS="$save_CFLAGS" - AC_DEFINE_UNQUOTED([PHP_HAVE_AVX512_VBMI_SUPPORTS], - [$have_avx512_vbmi_supports], [Whether the compiler supports AVX512 VBMI]) +dnl Check whether the compiler supports the AVX-512 extensions with the VBMI +dnl instruction set and define PHP_HAVE_AVX512_VBMI_SUPPORTS to 1 if found. Note +dnl that this is a compiler check, not a runtime check where additional +dnl adjustments are done in the C code. +dnl +AC_DEFUN([PHP_CHECK_AVX512_VBMI_SUPPORTS], +[AC_CACHE_CHECK([whether compiler supports AVX-512 VBMI], +[php_cv_have_avx512vbmi], +[save_CFLAGS="$CFLAGS" +CFLAGS="-mavx512f -mavx512cd -mavx512vl -mavx512dq -mavx512bw -mavx512vbmi $CFLAGS" +AC_LINK_IFELSE([AC_LANG_SOURCE([[ + #include + int main(void) { + __m512i mask = _mm512_set1_epi32(0x1); + char out[32]; + _mm512_storeu_si512(out, _mm512_permutexvar_epi8(mask, mask)); + return 0; + }]])], + [php_cv_have_avx512vbmi=yes], + [php_cv_have_avx512vbmi=no]) +CFLAGS="$save_CFLAGS" +]) +AS_VAR_IF([php_cv_have_avx512vbmi], [yes], + [AC_DEFINE([PHP_HAVE_AVX512_VBMI_SUPPORTS], [1], + [Define to 1 if the compiler supports AVX-512 VBMI.])]) ]) dnl