Add sodium_runtime_has_avx()

This commit is contained in:
Frank Denis 2015-11-03 14:18:43 +01:00
parent 754b386089
commit 049fd8fd6a
3 changed files with 29 additions and 0 deletions

View File

@ -331,6 +331,19 @@ AS_IF([test "x$EMSCRIPTEN" = "x"],[
[AC_MSG_RESULT(no)])
CFLAGS="$oldcflags"
oldcflags="$CFLAGS"
AX_CHECK_COMPILE_FLAG([-mavx], [CFLAGS="$CFLAGS -mavx"])
AC_MSG_CHECKING(for AVX instructions set)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#pragma GCC target("avx")
#include <immintrin.h>
]], [[ _mm256_zeroall(); ]])],
[AC_MSG_RESULT(yes)
AC_DEFINE([HAVE_AVXINTRIN_H], [1], [AVX is available])
AX_CHECK_COMPILE_FLAG([-mavx], [CFLAGS_AVX="-mavx"])],
[AC_MSG_RESULT(no)])
CFLAGS="$oldcflags"
oldcflags="$CFLAGS"
AX_CHECK_COMPILE_FLAG([-maes], [CFLAGS="$CFLAGS -maes"])
AX_CHECK_COMPILE_FLAG([-mpclmul], [CFLAGS="$CFLAGS -mpclmul"])

View File

@ -23,6 +23,9 @@ int sodium_runtime_has_ssse3(void);
SODIUM_EXPORT
int sodium_runtime_has_sse41(void);
SODIUM_EXPORT
int sodium_runtime_has_avx(void);
SODIUM_EXPORT
int sodium_runtime_has_pclmul(void);

View File

@ -12,6 +12,7 @@ typedef struct CPUFeatures_ {
int has_sse3;
int has_ssse3;
int has_sse41;
int has_avx;
int has_pclmul;
int has_aesni;
} CPUFeatures;
@ -22,6 +23,7 @@ static CPUFeatures _cpu_features;
#define CPUIDECX_SSE3 0x00000001
#define CPUIDECX_SSSE3 0x00000200
#define CPUIDECX_SSE41 0x00080000
#define CPUIDECX_AVX 0x10000000
#define CPUIDECX_PCLMUL 0x00000002
#define CPUIDECX_AESNI 0x02000000
@ -124,6 +126,12 @@ _sodium_runtime_intel_cpu_features(CPUFeatures * const cpu_features)
cpu_features->has_sse41 = ((cpu_info[2] & CPUIDECX_SSE41) != 0x0);
#endif
#ifndef HAVE_AVXINTRIN_H
cpu_features->has_avx = 0;
#else
cpu_features->has_avx = ((cpu_info[2] & CPUIDECX_AVX) != 0x0);
#endif
#ifndef HAVE_WMMINTRIN_H
cpu_features->has_pclmul = 0;
cpu_features->has_aesni = 0;
@ -172,6 +180,11 @@ sodium_runtime_has_sse41(void) {
return _cpu_features.has_sse41;
}
int
sodium_runtime_has_avx(void) {
return _cpu_features.has_avx;
}
int
sodium_runtime_has_pclmul(void) {
return _cpu_features.has_pclmul;