Check for AESNI & PCLMUL presence/usability
This commit is contained in:
parent
ab2e86748e
commit
e83e9b2d8e
20
configure.ac
20
configure.ac
@ -211,9 +211,6 @@ AX_CHECK_COMPILE_FLAG([-Wwrite-strings], [CFLAGS="$CFLAGS -Wwrite-strings"])
|
|||||||
AX_CHECK_COMPILE_FLAG([-Wdiv-by-zero], [CFLAGS="$CFLAGS -Wdiv-by-zero"])
|
AX_CHECK_COMPILE_FLAG([-Wdiv-by-zero], [CFLAGS="$CFLAGS -Wdiv-by-zero"])
|
||||||
AX_CHECK_COMPILE_FLAG([-Wsometimes-uninitialized], [CFLAGS="$CFLAGS -Wsometimes-uninitialized"])
|
AX_CHECK_COMPILE_FLAG([-Wsometimes-uninitialized], [CFLAGS="$CFLAGS -Wsometimes-uninitialized"])
|
||||||
|
|
||||||
AC_MSG_CHECKING([Checking if we can compile for westmere])
|
|
||||||
AX_CHECK_COMPILE_FLAG([-march=westmere $CFLAGS], [CFLAGS="-march=westmere $CFLAGS"])
|
|
||||||
|
|
||||||
AC_ARG_VAR([CWFLAGS], [define to compilation flags for generating extra warnings])
|
AC_ARG_VAR([CWFLAGS], [define to compilation flags for generating extra warnings])
|
||||||
|
|
||||||
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wall], [CWFLAGS="$CWFLAGS -Wall"])
|
AX_CHECK_COMPILE_FLAG([$CWFLAGS -Wall], [CWFLAGS="$CWFLAGS -Wall"])
|
||||||
@ -301,6 +298,23 @@ AS_IF([test "x$EMSCRIPTEN" = "x"],[
|
|||||||
[AC_MSG_RESULT(yes)
|
[AC_MSG_RESULT(yes)
|
||||||
AC_DEFINE([HAVE_TMMINTRIN_H], [1], [ssse3 is available])],
|
AC_DEFINE([HAVE_TMMINTRIN_H], [1], [ssse3 is available])],
|
||||||
[AC_MSG_RESULT(no)])
|
[AC_MSG_RESULT(no)])
|
||||||
|
|
||||||
|
AC_MSG_CHECKING(for AESNI instructions set and PCLMULQDQ)
|
||||||
|
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
|
||||||
|
#pragma GCC target("aes")
|
||||||
|
#pragma GCC target("pclmul")
|
||||||
|
#ifndef __AES__
|
||||||
|
# define __AES__
|
||||||
|
#endif
|
||||||
|
#ifndef __PCLMUL__
|
||||||
|
# define __PCLMUL__
|
||||||
|
#endif
|
||||||
|
#include <wmmintrin.h>
|
||||||
|
]], [[ __m128i x = _mm_aesimc_si128(_mm_setzero_si128());
|
||||||
|
__m128i y = _mm_clmulepi64_si128(_mm_setzero_si128(), _mm_setzero_si128(), 0);]])],
|
||||||
|
[AC_MSG_RESULT(yes)
|
||||||
|
AC_DEFINE([HAVE_WMMINTRIN_H], [1], [aesni is available])],
|
||||||
|
[AC_MSG_RESULT(no)])
|
||||||
])
|
])
|
||||||
|
|
||||||
AC_CHECK_HEADERS([sys/mman.h])
|
AC_CHECK_HEADERS([sys/mman.h])
|
||||||
|
@ -3,6 +3,23 @@
|
|||||||
* AES256-GCM, based on original code by Romain Dolbeau
|
* AES256-GCM, based on original code by Romain Dolbeau
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#pragma GCC target("sse")
|
||||||
|
#pragma GCC target("sse2")
|
||||||
|
#pragma GCC target("ssse3")
|
||||||
|
#pragma GCC target("sse4.1")
|
||||||
|
#pragma GCC target("aes")
|
||||||
|
#pragma GCC target("pclmul")
|
||||||
|
|
||||||
|
#ifndef __SSE4_1__
|
||||||
|
# define __SSE4_1__
|
||||||
|
#endif
|
||||||
|
#ifndef __AES__
|
||||||
|
# define __AES__
|
||||||
|
#endif
|
||||||
|
#ifndef __PCLMUL__
|
||||||
|
# define __PCLMUL__
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <immintrin.h>
|
#include <immintrin.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -20,6 +20,12 @@ int sodium_runtime_has_sse2(void);
|
|||||||
SODIUM_EXPORT
|
SODIUM_EXPORT
|
||||||
int sodium_runtime_has_sse3(void);
|
int sodium_runtime_has_sse3(void);
|
||||||
|
|
||||||
|
SODIUM_EXPORT
|
||||||
|
int sodium_runtime_has_pclmul(void);
|
||||||
|
|
||||||
|
SODIUM_EXPORT
|
||||||
|
int sodium_runtime_has_aesni(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -10,12 +10,16 @@ typedef struct CPUFeatures_ {
|
|||||||
int has_neon;
|
int has_neon;
|
||||||
int has_sse2;
|
int has_sse2;
|
||||||
int has_sse3;
|
int has_sse3;
|
||||||
|
int has_pclmul;
|
||||||
|
int has_aesni;
|
||||||
} CPUFeatures;
|
} CPUFeatures;
|
||||||
|
|
||||||
static CPUFeatures _cpu_features;
|
static CPUFeatures _cpu_features;
|
||||||
|
|
||||||
#define CPUID_SSE2 0x04000000
|
#define CPUID_SSE2 0x04000000
|
||||||
#define CPUIDECX_SSE3 0x00000001
|
#define CPUIDECX_SSE3 0x00000001
|
||||||
|
#define CPUIDECX_PCLMUL 0x00000002
|
||||||
|
#define CPUIDECX_AESNI 0x02000000
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_sodium_runtime_arm_cpu_features(CPUFeatures * const cpu_features)
|
_sodium_runtime_arm_cpu_features(CPUFeatures * const cpu_features)
|
||||||
@ -104,6 +108,14 @@ _sodium_runtime_intel_cpu_features(CPUFeatures * const cpu_features)
|
|||||||
cpu_features->has_sse3 = ((cpu_info[2] & CPUIDECX_SSE3) != 0x0);
|
cpu_features->has_sse3 = ((cpu_info[2] & CPUIDECX_SSE3) != 0x0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_WMMINTRIN_H
|
||||||
|
cpu_features->has_pclmul = 0;
|
||||||
|
cpu_features->has_aesni = 0;
|
||||||
|
#else
|
||||||
|
cpu_features->has_pclmul = ((cpu_info[2] & CPUIDECX_PCLMUL) != 0x0);
|
||||||
|
cpu_features->has_aesni = ((cpu_info[2] & CPUIDECX_AESNI) != 0x0);
|
||||||
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,3 +145,13 @@ int
|
|||||||
sodium_runtime_has_sse3(void) {
|
sodium_runtime_has_sse3(void) {
|
||||||
return _cpu_features.has_sse3;
|
return _cpu_features.has_sse3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
sodium_runtime_has_pclmul(void) {
|
||||||
|
return _cpu_features.has_pclmul;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
sodium_runtime_has_aesni(void) {
|
||||||
|
return _cpu_features.has_aesni;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user