]>
Commit | Line | Data |
---|---|---|
5ba3f43e A |
1 | /* |
2 | * cc_runtime_config.h | |
3 | * corecrypto | |
4 | * | |
5 | * Created on 09/18/2012 | |
6 | * | |
7 | * Copyright (c) 2012,2014,2015 Apple Inc. All rights reserved. | |
8 | * | |
9 | */ | |
10 | ||
11 | #ifndef CORECRYPTO_CC_RUNTIME_CONFIG_H_ | |
12 | #define CORECRYPTO_CC_RUNTIME_CONFIG_H_ | |
13 | ||
14 | #include <corecrypto/cc_config.h> | |
15 | ||
16 | /* Only intel systems have these runtime switches today. */ | |
17 | #if (CCSHA1_VNG_INTEL || CCSHA2_VNG_INTEL || CCAES_INTEL_ASM) \ | |
18 | && (defined(__x86_64__) || defined(__i386__)) | |
19 | ||
20 | #if CC_KERNEL | |
21 | #include <i386/cpuid.h> | |
22 | #define CC_HAS_AESNI() ((cpuid_features() & CPUID_FEATURE_AES) != 0) | |
23 | #define CC_HAS_SupplementalSSE3() ((cpuid_features() & CPUID_FEATURE_SSSE3) != 0) | |
24 | #define CC_HAS_AVX1() ((cpuid_features() & CPUID_FEATURE_AVX1_0) != 0) | |
25 | #define CC_HAS_AVX2() ((cpuid_info()->cpuid_leaf7_features & CPUID_LEAF7_FEATURE_AVX2) != 0) | |
26 | ||
27 | #elif CC_XNU_KERNEL_AVAILABLE | |
28 | # include <System/i386/cpu_capabilities.h> | |
29 | ||
30 | #ifndef kHasAVX2_0 /* 10.8 doesn't have kHasAVX2_0 defined */ | |
31 | #define kHasAVX2_0 0 | |
32 | #endif | |
33 | ||
34 | extern int _cpu_capabilities; | |
35 | #define CC_HAS_AESNI() (_cpu_capabilities & kHasAES) | |
36 | #define CC_HAS_SupplementalSSE3() (_cpu_capabilities & kHasSupplementalSSE3) | |
37 | #define CC_HAS_AVX1() (_cpu_capabilities & kHasAVX1_0) | |
38 | #define CC_HAS_AVX2() (_cpu_capabilities & kHasAVX2_0) | |
39 | #else | |
40 | #define CC_HAS_AESNI() 0 | |
41 | #define CC_HAS_SupplementalSSE3() 0 | |
42 | #define CC_HAS_AVX1() 0 | |
43 | #define CC_HAS_AVX2() 0 | |
44 | #endif | |
45 | ||
46 | #endif /* !(defined(__x86_64__) || defined(__i386__)) */ | |
47 | ||
48 | #endif /* CORECRYPTO_CC_RUNTIME_CONFIG_H_ */ |