blob: 6c67c348d50ecd146eb2ae875676042b426dfcff [file] [log] [blame]
Marat Dukhan547fa362017-03-03 02:47:26 -05001#pragma once
2#ifndef CPUINFO_H
3#define CPUINFO_H
4
5#ifndef __cplusplus
6 #include <stdbool.h>
7#endif
8
Hao Lu3617d5b2017-10-23 15:16:50 -07009#ifdef __APPLE__
10 #include <TargetConditionals.h>
11#endif
12
Marat Dukhan547fa362017-03-03 02:47:26 -050013#include <stdint.h>
14
15/* Identify architecture and define corresponding macro */
16
17#if defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(_M_IX86)
18 #define CPUINFO_ARCH_X86 1
19#endif
20
21#if defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)
22 #define CPUINFO_ARCH_X86_64 1
23#endif
24
25#if defined(__arm__) || defined(_M_ARM)
26 #define CPUINFO_ARCH_ARM 1
27#endif
28
29#if defined(__aarch64__) || defined(_M_ARM64)
30 #define CPUINFO_ARCH_ARM64 1
31#endif
32
33#if defined(__PPC64__) || defined(__powerpc64__) || defined(_ARCH_PPC64)
34 #define CPUINFO_ARCH_PPC64 1
35#endif
36
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -080037#if defined(__asmjs__)
Marat Dukhan547fa362017-03-03 02:47:26 -050038 #define CPUINFO_ARCH_ASMJS 1
39#endif
40
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -080041#if defined(__wasm__)
42 #if defined(__wasm_simd128__)
43 #define CPUINFO_ARCH_WASMSIMD 1
44 #else
45 #define CPUINFO_ARCH_WASM 1
46 #endif
47#endif
48
Marat Dukhan547fa362017-03-03 02:47:26 -050049/* Define other architecture-specific macros as 0 */
50
51#ifndef CPUINFO_ARCH_X86
52 #define CPUINFO_ARCH_X86 0
53#endif
54
55#ifndef CPUINFO_ARCH_X86_64
56 #define CPUINFO_ARCH_X86_64 0
57#endif
58
59#ifndef CPUINFO_ARCH_ARM
60 #define CPUINFO_ARCH_ARM 0
61#endif
62
63#ifndef CPUINFO_ARCH_ARM64
64 #define CPUINFO_ARCH_ARM64 0
65#endif
66
67#ifndef CPUINFO_ARCH_PPC64
68 #define CPUINFO_ARCH_PPC64 0
69#endif
70
Marat Dukhan547fa362017-03-03 02:47:26 -050071#ifndef CPUINFO_ARCH_ASMJS
72 #define CPUINFO_ARCH_ASMJS 0
73#endif
74
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -080075#ifndef CPUINFO_ARCH_WASM
76 #define CPUINFO_ARCH_WASM 0
77#endif
78
79#ifndef CPUINFO_ARCH_WASMSIMD
80 #define CPUINFO_ARCH_WASMSIMD 0
81#endif
82
Ashkan Aliabadi7e4c0092020-06-01 18:23:11 -070083#if CPUINFO_ARCH_X86 && defined(_MSC_VER)
84 #define CPUINFO_ABI __cdecl
85#elif CPUINFO_ARCH_X86 && defined(__GNUC__)
86 #define CPUINFO_ABI __attribute__((__cdecl__))
87#else
88 #define CPUINFO_ABI
89#endif
90
Marat Dukhan547fa362017-03-03 02:47:26 -050091#define CPUINFO_CACHE_UNIFIED 0x00000001
92#define CPUINFO_CACHE_INCLUSIVE 0x00000002
93#define CPUINFO_CACHE_COMPLEX_INDEXING 0x00000004
94
95struct cpuinfo_cache {
Marat Dukhan3045d4f2017-03-04 01:51:42 -050096 /** Cache size in bytes */
Marat Dukhan547fa362017-03-03 02:47:26 -050097 uint32_t size;
Marat Dukhan3045d4f2017-03-04 01:51:42 -050098 /** Number of ways of associativity */
Marat Dukhan547fa362017-03-03 02:47:26 -050099 uint32_t associativity;
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500100 /** Number of sets */
Marat Dukhan547fa362017-03-03 02:47:26 -0500101 uint32_t sets;
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500102 /** Number of partitions */
Marat Dukhan547fa362017-03-03 02:47:26 -0500103 uint32_t partitions;
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500104 /** Line size in bytes */
Marat Dukhan547fa362017-03-03 02:47:26 -0500105 uint32_t line_size;
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500106 /**
107 * Binary characteristics of the cache (unified cache, inclusive cache, cache with complex indexing).
108 *
109 * @see CPUINFO_CACHE_UNIFIED, CPUINFO_CACHE_INCLUSIVE, CPUINFO_CACHE_COMPLEX_INDEXING
110 */
Marat Dukhan547fa362017-03-03 02:47:26 -0500111 uint32_t flags;
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500112 /** Index of the first logical processor that shares this cache */
Marat Dukhanab3a1272017-08-25 23:20:07 -0700113 uint32_t processor_start;
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500114 /** Number of logical processors that share this cache */
Marat Dukhanab3a1272017-08-25 23:20:07 -0700115 uint32_t processor_count;
Marat Dukhan547fa362017-03-03 02:47:26 -0500116};
117
118struct cpuinfo_trace_cache {
119 uint32_t uops;
120 uint32_t associativity;
121};
122
123#define CPUINFO_PAGE_SIZE_4KB 0x1000
124#define CPUINFO_PAGE_SIZE_1MB 0x100000
125#define CPUINFO_PAGE_SIZE_2MB 0x200000
126#define CPUINFO_PAGE_SIZE_4MB 0x400000
127#define CPUINFO_PAGE_SIZE_16MB 0x1000000
128#define CPUINFO_PAGE_SIZE_1GB 0x40000000
129
130struct cpuinfo_tlb {
131 uint32_t entries;
132 uint32_t associativity;
133 uint64_t pages;
134};
135
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500136/** Vendor of processor core design */
Marat Dukhan547fa362017-03-03 02:47:26 -0500137enum cpuinfo_vendor {
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500138 /** Processor vendor is not known to the library, or the library failed to get vendor information from the OS. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500139 cpuinfo_vendor_unknown = 0,
Marat Dukhanb92e2ed2017-09-26 19:26:41 -0700140
Marat Dukhan547fa362017-03-03 02:47:26 -0500141 /* Active vendors of modern CPUs */
142
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500143 /**
144 * Intel Corporation. Vendor of x86, x86-64, IA64, and ARM processor microarchitectures.
145 *
146 * Sold its ARM design subsidiary in 2006. The last ARM processor design was released in 2004.
147 */
Marat Dukhan547fa362017-03-03 02:47:26 -0500148 cpuinfo_vendor_intel = 1,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500149 /** Advanced Micro Devices, Inc. Vendor of x86 and x86-64 processor microarchitectures. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500150 cpuinfo_vendor_amd = 2,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500151 /** ARM Holdings plc. Vendor of ARM and ARM64 processor microarchitectures. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500152 cpuinfo_vendor_arm = 3,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500153 /** Qualcomm Incorporated. Vendor of ARM and ARM64 processor microarchitectures. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500154 cpuinfo_vendor_qualcomm = 4,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500155 /** Apple Inc. Vendor of ARM and ARM64 processor microarchitectures. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500156 cpuinfo_vendor_apple = 5,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500157 /** Samsung Electronics Co., Ltd. Vendir if ARM64 processor microarchitectures. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500158 cpuinfo_vendor_samsung = 6,
Marat Dukhan93982f22017-10-20 13:10:23 -0700159 /** Nvidia Corporation. Vendor of ARM64-compatible processor microarchitectures. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500160 cpuinfo_vendor_nvidia = 7,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500161 /** MIPS Technologies, Inc. Vendor of MIPS processor microarchitectures. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500162 cpuinfo_vendor_mips = 8,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500163 /** International Business Machines Corporation. Vendor of PowerPC processor microarchitectures. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500164 cpuinfo_vendor_ibm = 9,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500165 /** Ingenic Semiconductor. Vendor of MIPS processor microarchitectures. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500166 cpuinfo_vendor_ingenic = 10,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500167 /**
168 * VIA Technologies, Inc. Vendor of x86 and x86-64 processor microarchitectures.
169 *
170 * Processors are designed by Centaur Technology, a subsidiary of VIA Technologies.
171 */
Marat Dukhan547fa362017-03-03 02:47:26 -0500172 cpuinfo_vendor_via = 11,
Marat Dukhan92dae312017-05-09 14:10:17 +0000173 /** Cavium, Inc. Vendor of ARM64 processor microarchitectures. */
174 cpuinfo_vendor_cavium = 12,
Marat Dukhan1ae7ff82018-05-13 19:30:58 -0700175 /** Broadcom, Inc. Vendor of ARM processor microarchitectures. */
176 cpuinfo_vendor_broadcom = 13,
Marat Dukhan029030c2018-05-13 20:10:22 -0700177 /** Applied Micro Circuits Corporation (APM). Vendor of ARM64 processor microarchitectures. */
178 cpuinfo_vendor_apm = 14,
Marat Dukhanb73f61a2018-09-02 23:57:56 +0300179 /**
180 * Huawei Technologies Co., Ltd. Vendor of ARM64 processor microarchitectures.
181 *
182 * Processors are designed by HiSilicon, a subsidiary of Huawei.
183 */
184 cpuinfo_vendor_huawei = 15,
Ashkan Aliabadidcf8e182020-03-19 19:34:26 -0700185 /**
186 * Hygon (Chengdu Haiguang Integrated Circuit Design Co., Ltd), Vendor of x86-64 processor microarchitectures.
187 *
188 * Processors are variants of AMD cores.
189 */
190 cpuinfo_vendor_hygon = 16,
Marat Dukhan547fa362017-03-03 02:47:26 -0500191
192 /* Active vendors of embedded CPUs */
193
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500194 /** Texas Instruments Inc. Vendor of ARM processor microarchitectures. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500195 cpuinfo_vendor_texas_instruments = 30,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500196 /** Marvell Technology Group Ltd. Vendor of ARM processor microarchitectures. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500197 cpuinfo_vendor_marvell = 31,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500198 /** RDC Semiconductor Co., Ltd. Vendor of x86 processor microarchitectures. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500199 cpuinfo_vendor_rdc = 32,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500200 /** DM&P Electronics Inc. Vendor of x86 processor microarchitectures. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500201 cpuinfo_vendor_dmp = 33,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500202 /** Motorola, Inc. Vendor of PowerPC and ARM processor microarchitectures. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500203 cpuinfo_vendor_motorola = 34,
204
205 /* Defunct CPU vendors */
Marat Dukhanb92e2ed2017-09-26 19:26:41 -0700206
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500207 /**
208 * Transmeta Corporation. Vendor of x86 processor microarchitectures.
209 *
210 * Now defunct. The last processor design was released in 2004.
211 * Transmeta processors implemented VLIW ISA and used binary translation to execute x86 code.
212 */
Marat Dukhan547fa362017-03-03 02:47:26 -0500213 cpuinfo_vendor_transmeta = 50,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500214 /**
215 * Cyrix Corporation. Vendor of x86 processor microarchitectures.
216 *
217 * Now defunct. The last processor design was released in 1996.
218 */
Marat Dukhan547fa362017-03-03 02:47:26 -0500219 cpuinfo_vendor_cyrix = 51,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500220 /**
221 * Rise Technology. Vendor of x86 processor microarchitectures.
222 *
223 * Now defunct. The last processor design was released in 1999.
224 */
Marat Dukhan547fa362017-03-03 02:47:26 -0500225 cpuinfo_vendor_rise = 52,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500226 /**
227 * National Semiconductor. Vendor of x86 processor microarchitectures.
228 *
229 * Sold its x86 design subsidiary in 1999. The last processor design was released in 1998.
230 */
Marat Dukhan547fa362017-03-03 02:47:26 -0500231 cpuinfo_vendor_nsc = 53,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500232 /**
233 * Silicon Integrated Systems. Vendor of x86 processor microarchitectures.
234 *
235 * Sold its x86 design subsidiary in 2001. The last processor design was released in 2001.
236 */
Marat Dukhan547fa362017-03-03 02:47:26 -0500237 cpuinfo_vendor_sis = 54,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500238 /**
239 * NexGen. Vendor of x86 processor microarchitectures.
240 *
241 * Now defunct. The last processor design was released in 1994.
242 * NexGen designed the first x86 microarchitecture which decomposed x86 instructions into simple microoperations.
243 */
Marat Dukhan547fa362017-03-03 02:47:26 -0500244 cpuinfo_vendor_nexgen = 55,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500245 /**
246 * United Microelectronics Corporation. Vendor of x86 processor microarchitectures.
247 *
248 * Ceased x86 in the early 1990s. The last processor design was released in 1991.
249 * Designed U5C and U5D processors. Both are 486 level.
250 */
Marat Dukhan547fa362017-03-03 02:47:26 -0500251 cpuinfo_vendor_umc = 56,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500252 /**
253 * Digital Equipment Corporation. Vendor of ARM processor microarchitecture.
254 *
255 * Sold its ARM designs in 1997. The last processor design was released in 1997.
256 */
Marat Dukhan547fa362017-03-03 02:47:26 -0500257 cpuinfo_vendor_dec = 57,
258};
259
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500260/**
261 * Processor microarchitecture
262 *
263 * Processors with different microarchitectures often have different instruction performance characteristics,
264 * and may have dramatically different pipeline organization.
265 */
Marat Dukhan547fa362017-03-03 02:47:26 -0500266enum cpuinfo_uarch {
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500267 /** Microarchitecture is unknown, or the library failed to get information about the microarchitecture from OS */
Marat Dukhan547fa362017-03-03 02:47:26 -0500268 cpuinfo_uarch_unknown = 0,
269
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500270 /** Pentium and Pentium MMX microarchitecture. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500271 cpuinfo_uarch_p5 = 0x00100100,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500272 /** Intel Quark microarchitecture. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500273 cpuinfo_uarch_quark = 0x00100101,
274
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500275 /** Pentium Pro, Pentium II, and Pentium III. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500276 cpuinfo_uarch_p6 = 0x00100200,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500277 /** Pentium M. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500278 cpuinfo_uarch_dothan = 0x00100201,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500279 /** Intel Core microarchitecture. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500280 cpuinfo_uarch_yonah = 0x00100202,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500281 /** Intel Core 2 microarchitecture on 65 nm process. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500282 cpuinfo_uarch_conroe = 0x00100203,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500283 /** Intel Core 2 microarchitecture on 45 nm process. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500284 cpuinfo_uarch_penryn = 0x00100204,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500285 /** Intel Nehalem and Westmere microarchitectures (Core i3/i5/i7 1st gen). */
Marat Dukhan547fa362017-03-03 02:47:26 -0500286 cpuinfo_uarch_nehalem = 0x00100205,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500287 /** Intel Sandy Bridge microarchitecture (Core i3/i5/i7 2nd gen). */
Marat Dukhan547fa362017-03-03 02:47:26 -0500288 cpuinfo_uarch_sandy_bridge = 0x00100206,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500289 /** Intel Ivy Bridge microarchitecture (Core i3/i5/i7 3rd gen). */
Marat Dukhan547fa362017-03-03 02:47:26 -0500290 cpuinfo_uarch_ivy_bridge = 0x00100207,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500291 /** Intel Haswell microarchitecture (Core i3/i5/i7 4th gen). */
Marat Dukhan547fa362017-03-03 02:47:26 -0500292 cpuinfo_uarch_haswell = 0x00100208,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500293 /** Intel Broadwell microarchitecture. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500294 cpuinfo_uarch_broadwell = 0x00100209,
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -0800295 /** Intel Sky Lake microarchitecture (14 nm, including Kaby/Coffee/Whiskey/Amber/Comet/Cascade/Cooper Lake). */
Marat Dukhan547fa362017-03-03 02:47:26 -0500296 cpuinfo_uarch_sky_lake = 0x0010020A,
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -0800297 /** DEPRECATED (Intel Kaby Lake microarchitecture). */
298 cpuinfo_uarch_kaby_lake = 0x0010020A,
299 /** Intel Palm Cove microarchitecture (10 nm, Cannon Lake). */
300 cpuinfo_uarch_palm_cove = 0x0010020B,
301 /** Intel Sunny Cove microarchitecture (10 nm, Ice Lake). */
302 cpuinfo_uarch_sunny_cove = 0x0010020C,
Marat Dukhan547fa362017-03-03 02:47:26 -0500303
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500304 /** Pentium 4 with Willamette, Northwood, or Foster cores. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500305 cpuinfo_uarch_willamette = 0x00100300,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500306 /** Pentium 4 with Prescott and later cores. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500307 cpuinfo_uarch_prescott = 0x00100301,
308
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500309 /** Intel Atom on 45 nm process. */
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -0800310 cpuinfo_uarch_bonnell = 0x00100400,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500311 /** Intel Atom on 32 nm process. */
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -0800312 cpuinfo_uarch_saltwell = 0x00100401,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500313 /** Intel Silvermont microarchitecture (22 nm out-of-order Atom). */
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -0800314 cpuinfo_uarch_silvermont = 0x00100402,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500315 /** Intel Airmont microarchitecture (14 nm out-of-order Atom). */
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -0800316 cpuinfo_uarch_airmont = 0x00100403,
317 /** Intel Goldmont microarchitecture (Denverton, Apollo Lake). */
318 cpuinfo_uarch_goldmont = 0x00100404,
319 /** Intel Goldmont Plus microarchitecture (Gemini Lake). */
320 cpuinfo_uarch_goldmont_plus = 0x00100405,
Marat Dukhan547fa362017-03-03 02:47:26 -0500321
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500322 /** Intel Knights Ferry HPC boards. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500323 cpuinfo_uarch_knights_ferry = 0x00100500,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500324 /** Intel Knights Corner HPC boards (aka Xeon Phi). */
Marat Dukhan547fa362017-03-03 02:47:26 -0500325 cpuinfo_uarch_knights_corner = 0x00100501,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500326 /** Intel Knights Landing microarchitecture (second-gen MIC). */
Marat Dukhan547fa362017-03-03 02:47:26 -0500327 cpuinfo_uarch_knights_landing = 0x00100502,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500328 /** Intel Knights Hill microarchitecture (third-gen MIC). */
Marat Dukhan547fa362017-03-03 02:47:26 -0500329 cpuinfo_uarch_knights_hill = 0x00100503,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500330 /** Intel Knights Mill Xeon Phi. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500331 cpuinfo_uarch_knights_mill = 0x00100504,
332
Marat Dukhan3c982762017-05-08 06:16:45 +0000333 /** Intel/Marvell XScale series. */
334 cpuinfo_uarch_xscale = 0x00100600,
335
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500336 /** AMD K5. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500337 cpuinfo_uarch_k5 = 0x00200100,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500338 /** AMD K6 and alike. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500339 cpuinfo_uarch_k6 = 0x00200101,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500340 /** AMD Athlon and Duron. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500341 cpuinfo_uarch_k7 = 0x00200102,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500342 /** AMD Athlon 64, Opteron 64. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500343 cpuinfo_uarch_k8 = 0x00200103,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500344 /** AMD Family 10h (Barcelona, Istambul, Magny-Cours). */
Marat Dukhan547fa362017-03-03 02:47:26 -0500345 cpuinfo_uarch_k10 = 0x00200104,
346 /**
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500347 * AMD Bulldozer microarchitecture
348 * Zambezi FX-series CPUs, Zurich, Valencia and Interlagos Opteron CPUs.
Marat Dukhan547fa362017-03-03 02:47:26 -0500349 */
350 cpuinfo_uarch_bulldozer = 0x00200105,
351 /**
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500352 * AMD Piledriver microarchitecture
353 * Vishera FX-series CPUs, Trinity and Richland APUs, Delhi, Seoul, Abu Dhabi Opteron CPUs.
Marat Dukhan547fa362017-03-03 02:47:26 -0500354 */
355 cpuinfo_uarch_piledriver = 0x00200106,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500356 /** AMD Steamroller microarchitecture (Kaveri APUs). */
Marat Dukhan547fa362017-03-03 02:47:26 -0500357 cpuinfo_uarch_steamroller = 0x00200107,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500358 /** AMD Excavator microarchitecture (Carizzo APUs). */
Marat Dukhan547fa362017-03-03 02:47:26 -0500359 cpuinfo_uarch_excavator = 0x00200108,
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -0800360 /** AMD Zen microarchitecture (12/14 nm Ryzen and EPYC CPUs). */
Marat Dukhan547fa362017-03-03 02:47:26 -0500361 cpuinfo_uarch_zen = 0x00200109,
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -0800362 /** AMD Zen 2 microarchitecture (7 nm Ryzen and EPYC CPUs). */
363 cpuinfo_uarch_zen2 = 0x0020010A,
Marat Dukhan547fa362017-03-03 02:47:26 -0500364
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500365 /** NSC Geode and AMD Geode GX and LX. */
Marat Dukhane25187d2017-04-16 05:03:07 -0400366 cpuinfo_uarch_geode = 0x00200200,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500367 /** AMD Bobcat mobile microarchitecture. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500368 cpuinfo_uarch_bobcat = 0x00200201,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500369 /** AMD Jaguar mobile microarchitecture. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500370 cpuinfo_uarch_jaguar = 0x00200202,
Marat Dukhan818e1992018-02-24 15:39:18 +0100371 /** AMD Puma mobile microarchitecture. */
372 cpuinfo_uarch_puma = 0x00200203,
Marat Dukhanb92e2ed2017-09-26 19:26:41 -0700373
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500374 /** ARM7 series. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500375 cpuinfo_uarch_arm7 = 0x00300100,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500376 /** ARM9 series. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500377 cpuinfo_uarch_arm9 = 0x00300101,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500378 /** ARM 1136, ARM 1156, ARM 1176, or ARM 11MPCore. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500379 cpuinfo_uarch_arm11 = 0x00300102,
380
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500381 /** ARM Cortex-A5. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500382 cpuinfo_uarch_cortex_a5 = 0x00300205,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500383 /** ARM Cortex-A7. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500384 cpuinfo_uarch_cortex_a7 = 0x00300207,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500385 /** ARM Cortex-A8. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500386 cpuinfo_uarch_cortex_a8 = 0x00300208,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500387 /** ARM Cortex-A9. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500388 cpuinfo_uarch_cortex_a9 = 0x00300209,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500389 /** ARM Cortex-A12. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500390 cpuinfo_uarch_cortex_a12 = 0x00300212,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500391 /** ARM Cortex-A15. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500392 cpuinfo_uarch_cortex_a15 = 0x00300215,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500393 /** ARM Cortex-A17. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500394 cpuinfo_uarch_cortex_a17 = 0x00300217,
395
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500396 /** ARM Cortex-A32. */
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -0800397 cpuinfo_uarch_cortex_a32 = 0x00300332,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500398 /** ARM Cortex-A35. */
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -0800399 cpuinfo_uarch_cortex_a35 = 0x00300335,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500400 /** ARM Cortex-A53. */
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -0800401 cpuinfo_uarch_cortex_a53 = 0x00300353,
Ashkan Aliabadidcf8e182020-03-19 19:34:26 -0700402 /** ARM Cortex-A55 revision 0 (restricted dual-issue capabilities compared to revision 1+). */
403 cpuinfo_uarch_cortex_a55r0 = 0x00300354,
Marat Dukhana8fb3dd2017-08-09 13:49:39 -0700404 /** ARM Cortex-A55. */
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -0800405 cpuinfo_uarch_cortex_a55 = 0x00300355,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500406 /** ARM Cortex-A57. */
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -0800407 cpuinfo_uarch_cortex_a57 = 0x00300357,
408 /** ARM Cortex-A65. */
409 cpuinfo_uarch_cortex_a65 = 0x00300365,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500410 /** ARM Cortex-A72. */
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -0800411 cpuinfo_uarch_cortex_a72 = 0x00300372,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500412 /** ARM Cortex-A73. */
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -0800413 cpuinfo_uarch_cortex_a73 = 0x00300373,
Marat Dukhana8fb3dd2017-08-09 13:49:39 -0700414 /** ARM Cortex-A75. */
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -0800415 cpuinfo_uarch_cortex_a75 = 0x00300375,
Marat Dukhanb73f61a2018-09-02 23:57:56 +0300416 /** ARM Cortex-A76. */
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -0800417 cpuinfo_uarch_cortex_a76 = 0x00300376,
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -0800418 /** ARM Cortex-A77. */
419 cpuinfo_uarch_cortex_a77 = 0x00300377,
420
421 /** ARM Neoverse N1. */
422 cpuinfo_uarch_neoverse_n1 = 0x00300400,
423 /** ARM Neoverse E1. */
424 cpuinfo_uarch_neoverse_e1 = 0x00300401,
Marat Dukhan547fa362017-03-03 02:47:26 -0500425
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500426 /** Qualcomm Scorpion. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500427 cpuinfo_uarch_scorpion = 0x00400100,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500428 /** Qualcomm Krait. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500429 cpuinfo_uarch_krait = 0x00400101,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500430 /** Qualcomm Kryo. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500431 cpuinfo_uarch_kryo = 0x00400102,
Marat Dukhan029030c2018-05-13 20:10:22 -0700432 /** Qualcomm Falkor. */
433 cpuinfo_uarch_falkor = 0x00400103,
434 /** Qualcomm Saphira. */
435 cpuinfo_uarch_saphira = 0x00400104,
Marat Dukhan547fa362017-03-03 02:47:26 -0500436
Marat Dukhan93982f22017-10-20 13:10:23 -0700437 /** Nvidia Denver. */
Marat Dukhan3c982762017-05-08 06:16:45 +0000438 cpuinfo_uarch_denver = 0x00500100,
Marat Dukhan1e6c8c92018-05-13 20:24:07 -0700439 /** Nvidia Denver 2. */
440 cpuinfo_uarch_denver2 = 0x00500101,
Marat Dukhan8101c502018-09-18 21:05:58 -0500441 /** Nvidia Carmel. */
442 cpuinfo_uarch_carmel = 0x00500102,
Marat Dukhan3c982762017-05-08 06:16:45 +0000443
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -0800444 /** Samsung Exynos M1 (Exynos 8890 big cores). */
445 cpuinfo_uarch_exynos_m1 = 0x00600100,
446 /** Samsung Exynos M2 (Exynos 8895 big cores). */
447 cpuinfo_uarch_exynos_m2 = 0x00600101,
448 /** Samsung Exynos M3 (Exynos 9810 big cores). */
449 cpuinfo_uarch_exynos_m3 = 0x00600102,
450 /** Samsung Exynos M4 (Exynos 9820 big cores). */
451 cpuinfo_uarch_exynos_m4 = 0x00600103,
452 /** Samsung Exynos M5 (Exynos 9830 big cores). */
453 cpuinfo_uarch_exynos_m5 = 0x00600104,
454
Ashkan Aliabadi7e4c0092020-06-01 18:23:11 -0700455 /* Deprecated synonym for Cortex-A76 */
456 cpuinfo_uarch_cortex_a76ae = 0x00300376,
457 /* Deprecated names for Exynos. */
Marat Dukhana750f2a2018-03-07 11:07:48 -0800458 cpuinfo_uarch_mongoose_m1 = 0x00600100,
459 cpuinfo_uarch_mongoose_m2 = 0x00600101,
Marat Dukhan10eae002018-03-29 18:36:31 -0700460 cpuinfo_uarch_meerkat_m3 = 0x00600102,
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -0800461 cpuinfo_uarch_meerkat_m4 = 0x00600103,
Marat Dukhan547fa362017-03-03 02:47:26 -0500462
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500463 /** Apple A6 and A6X processors. */
Marat Dukhan3c982762017-05-08 06:16:45 +0000464 cpuinfo_uarch_swift = 0x00700100,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500465 /** Apple A7 processor. */
Marat Dukhan3c982762017-05-08 06:16:45 +0000466 cpuinfo_uarch_cyclone = 0x00700101,
Hao Lu922070c2017-10-18 16:29:02 -0700467 /** Apple A8 and A8X processor. */
Marat Dukhan3c982762017-05-08 06:16:45 +0000468 cpuinfo_uarch_typhoon = 0x00700102,
Hao Lu922070c2017-10-18 16:29:02 -0700469 /** Apple A9 and A9X processor. */
Marat Dukhan3c982762017-05-08 06:16:45 +0000470 cpuinfo_uarch_twister = 0x00700103,
Hao Lu922070c2017-10-18 16:29:02 -0700471 /** Apple A10 and A10X processor. */
Marat Dukhan3c982762017-05-08 06:16:45 +0000472 cpuinfo_uarch_hurricane = 0x00700104,
Hao Lu922070c2017-10-18 16:29:02 -0700473 /** Apple A11 processor (big cores). */
474 cpuinfo_uarch_monsoon = 0x00700105,
475 /** Apple A11 processor (little cores). */
476 cpuinfo_uarch_mistral = 0x00700106,
Marat Dukhan44dafc52018-12-26 20:19:15 -0800477 /** Apple A12 processor (big cores). */
478 cpuinfo_uarch_vortex = 0x00700107,
479 /** Apple A12 processor (little cores). */
480 cpuinfo_uarch_tempest = 0x00700108,
Ashkan Aliabadidcf8e182020-03-19 19:34:26 -0700481 /** Apple A13 processor (big cores). */
482 cpuinfo_uarch_lightning = 0x00700109,
483 /** Apple A13 processor (little cores). */
484 cpuinfo_uarch_thunder = 0x0070010A,
Marat Dukhan92dae312017-05-09 14:10:17 +0000485
486 /** Cavium ThunderX. */
487 cpuinfo_uarch_thunderx = 0x00800100,
Marat Dukhan029030c2018-05-13 20:10:22 -0700488 /** Cavium ThunderX2 (originally Broadcom Vulkan). */
489 cpuinfo_uarch_thunderx2 = 0x00800200,
Marat Dukhan88718322017-08-24 10:12:20 -0700490
491 /** Marvell PJ4. */
492 cpuinfo_uarch_pj4 = 0x00900100,
Marat Dukhan1ae7ff82018-05-13 19:30:58 -0700493
494 /** Broadcom Brahma B15. */
495 cpuinfo_uarch_brahma_b15 = 0x00A00100,
496 /** Broadcom Brahma B53. */
497 cpuinfo_uarch_brahma_b53 = 0x00A00101,
Marat Dukhan029030c2018-05-13 20:10:22 -0700498
499 /** Applied Micro X-Gene. */
500 cpuinfo_uarch_xgene = 0x00B00100,
Ashkan Aliabadidcf8e182020-03-19 19:34:26 -0700501
502 /* Hygon Dhyana (a modification of AMD Zen for Chinese market). */
503 cpuinfo_uarch_dhyana = 0x01000100,
Ashkan Aliabadic2092212020-05-08 20:40:33 -0700504
505 /** HiSilicon TaiShan v110 (Huawei Kunpeng 920 series processors). */
506 cpuinfo_uarch_taishan_v110 = 0x00C00100,
Marat Dukhan547fa362017-03-03 02:47:26 -0500507};
508
509struct cpuinfo_processor {
Marat Dukhan2d37dc42017-09-25 01:32:37 -0700510 /** SMT (hyperthread) ID within a core */
511 uint32_t smt_id;
512 /** Core containing this logical processor */
513 const struct cpuinfo_core* core;
Marat Dukhan4d376c32018-03-18 11:36:39 -0700514 /** Cluster of cores containing this logical processor */
515 const struct cpuinfo_cluster* cluster;
Marat Dukhan2d37dc42017-09-25 01:32:37 -0700516 /** Physical package containing this logical processor */
517 const struct cpuinfo_package* package;
Marat Dukhan15e1df92017-09-13 11:10:10 -0700518#if defined(__linux__)
Marat Dukhan2d37dc42017-09-25 01:32:37 -0700519 /**
520 * Linux-specific ID for the logical processor:
521 * - Linux kernel exposes information about this logical processor in /sys/devices/system/cpu/cpu<linux_id>/
522 * - Bit <linux_id> in the cpu_set_t identifies this logical processor
523 */
Marat Dukhan15e1df92017-09-13 11:10:10 -0700524 int linux_id;
525#endif
Ashkan Aliabadic2092212020-05-08 20:40:33 -0700526#if defined(_WIN32) || defined(__CYGWIN__)
Marat Dukhanb2fc4ab2018-02-19 22:43:26 -0800527 /** Windows-specific ID for the group containing the logical processor. */
528 uint16_t windows_group_id;
529 /**
530 * Windows-specific ID of the logical processor within its group:
531 * - Bit <windows_processor_id> in the KAFFINITY mask identifies this logical processor within its group.
532 */
533 uint16_t windows_processor_id;
534#endif
Marat Dukhan2d37dc42017-09-25 01:32:37 -0700535#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
536 /** APIC ID (unique x86-specific ID of the logical processor) */
537 uint32_t apic_id;
538#endif
Marat Dukhan547fa362017-03-03 02:47:26 -0500539 struct {
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700540 /** Level 1 instruction cache */
Marat Dukhan547fa362017-03-03 02:47:26 -0500541 const struct cpuinfo_cache* l1i;
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700542 /** Level 1 data cache */
Marat Dukhan547fa362017-03-03 02:47:26 -0500543 const struct cpuinfo_cache* l1d;
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700544 /** Level 2 unified or data cache */
Marat Dukhan547fa362017-03-03 02:47:26 -0500545 const struct cpuinfo_cache* l2;
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700546 /** Level 3 unified or data cache */
Marat Dukhan547fa362017-03-03 02:47:26 -0500547 const struct cpuinfo_cache* l3;
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700548 /** Level 4 unified or data cache */
Marat Dukhan547fa362017-03-03 02:47:26 -0500549 const struct cpuinfo_cache* l4;
550 } cache;
551};
552
553struct cpuinfo_core {
Marat Dukhan4d376c32018-03-18 11:36:39 -0700554 /** Index of the first logical processor on this core. */
Marat Dukhanab3a1272017-08-25 23:20:07 -0700555 uint32_t processor_start;
Marat Dukhan2d37dc42017-09-25 01:32:37 -0700556 /** Number of logical processors on this core */
Marat Dukhanab3a1272017-08-25 23:20:07 -0700557 uint32_t processor_count;
Marat Dukhan2d37dc42017-09-25 01:32:37 -0700558 /** Core ID within a package */
559 uint32_t core_id;
Marat Dukhan4d376c32018-03-18 11:36:39 -0700560 /** Cluster containing this core */
561 const struct cpuinfo_cluster* cluster;
562 /** Physical package containing this core. */
Marat Dukhan2d37dc42017-09-25 01:32:37 -0700563 const struct cpuinfo_package* package;
564 /** Vendor of the CPU microarchitecture for this core */
565 enum cpuinfo_vendor vendor;
566 /** CPU microarchitecture for this core */
567 enum cpuinfo_uarch uarch;
568#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
569 /** Value of CPUID leaf 1 EAX register for this core */
570 uint32_t cpuid;
571#elif CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
572 /** Value of Main ID Register (MIDR) for this core */
573 uint32_t midr;
574#endif
Marat Dukhan28538f42018-03-10 14:28:14 -0800575 /** Clock rate (non-Turbo) of the core, in Hz */
576 uint64_t frequency;
Marat Dukhan547fa362017-03-03 02:47:26 -0500577};
578
Marat Dukhan4d376c32018-03-18 11:36:39 -0700579struct cpuinfo_cluster {
580 /** Index of the first logical processor in the cluster */
581 uint32_t processor_start;
582 /** Number of logical processors in the cluster */
583 uint32_t processor_count;
584 /** Index of the first core in the cluster */
585 uint32_t core_start;
586 /** Number of cores on the cluster */
587 uint32_t core_count;
588 /** Cluster ID within a package */
589 uint32_t cluster_id;
590 /** Physical package containing the cluster */
591 const struct cpuinfo_package* package;
592 /** CPU microarchitecture vendor of the cores in the cluster */
593 enum cpuinfo_vendor vendor;
594 /** CPU microarchitecture of the cores in the cluster */
595 enum cpuinfo_uarch uarch;
596#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
597 /** Value of CPUID leaf 1 EAX register of the cores in the cluster */
598 uint32_t cpuid;
599#elif CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
600 /** Value of Main ID Register (MIDR) of the cores in the cluster */
601 uint32_t midr;
602#endif
603 /** Clock rate (non-Turbo) of the cores in the cluster, in Hz */
604 uint64_t frequency;
605};
606
Marat Dukhanfb4fbe02017-09-13 00:51:05 -0700607#define CPUINFO_PACKAGE_NAME_MAX 48
608
Marat Dukhan547fa362017-03-03 02:47:26 -0500609struct cpuinfo_package {
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700610 /** SoC or processor chip model name */
Marat Dukhanfb4fbe02017-09-13 00:51:05 -0700611 char name[CPUINFO_PACKAGE_NAME_MAX];
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700612 /** Index of the first logical processor on this physical package */
Marat Dukhanab3a1272017-08-25 23:20:07 -0700613 uint32_t processor_start;
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700614 /** Number of logical processors on this physical package */
Marat Dukhanab3a1272017-08-25 23:20:07 -0700615 uint32_t processor_count;
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700616 /** Index of the first core on this physical package */
Marat Dukhanfb4fbe02017-09-13 00:51:05 -0700617 uint32_t core_start;
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700618 /** Number of cores on this physical package */
Marat Dukhan547fa362017-03-03 02:47:26 -0500619 uint32_t core_count;
Marat Dukhan4d376c32018-03-18 11:36:39 -0700620 /** Index of the first cluster of cores on this physical package */
621 uint32_t cluster_start;
622 /** Number of clusters of cores on this physical package */
623 uint32_t cluster_count;
Marat Dukhan547fa362017-03-03 02:47:26 -0500624};
625
Ashkan Aliabadidcf8e182020-03-19 19:34:26 -0700626struct cpuinfo_uarch_info {
627 /** Type of CPU microarchitecture */
628 enum cpuinfo_uarch uarch;
629#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
630 /** Value of CPUID leaf 1 EAX register for the microarchitecture */
631 uint32_t cpuid;
632#elif CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
633 /** Value of Main ID Register (MIDR) for the microarchitecture */
634 uint32_t midr;
635#endif
636 /** Number of logical processors with the microarchitecture */
637 uint32_t processor_count;
638 /** Number of cores with the microarchitecture */
639 uint32_t core_count;
640};
641
Marat Dukhan547fa362017-03-03 02:47:26 -0500642#ifdef __cplusplus
643extern "C" {
644#endif
645
Marat Dukhan53556512018-02-25 09:01:27 +0100646bool CPUINFO_ABI cpuinfo_initialize(void);
Marat Dukhan547fa362017-03-03 02:47:26 -0500647
648void CPUINFO_ABI cpuinfo_deinitialize(void);
649
650#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
Marat Dukhanf720d102017-09-26 10:33:47 -0700651 /* This structure is not a part of stable API. Use cpuinfo_has_x86_* functions instead. */
652 struct cpuinfo_x86_isa {
653 #if CPUINFO_ARCH_X86
654 bool rdtsc;
655 #endif
656 bool rdtscp;
657 bool rdpid;
658 bool sysenter;
659 #if CPUINFO_ARCH_X86
660 bool syscall;
661 #endif
662 bool msr;
663 bool clzero;
664 bool clflush;
665 bool clflushopt;
666 bool mwait;
667 bool mwaitx;
668 #if CPUINFO_ARCH_X86
669 bool emmx;
670 #endif
671 bool fxsave;
672 bool xsave;
673 #if CPUINFO_ARCH_X86
674 bool fpu;
675 bool mmx;
676 bool mmx_plus;
677 #endif
678 bool three_d_now;
679 bool three_d_now_plus;
680 #if CPUINFO_ARCH_X86
681 bool three_d_now_geode;
682 #endif
683 bool prefetch;
684 bool prefetchw;
685 bool prefetchwt1;
686 #if CPUINFO_ARCH_X86
687 bool daz;
688 bool sse;
689 bool sse2;
690 #endif
691 bool sse3;
692 bool ssse3;
693 bool sse4_1;
694 bool sse4_2;
695 bool sse4a;
696 bool misaligned_sse;
697 bool avx;
698 bool fma3;
699 bool fma4;
700 bool xop;
701 bool f16c;
702 bool avx2;
703 bool avx512f;
704 bool avx512pf;
705 bool avx512er;
706 bool avx512cd;
707 bool avx512dq;
708 bool avx512bw;
709 bool avx512vl;
710 bool avx512ifma;
711 bool avx512vbmi;
Marat Dukhan861d21a2017-10-13 07:10:25 -0700712 bool avx512vbmi2;
713 bool avx512bitalg;
Marat Dukhanf720d102017-09-26 10:33:47 -0700714 bool avx512vpopcntdq;
Marat Dukhan861d21a2017-10-13 07:10:25 -0700715 bool avx512vnni;
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -0800716 bool avx512bf16;
717 bool avx512vp2intersect;
Marat Dukhanf720d102017-09-26 10:33:47 -0700718 bool avx512_4vnniw;
719 bool avx512_4fmaps;
720 bool hle;
721 bool rtm;
722 bool xtest;
723 bool mpx;
724 #if CPUINFO_ARCH_X86
725 bool cmov;
726 bool cmpxchg8b;
727 #endif
728 bool cmpxchg16b;
729 bool clwb;
730 bool movbe;
731 #if CPUINFO_ARCH_X86_64
732 bool lahf_sahf;
733 #endif
734 bool fs_gs_base;
735 bool lzcnt;
736 bool popcnt;
737 bool tbm;
738 bool bmi;
739 bool bmi2;
740 bool adx;
741 bool aes;
Marat Dukhan861d21a2017-10-13 07:10:25 -0700742 bool vaes;
Marat Dukhanf720d102017-09-26 10:33:47 -0700743 bool pclmulqdq;
Marat Dukhan861d21a2017-10-13 07:10:25 -0700744 bool vpclmulqdq;
745 bool gfni;
Marat Dukhanf720d102017-09-26 10:33:47 -0700746 bool rdrand;
747 bool rdseed;
748 bool sha;
749 bool rng;
750 bool ace;
751 bool ace2;
752 bool phe;
753 bool pmm;
754 bool lwp;
755 };
756
Marat Dukhan547fa362017-03-03 02:47:26 -0500757 extern struct cpuinfo_x86_isa cpuinfo_isa;
758#endif
759
Marat Dukhanf720d102017-09-26 10:33:47 -0700760static inline bool cpuinfo_has_x86_rdtsc(void) {
761 #if CPUINFO_ARCH_X86_64
762 return true;
763 #elif CPUINFO_ARCH_X86
764 #if defined(__ANDROID__)
765 return true;
766 #else
767 return cpuinfo_isa.rdtsc;
768 #endif
769 #else
770 return false;
771 #endif
772}
773
774static inline bool cpuinfo_has_x86_rdtscp(void) {
775 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
776 return cpuinfo_isa.rdtscp;
777 #else
778 return false;
779 #endif
780}
781
782static inline bool cpuinfo_has_x86_rdpid(void) {
783 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
784 return cpuinfo_isa.rdpid;
785 #else
786 return false;
787 #endif
788}
789
790static inline bool cpuinfo_has_x86_clzero(void) {
791 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
792 return cpuinfo_isa.clzero;
793 #else
794 return false;
795 #endif
796}
797
798static inline bool cpuinfo_has_x86_mwait(void) {
799 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
800 return cpuinfo_isa.mwait;
801 #else
802 return false;
803 #endif
804}
805
806static inline bool cpuinfo_has_x86_mwaitx(void) {
807 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
808 return cpuinfo_isa.mwaitx;
809 #else
810 return false;
811 #endif
812}
813
814static inline bool cpuinfo_has_x86_fxsave(void) {
815 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
816 return cpuinfo_isa.fxsave;
817 #else
818 return false;
819 #endif
820}
821
822static inline bool cpuinfo_has_x86_xsave(void) {
823 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
824 return cpuinfo_isa.xsave;
825 #else
826 return false;
827 #endif
828}
829
830static inline bool cpuinfo_has_x86_fpu(void) {
831 #if CPUINFO_ARCH_X86_64
832 return true;
833 #elif CPUINFO_ARCH_X86
834 #if defined(__ANDROID__)
835 return true;
836 #else
837 return cpuinfo_isa.fpu;
838 #endif
839 #else
840 return false;
841 #endif
842}
843
844static inline bool cpuinfo_has_x86_mmx(void) {
845 #if CPUINFO_ARCH_X86_64
846 return true;
847 #elif CPUINFO_ARCH_X86
848 #if defined(__ANDROID__)
849 return true;
850 #else
851 return cpuinfo_isa.mmx;
852 #endif
853 #else
854 return false;
855 #endif
856}
857
858static inline bool cpuinfo_has_x86_mmx_plus(void) {
859 #if CPUINFO_ARCH_X86_64
860 return true;
861 #elif CPUINFO_ARCH_X86
862 #if defined(__ANDROID__)
863 return true;
864 #else
865 return cpuinfo_isa.mmx_plus;
866 #endif
867 #else
868 return false;
869 #endif
870}
871
872static inline bool cpuinfo_has_x86_3dnow(void) {
873 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
874 return cpuinfo_isa.three_d_now;
875 #else
876 return false;
877 #endif
878}
879
880static inline bool cpuinfo_has_x86_3dnow_plus(void) {
881 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
882 return cpuinfo_isa.three_d_now_plus;
883 #else
884 return false;
885 #endif
886}
887
888static inline bool cpuinfo_has_x86_3dnow_geode(void) {
889 #if CPUINFO_ARCH_X86_64
890 return false;
891 #elif CPUINFO_ARCH_X86
892 #if defined(__ANDROID__)
893 return false;
894 #else
895 return cpuinfo_isa.three_d_now_geode;
896 #endif
897 #else
898 return false;
899 #endif
900}
901
902static inline bool cpuinfo_has_x86_prefetch(void) {
903 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
904 return cpuinfo_isa.prefetch;
905 #else
906 return false;
907 #endif
908}
909
910static inline bool cpuinfo_has_x86_prefetchw(void) {
911 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
912 return cpuinfo_isa.prefetchw;
913 #else
914 return false;
915 #endif
916}
917
918static inline bool cpuinfo_has_x86_prefetchwt1(void) {
919 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
Marat Dukhan6022f802017-09-26 11:56:36 -0700920 return cpuinfo_isa.prefetchwt1;
Marat Dukhanf720d102017-09-26 10:33:47 -0700921 #else
922 return false;
923 #endif
924}
925
926static inline bool cpuinfo_has_x86_daz(void) {
927 #if CPUINFO_ARCH_X86_64
928 return true;
929 #elif CPUINFO_ARCH_X86
930 #if defined(__ANDROID__)
931 return true;
932 #else
933 return cpuinfo_isa.daz;
934 #endif
935 #else
936 return false;
937 #endif
938}
939
Marat Dukhan9da4c912017-09-26 10:53:28 -0700940static inline bool cpuinfo_has_x86_sse(void) {
941 #if CPUINFO_ARCH_X86_64
942 return true;
943 #elif CPUINFO_ARCH_X86
944 #if defined(__ANDROID__)
945 return true;
946 #else
947 return cpuinfo_isa.sse;
948 #endif
949 #else
950 return false;
951 #endif
952}
953
Marat Dukhanf720d102017-09-26 10:33:47 -0700954static inline bool cpuinfo_has_x86_sse2(void) {
955 #if CPUINFO_ARCH_X86_64
956 return true;
957 #elif CPUINFO_ARCH_X86
958 #if defined(__ANDROID__)
959 return true;
960 #else
961 return cpuinfo_isa.sse2;
962 #endif
963 #else
964 return false;
965 #endif
966}
967
968static inline bool cpuinfo_has_x86_sse3(void) {
969 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
970 #if defined(__ANDROID__)
971 return true;
972 #else
973 return cpuinfo_isa.sse3;
974 #endif
975 #else
976 return false;
977 #endif
978}
979
980static inline bool cpuinfo_has_x86_ssse3(void) {
981 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
982 #if defined(__ANDROID__)
983 return true;
984 #else
985 return cpuinfo_isa.ssse3;
986 #endif
987 #else
988 return false;
989 #endif
990}
991
992static inline bool cpuinfo_has_x86_sse4_1(void) {
993 #if CPUINFO_ARCH_X86_64
994 #if defined(__ANDROID__)
995 return true;
996 #else
997 return cpuinfo_isa.sse4_1;
998 #endif
999 #elif CPUINFO_ARCH_X86
1000 return cpuinfo_isa.sse4_1;
1001 #else
1002 return false;
1003 #endif
1004}
1005
1006static inline bool cpuinfo_has_x86_sse4_2(void) {
1007 #if CPUINFO_ARCH_X86_64
1008 #if defined(__ANDROID__)
1009 return true;
1010 #else
1011 return cpuinfo_isa.sse4_2;
1012 #endif
1013 #elif CPUINFO_ARCH_X86
1014 return cpuinfo_isa.sse4_2;
1015 #else
1016 return false;
1017 #endif
1018}
1019
1020static inline bool cpuinfo_has_x86_sse4a(void) {
1021 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1022 return cpuinfo_isa.sse4a;
1023 #else
1024 return false;
1025 #endif
1026}
1027
1028static inline bool cpuinfo_has_x86_misaligned_sse(void) {
1029 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1030 return cpuinfo_isa.misaligned_sse;
1031 #else
1032 return false;
1033 #endif
1034}
1035
1036static inline bool cpuinfo_has_x86_avx(void) {
1037 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1038 return cpuinfo_isa.avx;
1039 #else
1040 return false;
1041 #endif
1042}
1043
1044static inline bool cpuinfo_has_x86_fma3(void) {
1045 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1046 return cpuinfo_isa.fma3;
1047 #else
1048 return false;
1049 #endif
1050}
1051
1052static inline bool cpuinfo_has_x86_fma4(void) {
1053 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1054 return cpuinfo_isa.fma4;
1055 #else
1056 return false;
1057 #endif
1058}
1059
1060static inline bool cpuinfo_has_x86_xop(void) {
1061 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1062 return cpuinfo_isa.xop;
1063 #else
1064 return false;
1065 #endif
1066}
1067
1068static inline bool cpuinfo_has_x86_f16c(void) {
1069 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1070 return cpuinfo_isa.f16c;
1071 #else
1072 return false;
1073 #endif
1074}
1075
1076static inline bool cpuinfo_has_x86_avx2(void) {
1077 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1078 return cpuinfo_isa.avx2;
1079 #else
1080 return false;
1081 #endif
1082}
1083
1084static inline bool cpuinfo_has_x86_avx512f(void) {
1085 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1086 return cpuinfo_isa.avx512f;
1087 #else
1088 return false;
1089 #endif
1090}
1091
1092static inline bool cpuinfo_has_x86_avx512pf(void) {
1093 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1094 return cpuinfo_isa.avx512pf;
1095 #else
1096 return false;
1097 #endif
1098}
1099
1100static inline bool cpuinfo_has_x86_avx512er(void) {
1101 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1102 return cpuinfo_isa.avx512er;
1103 #else
1104 return false;
1105 #endif
1106}
1107
1108static inline bool cpuinfo_has_x86_avx512cd(void) {
1109 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1110 return cpuinfo_isa.avx512cd;
1111 #else
1112 return false;
1113 #endif
1114}
1115
1116static inline bool cpuinfo_has_x86_avx512dq(void) {
1117 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1118 return cpuinfo_isa.avx512dq;
1119 #else
1120 return false;
1121 #endif
1122}
1123
1124static inline bool cpuinfo_has_x86_avx512bw(void) {
1125 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1126 return cpuinfo_isa.avx512bw;
1127 #else
1128 return false;
1129 #endif
1130}
1131
1132static inline bool cpuinfo_has_x86_avx512vl(void) {
1133 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1134 return cpuinfo_isa.avx512vl;
1135 #else
1136 return false;
1137 #endif
1138}
1139
1140static inline bool cpuinfo_has_x86_avx512ifma(void) {
1141 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1142 return cpuinfo_isa.avx512ifma;
1143 #else
1144 return false;
1145 #endif
1146}
1147
1148static inline bool cpuinfo_has_x86_avx512vbmi(void) {
1149 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1150 return cpuinfo_isa.avx512vbmi;
1151 #else
1152 return false;
1153 #endif
1154}
1155
Marat Dukhan861d21a2017-10-13 07:10:25 -07001156static inline bool cpuinfo_has_x86_avx512vbmi2(void) {
1157 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1158 return cpuinfo_isa.avx512vbmi2;
1159 #else
1160 return false;
1161 #endif
1162}
1163
1164static inline bool cpuinfo_has_x86_avx512bitalg(void) {
1165 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1166 return cpuinfo_isa.avx512bitalg;
1167 #else
1168 return false;
1169 #endif
1170}
1171
Marat Dukhanf720d102017-09-26 10:33:47 -07001172static inline bool cpuinfo_has_x86_avx512vpopcntdq(void) {
1173 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1174 return cpuinfo_isa.avx512vpopcntdq;
1175 #else
1176 return false;
1177 #endif
1178}
1179
Marat Dukhan861d21a2017-10-13 07:10:25 -07001180static inline bool cpuinfo_has_x86_avx512vnni(void) {
Marat Dukhan6b33b232017-10-13 09:36:52 -07001181 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
Marat Dukhan861d21a2017-10-13 07:10:25 -07001182 return cpuinfo_isa.avx512vnni;
1183 #else
1184 return false;
1185 #endif
1186}
1187
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -08001188static inline bool cpuinfo_has_x86_avx512bf16(void) {
1189 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1190 return cpuinfo_isa.avx512bf16;
1191 #else
1192 return false;
1193 #endif
1194}
1195
1196static inline bool cpuinfo_has_x86_avx512vp2intersect(void) {
1197 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1198 return cpuinfo_isa.avx512vp2intersect;
1199 #else
1200 return false;
1201 #endif
1202}
1203
Marat Dukhanf720d102017-09-26 10:33:47 -07001204static inline bool cpuinfo_has_x86_avx512_4vnniw(void) {
1205 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1206 return cpuinfo_isa.avx512_4vnniw;
1207 #else
1208 return false;
1209 #endif
1210}
1211
1212static inline bool cpuinfo_has_x86_avx512_4fmaps(void) {
1213 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1214 return cpuinfo_isa.avx512_4fmaps;
1215 #else
1216 return false;
1217 #endif
1218}
1219
Marat Dukhan9e32e8d2017-09-26 11:02:37 -07001220static inline bool cpuinfo_has_x86_hle(void) {
1221 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1222 return cpuinfo_isa.hle;
1223 #else
1224 return false;
1225 #endif
1226}
1227
1228static inline bool cpuinfo_has_x86_rtm(void) {
1229 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1230 return cpuinfo_isa.rtm;
1231 #else
1232 return false;
1233 #endif
1234}
1235
1236static inline bool cpuinfo_has_x86_xtest(void) {
1237 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1238 return cpuinfo_isa.xtest;
1239 #else
1240 return false;
1241 #endif
1242}
1243
1244static inline bool cpuinfo_has_x86_mpx(void) {
1245 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1246 return cpuinfo_isa.mpx;
1247 #else
1248 return false;
1249 #endif
1250}
1251
Marat Dukhanf720d102017-09-26 10:33:47 -07001252static inline bool cpuinfo_has_x86_cmov(void) {
1253 #if CPUINFO_ARCH_X86_64
1254 return true;
1255 #elif CPUINFO_ARCH_X86
1256 return cpuinfo_isa.cmov;
1257 #else
1258 return false;
1259 #endif
1260}
1261
1262static inline bool cpuinfo_has_x86_cmpxchg8b(void) {
1263 #if CPUINFO_ARCH_X86_64
1264 return true;
1265 #elif CPUINFO_ARCH_X86
1266 return cpuinfo_isa.cmpxchg8b;
1267 #else
1268 return false;
1269 #endif
1270}
1271
1272static inline bool cpuinfo_has_x86_cmpxchg16b(void) {
1273 #if CPUINFO_ARCH_X86_64
1274 return cpuinfo_isa.cmpxchg16b;
1275 #else
1276 return false;
1277 #endif
1278}
1279
1280static inline bool cpuinfo_has_x86_clwb(void) {
1281 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1282 return cpuinfo_isa.clwb;
1283 #else
1284 return false;
1285 #endif
1286}
1287
1288static inline bool cpuinfo_has_x86_movbe(void) {
Marat Dukhan6022f802017-09-26 11:56:36 -07001289 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
Marat Dukhanf720d102017-09-26 10:33:47 -07001290 return cpuinfo_isa.movbe;
1291 #else
1292 return false;
1293 #endif
1294}
1295
Marat Dukhan30401972017-09-26 18:35:52 -07001296static inline bool cpuinfo_has_x86_lahf_sahf(void) {
Marat Dukhanf720d102017-09-26 10:33:47 -07001297 #if CPUINFO_ARCH_X86
1298 return true;
1299 #elif CPUINFO_ARCH_X86_64
1300 return cpuinfo_isa.lahf_sahf;
1301 #else
1302 return false;
1303 #endif
1304}
1305
1306static inline bool cpuinfo_has_x86_lzcnt(void) {
1307 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1308 return cpuinfo_isa.lzcnt;
1309 #else
1310 return false;
1311 #endif
1312}
1313
1314static inline bool cpuinfo_has_x86_popcnt(void) {
1315 #if CPUINFO_ARCH_X86_64
1316 #if defined(__ANDROID__)
1317 return true;
1318 #else
1319 return cpuinfo_isa.popcnt;
1320 #endif
1321 #elif CPUINFO_ARCH_X86
1322 return cpuinfo_isa.popcnt;
1323 #else
1324 return false;
1325 #endif
1326}
1327
1328static inline bool cpuinfo_has_x86_tbm(void) {
1329 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1330 return cpuinfo_isa.tbm;
1331 #else
1332 return false;
1333 #endif
1334}
1335
1336static inline bool cpuinfo_has_x86_bmi(void) {
1337 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1338 return cpuinfo_isa.bmi;
1339 #else
1340 return false;
1341 #endif
1342}
1343
1344static inline bool cpuinfo_has_x86_bmi2(void) {
1345 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1346 return cpuinfo_isa.bmi2;
1347 #else
1348 return false;
1349 #endif
1350}
1351
1352static inline bool cpuinfo_has_x86_adx(void) {
1353 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1354 return cpuinfo_isa.adx;
1355 #else
1356 return false;
1357 #endif
1358}
1359
1360static inline bool cpuinfo_has_x86_aes(void) {
1361 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1362 return cpuinfo_isa.aes;
1363 #else
1364 return false;
1365 #endif
1366}
1367
Marat Dukhan861d21a2017-10-13 07:10:25 -07001368static inline bool cpuinfo_has_x86_vaes(void) {
1369 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1370 return cpuinfo_isa.vaes;
1371 #else
1372 return false;
1373 #endif
1374}
1375
Marat Dukhanf720d102017-09-26 10:33:47 -07001376static inline bool cpuinfo_has_x86_pclmulqdq(void) {
1377 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1378 return cpuinfo_isa.pclmulqdq;
1379 #else
1380 return false;
1381 #endif
1382}
1383
Marat Dukhan861d21a2017-10-13 07:10:25 -07001384static inline bool cpuinfo_has_x86_vpclmulqdq(void) {
1385 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1386 return cpuinfo_isa.vpclmulqdq;
1387 #else
1388 return false;
1389 #endif
1390}
1391
1392static inline bool cpuinfo_has_x86_gfni(void) {
1393 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1394 return cpuinfo_isa.gfni;
1395 #else
1396 return false;
1397 #endif
1398}
1399
Marat Dukhanf720d102017-09-26 10:33:47 -07001400static inline bool cpuinfo_has_x86_rdrand(void) {
1401 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1402 return cpuinfo_isa.rdrand;
1403 #else
1404 return false;
1405 #endif
1406}
1407
1408static inline bool cpuinfo_has_x86_rdseed(void) {
1409 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1410 return cpuinfo_isa.rdseed;
1411 #else
1412 return false;
1413 #endif
1414}
1415
1416static inline bool cpuinfo_has_x86_sha(void) {
1417 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1418 return cpuinfo_isa.sha;
1419 #else
1420 return false;
1421 #endif
1422}
1423
Marat Dukhanab42e7e2017-05-09 13:19:39 +00001424#if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
Marat Dukhanf720d102017-09-26 10:33:47 -07001425 /* This structure is not a part of stable API. Use cpuinfo_has_arm_* functions instead. */
1426 struct cpuinfo_arm_isa {
1427 #if CPUINFO_ARCH_ARM
1428 bool thumb;
1429 bool thumb2;
1430 bool thumbee;
1431 bool jazelle;
1432 bool armv5e;
1433 bool armv6;
1434 bool armv6k;
1435 bool armv7;
1436 bool armv7mp;
1437 bool idiv;
1438
1439 bool vfpv2;
1440 bool vfpv3;
1441 bool d32;
1442 bool fp16;
1443 bool fma;
1444
1445 bool wmmx;
1446 bool wmmx2;
1447 bool neon;
1448 #endif
1449 #if CPUINFO_ARCH_ARM64
1450 bool atomics;
Marat Dukhanf720d102017-09-26 10:33:47 -07001451 #endif
Marat Dukhan7abab752018-04-19 22:03:52 -07001452 bool rdm;
1453 bool fp16arith;
Marat Dukhandb14c222018-12-19 02:34:17 -08001454 bool dot;
Marat Dukhan7abab752018-04-19 22:03:52 -07001455 bool jscvt;
1456 bool fcma;
Marat Dukhanf720d102017-09-26 10:33:47 -07001457
1458 bool aes;
1459 bool sha1;
1460 bool sha2;
1461 bool pmull;
1462 bool crc32;
1463 };
1464
Marat Dukhan3c982762017-05-08 06:16:45 +00001465 extern struct cpuinfo_arm_isa cpuinfo_isa;
1466#endif
1467
Marat Dukhanf720d102017-09-26 10:33:47 -07001468static inline bool cpuinfo_has_arm_thumb(void) {
1469 #if CPUINFO_ARCH_ARM
1470 return cpuinfo_isa.thumb;
1471 #else
1472 return false;
1473 #endif
1474}
1475
1476static inline bool cpuinfo_has_arm_thumb2(void) {
1477 #if CPUINFO_ARCH_ARM
1478 return cpuinfo_isa.thumb2;
1479 #else
1480 return false;
1481 #endif
1482}
1483
1484static inline bool cpuinfo_has_arm_v5e(void) {
1485 #if CPUINFO_ARCH_ARM
1486 return cpuinfo_isa.armv5e;
1487 #else
1488 return false;
1489 #endif
1490}
1491
1492static inline bool cpuinfo_has_arm_v6(void) {
1493 #if CPUINFO_ARCH_ARM
1494 return cpuinfo_isa.armv6;
1495 #else
1496 return false;
1497 #endif
1498}
1499
1500static inline bool cpuinfo_has_arm_v6k(void) {
1501 #if CPUINFO_ARCH_ARM
1502 return cpuinfo_isa.armv6k;
1503 #else
1504 return false;
1505 #endif
1506}
1507
1508static inline bool cpuinfo_has_arm_v7(void) {
1509 #if CPUINFO_ARCH_ARM
1510 return cpuinfo_isa.armv7;
1511 #else
1512 return false;
1513 #endif
1514}
1515
1516static inline bool cpuinfo_has_arm_v7mp(void) {
1517 #if CPUINFO_ARCH_ARM
1518 return cpuinfo_isa.armv7mp;
1519 #else
1520 return false;
1521 #endif
1522}
1523
1524static inline bool cpuinfo_has_arm_idiv(void) {
1525 #if CPUINFO_ARCH_ARM64
1526 return true;
1527 #elif CPUINFO_ARCH_ARM
1528 return cpuinfo_isa.idiv;
1529 #else
1530 return false;
1531 #endif
1532}
1533
1534static inline bool cpuinfo_has_arm_vfpv2(void) {
1535 #if CPUINFO_ARCH_ARM
1536 return cpuinfo_isa.vfpv2;
1537 #else
1538 return false;
1539 #endif
1540}
1541
1542static inline bool cpuinfo_has_arm_vfpv3(void) {
1543 #if CPUINFO_ARCH_ARM64
1544 return true;
1545 #elif CPUINFO_ARCH_ARM
1546 return cpuinfo_isa.vfpv3;
1547 #else
1548 return false;
1549 #endif
1550}
1551
1552static inline bool cpuinfo_has_arm_vfpv3_d32(void) {
1553 #if CPUINFO_ARCH_ARM64
1554 return true;
1555 #elif CPUINFO_ARCH_ARM
1556 return cpuinfo_isa.vfpv3 && cpuinfo_isa.d32;
1557 #else
1558 return false;
1559 #endif
1560}
1561
1562static inline bool cpuinfo_has_arm_vfpv3_fp16(void) {
1563 #if CPUINFO_ARCH_ARM64
1564 return true;
1565 #elif CPUINFO_ARCH_ARM
1566 return cpuinfo_isa.vfpv3 && cpuinfo_isa.fp16;
1567 #else
1568 return false;
1569 #endif
1570}
1571
1572static inline bool cpuinfo_has_arm_vfpv3_fp16_d32(void) {
1573 #if CPUINFO_ARCH_ARM64
1574 return true;
1575 #elif CPUINFO_ARCH_ARM
1576 return cpuinfo_isa.vfpv3 && cpuinfo_isa.fp16 && cpuinfo_isa.d32;
1577 #else
1578 return false;
1579 #endif
1580}
1581
Marat Dukhan6022f802017-09-26 11:56:36 -07001582static inline bool cpuinfo_has_arm_vfpv4(void) {
Marat Dukhanf720d102017-09-26 10:33:47 -07001583 #if CPUINFO_ARCH_ARM64
1584 return true;
1585 #elif CPUINFO_ARCH_ARM
1586 return cpuinfo_isa.vfpv3 && cpuinfo_isa.fma;
1587 #else
1588 return false;
1589 #endif
1590}
1591
Marat Dukhan6022f802017-09-26 11:56:36 -07001592static inline bool cpuinfo_has_arm_vfpv4_d32(void) {
Marat Dukhanf720d102017-09-26 10:33:47 -07001593 #if CPUINFO_ARCH_ARM64
1594 return true;
1595 #elif CPUINFO_ARCH_ARM
1596 return cpuinfo_isa.vfpv3 && cpuinfo_isa.fma && cpuinfo_isa.d32;
1597 #else
1598 return false;
1599 #endif
1600}
1601
1602static inline bool cpuinfo_has_arm_wmmx(void) {
1603 #if CPUINFO_ARCH_ARM
1604 return cpuinfo_isa.wmmx;
1605 #else
1606 return false;
1607 #endif
1608}
1609
1610static inline bool cpuinfo_has_arm_wmmx2(void) {
1611 #if CPUINFO_ARCH_ARM
1612 return cpuinfo_isa.wmmx2;
1613 #else
1614 return false;
1615 #endif
1616}
1617
1618static inline bool cpuinfo_has_arm_neon(void) {
1619 #if CPUINFO_ARCH_ARM64
1620 return true;
1621 #elif CPUINFO_ARCH_ARM
1622 return cpuinfo_isa.neon;
1623 #else
1624 return false;
1625 #endif
1626}
1627
1628static inline bool cpuinfo_has_arm_neon_fp16(void) {
1629 #if CPUINFO_ARCH_ARM64
1630 return true;
1631 #elif CPUINFO_ARCH_ARM
1632 return cpuinfo_isa.neon && cpuinfo_isa.fp16;
1633 #else
1634 return false;
1635 #endif
1636}
1637
1638static inline bool cpuinfo_has_arm_neon_fma(void) {
1639 #if CPUINFO_ARCH_ARM64
1640 return true;
1641 #elif CPUINFO_ARCH_ARM
1642 return cpuinfo_isa.neon && cpuinfo_isa.fma;
1643 #else
1644 return false;
1645 #endif
1646}
1647
1648static inline bool cpuinfo_has_arm_atomics(void) {
1649 #if CPUINFO_ARCH_ARM64
1650 return cpuinfo_isa.atomics;
1651 #else
1652 return false;
1653 #endif
1654}
1655
1656static inline bool cpuinfo_has_arm_neon_rdm(void) {
Marat Dukhan7abab752018-04-19 22:03:52 -07001657 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
Marat Dukhanf720d102017-09-26 10:33:47 -07001658 return cpuinfo_isa.rdm;
1659 #else
1660 return false;
1661 #endif
1662}
1663
Marat Dukhande2f71e2018-06-11 13:30:21 -07001664static inline bool cpuinfo_has_arm_neon_fp16_arith(void) {
1665 #if CPUINFO_ARCH_ARM
1666 return cpuinfo_isa.neon && cpuinfo_isa.fp16arith;
1667 #elif CPUINFO_ARCH_ARM64
1668 return cpuinfo_isa.fp16arith;
1669 #else
1670 return false;
1671 #endif
1672}
1673
Marat Dukhanf720d102017-09-26 10:33:47 -07001674static inline bool cpuinfo_has_arm_fp16_arith(void) {
Marat Dukhan7abab752018-04-19 22:03:52 -07001675 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
Marat Dukhanf720d102017-09-26 10:33:47 -07001676 return cpuinfo_isa.fp16arith;
1677 #else
1678 return false;
1679 #endif
1680}
1681
Marat Dukhandb14c222018-12-19 02:34:17 -08001682static inline bool cpuinfo_has_arm_neon_dot(void) {
1683 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1684 return cpuinfo_isa.dot;
1685 #else
1686 return false;
1687 #endif
1688}
1689
Marat Dukhanf720d102017-09-26 10:33:47 -07001690static inline bool cpuinfo_has_arm_jscvt(void) {
Marat Dukhan7abab752018-04-19 22:03:52 -07001691 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
Marat Dukhanf720d102017-09-26 10:33:47 -07001692 return cpuinfo_isa.jscvt;
1693 #else
1694 return false;
1695 #endif
1696}
1697
1698static inline bool cpuinfo_has_arm_fcma(void) {
Marat Dukhan7abab752018-04-19 22:03:52 -07001699 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
Marat Dukhanf720d102017-09-26 10:33:47 -07001700 return cpuinfo_isa.fcma;
1701 #else
1702 return false;
1703 #endif
1704}
1705
1706static inline bool cpuinfo_has_arm_aes(void) {
1707 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1708 return cpuinfo_isa.aes;
1709 #else
1710 return false;
1711 #endif
1712}
1713
1714static inline bool cpuinfo_has_arm_sha1(void) {
1715 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1716 return cpuinfo_isa.sha1;
1717 #else
1718 return false;
1719 #endif
1720}
1721
1722static inline bool cpuinfo_has_arm_sha2(void) {
1723 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1724 return cpuinfo_isa.sha2;
1725 #else
1726 return false;
1727 #endif
1728}
1729
1730static inline bool cpuinfo_has_arm_pmull(void) {
1731 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1732 return cpuinfo_isa.pmull;
1733 #else
1734 return false;
1735 #endif
1736}
1737
1738static inline bool cpuinfo_has_arm_crc32(void) {
1739 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1740 return cpuinfo_isa.crc32;
1741 #else
1742 return false;
1743 #endif
1744}
1745
Marat Dukhan7b5e4d52018-03-15 23:42:50 -07001746const struct cpuinfo_processor* CPUINFO_ABI cpuinfo_get_processors(void);
1747const struct cpuinfo_core* CPUINFO_ABI cpuinfo_get_cores(void);
Marat Dukhan4d376c32018-03-18 11:36:39 -07001748const struct cpuinfo_cluster* CPUINFO_ABI cpuinfo_get_clusters(void);
Marat Dukhan7b5e4d52018-03-15 23:42:50 -07001749const struct cpuinfo_package* CPUINFO_ABI cpuinfo_get_packages(void);
Ashkan Aliabadidcf8e182020-03-19 19:34:26 -07001750const struct cpuinfo_uarch_info* CPUINFO_ABI cpuinfo_get_uarchs(void);
Marat Dukhan30401972017-09-26 18:35:52 -07001751const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l1i_caches(void);
1752const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l1d_caches(void);
1753const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l2_caches(void);
1754const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l3_caches(void);
1755const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l4_caches(void);
Marat Dukhan3045d4f2017-03-04 01:51:42 -05001756
Marat Dukhan7b5e4d52018-03-15 23:42:50 -07001757const struct cpuinfo_processor* CPUINFO_ABI cpuinfo_get_processor(uint32_t index);
1758const struct cpuinfo_core* CPUINFO_ABI cpuinfo_get_core(uint32_t index);
Marat Dukhan4d376c32018-03-18 11:36:39 -07001759const struct cpuinfo_cluster* CPUINFO_ABI cpuinfo_get_cluster(uint32_t index);
Marat Dukhan7b5e4d52018-03-15 23:42:50 -07001760const struct cpuinfo_package* CPUINFO_ABI cpuinfo_get_package(uint32_t index);
Ashkan Aliabadidcf8e182020-03-19 19:34:26 -07001761const struct cpuinfo_uarch_info* CPUINFO_ABI cpuinfo_get_uarch(uint32_t index);
Marat Dukhan30401972017-09-26 18:35:52 -07001762const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l1i_cache(uint32_t index);
1763const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l1d_cache(uint32_t index);
1764const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l2_cache(uint32_t index);
1765const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l3_cache(uint32_t index);
1766const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l4_cache(uint32_t index);
Marat Dukhan3045d4f2017-03-04 01:51:42 -05001767
Marat Dukhan7b5e4d52018-03-15 23:42:50 -07001768uint32_t CPUINFO_ABI cpuinfo_get_processors_count(void);
1769uint32_t CPUINFO_ABI cpuinfo_get_cores_count(void);
Marat Dukhan4d376c32018-03-18 11:36:39 -07001770uint32_t CPUINFO_ABI cpuinfo_get_clusters_count(void);
Marat Dukhan7b5e4d52018-03-15 23:42:50 -07001771uint32_t CPUINFO_ABI cpuinfo_get_packages_count(void);
Ashkan Aliabadidcf8e182020-03-19 19:34:26 -07001772uint32_t CPUINFO_ABI cpuinfo_get_uarchs_count(void);
Marat Dukhan30401972017-09-26 18:35:52 -07001773uint32_t CPUINFO_ABI cpuinfo_get_l1i_caches_count(void);
1774uint32_t CPUINFO_ABI cpuinfo_get_l1d_caches_count(void);
1775uint32_t CPUINFO_ABI cpuinfo_get_l2_caches_count(void);
1776uint32_t CPUINFO_ABI cpuinfo_get_l3_caches_count(void);
1777uint32_t CPUINFO_ABI cpuinfo_get_l4_caches_count(void);
Marat Dukhan8ecad1a2017-05-08 07:21:57 +00001778
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -08001779/**
1780 * Returns upper bound on cache size.
1781 */
1782uint32_t CPUINFO_ABI cpuinfo_get_max_cache_size(void);
1783
Ashkan Aliabadidcf8e182020-03-19 19:34:26 -07001784/**
1785 * Identify the logical processor that executes the current thread.
1786 *
1787 * There is no guarantee that the thread will stay on the same logical processor for any time.
1788 * Callers should treat the result as only a hint, and be prepared to handle NULL return value.
1789 */
Marat Dukhan30401972017-09-26 18:35:52 -07001790const struct cpuinfo_processor* CPUINFO_ABI cpuinfo_get_current_processor(void);
Ashkan Aliabadidcf8e182020-03-19 19:34:26 -07001791
1792/**
1793 * Identify the core that executes the current thread.
1794 *
1795 * There is no guarantee that the thread will stay on the same core for any time.
1796 * Callers should treat the result as only a hint, and be prepared to handle NULL return value.
1797 */
Marat Dukhan30401972017-09-26 18:35:52 -07001798const struct cpuinfo_core* CPUINFO_ABI cpuinfo_get_current_core(void);
Marat Dukhan547fa362017-03-03 02:47:26 -05001799
Ashkan Aliabadidcf8e182020-03-19 19:34:26 -07001800/**
1801 * Identify the microarchitecture index of the core that executes the current thread.
Ashkan Aliabadic2092212020-05-08 20:40:33 -07001802 * If the system does not support such identification, the function returns 0.
Ashkan Aliabadidcf8e182020-03-19 19:34:26 -07001803 *
1804 * There is no guarantee that the thread will stay on the same type of core for any time.
1805 * Callers should treat the result as only a hint.
1806 */
1807uint32_t CPUINFO_ABI cpuinfo_get_current_uarch_index(void);
1808
Ashkan Aliabadic2092212020-05-08 20:40:33 -07001809/**
1810 * Identify the microarchitecture index of the core that executes the current thread.
1811 * If the system does not support such identification, the function returns the user-specified default value.
1812 *
1813 * There is no guarantee that the thread will stay on the same type of core for any time.
1814 * Callers should treat the result as only a hint.
1815 */
1816uint32_t CPUINFO_ABI cpuinfo_get_current_uarch_index_with_default(uint32_t default_uarch_index);
1817
Marat Dukhan547fa362017-03-03 02:47:26 -05001818#ifdef __cplusplus
1819} /* extern "C" */
1820#endif
1821
1822#endif /* CPUINFO_H */