blob: 91a725b964f80f23b7bbcc87159fb17f98ce6729 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/* cpuid.h
2 *
3 * Copyright (C) 2006-2021 wolfSSL Inc.
4 *
5 * This file is part of wolfSSL.
6 *
7 * wolfSSL is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * wolfSSL is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20 */
21
22
23
24#ifndef WOLF_CRYPT_CPUID_H
25#define WOLF_CRYPT_CPUID_H
26
27
28#include <wolfssl/wolfcrypt/types.h>
29
30
31#ifdef __cplusplus
32 extern "C" {
33#endif
34
35#if (defined(WOLFSSL_X86_64_BUILD) || defined(USE_INTEL_SPEEDUP) || \
36 defined(WOLFSSL_AESNI) || defined(WOLFSSL_SP_X86_64_ASM)) && \
37 !defined(WOLFSSL_NO_ASM)
38
39 #define CPUID_AVX1 0x0001
40 #define CPUID_AVX2 0x0002
41 #define CPUID_RDRAND 0x0004
42 #define CPUID_RDSEED 0x0008
43 #define CPUID_BMI2 0x0010 /* MULX, RORX */
44 #define CPUID_AESNI 0x0020
45 #define CPUID_ADX 0x0040 /* ADCX, ADOX */
46 #define CPUID_MOVBE 0x0080 /* Move and byte swap */
47
48 #define IS_INTEL_AVX1(f) ((f) & CPUID_AVX1)
49 #define IS_INTEL_AVX2(f) ((f) & CPUID_AVX2)
50 #define IS_INTEL_RDRAND(f) ((f) & CPUID_RDRAND)
51 #define IS_INTEL_RDSEED(f) ((f) & CPUID_RDSEED)
52 #define IS_INTEL_BMI2(f) ((f) & CPUID_BMI2)
53 #define IS_INTEL_AESNI(f) ((f) & CPUID_AESNI)
54 #define IS_INTEL_ADX(f) ((f) & CPUID_ADX)
55 #define IS_INTEL_MOVBE(f) ((f) & CPUID_MOVBE)
56
57 void cpuid_set_flags(void);
58 word32 cpuid_get_flags(void);
59
60 /* Public APIs to modify flags. */
61 WOLFSSL_API void cpuid_select_flags(word32 flags);
62 WOLFSSL_API void cpuid_set_flag(word32 flag);
63 WOLFSSL_API void cpuid_clear_flag(word32 flag);
64
65#endif
66
67#ifdef __cplusplus
68 } /* extern "C" */
69#endif
70
71
72#endif /* WOLF_CRYPT_CPUID_H */