Skip to content

base64: add avx512 and vbmi version. #6361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions Zend/zend_cpuinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ typedef enum _zend_cpu_feature {

/* EBX */
ZEND_CPU_FEATURE_AVX2 = (1<<5 | ZEND_CPU_EBX_MASK),
ZEND_CPU_FEATURE_AVX512F = (1<<16 | ZEND_CPU_EBX_MASK),
ZEND_CPU_FEATURE_AVX512DQ = (1<<17 | ZEND_CPU_EBX_MASK),
ZEND_CPU_FEATURE_AVX512CD = (1<<28 | ZEND_CPU_EBX_MASK),
/* intentionally don't support = (1<<30 | ZEND_CPU_EBX_MASK) */
/* intentionally don't support = (1<<31 | ZEND_CPU_EBX_MASK) */

/* EDX */
ZEND_CPU_FEATURE_FPU = (1<<0 | ZEND_CPU_EDX_MASK),
Expand Down Expand Up @@ -174,6 +179,29 @@ static inline int zend_cpu_supports_avx2(void) {
#endif
return __builtin_cpu_supports("avx2");
}

#if PHP_HAVE_AVX512_SUPPORTS
ZEND_NO_SANITIZE_ADDRESS
static inline int zend_cpu_supports_avx512(void) {
#if PHP_HAVE_BUILTIN_CPU_INIT
__builtin_cpu_init();
#endif
return __builtin_cpu_supports("avx512f") && __builtin_cpu_supports("avx512dq")
&& __builtin_cpu_supports("avx512cd") && __builtin_cpu_supports("avx512bw")
&& __builtin_cpu_supports("avx512vl");
}
#endif

#if PHP_HAVE_AVX512_VBMI_SUPPORTS
ZEND_NO_SANITIZE_ADDRESS
static inline int zend_cpu_supports_avx512_vbmi(void) {
#if PHP_HAVE_BUILTIN_CPU_INIT
__builtin_cpu_init();
#endif
return zend_cpu_supports_avx512() && __builtin_cpu_supports("avx512vbmi");
}
#endif

#else

static inline int zend_cpu_supports_sse2(void) {
Expand Down Expand Up @@ -203,6 +231,16 @@ static inline int zend_cpu_supports_avx(void) {
static inline int zend_cpu_supports_avx2(void) {
return zend_cpu_supports(ZEND_CPU_FEATURE_AVX2);
}

static inline int zend_cpu_supports_avx512(void) {
/* TODO: avx512_bw/avx512_vl use bit 30/31 which are reserved for mask */
return 0;
}

static zend_always_inline int zend_cpu_supports_avx512_vbmi(void) {
/* TODO: avx512_vbmi use ECX of cpuid 7 */
return 0;
}
#endif

/* __builtin_cpu_supports has pclmul from gcc9 */
Expand Down
40 changes: 40 additions & 0 deletions Zend/zend_portability.h
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,46 @@ extern "C++" {
# define ZEND_INTRIN_AVX2_FUNC_DECL(func)
#endif

#if PHP_HAVE_AVX512_SUPPORTS && defined(HAVE_FUNC_ATTRIBUTE_TARGET) || defined(ZEND_WIN32)
#define ZEND_INTRIN_AVX512_RESOLVER 1
#endif

#if defined(ZEND_INTRIN_AVX512_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET)
# define ZEND_INTRIN_AVX512_FUNC_PROTO 1
#elif defined(ZEND_INTRIN_AVX512_RESOLVER)
# define ZEND_INTRIN_AVX512_FUNC_PTR 1
#endif

#ifdef ZEND_INTRIN_AVX512_RESOLVER
# ifdef HAVE_FUNC_ATTRIBUTE_TARGET
# define ZEND_INTRIN_AVX512_FUNC_DECL(func) ZEND_API func __attribute__((target("avx512f,avx512cd,avx512vl,avx512dq,avx512bw")))
# else
# define ZEND_INTRIN_AVX512_FUNC_DECL(func) func
# endif
#else
# define ZEND_INTRIN_AVX512_FUNC_DECL(func)
#endif

#if PHP_HAVE_AVX512_VBMI_SUPPORTS && defined(HAVE_FUNC_ATTRIBUTE_TARGET)
#define ZEND_INTRIN_AVX512_VBMI_RESOLVER 1
#endif

#if defined(ZEND_INTRIN_AVX512_VBMI_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET)
# define ZEND_INTRIN_AVX512_VBMI_FUNC_PROTO 1
#elif defined(ZEND_INTRIN_AVX512_VBMI_RESOLVER)
# define ZEND_INTRIN_AVX512_VBMI_FUNC_PTR 1
#endif

#ifdef ZEND_INTRIN_AVX512_VBMI_RESOLVER
# ifdef HAVE_FUNC_ATTRIBUTE_TARGET
# define ZEND_INTRIN_AVX512_VBMI_FUNC_DECL(func) ZEND_API func __attribute__((target("avx512f,avx512cd,avx512vl,avx512dq,avx512bw,avx512vbmi")))
# else
# define ZEND_INTRIN_AVX512_VBMI_FUNC_DECL(func) func
# endif
#else
# define ZEND_INTRIN_AVX512_VBMI_FUNC_DECL(func)
#endif

/* Intrinsics macros end. */

#ifdef ZEND_WIN32
Expand Down
55 changes: 55 additions & 0 deletions build/php.m4
Original file line number Diff line number Diff line change
Expand Up @@ -2807,3 +2807,58 @@ AC_DEFUN([PHP_CHECK_PROCCTL],
AC_MSG_RESULT([no])
])
])

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 <immintrin.h>
int main() {
__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
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 <immintrin.h>
int main() {
__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])
])
4 changes: 4 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,10 @@ dnl Check prctl
PHP_CHECK_PRCTL
dnl Check procctl
PHP_CHECK_PROCCTL
dnl Check AVX512
PHP_CHECK_AVX512_SUPPORTS
dnl Check AVX512 VBMI
PHP_CHECK_AVX512_VBMI_SUPPORTS

dnl Check for __alignof__ support in the compiler
AC_CACHE_CHECK(whether the compiler supports __alignof__, ac_cv_alignof_exists,[
Expand Down
Loading