Use getauxval on Linux for features

getauxval() is the recommended way to determine features on Linux. Its likely less expensive than CPU probing for SIGILLs. We gave up portability, but some gained stability
pull/461/head
Jeffrey Walton 2017-08-07 07:37:08 -04:00
parent 08cb017836
commit 89ccfad2d0
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
5 changed files with 68 additions and 0 deletions

View File

@ -15,6 +15,13 @@
# undef CRYPTOPP_ARM_CRC32_AVAILABLE
#endif
#if defined(__linux__)
# include <sys/auxv.h>
# ifndef HWCAP_CRC32
# define HWCAP_CRC32 (1 << 7)
# endif
#endif
#if (CRYPTOPP_SSE42_AVAILABLE)
# include "nmmintrin.h"
#endif
@ -71,6 +78,11 @@ bool CPU_TryCRC32_ARMV8()
}
return result;
#else
# if defined(__linux__)
if (getauxval(AT_HWCAP) & HWCAP_CRC32)
return true;
# endif
// longjmp and clobber warnings. Volatile is required.
// http://github.com/weidai11/cryptopp/issues/24 and http://stackoverflow.com/q/7721854
volatile bool result = true;

View File

@ -15,6 +15,13 @@
# undef CRYPTOPP_ARM_PMULL_AVAILABLE
#endif
#if defined(__linux__)
# include <sys/auxv.h>
# ifndef HWCAP_PMULL
# define HWCAP_PMULL (1 << 4)
# endif
#endif
#if (CRYPTOPP_CLMUL_AVAILABLE)
# include "tmmintrin.h"
# include "wmmintrin.h"
@ -204,6 +211,11 @@ bool CPU_TryPMULL_ARMV8()
}
return result;
# else
# if defined(__linux__)
if (getauxval(AT_HWCAP) & HWCAP_PMULL)
return true;
# endif
// longjmp and clobber warnings. Volatile is required.
// http://github.com/weidai11/cryptopp/issues/24 and http://stackoverflow.com/q/7721854
volatile bool result = true;

View File

@ -9,6 +9,13 @@
#include "pch.h"
#include "config.h"
#if defined(__linux__)
# include <sys/auxv.h>
# ifndef HWCAP_ASIMD
# define HWCAP_ASIMD (1 << 1)
# endif
#endif
#if (CRYPTOPP_ARM_NEON_AVAILABLE)
# include "arm_neon.h"
#endif
@ -63,6 +70,11 @@ bool CPU_TryNEON_ARM()
}
return result;
# else
# if defined(__linux__) && (defined(__aarch32__) || defined(__aarch64__))
if (getauxval(AT_HWCAP) & HWCAP_ASIMD)
return true;
# endif
// longjmp and clobber warnings. Volatile is required.
// http://github.com/weidai11/cryptopp/issues/24 and http://stackoverflow.com/q/7721854
volatile bool result = true;

View File

@ -20,6 +20,13 @@
# undef CRYPTOPP_ARM_AES_AVAILABLE
#endif
#if defined(__linux__)
# include <sys/auxv.h>
# ifndef HWCAP_AES
# define HWCAP_AES (1 << 3)
# endif
#endif
#if (CRYPTOPP_SSE41_AVAILABLE)
// Hack... Apple conflates SSE4.1 and SSE4.2. Without __SSE4_2__,
// Apple fails the compile with "SSE4.2 instruction set not enabled"
@ -94,6 +101,11 @@ bool CPU_TryAES_ARMV8()
}
return result;
# else
# if defined(__linux__)
if (getauxval(AT_HWCAP) & HWCAP_AES)
return true;
# endif
// longjmp and clobber warnings. Volatile is required.
// http://github.com/weidai11/cryptopp/issues/24 and http://stackoverflow.com/q/7721854
volatile bool result = true;

View File

@ -15,6 +15,16 @@
# undef CRYPTOPP_ARM_SHA_AVAILABLE
#endif
#if defined(__linux__)
# include <sys/auxv.h>
# ifndef HWCAP_SHA1
# define HWCAP_SHA1 (1 << 5)
# endif
# ifndef HWCAP_SHA2
# define HWCAP_SHA2 (1 << 6)
# endif
#endif
#if (CRYPTOPP_SSE42_AVAILABLE)
# include "nmmintrin.h"
#endif
@ -75,6 +85,11 @@ bool CPU_TrySHA1_ARMV8()
}
return result;
# else
# if defined(__linux__)
if (getauxval(AT_HWCAP) & HWCAP_SHA1)
return true;
# endif
// longjmp and clobber warnings. Volatile is required.
// http://github.com/weidai11/cryptopp/issues/24 and http://stackoverflow.com/q/7721854
volatile bool result = true;
@ -133,6 +148,11 @@ bool CPU_TrySHA2_ARMV8()
}
return result;
#else
# if defined(__linux__)
if (getauxval(AT_HWCAP) & HWCAP_SHA2)
return true;
# endif
// longjmp and clobber warnings. Volatile is required.
// http://github.com/weidai11/cryptopp/issues/24 and http://stackoverflow.com/q/7721854
volatile bool result = true;