Crypto++  8.8
Free C++ class library of cryptographic schemes
Macros
cpu.h File Reference

Functions for CPU features and intrinsics. More...

Go to the source code of this file.

Macros

#define NEW_LINE
 
#define INTEL_PREFIX
 
#define INTEL_NOPREFIX
 
#define ATT_PREFIX
 
#define ATT_NOPREFIX
 
#define PERCENT_PASTE(x)   "%" #x
 
#define PERCENT_REG(x)   PERCENT_PASTE(x)
 

Detailed Description

Functions for CPU features and intrinsics.

The CPU functions are used in IA-32, ARM and PowerPC code paths. The functions provide cpu specific feature testing on IA-32, ARM and PowerPC machines.

Feature detection uses CPUID on IA-32, like Intel and AMD. On other platforms a two-part strategy is used. First, the library attempts to *Query* the OS for a feature, like using Linux getauxval() or android_getCpuFeatures(). If that fails, then *Probe* the cpu executing an instruction and an observe a SIGILL if unsupported. The general pattern used by the library is:

   g_hasCRC32 = CPU_QueryCRC32() || CPU_ProbeCRC32();
   g_hasPMULL = CPU_QueryPMULL() || CPU_ProbePMULL();
   g_hasAES  = CPU_QueryAES() || CPU_ProbeAES();

Generally speaking, CPU_Query() is in the source file cpu.cpp because it does not require special architectural flags. CPU_Probe() is in a source file that receives architectural flags, like sse_simd.cpp, neon_simd.cpp and ppc_simd.cpp. For example, compiling neon_simd.cpp on an ARM64 machine will have -march=armv8-a applied during a compile to make the instruction set architecture (ISA) available.

The cpu probes are expensive when compared to a standard OS feature query. The library also avoids probes on Apple platforms because Apple's signal handling for SIGILLs appears to corrupt memory. CPU_Probe() will unconditionally return false for Apple platforms. OpenSSL experienced the same problem and moved away from SIGILL probes on Apple.

Definition in file cpu.h.