Check for AVX512F support
This commit is contained in:
parent
80095105bb
commit
1c0677b09f
20
configure.ac
20
configure.ac
@ -433,6 +433,25 @@ return _mm256_movemask_ps(_mm256_cmp_ps(x, y, _CMP_NEQ_OQ));
|
||||
[AC_MSG_RESULT(no)])
|
||||
CFLAGS="$oldcflags"
|
||||
|
||||
oldcflags="$CFLAGS"
|
||||
AX_CHECK_COMPILE_FLAG([-mavx512f], [CFLAGS="$CFLAGS -mavx512f"])
|
||||
AC_MSG_CHECKING(for AVX512F instructions set)
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
|
||||
#ifdef __native_client__
|
||||
# error NativeClient detected - Avoiding AVX512F opcodes
|
||||
#endif
|
||||
#pragma GCC target("avx512f")
|
||||
#include <immintrin.h>
|
||||
]], [[
|
||||
__m512i x = _mm512_setzero_epi32();
|
||||
__m512i y = _mm512_permutexvar_epi64(_mm512_setr_epi64(0, 1, 4, 5, 2, 3, 6, 7), x);
|
||||
]])],
|
||||
[AC_MSG_RESULT(yes)
|
||||
AC_DEFINE([HAVE_AVX512FINTRIN_H], [1], [AVX512F is available])
|
||||
AX_CHECK_COMPILE_FLAG([-mavx512f], [CFLAGS_AVX512F="-mavx512f"])],
|
||||
[AC_MSG_RESULT(no)])
|
||||
CFLAGS="$oldcflags"
|
||||
|
||||
oldcflags="$CFLAGS"
|
||||
AX_CHECK_COMPILE_FLAG([-maes], [CFLAGS="$CFLAGS -maes"])
|
||||
AX_CHECK_COMPILE_FLAG([-mpclmul], [CFLAGS="$CFLAGS -mpclmul"])
|
||||
@ -463,6 +482,7 @@ AC_SUBST(CFLAGS_SSSE3)
|
||||
AC_SUBST(CFLAGS_SSE41)
|
||||
AC_SUBST(CFLAGS_AVX)
|
||||
AC_SUBST(CFLAGS_AVX2)
|
||||
AC_SUBST(CFLAGS_AVX512F)
|
||||
AC_SUBST(CFLAGS_AESNI)
|
||||
AC_SUBST(CFLAGS_PCLMUL)
|
||||
|
||||
|
@ -29,6 +29,9 @@ int sodium_runtime_has_avx(void);
|
||||
SODIUM_EXPORT __attribute__((weak))
|
||||
int sodium_runtime_has_avx2(void);
|
||||
|
||||
SODIUM_EXPORT __attribute__((weak))
|
||||
int sodium_runtime_has_avx512f(void);
|
||||
|
||||
SODIUM_EXPORT __attribute__((weak))
|
||||
int sodium_runtime_has_pclmul(void);
|
||||
|
||||
|
@ -16,6 +16,7 @@ typedef struct CPUFeatures_ {
|
||||
int has_sse41;
|
||||
int has_avx;
|
||||
int has_avx2;
|
||||
int has_avx512f;
|
||||
int has_pclmul;
|
||||
int has_aesni;
|
||||
} CPUFeatures;
|
||||
@ -23,6 +24,7 @@ typedef struct CPUFeatures_ {
|
||||
static CPUFeatures _cpu_features;
|
||||
|
||||
#define CPUID_EBX_AVX2 0x00000020
|
||||
#define CPUID_EBX_AVX512F 0x00010000
|
||||
|
||||
#define CPUID_ECX_SSE3 0x00000001
|
||||
#define CPUID_ECX_PCLMUL 0x00000002
|
||||
@ -176,6 +178,16 @@ _sodium_runtime_intel_cpu_features(CPUFeatures * const cpu_features)
|
||||
}
|
||||
#endif
|
||||
|
||||
cpu_features->has_avx512f = 0;
|
||||
#ifdef HAVE_AVX512FINTRIN_H
|
||||
if (cpu_features->has_avx2) {
|
||||
unsigned int cpu_info7[4];
|
||||
|
||||
_cpuid(cpu_info7, 0x00000007);
|
||||
cpu_features->has_avx512f = ((cpu_info7[1] & CPUID_EBX_AVX512F) != 0x0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WMMINTRIN_H
|
||||
cpu_features->has_pclmul = ((cpu_info[2] & CPUID_ECX_PCLMUL) != 0x0);
|
||||
cpu_features->has_aesni = ((cpu_info[2] & CPUID_ECX_AESNI) != 0x0);
|
||||
@ -241,6 +253,12 @@ sodium_runtime_has_avx2(void)
|
||||
return _cpu_features.has_avx2;
|
||||
}
|
||||
|
||||
int
|
||||
sodium_runtime_has_avx512f(void)
|
||||
{
|
||||
return _cpu_features.has_avx512f;
|
||||
}
|
||||
|
||||
int
|
||||
sodium_runtime_has_pclmul(void)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user