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 | #define CC_HAS_AVX512_AND_IN_KERNEL() ((cpuid_info()->cpuid_leaf7_features & CPUID_LEAF7_FEATURE_AVX512F) !=0) |
27 | |
28 | #elif CC_XNU_KERNEL_AVAILABLE |
29 | # include <System/i386/cpu_capabilities.h> |
30 | |
31 | #ifndef kHasAVX2_0 /* 10.8 doesn't have kHasAVX2_0 defined */ |
32 | #define kHasAVX2_0 0 |
33 | #endif |
34 | |
35 | extern int _cpu_capabilities; |
36 | #define CC_HAS_AESNI() (_cpu_capabilities & kHasAES) |
37 | #define CC_HAS_SupplementalSSE3() (_cpu_capabilities & kHasSupplementalSSE3) |
38 | #define CC_HAS_AVX1() (_cpu_capabilities & kHasAVX1_0) |
39 | #define CC_HAS_AVX2() (_cpu_capabilities & kHasAVX2_0) |
40 | #define CC_HAS_AVX512_AND_IN_KERNEL() 0 |
41 | #else |
42 | #define CC_HAS_AESNI() 0 |
43 | #define CC_HAS_SupplementalSSE3() 0 |
44 | #define CC_HAS_AVX1() 0 |
45 | #define CC_HAS_AVX2() 0 |
46 | #define CC_HAS_AVX512_AND_IN_KERNEL() 0 |
47 | #endif |
48 | |
49 | #endif /* !(defined(__x86_64__) || defined(__i386__)) */ |
50 | |
51 | #endif /* CORECRYPTO_CC_RUNTIME_CONFIG_H_ */ |
52 | |