blob: e2e65641af6e889c55a01a2ade426c85885e70b7 [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,
Ashkan Aliabadif5582412020-06-11 21:17:20 -0700420 /** ARM Cortex-A78. */
421 cpuinfo_uarch_cortex_a78 = 0x00300378,
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -0800422
423 /** ARM Neoverse N1. */
424 cpuinfo_uarch_neoverse_n1 = 0x00300400,
425 /** ARM Neoverse E1. */
426 cpuinfo_uarch_neoverse_e1 = 0x00300401,
Marat Dukhan547fa362017-03-03 02:47:26 -0500427
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500428 /** Qualcomm Scorpion. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500429 cpuinfo_uarch_scorpion = 0x00400100,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500430 /** Qualcomm Krait. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500431 cpuinfo_uarch_krait = 0x00400101,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500432 /** Qualcomm Kryo. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500433 cpuinfo_uarch_kryo = 0x00400102,
Marat Dukhan029030c2018-05-13 20:10:22 -0700434 /** Qualcomm Falkor. */
435 cpuinfo_uarch_falkor = 0x00400103,
436 /** Qualcomm Saphira. */
437 cpuinfo_uarch_saphira = 0x00400104,
Marat Dukhan547fa362017-03-03 02:47:26 -0500438
Marat Dukhan93982f22017-10-20 13:10:23 -0700439 /** Nvidia Denver. */
Marat Dukhan3c982762017-05-08 06:16:45 +0000440 cpuinfo_uarch_denver = 0x00500100,
Marat Dukhan1e6c8c92018-05-13 20:24:07 -0700441 /** Nvidia Denver 2. */
442 cpuinfo_uarch_denver2 = 0x00500101,
Marat Dukhan8101c502018-09-18 21:05:58 -0500443 /** Nvidia Carmel. */
444 cpuinfo_uarch_carmel = 0x00500102,
Marat Dukhan3c982762017-05-08 06:16:45 +0000445
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -0800446 /** Samsung Exynos M1 (Exynos 8890 big cores). */
447 cpuinfo_uarch_exynos_m1 = 0x00600100,
448 /** Samsung Exynos M2 (Exynos 8895 big cores). */
449 cpuinfo_uarch_exynos_m2 = 0x00600101,
450 /** Samsung Exynos M3 (Exynos 9810 big cores). */
451 cpuinfo_uarch_exynos_m3 = 0x00600102,
452 /** Samsung Exynos M4 (Exynos 9820 big cores). */
453 cpuinfo_uarch_exynos_m4 = 0x00600103,
454 /** Samsung Exynos M5 (Exynos 9830 big cores). */
455 cpuinfo_uarch_exynos_m5 = 0x00600104,
456
Ashkan Aliabadi7e4c0092020-06-01 18:23:11 -0700457 /* Deprecated synonym for Cortex-A76 */
458 cpuinfo_uarch_cortex_a76ae = 0x00300376,
459 /* Deprecated names for Exynos. */
Marat Dukhana750f2a2018-03-07 11:07:48 -0800460 cpuinfo_uarch_mongoose_m1 = 0x00600100,
461 cpuinfo_uarch_mongoose_m2 = 0x00600101,
Marat Dukhan10eae002018-03-29 18:36:31 -0700462 cpuinfo_uarch_meerkat_m3 = 0x00600102,
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -0800463 cpuinfo_uarch_meerkat_m4 = 0x00600103,
Marat Dukhan547fa362017-03-03 02:47:26 -0500464
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500465 /** Apple A6 and A6X processors. */
Marat Dukhan3c982762017-05-08 06:16:45 +0000466 cpuinfo_uarch_swift = 0x00700100,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500467 /** Apple A7 processor. */
Marat Dukhan3c982762017-05-08 06:16:45 +0000468 cpuinfo_uarch_cyclone = 0x00700101,
Hao Lu922070c2017-10-18 16:29:02 -0700469 /** Apple A8 and A8X processor. */
Marat Dukhan3c982762017-05-08 06:16:45 +0000470 cpuinfo_uarch_typhoon = 0x00700102,
Hao Lu922070c2017-10-18 16:29:02 -0700471 /** Apple A9 and A9X processor. */
Marat Dukhan3c982762017-05-08 06:16:45 +0000472 cpuinfo_uarch_twister = 0x00700103,
Hao Lu922070c2017-10-18 16:29:02 -0700473 /** Apple A10 and A10X processor. */
Marat Dukhan3c982762017-05-08 06:16:45 +0000474 cpuinfo_uarch_hurricane = 0x00700104,
Hao Lu922070c2017-10-18 16:29:02 -0700475 /** Apple A11 processor (big cores). */
476 cpuinfo_uarch_monsoon = 0x00700105,
477 /** Apple A11 processor (little cores). */
478 cpuinfo_uarch_mistral = 0x00700106,
Marat Dukhan44dafc52018-12-26 20:19:15 -0800479 /** Apple A12 processor (big cores). */
480 cpuinfo_uarch_vortex = 0x00700107,
481 /** Apple A12 processor (little cores). */
482 cpuinfo_uarch_tempest = 0x00700108,
Ashkan Aliabadidcf8e182020-03-19 19:34:26 -0700483 /** Apple A13 processor (big cores). */
484 cpuinfo_uarch_lightning = 0x00700109,
485 /** Apple A13 processor (little cores). */
486 cpuinfo_uarch_thunder = 0x0070010A,
Nikita Shulgaed8b86a2020-11-18 17:25:18 -0800487 /** Apple M1 processor (big cores). */
488 cpuinfo_uarch_firestorm = 0x0070010B,
489 /** Apple M1 processor (little cores). */
490 cpuinfo_uarch_icestorm = 0x0070010C,
Marat Dukhan92dae312017-05-09 14:10:17 +0000491
492 /** Cavium ThunderX. */
493 cpuinfo_uarch_thunderx = 0x00800100,
Marat Dukhan029030c2018-05-13 20:10:22 -0700494 /** Cavium ThunderX2 (originally Broadcom Vulkan). */
495 cpuinfo_uarch_thunderx2 = 0x00800200,
Marat Dukhan88718322017-08-24 10:12:20 -0700496
497 /** Marvell PJ4. */
498 cpuinfo_uarch_pj4 = 0x00900100,
Marat Dukhan1ae7ff82018-05-13 19:30:58 -0700499
500 /** Broadcom Brahma B15. */
501 cpuinfo_uarch_brahma_b15 = 0x00A00100,
502 /** Broadcom Brahma B53. */
503 cpuinfo_uarch_brahma_b53 = 0x00A00101,
Marat Dukhan029030c2018-05-13 20:10:22 -0700504
505 /** Applied Micro X-Gene. */
506 cpuinfo_uarch_xgene = 0x00B00100,
Ashkan Aliabadidcf8e182020-03-19 19:34:26 -0700507
508 /* Hygon Dhyana (a modification of AMD Zen for Chinese market). */
509 cpuinfo_uarch_dhyana = 0x01000100,
Ashkan Aliabadic2092212020-05-08 20:40:33 -0700510
511 /** HiSilicon TaiShan v110 (Huawei Kunpeng 920 series processors). */
512 cpuinfo_uarch_taishan_v110 = 0x00C00100,
Marat Dukhan547fa362017-03-03 02:47:26 -0500513};
514
515struct cpuinfo_processor {
Marat Dukhan2d37dc42017-09-25 01:32:37 -0700516 /** SMT (hyperthread) ID within a core */
517 uint32_t smt_id;
518 /** Core containing this logical processor */
519 const struct cpuinfo_core* core;
Marat Dukhan4d376c32018-03-18 11:36:39 -0700520 /** Cluster of cores containing this logical processor */
521 const struct cpuinfo_cluster* cluster;
Marat Dukhan2d37dc42017-09-25 01:32:37 -0700522 /** Physical package containing this logical processor */
523 const struct cpuinfo_package* package;
Marat Dukhan15e1df92017-09-13 11:10:10 -0700524#if defined(__linux__)
Marat Dukhan2d37dc42017-09-25 01:32:37 -0700525 /**
526 * Linux-specific ID for the logical processor:
527 * - Linux kernel exposes information about this logical processor in /sys/devices/system/cpu/cpu<linux_id>/
528 * - Bit <linux_id> in the cpu_set_t identifies this logical processor
529 */
Marat Dukhan15e1df92017-09-13 11:10:10 -0700530 int linux_id;
531#endif
Ashkan Aliabadic2092212020-05-08 20:40:33 -0700532#if defined(_WIN32) || defined(__CYGWIN__)
Marat Dukhanb2fc4ab2018-02-19 22:43:26 -0800533 /** Windows-specific ID for the group containing the logical processor. */
534 uint16_t windows_group_id;
535 /**
536 * Windows-specific ID of the logical processor within its group:
537 * - Bit <windows_processor_id> in the KAFFINITY mask identifies this logical processor within its group.
538 */
539 uint16_t windows_processor_id;
540#endif
Marat Dukhan2d37dc42017-09-25 01:32:37 -0700541#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
542 /** APIC ID (unique x86-specific ID of the logical processor) */
543 uint32_t apic_id;
544#endif
Marat Dukhan547fa362017-03-03 02:47:26 -0500545 struct {
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700546 /** Level 1 instruction cache */
Marat Dukhan547fa362017-03-03 02:47:26 -0500547 const struct cpuinfo_cache* l1i;
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700548 /** Level 1 data cache */
Marat Dukhan547fa362017-03-03 02:47:26 -0500549 const struct cpuinfo_cache* l1d;
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700550 /** Level 2 unified or data cache */
Marat Dukhan547fa362017-03-03 02:47:26 -0500551 const struct cpuinfo_cache* l2;
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700552 /** Level 3 unified or data cache */
Marat Dukhan547fa362017-03-03 02:47:26 -0500553 const struct cpuinfo_cache* l3;
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700554 /** Level 4 unified or data cache */
Marat Dukhan547fa362017-03-03 02:47:26 -0500555 const struct cpuinfo_cache* l4;
556 } cache;
557};
558
559struct cpuinfo_core {
Marat Dukhan4d376c32018-03-18 11:36:39 -0700560 /** Index of the first logical processor on this core. */
Marat Dukhanab3a1272017-08-25 23:20:07 -0700561 uint32_t processor_start;
Marat Dukhan2d37dc42017-09-25 01:32:37 -0700562 /** Number of logical processors on this core */
Marat Dukhanab3a1272017-08-25 23:20:07 -0700563 uint32_t processor_count;
Marat Dukhan2d37dc42017-09-25 01:32:37 -0700564 /** Core ID within a package */
565 uint32_t core_id;
Marat Dukhan4d376c32018-03-18 11:36:39 -0700566 /** Cluster containing this core */
567 const struct cpuinfo_cluster* cluster;
568 /** Physical package containing this core. */
Marat Dukhan2d37dc42017-09-25 01:32:37 -0700569 const struct cpuinfo_package* package;
570 /** Vendor of the CPU microarchitecture for this core */
571 enum cpuinfo_vendor vendor;
572 /** CPU microarchitecture for this core */
573 enum cpuinfo_uarch uarch;
574#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
575 /** Value of CPUID leaf 1 EAX register for this core */
576 uint32_t cpuid;
577#elif CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
578 /** Value of Main ID Register (MIDR) for this core */
579 uint32_t midr;
580#endif
Marat Dukhan28538f42018-03-10 14:28:14 -0800581 /** Clock rate (non-Turbo) of the core, in Hz */
582 uint64_t frequency;
Marat Dukhan547fa362017-03-03 02:47:26 -0500583};
584
Marat Dukhan4d376c32018-03-18 11:36:39 -0700585struct cpuinfo_cluster {
586 /** Index of the first logical processor in the cluster */
587 uint32_t processor_start;
588 /** Number of logical processors in the cluster */
589 uint32_t processor_count;
590 /** Index of the first core in the cluster */
591 uint32_t core_start;
592 /** Number of cores on the cluster */
593 uint32_t core_count;
594 /** Cluster ID within a package */
595 uint32_t cluster_id;
596 /** Physical package containing the cluster */
597 const struct cpuinfo_package* package;
598 /** CPU microarchitecture vendor of the cores in the cluster */
599 enum cpuinfo_vendor vendor;
600 /** CPU microarchitecture of the cores in the cluster */
601 enum cpuinfo_uarch uarch;
602#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
603 /** Value of CPUID leaf 1 EAX register of the cores in the cluster */
604 uint32_t cpuid;
605#elif CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
606 /** Value of Main ID Register (MIDR) of the cores in the cluster */
607 uint32_t midr;
608#endif
609 /** Clock rate (non-Turbo) of the cores in the cluster, in Hz */
610 uint64_t frequency;
611};
612
Marat Dukhanfb4fbe02017-09-13 00:51:05 -0700613#define CPUINFO_PACKAGE_NAME_MAX 48
614
Marat Dukhan547fa362017-03-03 02:47:26 -0500615struct cpuinfo_package {
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700616 /** SoC or processor chip model name */
Marat Dukhanfb4fbe02017-09-13 00:51:05 -0700617 char name[CPUINFO_PACKAGE_NAME_MAX];
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700618 /** Index of the first logical processor on this physical package */
Marat Dukhanab3a1272017-08-25 23:20:07 -0700619 uint32_t processor_start;
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700620 /** Number of logical processors on this physical package */
Marat Dukhanab3a1272017-08-25 23:20:07 -0700621 uint32_t processor_count;
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700622 /** Index of the first core on this physical package */
Marat Dukhanfb4fbe02017-09-13 00:51:05 -0700623 uint32_t core_start;
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700624 /** Number of cores on this physical package */
Marat Dukhan547fa362017-03-03 02:47:26 -0500625 uint32_t core_count;
Marat Dukhan4d376c32018-03-18 11:36:39 -0700626 /** Index of the first cluster of cores on this physical package */
627 uint32_t cluster_start;
628 /** Number of clusters of cores on this physical package */
629 uint32_t cluster_count;
Marat Dukhan547fa362017-03-03 02:47:26 -0500630};
631
Ashkan Aliabadidcf8e182020-03-19 19:34:26 -0700632struct cpuinfo_uarch_info {
633 /** Type of CPU microarchitecture */
634 enum cpuinfo_uarch uarch;
635#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
636 /** Value of CPUID leaf 1 EAX register for the microarchitecture */
637 uint32_t cpuid;
638#elif CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
639 /** Value of Main ID Register (MIDR) for the microarchitecture */
640 uint32_t midr;
641#endif
642 /** Number of logical processors with the microarchitecture */
643 uint32_t processor_count;
644 /** Number of cores with the microarchitecture */
645 uint32_t core_count;
646};
647
Marat Dukhan547fa362017-03-03 02:47:26 -0500648#ifdef __cplusplus
649extern "C" {
650#endif
651
Marat Dukhan53556512018-02-25 09:01:27 +0100652bool CPUINFO_ABI cpuinfo_initialize(void);
Marat Dukhan547fa362017-03-03 02:47:26 -0500653
654void CPUINFO_ABI cpuinfo_deinitialize(void);
655
656#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
Marat Dukhanf720d102017-09-26 10:33:47 -0700657 /* This structure is not a part of stable API. Use cpuinfo_has_x86_* functions instead. */
658 struct cpuinfo_x86_isa {
659 #if CPUINFO_ARCH_X86
660 bool rdtsc;
661 #endif
662 bool rdtscp;
663 bool rdpid;
664 bool sysenter;
665 #if CPUINFO_ARCH_X86
666 bool syscall;
667 #endif
668 bool msr;
669 bool clzero;
670 bool clflush;
671 bool clflushopt;
672 bool mwait;
673 bool mwaitx;
674 #if CPUINFO_ARCH_X86
675 bool emmx;
676 #endif
677 bool fxsave;
678 bool xsave;
679 #if CPUINFO_ARCH_X86
680 bool fpu;
681 bool mmx;
682 bool mmx_plus;
683 #endif
684 bool three_d_now;
685 bool three_d_now_plus;
686 #if CPUINFO_ARCH_X86
687 bool three_d_now_geode;
688 #endif
689 bool prefetch;
690 bool prefetchw;
691 bool prefetchwt1;
692 #if CPUINFO_ARCH_X86
693 bool daz;
694 bool sse;
695 bool sse2;
696 #endif
697 bool sse3;
698 bool ssse3;
699 bool sse4_1;
700 bool sse4_2;
701 bool sse4a;
702 bool misaligned_sse;
703 bool avx;
704 bool fma3;
705 bool fma4;
706 bool xop;
707 bool f16c;
708 bool avx2;
709 bool avx512f;
710 bool avx512pf;
711 bool avx512er;
712 bool avx512cd;
713 bool avx512dq;
714 bool avx512bw;
715 bool avx512vl;
716 bool avx512ifma;
717 bool avx512vbmi;
Marat Dukhan861d21a2017-10-13 07:10:25 -0700718 bool avx512vbmi2;
719 bool avx512bitalg;
Marat Dukhanf720d102017-09-26 10:33:47 -0700720 bool avx512vpopcntdq;
Marat Dukhan861d21a2017-10-13 07:10:25 -0700721 bool avx512vnni;
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -0800722 bool avx512bf16;
723 bool avx512vp2intersect;
Marat Dukhanf720d102017-09-26 10:33:47 -0700724 bool avx512_4vnniw;
725 bool avx512_4fmaps;
726 bool hle;
727 bool rtm;
728 bool xtest;
729 bool mpx;
730 #if CPUINFO_ARCH_X86
731 bool cmov;
732 bool cmpxchg8b;
733 #endif
734 bool cmpxchg16b;
735 bool clwb;
736 bool movbe;
737 #if CPUINFO_ARCH_X86_64
738 bool lahf_sahf;
739 #endif
740 bool fs_gs_base;
741 bool lzcnt;
742 bool popcnt;
743 bool tbm;
744 bool bmi;
745 bool bmi2;
746 bool adx;
747 bool aes;
Marat Dukhan861d21a2017-10-13 07:10:25 -0700748 bool vaes;
Marat Dukhanf720d102017-09-26 10:33:47 -0700749 bool pclmulqdq;
Marat Dukhan861d21a2017-10-13 07:10:25 -0700750 bool vpclmulqdq;
751 bool gfni;
Marat Dukhanf720d102017-09-26 10:33:47 -0700752 bool rdrand;
753 bool rdseed;
754 bool sha;
755 bool rng;
756 bool ace;
757 bool ace2;
758 bool phe;
759 bool pmm;
760 bool lwp;
761 };
762
Marat Dukhan547fa362017-03-03 02:47:26 -0500763 extern struct cpuinfo_x86_isa cpuinfo_isa;
764#endif
765
Marat Dukhanf720d102017-09-26 10:33:47 -0700766static inline bool cpuinfo_has_x86_rdtsc(void) {
767 #if CPUINFO_ARCH_X86_64
768 return true;
769 #elif CPUINFO_ARCH_X86
770 #if defined(__ANDROID__)
771 return true;
772 #else
773 return cpuinfo_isa.rdtsc;
774 #endif
775 #else
776 return false;
777 #endif
778}
779
780static inline bool cpuinfo_has_x86_rdtscp(void) {
781 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
782 return cpuinfo_isa.rdtscp;
783 #else
784 return false;
785 #endif
786}
787
788static inline bool cpuinfo_has_x86_rdpid(void) {
789 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
790 return cpuinfo_isa.rdpid;
791 #else
792 return false;
793 #endif
794}
795
796static inline bool cpuinfo_has_x86_clzero(void) {
797 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
798 return cpuinfo_isa.clzero;
799 #else
800 return false;
801 #endif
802}
803
804static inline bool cpuinfo_has_x86_mwait(void) {
805 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
806 return cpuinfo_isa.mwait;
807 #else
808 return false;
809 #endif
810}
811
812static inline bool cpuinfo_has_x86_mwaitx(void) {
813 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
814 return cpuinfo_isa.mwaitx;
815 #else
816 return false;
817 #endif
818}
819
820static inline bool cpuinfo_has_x86_fxsave(void) {
821 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
822 return cpuinfo_isa.fxsave;
823 #else
824 return false;
825 #endif
826}
827
828static inline bool cpuinfo_has_x86_xsave(void) {
829 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
830 return cpuinfo_isa.xsave;
831 #else
832 return false;
833 #endif
834}
835
836static inline bool cpuinfo_has_x86_fpu(void) {
837 #if CPUINFO_ARCH_X86_64
838 return true;
839 #elif CPUINFO_ARCH_X86
840 #if defined(__ANDROID__)
841 return true;
842 #else
843 return cpuinfo_isa.fpu;
844 #endif
845 #else
846 return false;
847 #endif
848}
849
850static inline bool cpuinfo_has_x86_mmx(void) {
851 #if CPUINFO_ARCH_X86_64
852 return true;
853 #elif CPUINFO_ARCH_X86
854 #if defined(__ANDROID__)
855 return true;
856 #else
857 return cpuinfo_isa.mmx;
858 #endif
859 #else
860 return false;
861 #endif
862}
863
864static inline bool cpuinfo_has_x86_mmx_plus(void) {
865 #if CPUINFO_ARCH_X86_64
866 return true;
867 #elif CPUINFO_ARCH_X86
868 #if defined(__ANDROID__)
869 return true;
870 #else
871 return cpuinfo_isa.mmx_plus;
872 #endif
873 #else
874 return false;
875 #endif
876}
877
878static inline bool cpuinfo_has_x86_3dnow(void) {
879 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
880 return cpuinfo_isa.three_d_now;
881 #else
882 return false;
883 #endif
884}
885
886static inline bool cpuinfo_has_x86_3dnow_plus(void) {
887 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
888 return cpuinfo_isa.three_d_now_plus;
889 #else
890 return false;
891 #endif
892}
893
894static inline bool cpuinfo_has_x86_3dnow_geode(void) {
895 #if CPUINFO_ARCH_X86_64
896 return false;
897 #elif CPUINFO_ARCH_X86
898 #if defined(__ANDROID__)
899 return false;
900 #else
901 return cpuinfo_isa.three_d_now_geode;
902 #endif
903 #else
904 return false;
905 #endif
906}
907
908static inline bool cpuinfo_has_x86_prefetch(void) {
909 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
910 return cpuinfo_isa.prefetch;
911 #else
912 return false;
913 #endif
914}
915
916static inline bool cpuinfo_has_x86_prefetchw(void) {
917 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
918 return cpuinfo_isa.prefetchw;
919 #else
920 return false;
921 #endif
922}
923
924static inline bool cpuinfo_has_x86_prefetchwt1(void) {
925 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
Marat Dukhan6022f802017-09-26 11:56:36 -0700926 return cpuinfo_isa.prefetchwt1;
Marat Dukhanf720d102017-09-26 10:33:47 -0700927 #else
928 return false;
929 #endif
930}
931
932static inline bool cpuinfo_has_x86_daz(void) {
933 #if CPUINFO_ARCH_X86_64
934 return true;
935 #elif CPUINFO_ARCH_X86
936 #if defined(__ANDROID__)
937 return true;
938 #else
939 return cpuinfo_isa.daz;
940 #endif
941 #else
942 return false;
943 #endif
944}
945
Marat Dukhan9da4c912017-09-26 10:53:28 -0700946static inline bool cpuinfo_has_x86_sse(void) {
947 #if CPUINFO_ARCH_X86_64
948 return true;
949 #elif CPUINFO_ARCH_X86
950 #if defined(__ANDROID__)
951 return true;
952 #else
953 return cpuinfo_isa.sse;
954 #endif
955 #else
956 return false;
957 #endif
958}
959
Marat Dukhanf720d102017-09-26 10:33:47 -0700960static inline bool cpuinfo_has_x86_sse2(void) {
961 #if CPUINFO_ARCH_X86_64
962 return true;
963 #elif CPUINFO_ARCH_X86
964 #if defined(__ANDROID__)
965 return true;
966 #else
967 return cpuinfo_isa.sse2;
968 #endif
969 #else
970 return false;
971 #endif
972}
973
974static inline bool cpuinfo_has_x86_sse3(void) {
975 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
976 #if defined(__ANDROID__)
977 return true;
978 #else
979 return cpuinfo_isa.sse3;
980 #endif
981 #else
982 return false;
983 #endif
984}
985
986static inline bool cpuinfo_has_x86_ssse3(void) {
987 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
988 #if defined(__ANDROID__)
989 return true;
990 #else
991 return cpuinfo_isa.ssse3;
992 #endif
993 #else
994 return false;
995 #endif
996}
997
998static inline bool cpuinfo_has_x86_sse4_1(void) {
999 #if CPUINFO_ARCH_X86_64
1000 #if defined(__ANDROID__)
1001 return true;
1002 #else
1003 return cpuinfo_isa.sse4_1;
1004 #endif
1005 #elif CPUINFO_ARCH_X86
1006 return cpuinfo_isa.sse4_1;
1007 #else
1008 return false;
1009 #endif
1010}
1011
1012static inline bool cpuinfo_has_x86_sse4_2(void) {
1013 #if CPUINFO_ARCH_X86_64
1014 #if defined(__ANDROID__)
1015 return true;
1016 #else
1017 return cpuinfo_isa.sse4_2;
1018 #endif
1019 #elif CPUINFO_ARCH_X86
1020 return cpuinfo_isa.sse4_2;
1021 #else
1022 return false;
1023 #endif
1024}
1025
1026static inline bool cpuinfo_has_x86_sse4a(void) {
1027 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1028 return cpuinfo_isa.sse4a;
1029 #else
1030 return false;
1031 #endif
1032}
1033
1034static inline bool cpuinfo_has_x86_misaligned_sse(void) {
1035 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1036 return cpuinfo_isa.misaligned_sse;
1037 #else
1038 return false;
1039 #endif
1040}
1041
1042static inline bool cpuinfo_has_x86_avx(void) {
1043 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1044 return cpuinfo_isa.avx;
1045 #else
1046 return false;
1047 #endif
1048}
1049
1050static inline bool cpuinfo_has_x86_fma3(void) {
1051 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1052 return cpuinfo_isa.fma3;
1053 #else
1054 return false;
1055 #endif
1056}
1057
1058static inline bool cpuinfo_has_x86_fma4(void) {
1059 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1060 return cpuinfo_isa.fma4;
1061 #else
1062 return false;
1063 #endif
1064}
1065
1066static inline bool cpuinfo_has_x86_xop(void) {
1067 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1068 return cpuinfo_isa.xop;
1069 #else
1070 return false;
1071 #endif
1072}
1073
1074static inline bool cpuinfo_has_x86_f16c(void) {
1075 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1076 return cpuinfo_isa.f16c;
1077 #else
1078 return false;
1079 #endif
1080}
1081
1082static inline bool cpuinfo_has_x86_avx2(void) {
1083 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1084 return cpuinfo_isa.avx2;
1085 #else
1086 return false;
1087 #endif
1088}
1089
1090static inline bool cpuinfo_has_x86_avx512f(void) {
1091 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1092 return cpuinfo_isa.avx512f;
1093 #else
1094 return false;
1095 #endif
1096}
1097
1098static inline bool cpuinfo_has_x86_avx512pf(void) {
1099 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1100 return cpuinfo_isa.avx512pf;
1101 #else
1102 return false;
1103 #endif
1104}
1105
1106static inline bool cpuinfo_has_x86_avx512er(void) {
1107 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1108 return cpuinfo_isa.avx512er;
1109 #else
1110 return false;
1111 #endif
1112}
1113
1114static inline bool cpuinfo_has_x86_avx512cd(void) {
1115 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1116 return cpuinfo_isa.avx512cd;
1117 #else
1118 return false;
1119 #endif
1120}
1121
1122static inline bool cpuinfo_has_x86_avx512dq(void) {
1123 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1124 return cpuinfo_isa.avx512dq;
1125 #else
1126 return false;
1127 #endif
1128}
1129
1130static inline bool cpuinfo_has_x86_avx512bw(void) {
1131 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1132 return cpuinfo_isa.avx512bw;
1133 #else
1134 return false;
1135 #endif
1136}
1137
1138static inline bool cpuinfo_has_x86_avx512vl(void) {
1139 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1140 return cpuinfo_isa.avx512vl;
1141 #else
1142 return false;
1143 #endif
1144}
1145
1146static inline bool cpuinfo_has_x86_avx512ifma(void) {
1147 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1148 return cpuinfo_isa.avx512ifma;
1149 #else
1150 return false;
1151 #endif
1152}
1153
1154static inline bool cpuinfo_has_x86_avx512vbmi(void) {
1155 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1156 return cpuinfo_isa.avx512vbmi;
1157 #else
1158 return false;
1159 #endif
1160}
1161
Marat Dukhan861d21a2017-10-13 07:10:25 -07001162static inline bool cpuinfo_has_x86_avx512vbmi2(void) {
1163 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1164 return cpuinfo_isa.avx512vbmi2;
1165 #else
1166 return false;
1167 #endif
1168}
1169
1170static inline bool cpuinfo_has_x86_avx512bitalg(void) {
1171 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1172 return cpuinfo_isa.avx512bitalg;
1173 #else
1174 return false;
1175 #endif
1176}
1177
Marat Dukhanf720d102017-09-26 10:33:47 -07001178static inline bool cpuinfo_has_x86_avx512vpopcntdq(void) {
1179 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1180 return cpuinfo_isa.avx512vpopcntdq;
1181 #else
1182 return false;
1183 #endif
1184}
1185
Marat Dukhan861d21a2017-10-13 07:10:25 -07001186static inline bool cpuinfo_has_x86_avx512vnni(void) {
Marat Dukhan6b33b232017-10-13 09:36:52 -07001187 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
Marat Dukhan861d21a2017-10-13 07:10:25 -07001188 return cpuinfo_isa.avx512vnni;
1189 #else
1190 return false;
1191 #endif
1192}
1193
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -08001194static inline bool cpuinfo_has_x86_avx512bf16(void) {
1195 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1196 return cpuinfo_isa.avx512bf16;
1197 #else
1198 return false;
1199 #endif
1200}
1201
1202static inline bool cpuinfo_has_x86_avx512vp2intersect(void) {
1203 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1204 return cpuinfo_isa.avx512vp2intersect;
1205 #else
1206 return false;
1207 #endif
1208}
1209
Marat Dukhanf720d102017-09-26 10:33:47 -07001210static inline bool cpuinfo_has_x86_avx512_4vnniw(void) {
1211 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1212 return cpuinfo_isa.avx512_4vnniw;
1213 #else
1214 return false;
1215 #endif
1216}
1217
1218static inline bool cpuinfo_has_x86_avx512_4fmaps(void) {
1219 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1220 return cpuinfo_isa.avx512_4fmaps;
1221 #else
1222 return false;
1223 #endif
1224}
1225
Marat Dukhan9e32e8d2017-09-26 11:02:37 -07001226static inline bool cpuinfo_has_x86_hle(void) {
1227 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1228 return cpuinfo_isa.hle;
1229 #else
1230 return false;
1231 #endif
1232}
1233
1234static inline bool cpuinfo_has_x86_rtm(void) {
1235 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1236 return cpuinfo_isa.rtm;
1237 #else
1238 return false;
1239 #endif
1240}
1241
1242static inline bool cpuinfo_has_x86_xtest(void) {
1243 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1244 return cpuinfo_isa.xtest;
1245 #else
1246 return false;
1247 #endif
1248}
1249
1250static inline bool cpuinfo_has_x86_mpx(void) {
1251 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1252 return cpuinfo_isa.mpx;
1253 #else
1254 return false;
1255 #endif
1256}
1257
Marat Dukhanf720d102017-09-26 10:33:47 -07001258static inline bool cpuinfo_has_x86_cmov(void) {
1259 #if CPUINFO_ARCH_X86_64
1260 return true;
1261 #elif CPUINFO_ARCH_X86
1262 return cpuinfo_isa.cmov;
1263 #else
1264 return false;
1265 #endif
1266}
1267
1268static inline bool cpuinfo_has_x86_cmpxchg8b(void) {
1269 #if CPUINFO_ARCH_X86_64
1270 return true;
1271 #elif CPUINFO_ARCH_X86
1272 return cpuinfo_isa.cmpxchg8b;
1273 #else
1274 return false;
1275 #endif
1276}
1277
1278static inline bool cpuinfo_has_x86_cmpxchg16b(void) {
1279 #if CPUINFO_ARCH_X86_64
1280 return cpuinfo_isa.cmpxchg16b;
1281 #else
1282 return false;
1283 #endif
1284}
1285
1286static inline bool cpuinfo_has_x86_clwb(void) {
1287 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1288 return cpuinfo_isa.clwb;
1289 #else
1290 return false;
1291 #endif
1292}
1293
1294static inline bool cpuinfo_has_x86_movbe(void) {
Marat Dukhan6022f802017-09-26 11:56:36 -07001295 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
Marat Dukhanf720d102017-09-26 10:33:47 -07001296 return cpuinfo_isa.movbe;
1297 #else
1298 return false;
1299 #endif
1300}
1301
Marat Dukhan30401972017-09-26 18:35:52 -07001302static inline bool cpuinfo_has_x86_lahf_sahf(void) {
Marat Dukhanf720d102017-09-26 10:33:47 -07001303 #if CPUINFO_ARCH_X86
1304 return true;
1305 #elif CPUINFO_ARCH_X86_64
1306 return cpuinfo_isa.lahf_sahf;
1307 #else
1308 return false;
1309 #endif
1310}
1311
1312static inline bool cpuinfo_has_x86_lzcnt(void) {
1313 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1314 return cpuinfo_isa.lzcnt;
1315 #else
1316 return false;
1317 #endif
1318}
1319
1320static inline bool cpuinfo_has_x86_popcnt(void) {
1321 #if CPUINFO_ARCH_X86_64
1322 #if defined(__ANDROID__)
1323 return true;
1324 #else
1325 return cpuinfo_isa.popcnt;
1326 #endif
1327 #elif CPUINFO_ARCH_X86
1328 return cpuinfo_isa.popcnt;
1329 #else
1330 return false;
1331 #endif
1332}
1333
1334static inline bool cpuinfo_has_x86_tbm(void) {
1335 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1336 return cpuinfo_isa.tbm;
1337 #else
1338 return false;
1339 #endif
1340}
1341
1342static inline bool cpuinfo_has_x86_bmi(void) {
1343 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1344 return cpuinfo_isa.bmi;
1345 #else
1346 return false;
1347 #endif
1348}
1349
1350static inline bool cpuinfo_has_x86_bmi2(void) {
1351 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1352 return cpuinfo_isa.bmi2;
1353 #else
1354 return false;
1355 #endif
1356}
1357
1358static inline bool cpuinfo_has_x86_adx(void) {
1359 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1360 return cpuinfo_isa.adx;
1361 #else
1362 return false;
1363 #endif
1364}
1365
1366static inline bool cpuinfo_has_x86_aes(void) {
1367 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1368 return cpuinfo_isa.aes;
1369 #else
1370 return false;
1371 #endif
1372}
1373
Marat Dukhan861d21a2017-10-13 07:10:25 -07001374static inline bool cpuinfo_has_x86_vaes(void) {
1375 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1376 return cpuinfo_isa.vaes;
1377 #else
1378 return false;
1379 #endif
1380}
1381
Marat Dukhanf720d102017-09-26 10:33:47 -07001382static inline bool cpuinfo_has_x86_pclmulqdq(void) {
1383 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1384 return cpuinfo_isa.pclmulqdq;
1385 #else
1386 return false;
1387 #endif
1388}
1389
Marat Dukhan861d21a2017-10-13 07:10:25 -07001390static inline bool cpuinfo_has_x86_vpclmulqdq(void) {
1391 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1392 return cpuinfo_isa.vpclmulqdq;
1393 #else
1394 return false;
1395 #endif
1396}
1397
1398static inline bool cpuinfo_has_x86_gfni(void) {
1399 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1400 return cpuinfo_isa.gfni;
1401 #else
1402 return false;
1403 #endif
1404}
1405
Marat Dukhanf720d102017-09-26 10:33:47 -07001406static inline bool cpuinfo_has_x86_rdrand(void) {
1407 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1408 return cpuinfo_isa.rdrand;
1409 #else
1410 return false;
1411 #endif
1412}
1413
1414static inline bool cpuinfo_has_x86_rdseed(void) {
1415 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1416 return cpuinfo_isa.rdseed;
1417 #else
1418 return false;
1419 #endif
1420}
1421
1422static inline bool cpuinfo_has_x86_sha(void) {
1423 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1424 return cpuinfo_isa.sha;
1425 #else
1426 return false;
1427 #endif
1428}
1429
Marat Dukhanab42e7e2017-05-09 13:19:39 +00001430#if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
Marat Dukhanf720d102017-09-26 10:33:47 -07001431 /* This structure is not a part of stable API. Use cpuinfo_has_arm_* functions instead. */
1432 struct cpuinfo_arm_isa {
1433 #if CPUINFO_ARCH_ARM
1434 bool thumb;
1435 bool thumb2;
1436 bool thumbee;
1437 bool jazelle;
1438 bool armv5e;
1439 bool armv6;
1440 bool armv6k;
1441 bool armv7;
1442 bool armv7mp;
Ashkan Aliabadif5582412020-06-11 21:17:20 -07001443 bool armv8;
Marat Dukhanf720d102017-09-26 10:33:47 -07001444 bool idiv;
1445
1446 bool vfpv2;
1447 bool vfpv3;
1448 bool d32;
1449 bool fp16;
1450 bool fma;
1451
1452 bool wmmx;
1453 bool wmmx2;
1454 bool neon;
1455 #endif
1456 #if CPUINFO_ARCH_ARM64
1457 bool atomics;
Marat Dukhanf720d102017-09-26 10:33:47 -07001458 #endif
Marat Dukhan7abab752018-04-19 22:03:52 -07001459 bool rdm;
1460 bool fp16arith;
Marat Dukhandb14c222018-12-19 02:34:17 -08001461 bool dot;
Marat Dukhan7abab752018-04-19 22:03:52 -07001462 bool jscvt;
1463 bool fcma;
Marat Dukhanf720d102017-09-26 10:33:47 -07001464
1465 bool aes;
1466 bool sha1;
1467 bool sha2;
1468 bool pmull;
1469 bool crc32;
1470 };
1471
Marat Dukhan3c982762017-05-08 06:16:45 +00001472 extern struct cpuinfo_arm_isa cpuinfo_isa;
1473#endif
1474
Marat Dukhanf720d102017-09-26 10:33:47 -07001475static inline bool cpuinfo_has_arm_thumb(void) {
1476 #if CPUINFO_ARCH_ARM
1477 return cpuinfo_isa.thumb;
1478 #else
1479 return false;
1480 #endif
1481}
1482
1483static inline bool cpuinfo_has_arm_thumb2(void) {
1484 #if CPUINFO_ARCH_ARM
1485 return cpuinfo_isa.thumb2;
1486 #else
1487 return false;
1488 #endif
1489}
1490
1491static inline bool cpuinfo_has_arm_v5e(void) {
1492 #if CPUINFO_ARCH_ARM
1493 return cpuinfo_isa.armv5e;
1494 #else
1495 return false;
1496 #endif
1497}
1498
1499static inline bool cpuinfo_has_arm_v6(void) {
1500 #if CPUINFO_ARCH_ARM
1501 return cpuinfo_isa.armv6;
1502 #else
1503 return false;
1504 #endif
1505}
1506
1507static inline bool cpuinfo_has_arm_v6k(void) {
1508 #if CPUINFO_ARCH_ARM
1509 return cpuinfo_isa.armv6k;
1510 #else
1511 return false;
1512 #endif
1513}
1514
1515static inline bool cpuinfo_has_arm_v7(void) {
1516 #if CPUINFO_ARCH_ARM
1517 return cpuinfo_isa.armv7;
1518 #else
1519 return false;
1520 #endif
1521}
1522
1523static inline bool cpuinfo_has_arm_v7mp(void) {
1524 #if CPUINFO_ARCH_ARM
1525 return cpuinfo_isa.armv7mp;
1526 #else
1527 return false;
1528 #endif
1529}
1530
Ashkan Aliabadif5582412020-06-11 21:17:20 -07001531static inline bool cpuinfo_has_arm_v8(void) {
1532 #if CPUINFO_ARCH_ARM64
1533 return true;
1534 #elif CPUINFO_ARCH_ARM
1535 return cpuinfo_isa.armv8;
1536 #else
1537 return false;
1538 #endif
1539}
1540
Marat Dukhanf720d102017-09-26 10:33:47 -07001541static inline bool cpuinfo_has_arm_idiv(void) {
1542 #if CPUINFO_ARCH_ARM64
1543 return true;
1544 #elif CPUINFO_ARCH_ARM
1545 return cpuinfo_isa.idiv;
1546 #else
1547 return false;
1548 #endif
1549}
1550
1551static inline bool cpuinfo_has_arm_vfpv2(void) {
1552 #if CPUINFO_ARCH_ARM
1553 return cpuinfo_isa.vfpv2;
1554 #else
1555 return false;
1556 #endif
1557}
1558
1559static inline bool cpuinfo_has_arm_vfpv3(void) {
1560 #if CPUINFO_ARCH_ARM64
1561 return true;
1562 #elif CPUINFO_ARCH_ARM
1563 return cpuinfo_isa.vfpv3;
1564 #else
1565 return false;
1566 #endif
1567}
1568
1569static inline bool cpuinfo_has_arm_vfpv3_d32(void) {
1570 #if CPUINFO_ARCH_ARM64
1571 return true;
1572 #elif CPUINFO_ARCH_ARM
1573 return cpuinfo_isa.vfpv3 && cpuinfo_isa.d32;
1574 #else
1575 return false;
1576 #endif
1577}
1578
1579static inline bool cpuinfo_has_arm_vfpv3_fp16(void) {
1580 #if CPUINFO_ARCH_ARM64
1581 return true;
1582 #elif CPUINFO_ARCH_ARM
1583 return cpuinfo_isa.vfpv3 && cpuinfo_isa.fp16;
1584 #else
1585 return false;
1586 #endif
1587}
1588
1589static inline bool cpuinfo_has_arm_vfpv3_fp16_d32(void) {
1590 #if CPUINFO_ARCH_ARM64
1591 return true;
1592 #elif CPUINFO_ARCH_ARM
1593 return cpuinfo_isa.vfpv3 && cpuinfo_isa.fp16 && cpuinfo_isa.d32;
1594 #else
1595 return false;
1596 #endif
1597}
1598
Marat Dukhan6022f802017-09-26 11:56:36 -07001599static inline bool cpuinfo_has_arm_vfpv4(void) {
Marat Dukhanf720d102017-09-26 10:33:47 -07001600 #if CPUINFO_ARCH_ARM64
1601 return true;
1602 #elif CPUINFO_ARCH_ARM
1603 return cpuinfo_isa.vfpv3 && cpuinfo_isa.fma;
1604 #else
1605 return false;
1606 #endif
1607}
1608
Marat Dukhan6022f802017-09-26 11:56:36 -07001609static inline bool cpuinfo_has_arm_vfpv4_d32(void) {
Marat Dukhanf720d102017-09-26 10:33:47 -07001610 #if CPUINFO_ARCH_ARM64
1611 return true;
1612 #elif CPUINFO_ARCH_ARM
1613 return cpuinfo_isa.vfpv3 && cpuinfo_isa.fma && cpuinfo_isa.d32;
1614 #else
1615 return false;
1616 #endif
1617}
1618
1619static inline bool cpuinfo_has_arm_wmmx(void) {
1620 #if CPUINFO_ARCH_ARM
1621 return cpuinfo_isa.wmmx;
1622 #else
1623 return false;
1624 #endif
1625}
1626
1627static inline bool cpuinfo_has_arm_wmmx2(void) {
1628 #if CPUINFO_ARCH_ARM
1629 return cpuinfo_isa.wmmx2;
1630 #else
1631 return false;
1632 #endif
1633}
1634
1635static inline bool cpuinfo_has_arm_neon(void) {
1636 #if CPUINFO_ARCH_ARM64
1637 return true;
1638 #elif CPUINFO_ARCH_ARM
1639 return cpuinfo_isa.neon;
1640 #else
1641 return false;
1642 #endif
1643}
1644
1645static inline bool cpuinfo_has_arm_neon_fp16(void) {
1646 #if CPUINFO_ARCH_ARM64
1647 return true;
1648 #elif CPUINFO_ARCH_ARM
1649 return cpuinfo_isa.neon && cpuinfo_isa.fp16;
1650 #else
1651 return false;
1652 #endif
1653}
1654
1655static inline bool cpuinfo_has_arm_neon_fma(void) {
1656 #if CPUINFO_ARCH_ARM64
1657 return true;
1658 #elif CPUINFO_ARCH_ARM
1659 return cpuinfo_isa.neon && cpuinfo_isa.fma;
1660 #else
1661 return false;
1662 #endif
1663}
1664
Ashkan Aliabadif5582412020-06-11 21:17:20 -07001665static inline bool cpuinfo_has_arm_neon_v8(void) {
1666 #if CPUINFO_ARCH_ARM64
1667 return true;
1668 #elif CPUINFO_ARCH_ARM
1669 return cpuinfo_isa.neon && cpuinfo_isa.armv8;
1670 #else
1671 return false;
1672 #endif
1673}
1674
Marat Dukhanf720d102017-09-26 10:33:47 -07001675static inline bool cpuinfo_has_arm_atomics(void) {
1676 #if CPUINFO_ARCH_ARM64
1677 return cpuinfo_isa.atomics;
1678 #else
1679 return false;
1680 #endif
1681}
1682
1683static inline bool cpuinfo_has_arm_neon_rdm(void) {
Marat Dukhan7abab752018-04-19 22:03:52 -07001684 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
Marat Dukhanf720d102017-09-26 10:33:47 -07001685 return cpuinfo_isa.rdm;
1686 #else
1687 return false;
1688 #endif
1689}
1690
Marat Dukhande2f71e2018-06-11 13:30:21 -07001691static inline bool cpuinfo_has_arm_neon_fp16_arith(void) {
1692 #if CPUINFO_ARCH_ARM
1693 return cpuinfo_isa.neon && cpuinfo_isa.fp16arith;
1694 #elif CPUINFO_ARCH_ARM64
1695 return cpuinfo_isa.fp16arith;
1696 #else
1697 return false;
1698 #endif
1699}
1700
Marat Dukhanf720d102017-09-26 10:33:47 -07001701static inline bool cpuinfo_has_arm_fp16_arith(void) {
Marat Dukhan7abab752018-04-19 22:03:52 -07001702 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
Marat Dukhanf720d102017-09-26 10:33:47 -07001703 return cpuinfo_isa.fp16arith;
1704 #else
1705 return false;
1706 #endif
1707}
1708
Marat Dukhandb14c222018-12-19 02:34:17 -08001709static inline bool cpuinfo_has_arm_neon_dot(void) {
1710 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1711 return cpuinfo_isa.dot;
1712 #else
1713 return false;
1714 #endif
1715}
1716
Marat Dukhanf720d102017-09-26 10:33:47 -07001717static inline bool cpuinfo_has_arm_jscvt(void) {
Marat Dukhan7abab752018-04-19 22:03:52 -07001718 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
Marat Dukhanf720d102017-09-26 10:33:47 -07001719 return cpuinfo_isa.jscvt;
1720 #else
1721 return false;
1722 #endif
1723}
1724
1725static inline bool cpuinfo_has_arm_fcma(void) {
Marat Dukhan7abab752018-04-19 22:03:52 -07001726 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
Marat Dukhanf720d102017-09-26 10:33:47 -07001727 return cpuinfo_isa.fcma;
1728 #else
1729 return false;
1730 #endif
1731}
1732
1733static inline bool cpuinfo_has_arm_aes(void) {
1734 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1735 return cpuinfo_isa.aes;
1736 #else
1737 return false;
1738 #endif
1739}
1740
1741static inline bool cpuinfo_has_arm_sha1(void) {
1742 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1743 return cpuinfo_isa.sha1;
1744 #else
1745 return false;
1746 #endif
1747}
1748
1749static inline bool cpuinfo_has_arm_sha2(void) {
1750 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1751 return cpuinfo_isa.sha2;
1752 #else
1753 return false;
1754 #endif
1755}
1756
1757static inline bool cpuinfo_has_arm_pmull(void) {
1758 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1759 return cpuinfo_isa.pmull;
1760 #else
1761 return false;
1762 #endif
1763}
1764
1765static inline bool cpuinfo_has_arm_crc32(void) {
1766 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1767 return cpuinfo_isa.crc32;
1768 #else
1769 return false;
1770 #endif
1771}
1772
Marat Dukhan7b5e4d52018-03-15 23:42:50 -07001773const struct cpuinfo_processor* CPUINFO_ABI cpuinfo_get_processors(void);
1774const struct cpuinfo_core* CPUINFO_ABI cpuinfo_get_cores(void);
Marat Dukhan4d376c32018-03-18 11:36:39 -07001775const struct cpuinfo_cluster* CPUINFO_ABI cpuinfo_get_clusters(void);
Marat Dukhan7b5e4d52018-03-15 23:42:50 -07001776const struct cpuinfo_package* CPUINFO_ABI cpuinfo_get_packages(void);
Ashkan Aliabadidcf8e182020-03-19 19:34:26 -07001777const struct cpuinfo_uarch_info* CPUINFO_ABI cpuinfo_get_uarchs(void);
Marat Dukhan30401972017-09-26 18:35:52 -07001778const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l1i_caches(void);
1779const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l1d_caches(void);
1780const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l2_caches(void);
1781const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l3_caches(void);
1782const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l4_caches(void);
Marat Dukhan3045d4f2017-03-04 01:51:42 -05001783
Marat Dukhan7b5e4d52018-03-15 23:42:50 -07001784const struct cpuinfo_processor* CPUINFO_ABI cpuinfo_get_processor(uint32_t index);
1785const struct cpuinfo_core* CPUINFO_ABI cpuinfo_get_core(uint32_t index);
Marat Dukhan4d376c32018-03-18 11:36:39 -07001786const struct cpuinfo_cluster* CPUINFO_ABI cpuinfo_get_cluster(uint32_t index);
Marat Dukhan7b5e4d52018-03-15 23:42:50 -07001787const struct cpuinfo_package* CPUINFO_ABI cpuinfo_get_package(uint32_t index);
Ashkan Aliabadidcf8e182020-03-19 19:34:26 -07001788const struct cpuinfo_uarch_info* CPUINFO_ABI cpuinfo_get_uarch(uint32_t index);
Marat Dukhan30401972017-09-26 18:35:52 -07001789const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l1i_cache(uint32_t index);
1790const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l1d_cache(uint32_t index);
1791const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l2_cache(uint32_t index);
1792const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l3_cache(uint32_t index);
1793const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l4_cache(uint32_t index);
Marat Dukhan3045d4f2017-03-04 01:51:42 -05001794
Marat Dukhan7b5e4d52018-03-15 23:42:50 -07001795uint32_t CPUINFO_ABI cpuinfo_get_processors_count(void);
1796uint32_t CPUINFO_ABI cpuinfo_get_cores_count(void);
Marat Dukhan4d376c32018-03-18 11:36:39 -07001797uint32_t CPUINFO_ABI cpuinfo_get_clusters_count(void);
Marat Dukhan7b5e4d52018-03-15 23:42:50 -07001798uint32_t CPUINFO_ABI cpuinfo_get_packages_count(void);
Ashkan Aliabadidcf8e182020-03-19 19:34:26 -07001799uint32_t CPUINFO_ABI cpuinfo_get_uarchs_count(void);
Marat Dukhan30401972017-09-26 18:35:52 -07001800uint32_t CPUINFO_ABI cpuinfo_get_l1i_caches_count(void);
1801uint32_t CPUINFO_ABI cpuinfo_get_l1d_caches_count(void);
1802uint32_t CPUINFO_ABI cpuinfo_get_l2_caches_count(void);
1803uint32_t CPUINFO_ABI cpuinfo_get_l3_caches_count(void);
1804uint32_t CPUINFO_ABI cpuinfo_get_l4_caches_count(void);
Marat Dukhan8ecad1a2017-05-08 07:21:57 +00001805
Ashkan Aliabadi0e6bde92020-01-21 14:15:03 -08001806/**
1807 * Returns upper bound on cache size.
1808 */
1809uint32_t CPUINFO_ABI cpuinfo_get_max_cache_size(void);
1810
Ashkan Aliabadidcf8e182020-03-19 19:34:26 -07001811/**
1812 * Identify the logical processor that executes the current thread.
1813 *
1814 * There is no guarantee that the thread will stay on the same logical processor for any time.
1815 * Callers should treat the result as only a hint, and be prepared to handle NULL return value.
1816 */
Marat Dukhan30401972017-09-26 18:35:52 -07001817const struct cpuinfo_processor* CPUINFO_ABI cpuinfo_get_current_processor(void);
Ashkan Aliabadidcf8e182020-03-19 19:34:26 -07001818
1819/**
1820 * Identify the core that executes the current thread.
1821 *
1822 * There is no guarantee that the thread will stay on the same core for any time.
1823 * Callers should treat the result as only a hint, and be prepared to handle NULL return value.
1824 */
Marat Dukhan30401972017-09-26 18:35:52 -07001825const struct cpuinfo_core* CPUINFO_ABI cpuinfo_get_current_core(void);
Marat Dukhan547fa362017-03-03 02:47:26 -05001826
Ashkan Aliabadidcf8e182020-03-19 19:34:26 -07001827/**
1828 * Identify the microarchitecture index of the core that executes the current thread.
Ashkan Aliabadic2092212020-05-08 20:40:33 -07001829 * If the system does not support such identification, the function returns 0.
Ashkan Aliabadidcf8e182020-03-19 19:34:26 -07001830 *
1831 * There is no guarantee that the thread will stay on the same type of core for any time.
1832 * Callers should treat the result as only a hint.
1833 */
1834uint32_t CPUINFO_ABI cpuinfo_get_current_uarch_index(void);
1835
Ashkan Aliabadic2092212020-05-08 20:40:33 -07001836/**
1837 * Identify the microarchitecture index of the core that executes the current thread.
1838 * If the system does not support such identification, the function returns the user-specified default value.
1839 *
1840 * There is no guarantee that the thread will stay on the same type of core for any time.
1841 * Callers should treat the result as only a hint.
1842 */
1843uint32_t CPUINFO_ABI cpuinfo_get_current_uarch_index_with_default(uint32_t default_uarch_index);
1844
Marat Dukhan547fa362017-03-03 02:47:26 -05001845#ifdef __cplusplus
1846} /* extern "C" */
1847#endif
1848
1849#endif /* CPUINFO_H */