Security Scol plugin
|
Functions for CPU features and intrinsics. More...
#include "config.h"
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) |
Functions | |
int | GetCacheLineSize () |
Provides the cache line size. | |
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.
|
inline |
Provides the cache line size.
GetCacheLineSize() returns the lower bound on the size of a cache line, if it is available. If the value is not available at runtime, then 32 is returned for a 32-bit processor and 64 is returned for a 64-bit processor.
x86/x32/x64 uses CPUID to determine the value and it is usually accurate. PowerPC and AIX also makes the value available to user space and it is also usually accurate. The ARM processor equivalent is a privileged instruction, so a compile time value is returned.