blob: 69852dff57be6298433f4b7f30fba3bcf83ae87d [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
37#if defined(__pnacl__)
38 #define CPUINFO_ARCH_PNACL 1
39#endif
40
41#if defined(EMSCRIPTEN)
42 #define CPUINFO_ARCH_ASMJS 1
43#endif
44
45#if CPUINFO_ARCH_X86 && defined(_MSC_VER)
46 #define CPUINFO_ABI __cdecl
47#elif CPUINFO_ARCH_X86 && defined(__GNUC__)
48 #define CPUINFO_ABI __attribute__((__cdecl__))
49#else
50 #define CPUINFO_ABI
51#endif
52
53/* Define other architecture-specific macros as 0 */
54
55#ifndef CPUINFO_ARCH_X86
56 #define CPUINFO_ARCH_X86 0
57#endif
58
59#ifndef CPUINFO_ARCH_X86_64
60 #define CPUINFO_ARCH_X86_64 0
61#endif
62
63#ifndef CPUINFO_ARCH_ARM
64 #define CPUINFO_ARCH_ARM 0
65#endif
66
67#ifndef CPUINFO_ARCH_ARM64
68 #define CPUINFO_ARCH_ARM64 0
69#endif
70
71#ifndef CPUINFO_ARCH_PPC64
72 #define CPUINFO_ARCH_PPC64 0
73#endif
74
75#ifndef CPUINFO_ARCH_PNACL
76 #define CPUINFO_ARCH_PNACL 0
77#endif
78
79#ifndef CPUINFO_ARCH_ASMJS
80 #define CPUINFO_ARCH_ASMJS 0
81#endif
82
Marat Dukhan547fa362017-03-03 02:47:26 -050083#define CPUINFO_CACHE_UNIFIED 0x00000001
84#define CPUINFO_CACHE_INCLUSIVE 0x00000002
85#define CPUINFO_CACHE_COMPLEX_INDEXING 0x00000004
86
87struct cpuinfo_cache {
Marat Dukhan3045d4f2017-03-04 01:51:42 -050088 /** Cache size in bytes */
Marat Dukhan547fa362017-03-03 02:47:26 -050089 uint32_t size;
Marat Dukhan3045d4f2017-03-04 01:51:42 -050090 /** Number of ways of associativity */
Marat Dukhan547fa362017-03-03 02:47:26 -050091 uint32_t associativity;
Marat Dukhan3045d4f2017-03-04 01:51:42 -050092 /** Number of sets */
Marat Dukhan547fa362017-03-03 02:47:26 -050093 uint32_t sets;
Marat Dukhan3045d4f2017-03-04 01:51:42 -050094 /** Number of partitions */
Marat Dukhan547fa362017-03-03 02:47:26 -050095 uint32_t partitions;
Marat Dukhan3045d4f2017-03-04 01:51:42 -050096 /** Line size in bytes */
Marat Dukhan547fa362017-03-03 02:47:26 -050097 uint32_t line_size;
Marat Dukhan3045d4f2017-03-04 01:51:42 -050098 /**
99 * Binary characteristics of the cache (unified cache, inclusive cache, cache with complex indexing).
100 *
101 * @see CPUINFO_CACHE_UNIFIED, CPUINFO_CACHE_INCLUSIVE, CPUINFO_CACHE_COMPLEX_INDEXING
102 */
Marat Dukhan547fa362017-03-03 02:47:26 -0500103 uint32_t flags;
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500104 /** Index of the first logical processor that shares this cache */
Marat Dukhanab3a1272017-08-25 23:20:07 -0700105 uint32_t processor_start;
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500106 /** Number of logical processors that share this cache */
Marat Dukhanab3a1272017-08-25 23:20:07 -0700107 uint32_t processor_count;
Marat Dukhan547fa362017-03-03 02:47:26 -0500108};
109
110struct cpuinfo_trace_cache {
111 uint32_t uops;
112 uint32_t associativity;
113};
114
115#define CPUINFO_PAGE_SIZE_4KB 0x1000
116#define CPUINFO_PAGE_SIZE_1MB 0x100000
117#define CPUINFO_PAGE_SIZE_2MB 0x200000
118#define CPUINFO_PAGE_SIZE_4MB 0x400000
119#define CPUINFO_PAGE_SIZE_16MB 0x1000000
120#define CPUINFO_PAGE_SIZE_1GB 0x40000000
121
122struct cpuinfo_tlb {
123 uint32_t entries;
124 uint32_t associativity;
125 uint64_t pages;
126};
127
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500128/** Vendor of processor core design */
Marat Dukhan547fa362017-03-03 02:47:26 -0500129enum cpuinfo_vendor {
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500130 /** 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 -0500131 cpuinfo_vendor_unknown = 0,
Marat Dukhanb92e2ed2017-09-26 19:26:41 -0700132
Marat Dukhan547fa362017-03-03 02:47:26 -0500133 /* Active vendors of modern CPUs */
134
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500135 /**
136 * Intel Corporation. Vendor of x86, x86-64, IA64, and ARM processor microarchitectures.
137 *
138 * Sold its ARM design subsidiary in 2006. The last ARM processor design was released in 2004.
139 */
Marat Dukhan547fa362017-03-03 02:47:26 -0500140 cpuinfo_vendor_intel = 1,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500141 /** Advanced Micro Devices, Inc. Vendor of x86 and x86-64 processor microarchitectures. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500142 cpuinfo_vendor_amd = 2,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500143 /** ARM Holdings plc. Vendor of ARM and ARM64 processor microarchitectures. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500144 cpuinfo_vendor_arm = 3,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500145 /** Qualcomm Incorporated. Vendor of ARM and ARM64 processor microarchitectures. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500146 cpuinfo_vendor_qualcomm = 4,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500147 /** Apple Inc. Vendor of ARM and ARM64 processor microarchitectures. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500148 cpuinfo_vendor_apple = 5,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500149 /** Samsung Electronics Co., Ltd. Vendir if ARM64 processor microarchitectures. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500150 cpuinfo_vendor_samsung = 6,
Marat Dukhan93982f22017-10-20 13:10:23 -0700151 /** Nvidia Corporation. Vendor of ARM64-compatible processor microarchitectures. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500152 cpuinfo_vendor_nvidia = 7,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500153 /** MIPS Technologies, Inc. Vendor of MIPS processor microarchitectures. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500154 cpuinfo_vendor_mips = 8,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500155 /** International Business Machines Corporation. Vendor of PowerPC processor microarchitectures. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500156 cpuinfo_vendor_ibm = 9,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500157 /** Ingenic Semiconductor. Vendor of MIPS processor microarchitectures. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500158 cpuinfo_vendor_ingenic = 10,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500159 /**
160 * VIA Technologies, Inc. Vendor of x86 and x86-64 processor microarchitectures.
161 *
162 * Processors are designed by Centaur Technology, a subsidiary of VIA Technologies.
163 */
Marat Dukhan547fa362017-03-03 02:47:26 -0500164 cpuinfo_vendor_via = 11,
Marat Dukhan92dae312017-05-09 14:10:17 +0000165 /** Cavium, Inc. Vendor of ARM64 processor microarchitectures. */
166 cpuinfo_vendor_cavium = 12,
Marat Dukhan1ae7ff82018-05-13 19:30:58 -0700167 /** Broadcom, Inc. Vendor of ARM processor microarchitectures. */
168 cpuinfo_vendor_broadcom = 13,
Marat Dukhan029030c2018-05-13 20:10:22 -0700169 /** Applied Micro Circuits Corporation (APM). Vendor of ARM64 processor microarchitectures. */
170 cpuinfo_vendor_apm = 14,
Marat Dukhanb73f61a2018-09-02 23:57:56 +0300171 /**
172 * Huawei Technologies Co., Ltd. Vendor of ARM64 processor microarchitectures.
173 *
174 * Processors are designed by HiSilicon, a subsidiary of Huawei.
175 */
176 cpuinfo_vendor_huawei = 15,
Marat Dukhan547fa362017-03-03 02:47:26 -0500177
178 /* Active vendors of embedded CPUs */
179
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500180 /** Texas Instruments Inc. Vendor of ARM processor microarchitectures. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500181 cpuinfo_vendor_texas_instruments = 30,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500182 /** Marvell Technology Group Ltd. Vendor of ARM processor microarchitectures. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500183 cpuinfo_vendor_marvell = 31,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500184 /** RDC Semiconductor Co., Ltd. Vendor of x86 processor microarchitectures. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500185 cpuinfo_vendor_rdc = 32,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500186 /** DM&P Electronics Inc. Vendor of x86 processor microarchitectures. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500187 cpuinfo_vendor_dmp = 33,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500188 /** Motorola, Inc. Vendor of PowerPC and ARM processor microarchitectures. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500189 cpuinfo_vendor_motorola = 34,
190
191 /* Defunct CPU vendors */
Marat Dukhanb92e2ed2017-09-26 19:26:41 -0700192
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500193 /**
194 * Transmeta Corporation. Vendor of x86 processor microarchitectures.
195 *
196 * Now defunct. The last processor design was released in 2004.
197 * Transmeta processors implemented VLIW ISA and used binary translation to execute x86 code.
198 */
Marat Dukhan547fa362017-03-03 02:47:26 -0500199 cpuinfo_vendor_transmeta = 50,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500200 /**
201 * Cyrix Corporation. Vendor of x86 processor microarchitectures.
202 *
203 * Now defunct. The last processor design was released in 1996.
204 */
Marat Dukhan547fa362017-03-03 02:47:26 -0500205 cpuinfo_vendor_cyrix = 51,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500206 /**
207 * Rise Technology. Vendor of x86 processor microarchitectures.
208 *
209 * Now defunct. The last processor design was released in 1999.
210 */
Marat Dukhan547fa362017-03-03 02:47:26 -0500211 cpuinfo_vendor_rise = 52,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500212 /**
213 * National Semiconductor. Vendor of x86 processor microarchitectures.
214 *
215 * Sold its x86 design subsidiary in 1999. The last processor design was released in 1998.
216 */
Marat Dukhan547fa362017-03-03 02:47:26 -0500217 cpuinfo_vendor_nsc = 53,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500218 /**
219 * Silicon Integrated Systems. Vendor of x86 processor microarchitectures.
220 *
221 * Sold its x86 design subsidiary in 2001. The last processor design was released in 2001.
222 */
Marat Dukhan547fa362017-03-03 02:47:26 -0500223 cpuinfo_vendor_sis = 54,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500224 /**
225 * NexGen. Vendor of x86 processor microarchitectures.
226 *
227 * Now defunct. The last processor design was released in 1994.
228 * NexGen designed the first x86 microarchitecture which decomposed x86 instructions into simple microoperations.
229 */
Marat Dukhan547fa362017-03-03 02:47:26 -0500230 cpuinfo_vendor_nexgen = 55,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500231 /**
232 * United Microelectronics Corporation. Vendor of x86 processor microarchitectures.
233 *
234 * Ceased x86 in the early 1990s. The last processor design was released in 1991.
235 * Designed U5C and U5D processors. Both are 486 level.
236 */
Marat Dukhan547fa362017-03-03 02:47:26 -0500237 cpuinfo_vendor_umc = 56,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500238 /**
239 * Digital Equipment Corporation. Vendor of ARM processor microarchitecture.
240 *
241 * Sold its ARM designs in 1997. The last processor design was released in 1997.
242 */
Marat Dukhan547fa362017-03-03 02:47:26 -0500243 cpuinfo_vendor_dec = 57,
244};
245
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500246/**
247 * Processor microarchitecture
248 *
249 * Processors with different microarchitectures often have different instruction performance characteristics,
250 * and may have dramatically different pipeline organization.
251 */
Marat Dukhan547fa362017-03-03 02:47:26 -0500252enum cpuinfo_uarch {
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500253 /** Microarchitecture is unknown, or the library failed to get information about the microarchitecture from OS */
Marat Dukhan547fa362017-03-03 02:47:26 -0500254 cpuinfo_uarch_unknown = 0,
255
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500256 /** Pentium and Pentium MMX microarchitecture. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500257 cpuinfo_uarch_p5 = 0x00100100,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500258 /** Intel Quark microarchitecture. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500259 cpuinfo_uarch_quark = 0x00100101,
260
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500261 /** Pentium Pro, Pentium II, and Pentium III. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500262 cpuinfo_uarch_p6 = 0x00100200,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500263 /** Pentium M. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500264 cpuinfo_uarch_dothan = 0x00100201,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500265 /** Intel Core microarchitecture. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500266 cpuinfo_uarch_yonah = 0x00100202,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500267 /** Intel Core 2 microarchitecture on 65 nm process. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500268 cpuinfo_uarch_conroe = 0x00100203,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500269 /** Intel Core 2 microarchitecture on 45 nm process. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500270 cpuinfo_uarch_penryn = 0x00100204,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500271 /** Intel Nehalem and Westmere microarchitectures (Core i3/i5/i7 1st gen). */
Marat Dukhan547fa362017-03-03 02:47:26 -0500272 cpuinfo_uarch_nehalem = 0x00100205,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500273 /** Intel Sandy Bridge microarchitecture (Core i3/i5/i7 2nd gen). */
Marat Dukhan547fa362017-03-03 02:47:26 -0500274 cpuinfo_uarch_sandy_bridge = 0x00100206,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500275 /** Intel Ivy Bridge microarchitecture (Core i3/i5/i7 3rd gen). */
Marat Dukhan547fa362017-03-03 02:47:26 -0500276 cpuinfo_uarch_ivy_bridge = 0x00100207,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500277 /** Intel Haswell microarchitecture (Core i3/i5/i7 4th gen). */
Marat Dukhan547fa362017-03-03 02:47:26 -0500278 cpuinfo_uarch_haswell = 0x00100208,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500279 /** Intel Broadwell microarchitecture. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500280 cpuinfo_uarch_broadwell = 0x00100209,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500281 /** Intel Sky Lake microarchitecture. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500282 cpuinfo_uarch_sky_lake = 0x0010020A,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500283 /** Intel Kaby Lake microarchitecture. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500284 cpuinfo_uarch_kaby_lake = 0x0010020B,
285
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500286 /** Pentium 4 with Willamette, Northwood, or Foster cores. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500287 cpuinfo_uarch_willamette = 0x00100300,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500288 /** Pentium 4 with Prescott and later cores. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500289 cpuinfo_uarch_prescott = 0x00100301,
290
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500291 /** Intel Atom on 45 nm process. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500292 cpuinfo_uarch_bonnell = 0x00100400,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500293 /** Intel Atom on 32 nm process. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500294 cpuinfo_uarch_saltwell = 0x00100401,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500295 /** Intel Silvermont microarchitecture (22 nm out-of-order Atom). */
Marat Dukhan547fa362017-03-03 02:47:26 -0500296 cpuinfo_uarch_silvermont = 0x00100402,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500297 /** Intel Airmont microarchitecture (14 nm out-of-order Atom). */
Marat Dukhan547fa362017-03-03 02:47:26 -0500298 cpuinfo_uarch_airmont = 0x00100403,
299
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500300 /** Intel Knights Ferry HPC boards. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500301 cpuinfo_uarch_knights_ferry = 0x00100500,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500302 /** Intel Knights Corner HPC boards (aka Xeon Phi). */
Marat Dukhan547fa362017-03-03 02:47:26 -0500303 cpuinfo_uarch_knights_corner = 0x00100501,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500304 /** Intel Knights Landing microarchitecture (second-gen MIC). */
Marat Dukhan547fa362017-03-03 02:47:26 -0500305 cpuinfo_uarch_knights_landing = 0x00100502,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500306 /** Intel Knights Hill microarchitecture (third-gen MIC). */
Marat Dukhan547fa362017-03-03 02:47:26 -0500307 cpuinfo_uarch_knights_hill = 0x00100503,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500308 /** Intel Knights Mill Xeon Phi. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500309 cpuinfo_uarch_knights_mill = 0x00100504,
310
Marat Dukhan3c982762017-05-08 06:16:45 +0000311 /** Intel/Marvell XScale series. */
312 cpuinfo_uarch_xscale = 0x00100600,
313
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500314 /** AMD K5. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500315 cpuinfo_uarch_k5 = 0x00200100,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500316 /** AMD K6 and alike. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500317 cpuinfo_uarch_k6 = 0x00200101,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500318 /** AMD Athlon and Duron. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500319 cpuinfo_uarch_k7 = 0x00200102,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500320 /** AMD Athlon 64, Opteron 64. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500321 cpuinfo_uarch_k8 = 0x00200103,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500322 /** AMD Family 10h (Barcelona, Istambul, Magny-Cours). */
Marat Dukhan547fa362017-03-03 02:47:26 -0500323 cpuinfo_uarch_k10 = 0x00200104,
324 /**
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500325 * AMD Bulldozer microarchitecture
326 * Zambezi FX-series CPUs, Zurich, Valencia and Interlagos Opteron CPUs.
Marat Dukhan547fa362017-03-03 02:47:26 -0500327 */
328 cpuinfo_uarch_bulldozer = 0x00200105,
329 /**
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500330 * AMD Piledriver microarchitecture
331 * Vishera FX-series CPUs, Trinity and Richland APUs, Delhi, Seoul, Abu Dhabi Opteron CPUs.
Marat Dukhan547fa362017-03-03 02:47:26 -0500332 */
333 cpuinfo_uarch_piledriver = 0x00200106,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500334 /** AMD Steamroller microarchitecture (Kaveri APUs). */
Marat Dukhan547fa362017-03-03 02:47:26 -0500335 cpuinfo_uarch_steamroller = 0x00200107,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500336 /** AMD Excavator microarchitecture (Carizzo APUs). */
Marat Dukhan547fa362017-03-03 02:47:26 -0500337 cpuinfo_uarch_excavator = 0x00200108,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500338 /** AMD Zen microarchitecture (Ryzen CPUs). */
Marat Dukhan547fa362017-03-03 02:47:26 -0500339 cpuinfo_uarch_zen = 0x00200109,
340
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500341 /** NSC Geode and AMD Geode GX and LX. */
Marat Dukhane25187d2017-04-16 05:03:07 -0400342 cpuinfo_uarch_geode = 0x00200200,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500343 /** AMD Bobcat mobile microarchitecture. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500344 cpuinfo_uarch_bobcat = 0x00200201,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500345 /** AMD Jaguar mobile microarchitecture. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500346 cpuinfo_uarch_jaguar = 0x00200202,
Marat Dukhan818e1992018-02-24 15:39:18 +0100347 /** AMD Puma mobile microarchitecture. */
348 cpuinfo_uarch_puma = 0x00200203,
Marat Dukhanb92e2ed2017-09-26 19:26:41 -0700349
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500350 /** ARM7 series. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500351 cpuinfo_uarch_arm7 = 0x00300100,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500352 /** ARM9 series. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500353 cpuinfo_uarch_arm9 = 0x00300101,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500354 /** ARM 1136, ARM 1156, ARM 1176, or ARM 11MPCore. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500355 cpuinfo_uarch_arm11 = 0x00300102,
356
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500357 /** ARM Cortex-A5. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500358 cpuinfo_uarch_cortex_a5 = 0x00300205,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500359 /** ARM Cortex-A7. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500360 cpuinfo_uarch_cortex_a7 = 0x00300207,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500361 /** ARM Cortex-A8. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500362 cpuinfo_uarch_cortex_a8 = 0x00300208,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500363 /** ARM Cortex-A9. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500364 cpuinfo_uarch_cortex_a9 = 0x00300209,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500365 /** ARM Cortex-A12. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500366 cpuinfo_uarch_cortex_a12 = 0x00300212,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500367 /** ARM Cortex-A15. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500368 cpuinfo_uarch_cortex_a15 = 0x00300215,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500369 /** ARM Cortex-A17. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500370 cpuinfo_uarch_cortex_a17 = 0x00300217,
371
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500372 /** ARM Cortex-A32. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500373 cpuinfo_uarch_cortex_a32 = 0x00300332,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500374 /** ARM Cortex-A35. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500375 cpuinfo_uarch_cortex_a35 = 0x00300335,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500376 /** ARM Cortex-A53. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500377 cpuinfo_uarch_cortex_a53 = 0x00300353,
Marat Dukhana8fb3dd2017-08-09 13:49:39 -0700378 /** ARM Cortex-A55. */
379 cpuinfo_uarch_cortex_a55 = 0x00300355,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500380 /** ARM Cortex-A57. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500381 cpuinfo_uarch_cortex_a57 = 0x00300357,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500382 /** ARM Cortex-A72. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500383 cpuinfo_uarch_cortex_a72 = 0x00300372,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500384 /** ARM Cortex-A73. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500385 cpuinfo_uarch_cortex_a73 = 0x00300373,
Marat Dukhana8fb3dd2017-08-09 13:49:39 -0700386 /** ARM Cortex-A75. */
387 cpuinfo_uarch_cortex_a75 = 0x00300375,
Marat Dukhanb73f61a2018-09-02 23:57:56 +0300388 /** ARM Cortex-A76. */
389 cpuinfo_uarch_cortex_a76 = 0x00300376,
Marat Dukhan547fa362017-03-03 02:47:26 -0500390
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500391 /** Qualcomm Scorpion. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500392 cpuinfo_uarch_scorpion = 0x00400100,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500393 /** Qualcomm Krait. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500394 cpuinfo_uarch_krait = 0x00400101,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500395 /** Qualcomm Kryo. */
Marat Dukhan547fa362017-03-03 02:47:26 -0500396 cpuinfo_uarch_kryo = 0x00400102,
Marat Dukhan029030c2018-05-13 20:10:22 -0700397 /** Qualcomm Falkor. */
398 cpuinfo_uarch_falkor = 0x00400103,
399 /** Qualcomm Saphira. */
400 cpuinfo_uarch_saphira = 0x00400104,
Marat Dukhan547fa362017-03-03 02:47:26 -0500401
Marat Dukhan93982f22017-10-20 13:10:23 -0700402 /** Nvidia Denver. */
Marat Dukhan3c982762017-05-08 06:16:45 +0000403 cpuinfo_uarch_denver = 0x00500100,
Marat Dukhan1e6c8c92018-05-13 20:24:07 -0700404 /** Nvidia Denver 2. */
405 cpuinfo_uarch_denver2 = 0x00500101,
Marat Dukhan3c982762017-05-08 06:16:45 +0000406
Marat Dukhandcf096d2018-03-07 11:09:16 -0800407 /** Samsung Mongoose M1 (Exynos 8890 big cores). */
Marat Dukhana750f2a2018-03-07 11:07:48 -0800408 cpuinfo_uarch_mongoose_m1 = 0x00600100,
Marat Dukhandcf096d2018-03-07 11:09:16 -0800409 /** Samsung Mongoose M2 (Exynos 8895 big cores). */
Marat Dukhana750f2a2018-03-07 11:07:48 -0800410 cpuinfo_uarch_mongoose_m2 = 0x00600101,
Marat Dukhan10eae002018-03-29 18:36:31 -0700411 /** Samsung Meerkat M3 (Exynos 9810 big cores). */
412 cpuinfo_uarch_meerkat_m3 = 0x00600102,
Marat Dukhan547fa362017-03-03 02:47:26 -0500413
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500414 /** Apple A6 and A6X processors. */
Marat Dukhan3c982762017-05-08 06:16:45 +0000415 cpuinfo_uarch_swift = 0x00700100,
Marat Dukhan3045d4f2017-03-04 01:51:42 -0500416 /** Apple A7 processor. */
Marat Dukhan3c982762017-05-08 06:16:45 +0000417 cpuinfo_uarch_cyclone = 0x00700101,
Hao Lu922070c2017-10-18 16:29:02 -0700418 /** Apple A8 and A8X processor. */
Marat Dukhan3c982762017-05-08 06:16:45 +0000419 cpuinfo_uarch_typhoon = 0x00700102,
Hao Lu922070c2017-10-18 16:29:02 -0700420 /** Apple A9 and A9X processor. */
Marat Dukhan3c982762017-05-08 06:16:45 +0000421 cpuinfo_uarch_twister = 0x00700103,
Hao Lu922070c2017-10-18 16:29:02 -0700422 /** Apple A10 and A10X processor. */
Marat Dukhan3c982762017-05-08 06:16:45 +0000423 cpuinfo_uarch_hurricane = 0x00700104,
Hao Lu922070c2017-10-18 16:29:02 -0700424 /** Apple A11 processor (big cores). */
425 cpuinfo_uarch_monsoon = 0x00700105,
426 /** Apple A11 processor (little cores). */
427 cpuinfo_uarch_mistral = 0x00700106,
Marat Dukhan92dae312017-05-09 14:10:17 +0000428
429 /** Cavium ThunderX. */
430 cpuinfo_uarch_thunderx = 0x00800100,
Marat Dukhan029030c2018-05-13 20:10:22 -0700431 /** Cavium ThunderX2 (originally Broadcom Vulkan). */
432 cpuinfo_uarch_thunderx2 = 0x00800200,
Marat Dukhan88718322017-08-24 10:12:20 -0700433
434 /** Marvell PJ4. */
435 cpuinfo_uarch_pj4 = 0x00900100,
Marat Dukhan1ae7ff82018-05-13 19:30:58 -0700436
437 /** Broadcom Brahma B15. */
438 cpuinfo_uarch_brahma_b15 = 0x00A00100,
439 /** Broadcom Brahma B53. */
440 cpuinfo_uarch_brahma_b53 = 0x00A00101,
Marat Dukhan029030c2018-05-13 20:10:22 -0700441
442 /** Applied Micro X-Gene. */
443 cpuinfo_uarch_xgene = 0x00B00100,
Marat Dukhan547fa362017-03-03 02:47:26 -0500444};
445
446struct cpuinfo_processor {
Marat Dukhan2d37dc42017-09-25 01:32:37 -0700447 /** SMT (hyperthread) ID within a core */
448 uint32_t smt_id;
449 /** Core containing this logical processor */
450 const struct cpuinfo_core* core;
Marat Dukhan4d376c32018-03-18 11:36:39 -0700451 /** Cluster of cores containing this logical processor */
452 const struct cpuinfo_cluster* cluster;
Marat Dukhan2d37dc42017-09-25 01:32:37 -0700453 /** Physical package containing this logical processor */
454 const struct cpuinfo_package* package;
Marat Dukhan15e1df92017-09-13 11:10:10 -0700455#if defined(__linux__)
Marat Dukhan2d37dc42017-09-25 01:32:37 -0700456 /**
457 * Linux-specific ID for the logical processor:
458 * - Linux kernel exposes information about this logical processor in /sys/devices/system/cpu/cpu<linux_id>/
459 * - Bit <linux_id> in the cpu_set_t identifies this logical processor
460 */
Marat Dukhan15e1df92017-09-13 11:10:10 -0700461 int linux_id;
462#endif
Marat Dukhanb2fc4ab2018-02-19 22:43:26 -0800463#if defined(_WIN32)
464 /** Windows-specific ID for the group containing the logical processor. */
465 uint16_t windows_group_id;
466 /**
467 * Windows-specific ID of the logical processor within its group:
468 * - Bit <windows_processor_id> in the KAFFINITY mask identifies this logical processor within its group.
469 */
470 uint16_t windows_processor_id;
471#endif
Marat Dukhan2d37dc42017-09-25 01:32:37 -0700472#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
473 /** APIC ID (unique x86-specific ID of the logical processor) */
474 uint32_t apic_id;
475#endif
Marat Dukhan547fa362017-03-03 02:47:26 -0500476 struct {
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700477 /** Level 1 instruction cache */
Marat Dukhan547fa362017-03-03 02:47:26 -0500478 const struct cpuinfo_cache* l1i;
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700479 /** Level 1 data cache */
Marat Dukhan547fa362017-03-03 02:47:26 -0500480 const struct cpuinfo_cache* l1d;
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700481 /** Level 2 unified or data cache */
Marat Dukhan547fa362017-03-03 02:47:26 -0500482 const struct cpuinfo_cache* l2;
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700483 /** Level 3 unified or data cache */
Marat Dukhan547fa362017-03-03 02:47:26 -0500484 const struct cpuinfo_cache* l3;
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700485 /** Level 4 unified or data cache */
Marat Dukhan547fa362017-03-03 02:47:26 -0500486 const struct cpuinfo_cache* l4;
487 } cache;
488};
489
490struct cpuinfo_core {
Marat Dukhan4d376c32018-03-18 11:36:39 -0700491 /** Index of the first logical processor on this core. */
Marat Dukhanab3a1272017-08-25 23:20:07 -0700492 uint32_t processor_start;
Marat Dukhan2d37dc42017-09-25 01:32:37 -0700493 /** Number of logical processors on this core */
Marat Dukhanab3a1272017-08-25 23:20:07 -0700494 uint32_t processor_count;
Marat Dukhan2d37dc42017-09-25 01:32:37 -0700495 /** Core ID within a package */
496 uint32_t core_id;
Marat Dukhan4d376c32018-03-18 11:36:39 -0700497 /** Cluster containing this core */
498 const struct cpuinfo_cluster* cluster;
499 /** Physical package containing this core. */
Marat Dukhan2d37dc42017-09-25 01:32:37 -0700500 const struct cpuinfo_package* package;
501 /** Vendor of the CPU microarchitecture for this core */
502 enum cpuinfo_vendor vendor;
503 /** CPU microarchitecture for this core */
504 enum cpuinfo_uarch uarch;
505#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
506 /** Value of CPUID leaf 1 EAX register for this core */
507 uint32_t cpuid;
508#elif CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
509 /** Value of Main ID Register (MIDR) for this core */
510 uint32_t midr;
511#endif
Marat Dukhan28538f42018-03-10 14:28:14 -0800512 /** Clock rate (non-Turbo) of the core, in Hz */
513 uint64_t frequency;
Marat Dukhan547fa362017-03-03 02:47:26 -0500514};
515
Marat Dukhan4d376c32018-03-18 11:36:39 -0700516struct cpuinfo_cluster {
517 /** Index of the first logical processor in the cluster */
518 uint32_t processor_start;
519 /** Number of logical processors in the cluster */
520 uint32_t processor_count;
521 /** Index of the first core in the cluster */
522 uint32_t core_start;
523 /** Number of cores on the cluster */
524 uint32_t core_count;
525 /** Cluster ID within a package */
526 uint32_t cluster_id;
527 /** Physical package containing the cluster */
528 const struct cpuinfo_package* package;
529 /** CPU microarchitecture vendor of the cores in the cluster */
530 enum cpuinfo_vendor vendor;
531 /** CPU microarchitecture of the cores in the cluster */
532 enum cpuinfo_uarch uarch;
533#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
534 /** Value of CPUID leaf 1 EAX register of the cores in the cluster */
535 uint32_t cpuid;
536#elif CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
537 /** Value of Main ID Register (MIDR) of the cores in the cluster */
538 uint32_t midr;
539#endif
540 /** Clock rate (non-Turbo) of the cores in the cluster, in Hz */
541 uint64_t frequency;
542};
543
Marat Dukhanfb4fbe02017-09-13 00:51:05 -0700544#define CPUINFO_PACKAGE_NAME_MAX 48
Marat Dukhanc40c7312017-09-21 16:08:18 -0700545#define CPUINFO_GPU_NAME_MAX 64
Marat Dukhanfb4fbe02017-09-13 00:51:05 -0700546
Marat Dukhan547fa362017-03-03 02:47:26 -0500547struct cpuinfo_package {
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700548 /** SoC or processor chip model name */
Marat Dukhanfb4fbe02017-09-13 00:51:05 -0700549 char name[CPUINFO_PACKAGE_NAME_MAX];
Hao Lu3617d5b2017-10-23 15:16:50 -0700550#if defined(__ANDROID__) || (defined(__APPLE__) && TARGET_OS_IPHONE)
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700551 /** Integrated GPU model name */
552 char gpu_name[CPUINFO_GPU_NAME_MAX];
553#endif
554 /** Index of the first logical processor on this physical package */
Marat Dukhanab3a1272017-08-25 23:20:07 -0700555 uint32_t processor_start;
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700556 /** Number of logical processors on this physical package */
Marat Dukhanab3a1272017-08-25 23:20:07 -0700557 uint32_t processor_count;
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700558 /** Index of the first core on this physical package */
Marat Dukhanfb4fbe02017-09-13 00:51:05 -0700559 uint32_t core_start;
Marat Dukhan8f79efb2017-09-25 11:17:21 -0700560 /** Number of cores on this physical package */
Marat Dukhan547fa362017-03-03 02:47:26 -0500561 uint32_t core_count;
Marat Dukhan4d376c32018-03-18 11:36:39 -0700562 /** Index of the first cluster of cores on this physical package */
563 uint32_t cluster_start;
564 /** Number of clusters of cores on this physical package */
565 uint32_t cluster_count;
Marat Dukhan547fa362017-03-03 02:47:26 -0500566};
567
568#ifdef __cplusplus
569extern "C" {
570#endif
571
Marat Dukhan53556512018-02-25 09:01:27 +0100572bool CPUINFO_ABI cpuinfo_initialize(void);
Marat Dukhan547fa362017-03-03 02:47:26 -0500573
574void CPUINFO_ABI cpuinfo_deinitialize(void);
575
576#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
Marat Dukhanf720d102017-09-26 10:33:47 -0700577 /* This structure is not a part of stable API. Use cpuinfo_has_x86_* functions instead. */
578 struct cpuinfo_x86_isa {
579 #if CPUINFO_ARCH_X86
580 bool rdtsc;
581 #endif
582 bool rdtscp;
583 bool rdpid;
584 bool sysenter;
585 #if CPUINFO_ARCH_X86
586 bool syscall;
587 #endif
588 bool msr;
589 bool clzero;
590 bool clflush;
591 bool clflushopt;
592 bool mwait;
593 bool mwaitx;
594 #if CPUINFO_ARCH_X86
595 bool emmx;
596 #endif
597 bool fxsave;
598 bool xsave;
599 #if CPUINFO_ARCH_X86
600 bool fpu;
601 bool mmx;
602 bool mmx_plus;
603 #endif
604 bool three_d_now;
605 bool three_d_now_plus;
606 #if CPUINFO_ARCH_X86
607 bool three_d_now_geode;
608 #endif
609 bool prefetch;
610 bool prefetchw;
611 bool prefetchwt1;
612 #if CPUINFO_ARCH_X86
613 bool daz;
614 bool sse;
615 bool sse2;
616 #endif
617 bool sse3;
618 bool ssse3;
619 bool sse4_1;
620 bool sse4_2;
621 bool sse4a;
622 bool misaligned_sse;
623 bool avx;
624 bool fma3;
625 bool fma4;
626 bool xop;
627 bool f16c;
628 bool avx2;
629 bool avx512f;
630 bool avx512pf;
631 bool avx512er;
632 bool avx512cd;
633 bool avx512dq;
634 bool avx512bw;
635 bool avx512vl;
636 bool avx512ifma;
637 bool avx512vbmi;
Marat Dukhan861d21a2017-10-13 07:10:25 -0700638 bool avx512vbmi2;
639 bool avx512bitalg;
Marat Dukhanf720d102017-09-26 10:33:47 -0700640 bool avx512vpopcntdq;
Marat Dukhan861d21a2017-10-13 07:10:25 -0700641 bool avx512vnni;
Marat Dukhanf720d102017-09-26 10:33:47 -0700642 bool avx512_4vnniw;
643 bool avx512_4fmaps;
644 bool hle;
645 bool rtm;
646 bool xtest;
647 bool mpx;
648 #if CPUINFO_ARCH_X86
649 bool cmov;
650 bool cmpxchg8b;
651 #endif
652 bool cmpxchg16b;
653 bool clwb;
654 bool movbe;
655 #if CPUINFO_ARCH_X86_64
656 bool lahf_sahf;
657 #endif
658 bool fs_gs_base;
659 bool lzcnt;
660 bool popcnt;
661 bool tbm;
662 bool bmi;
663 bool bmi2;
664 bool adx;
665 bool aes;
Marat Dukhan861d21a2017-10-13 07:10:25 -0700666 bool vaes;
Marat Dukhanf720d102017-09-26 10:33:47 -0700667 bool pclmulqdq;
Marat Dukhan861d21a2017-10-13 07:10:25 -0700668 bool vpclmulqdq;
669 bool gfni;
Marat Dukhanf720d102017-09-26 10:33:47 -0700670 bool rdrand;
671 bool rdseed;
672 bool sha;
673 bool rng;
674 bool ace;
675 bool ace2;
676 bool phe;
677 bool pmm;
678 bool lwp;
679 };
680
Marat Dukhan547fa362017-03-03 02:47:26 -0500681 extern struct cpuinfo_x86_isa cpuinfo_isa;
682#endif
683
Marat Dukhanf720d102017-09-26 10:33:47 -0700684static inline bool cpuinfo_has_x86_rdtsc(void) {
685 #if CPUINFO_ARCH_X86_64
686 return true;
687 #elif CPUINFO_ARCH_X86
688 #if defined(__ANDROID__)
689 return true;
690 #else
691 return cpuinfo_isa.rdtsc;
692 #endif
693 #else
694 return false;
695 #endif
696}
697
698static inline bool cpuinfo_has_x86_rdtscp(void) {
699 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
700 return cpuinfo_isa.rdtscp;
701 #else
702 return false;
703 #endif
704}
705
706static inline bool cpuinfo_has_x86_rdpid(void) {
707 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
708 return cpuinfo_isa.rdpid;
709 #else
710 return false;
711 #endif
712}
713
714static inline bool cpuinfo_has_x86_clzero(void) {
715 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
716 return cpuinfo_isa.clzero;
717 #else
718 return false;
719 #endif
720}
721
722static inline bool cpuinfo_has_x86_mwait(void) {
723 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
724 return cpuinfo_isa.mwait;
725 #else
726 return false;
727 #endif
728}
729
730static inline bool cpuinfo_has_x86_mwaitx(void) {
731 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
732 return cpuinfo_isa.mwaitx;
733 #else
734 return false;
735 #endif
736}
737
738static inline bool cpuinfo_has_x86_fxsave(void) {
739 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
740 return cpuinfo_isa.fxsave;
741 #else
742 return false;
743 #endif
744}
745
746static inline bool cpuinfo_has_x86_xsave(void) {
747 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
748 return cpuinfo_isa.xsave;
749 #else
750 return false;
751 #endif
752}
753
754static inline bool cpuinfo_has_x86_fpu(void) {
755 #if CPUINFO_ARCH_X86_64
756 return true;
757 #elif CPUINFO_ARCH_X86
758 #if defined(__ANDROID__)
759 return true;
760 #else
761 return cpuinfo_isa.fpu;
762 #endif
763 #else
764 return false;
765 #endif
766}
767
768static inline bool cpuinfo_has_x86_mmx(void) {
769 #if CPUINFO_ARCH_X86_64
770 return true;
771 #elif CPUINFO_ARCH_X86
772 #if defined(__ANDROID__)
773 return true;
774 #else
775 return cpuinfo_isa.mmx;
776 #endif
777 #else
778 return false;
779 #endif
780}
781
782static inline bool cpuinfo_has_x86_mmx_plus(void) {
783 #if CPUINFO_ARCH_X86_64
784 return true;
785 #elif CPUINFO_ARCH_X86
786 #if defined(__ANDROID__)
787 return true;
788 #else
789 return cpuinfo_isa.mmx_plus;
790 #endif
791 #else
792 return false;
793 #endif
794}
795
796static inline bool cpuinfo_has_x86_3dnow(void) {
797 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
798 return cpuinfo_isa.three_d_now;
799 #else
800 return false;
801 #endif
802}
803
804static inline bool cpuinfo_has_x86_3dnow_plus(void) {
805 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
806 return cpuinfo_isa.three_d_now_plus;
807 #else
808 return false;
809 #endif
810}
811
812static inline bool cpuinfo_has_x86_3dnow_geode(void) {
813 #if CPUINFO_ARCH_X86_64
814 return false;
815 #elif CPUINFO_ARCH_X86
816 #if defined(__ANDROID__)
817 return false;
818 #else
819 return cpuinfo_isa.three_d_now_geode;
820 #endif
821 #else
822 return false;
823 #endif
824}
825
826static inline bool cpuinfo_has_x86_prefetch(void) {
827 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
828 return cpuinfo_isa.prefetch;
829 #else
830 return false;
831 #endif
832}
833
834static inline bool cpuinfo_has_x86_prefetchw(void) {
835 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
836 return cpuinfo_isa.prefetchw;
837 #else
838 return false;
839 #endif
840}
841
842static inline bool cpuinfo_has_x86_prefetchwt1(void) {
843 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
Marat Dukhan6022f802017-09-26 11:56:36 -0700844 return cpuinfo_isa.prefetchwt1;
Marat Dukhanf720d102017-09-26 10:33:47 -0700845 #else
846 return false;
847 #endif
848}
849
850static inline bool cpuinfo_has_x86_daz(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.daz;
858 #endif
859 #else
860 return false;
861 #endif
862}
863
Marat Dukhan9da4c912017-09-26 10:53:28 -0700864static inline bool cpuinfo_has_x86_sse(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.sse;
872 #endif
873 #else
874 return false;
875 #endif
876}
877
Marat Dukhanf720d102017-09-26 10:33:47 -0700878static inline bool cpuinfo_has_x86_sse2(void) {
879 #if CPUINFO_ARCH_X86_64
880 return true;
881 #elif CPUINFO_ARCH_X86
882 #if defined(__ANDROID__)
883 return true;
884 #else
885 return cpuinfo_isa.sse2;
886 #endif
887 #else
888 return false;
889 #endif
890}
891
892static inline bool cpuinfo_has_x86_sse3(void) {
893 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
894 #if defined(__ANDROID__)
895 return true;
896 #else
897 return cpuinfo_isa.sse3;
898 #endif
899 #else
900 return false;
901 #endif
902}
903
904static inline bool cpuinfo_has_x86_ssse3(void) {
905 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
906 #if defined(__ANDROID__)
907 return true;
908 #else
909 return cpuinfo_isa.ssse3;
910 #endif
911 #else
912 return false;
913 #endif
914}
915
916static inline bool cpuinfo_has_x86_sse4_1(void) {
917 #if CPUINFO_ARCH_X86_64
918 #if defined(__ANDROID__)
919 return true;
920 #else
921 return cpuinfo_isa.sse4_1;
922 #endif
923 #elif CPUINFO_ARCH_X86
924 return cpuinfo_isa.sse4_1;
925 #else
926 return false;
927 #endif
928}
929
930static inline bool cpuinfo_has_x86_sse4_2(void) {
931 #if CPUINFO_ARCH_X86_64
932 #if defined(__ANDROID__)
933 return true;
934 #else
935 return cpuinfo_isa.sse4_2;
936 #endif
937 #elif CPUINFO_ARCH_X86
938 return cpuinfo_isa.sse4_2;
939 #else
940 return false;
941 #endif
942}
943
944static inline bool cpuinfo_has_x86_sse4a(void) {
945 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
946 return cpuinfo_isa.sse4a;
947 #else
948 return false;
949 #endif
950}
951
952static inline bool cpuinfo_has_x86_misaligned_sse(void) {
953 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
954 return cpuinfo_isa.misaligned_sse;
955 #else
956 return false;
957 #endif
958}
959
960static inline bool cpuinfo_has_x86_avx(void) {
961 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
962 return cpuinfo_isa.avx;
963 #else
964 return false;
965 #endif
966}
967
968static inline bool cpuinfo_has_x86_fma3(void) {
969 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
970 return cpuinfo_isa.fma3;
971 #else
972 return false;
973 #endif
974}
975
976static inline bool cpuinfo_has_x86_fma4(void) {
977 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
978 return cpuinfo_isa.fma4;
979 #else
980 return false;
981 #endif
982}
983
984static inline bool cpuinfo_has_x86_xop(void) {
985 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
986 return cpuinfo_isa.xop;
987 #else
988 return false;
989 #endif
990}
991
992static inline bool cpuinfo_has_x86_f16c(void) {
993 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
994 return cpuinfo_isa.f16c;
995 #else
996 return false;
997 #endif
998}
999
1000static inline bool cpuinfo_has_x86_avx2(void) {
1001 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1002 return cpuinfo_isa.avx2;
1003 #else
1004 return false;
1005 #endif
1006}
1007
1008static inline bool cpuinfo_has_x86_avx512f(void) {
1009 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1010 return cpuinfo_isa.avx512f;
1011 #else
1012 return false;
1013 #endif
1014}
1015
1016static inline bool cpuinfo_has_x86_avx512pf(void) {
1017 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1018 return cpuinfo_isa.avx512pf;
1019 #else
1020 return false;
1021 #endif
1022}
1023
1024static inline bool cpuinfo_has_x86_avx512er(void) {
1025 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1026 return cpuinfo_isa.avx512er;
1027 #else
1028 return false;
1029 #endif
1030}
1031
1032static inline bool cpuinfo_has_x86_avx512cd(void) {
1033 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1034 return cpuinfo_isa.avx512cd;
1035 #else
1036 return false;
1037 #endif
1038}
1039
1040static inline bool cpuinfo_has_x86_avx512dq(void) {
1041 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1042 return cpuinfo_isa.avx512dq;
1043 #else
1044 return false;
1045 #endif
1046}
1047
1048static inline bool cpuinfo_has_x86_avx512bw(void) {
1049 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1050 return cpuinfo_isa.avx512bw;
1051 #else
1052 return false;
1053 #endif
1054}
1055
1056static inline bool cpuinfo_has_x86_avx512vl(void) {
1057 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1058 return cpuinfo_isa.avx512vl;
1059 #else
1060 return false;
1061 #endif
1062}
1063
1064static inline bool cpuinfo_has_x86_avx512ifma(void) {
1065 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1066 return cpuinfo_isa.avx512ifma;
1067 #else
1068 return false;
1069 #endif
1070}
1071
1072static inline bool cpuinfo_has_x86_avx512vbmi(void) {
1073 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1074 return cpuinfo_isa.avx512vbmi;
1075 #else
1076 return false;
1077 #endif
1078}
1079
Marat Dukhan861d21a2017-10-13 07:10:25 -07001080static inline bool cpuinfo_has_x86_avx512vbmi2(void) {
1081 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1082 return cpuinfo_isa.avx512vbmi2;
1083 #else
1084 return false;
1085 #endif
1086}
1087
1088static inline bool cpuinfo_has_x86_avx512bitalg(void) {
1089 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1090 return cpuinfo_isa.avx512bitalg;
1091 #else
1092 return false;
1093 #endif
1094}
1095
Marat Dukhanf720d102017-09-26 10:33:47 -07001096static inline bool cpuinfo_has_x86_avx512vpopcntdq(void) {
1097 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1098 return cpuinfo_isa.avx512vpopcntdq;
1099 #else
1100 return false;
1101 #endif
1102}
1103
Marat Dukhan861d21a2017-10-13 07:10:25 -07001104static inline bool cpuinfo_has_x86_avx512vnni(void) {
Marat Dukhan6b33b232017-10-13 09:36:52 -07001105 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
Marat Dukhan861d21a2017-10-13 07:10:25 -07001106 return cpuinfo_isa.avx512vnni;
1107 #else
1108 return false;
1109 #endif
1110}
1111
Marat Dukhanf720d102017-09-26 10:33:47 -07001112static inline bool cpuinfo_has_x86_avx512_4vnniw(void) {
1113 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1114 return cpuinfo_isa.avx512_4vnniw;
1115 #else
1116 return false;
1117 #endif
1118}
1119
1120static inline bool cpuinfo_has_x86_avx512_4fmaps(void) {
1121 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1122 return cpuinfo_isa.avx512_4fmaps;
1123 #else
1124 return false;
1125 #endif
1126}
1127
Marat Dukhan9e32e8d2017-09-26 11:02:37 -07001128static inline bool cpuinfo_has_x86_hle(void) {
1129 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1130 return cpuinfo_isa.hle;
1131 #else
1132 return false;
1133 #endif
1134}
1135
1136static inline bool cpuinfo_has_x86_rtm(void) {
1137 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1138 return cpuinfo_isa.rtm;
1139 #else
1140 return false;
1141 #endif
1142}
1143
1144static inline bool cpuinfo_has_x86_xtest(void) {
1145 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1146 return cpuinfo_isa.xtest;
1147 #else
1148 return false;
1149 #endif
1150}
1151
1152static inline bool cpuinfo_has_x86_mpx(void) {
1153 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1154 return cpuinfo_isa.mpx;
1155 #else
1156 return false;
1157 #endif
1158}
1159
Marat Dukhanf720d102017-09-26 10:33:47 -07001160static inline bool cpuinfo_has_x86_cmov(void) {
1161 #if CPUINFO_ARCH_X86_64
1162 return true;
1163 #elif CPUINFO_ARCH_X86
1164 return cpuinfo_isa.cmov;
1165 #else
1166 return false;
1167 #endif
1168}
1169
1170static inline bool cpuinfo_has_x86_cmpxchg8b(void) {
1171 #if CPUINFO_ARCH_X86_64
1172 return true;
1173 #elif CPUINFO_ARCH_X86
1174 return cpuinfo_isa.cmpxchg8b;
1175 #else
1176 return false;
1177 #endif
1178}
1179
1180static inline bool cpuinfo_has_x86_cmpxchg16b(void) {
1181 #if CPUINFO_ARCH_X86_64
1182 return cpuinfo_isa.cmpxchg16b;
1183 #else
1184 return false;
1185 #endif
1186}
1187
1188static inline bool cpuinfo_has_x86_clwb(void) {
1189 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1190 return cpuinfo_isa.clwb;
1191 #else
1192 return false;
1193 #endif
1194}
1195
1196static inline bool cpuinfo_has_x86_movbe(void) {
Marat Dukhan6022f802017-09-26 11:56:36 -07001197 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
Marat Dukhanf720d102017-09-26 10:33:47 -07001198 return cpuinfo_isa.movbe;
1199 #else
1200 return false;
1201 #endif
1202}
1203
Marat Dukhan30401972017-09-26 18:35:52 -07001204static inline bool cpuinfo_has_x86_lahf_sahf(void) {
Marat Dukhanf720d102017-09-26 10:33:47 -07001205 #if CPUINFO_ARCH_X86
1206 return true;
1207 #elif CPUINFO_ARCH_X86_64
1208 return cpuinfo_isa.lahf_sahf;
1209 #else
1210 return false;
1211 #endif
1212}
1213
1214static inline bool cpuinfo_has_x86_lzcnt(void) {
1215 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1216 return cpuinfo_isa.lzcnt;
1217 #else
1218 return false;
1219 #endif
1220}
1221
1222static inline bool cpuinfo_has_x86_popcnt(void) {
1223 #if CPUINFO_ARCH_X86_64
1224 #if defined(__ANDROID__)
1225 return true;
1226 #else
1227 return cpuinfo_isa.popcnt;
1228 #endif
1229 #elif CPUINFO_ARCH_X86
1230 return cpuinfo_isa.popcnt;
1231 #else
1232 return false;
1233 #endif
1234}
1235
1236static inline bool cpuinfo_has_x86_tbm(void) {
1237 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1238 return cpuinfo_isa.tbm;
1239 #else
1240 return false;
1241 #endif
1242}
1243
1244static inline bool cpuinfo_has_x86_bmi(void) {
1245 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1246 return cpuinfo_isa.bmi;
1247 #else
1248 return false;
1249 #endif
1250}
1251
1252static inline bool cpuinfo_has_x86_bmi2(void) {
1253 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1254 return cpuinfo_isa.bmi2;
1255 #else
1256 return false;
1257 #endif
1258}
1259
1260static inline bool cpuinfo_has_x86_adx(void) {
1261 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1262 return cpuinfo_isa.adx;
1263 #else
1264 return false;
1265 #endif
1266}
1267
1268static inline bool cpuinfo_has_x86_aes(void) {
1269 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1270 return cpuinfo_isa.aes;
1271 #else
1272 return false;
1273 #endif
1274}
1275
Marat Dukhan861d21a2017-10-13 07:10:25 -07001276static inline bool cpuinfo_has_x86_vaes(void) {
1277 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1278 return cpuinfo_isa.vaes;
1279 #else
1280 return false;
1281 #endif
1282}
1283
Marat Dukhanf720d102017-09-26 10:33:47 -07001284static inline bool cpuinfo_has_x86_pclmulqdq(void) {
1285 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1286 return cpuinfo_isa.pclmulqdq;
1287 #else
1288 return false;
1289 #endif
1290}
1291
Marat Dukhan861d21a2017-10-13 07:10:25 -07001292static inline bool cpuinfo_has_x86_vpclmulqdq(void) {
1293 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1294 return cpuinfo_isa.vpclmulqdq;
1295 #else
1296 return false;
1297 #endif
1298}
1299
1300static inline bool cpuinfo_has_x86_gfni(void) {
1301 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1302 return cpuinfo_isa.gfni;
1303 #else
1304 return false;
1305 #endif
1306}
1307
Marat Dukhanf720d102017-09-26 10:33:47 -07001308static inline bool cpuinfo_has_x86_rdrand(void) {
1309 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1310 return cpuinfo_isa.rdrand;
1311 #else
1312 return false;
1313 #endif
1314}
1315
1316static inline bool cpuinfo_has_x86_rdseed(void) {
1317 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1318 return cpuinfo_isa.rdseed;
1319 #else
1320 return false;
1321 #endif
1322}
1323
1324static inline bool cpuinfo_has_x86_sha(void) {
1325 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1326 return cpuinfo_isa.sha;
1327 #else
1328 return false;
1329 #endif
1330}
1331
Marat Dukhanab42e7e2017-05-09 13:19:39 +00001332#if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
Marat Dukhanf720d102017-09-26 10:33:47 -07001333 /* This structure is not a part of stable API. Use cpuinfo_has_arm_* functions instead. */
1334 struct cpuinfo_arm_isa {
1335 #if CPUINFO_ARCH_ARM
1336 bool thumb;
1337 bool thumb2;
1338 bool thumbee;
1339 bool jazelle;
1340 bool armv5e;
1341 bool armv6;
1342 bool armv6k;
1343 bool armv7;
1344 bool armv7mp;
1345 bool idiv;
1346
1347 bool vfpv2;
1348 bool vfpv3;
1349 bool d32;
1350 bool fp16;
1351 bool fma;
1352
1353 bool wmmx;
1354 bool wmmx2;
1355 bool neon;
1356 #endif
1357 #if CPUINFO_ARCH_ARM64
1358 bool atomics;
Marat Dukhanf720d102017-09-26 10:33:47 -07001359 #endif
Marat Dukhan7abab752018-04-19 22:03:52 -07001360 bool rdm;
1361 bool fp16arith;
1362 bool jscvt;
1363 bool fcma;
Marat Dukhanf720d102017-09-26 10:33:47 -07001364
1365 bool aes;
1366 bool sha1;
1367 bool sha2;
1368 bool pmull;
1369 bool crc32;
1370 };
1371
Marat Dukhan3c982762017-05-08 06:16:45 +00001372 extern struct cpuinfo_arm_isa cpuinfo_isa;
1373#endif
1374
Marat Dukhanf720d102017-09-26 10:33:47 -07001375static inline bool cpuinfo_has_arm_thumb(void) {
1376 #if CPUINFO_ARCH_ARM
1377 return cpuinfo_isa.thumb;
1378 #else
1379 return false;
1380 #endif
1381}
1382
1383static inline bool cpuinfo_has_arm_thumb2(void) {
1384 #if CPUINFO_ARCH_ARM
1385 return cpuinfo_isa.thumb2;
1386 #else
1387 return false;
1388 #endif
1389}
1390
1391static inline bool cpuinfo_has_arm_v5e(void) {
1392 #if CPUINFO_ARCH_ARM
1393 return cpuinfo_isa.armv5e;
1394 #else
1395 return false;
1396 #endif
1397}
1398
1399static inline bool cpuinfo_has_arm_v6(void) {
1400 #if CPUINFO_ARCH_ARM
1401 return cpuinfo_isa.armv6;
1402 #else
1403 return false;
1404 #endif
1405}
1406
1407static inline bool cpuinfo_has_arm_v6k(void) {
1408 #if CPUINFO_ARCH_ARM
1409 return cpuinfo_isa.armv6k;
1410 #else
1411 return false;
1412 #endif
1413}
1414
1415static inline bool cpuinfo_has_arm_v7(void) {
1416 #if CPUINFO_ARCH_ARM
1417 return cpuinfo_isa.armv7;
1418 #else
1419 return false;
1420 #endif
1421}
1422
1423static inline bool cpuinfo_has_arm_v7mp(void) {
1424 #if CPUINFO_ARCH_ARM
1425 return cpuinfo_isa.armv7mp;
1426 #else
1427 return false;
1428 #endif
1429}
1430
1431static inline bool cpuinfo_has_arm_idiv(void) {
1432 #if CPUINFO_ARCH_ARM64
1433 return true;
1434 #elif CPUINFO_ARCH_ARM
1435 return cpuinfo_isa.idiv;
1436 #else
1437 return false;
1438 #endif
1439}
1440
1441static inline bool cpuinfo_has_arm_vfpv2(void) {
1442 #if CPUINFO_ARCH_ARM
1443 return cpuinfo_isa.vfpv2;
1444 #else
1445 return false;
1446 #endif
1447}
1448
1449static inline bool cpuinfo_has_arm_vfpv3(void) {
1450 #if CPUINFO_ARCH_ARM64
1451 return true;
1452 #elif CPUINFO_ARCH_ARM
1453 return cpuinfo_isa.vfpv3;
1454 #else
1455 return false;
1456 #endif
1457}
1458
1459static inline bool cpuinfo_has_arm_vfpv3_d32(void) {
1460 #if CPUINFO_ARCH_ARM64
1461 return true;
1462 #elif CPUINFO_ARCH_ARM
1463 return cpuinfo_isa.vfpv3 && cpuinfo_isa.d32;
1464 #else
1465 return false;
1466 #endif
1467}
1468
1469static inline bool cpuinfo_has_arm_vfpv3_fp16(void) {
1470 #if CPUINFO_ARCH_ARM64
1471 return true;
1472 #elif CPUINFO_ARCH_ARM
1473 return cpuinfo_isa.vfpv3 && cpuinfo_isa.fp16;
1474 #else
1475 return false;
1476 #endif
1477}
1478
1479static inline bool cpuinfo_has_arm_vfpv3_fp16_d32(void) {
1480 #if CPUINFO_ARCH_ARM64
1481 return true;
1482 #elif CPUINFO_ARCH_ARM
1483 return cpuinfo_isa.vfpv3 && cpuinfo_isa.fp16 && cpuinfo_isa.d32;
1484 #else
1485 return false;
1486 #endif
1487}
1488
Marat Dukhan6022f802017-09-26 11:56:36 -07001489static inline bool cpuinfo_has_arm_vfpv4(void) {
Marat Dukhanf720d102017-09-26 10:33:47 -07001490 #if CPUINFO_ARCH_ARM64
1491 return true;
1492 #elif CPUINFO_ARCH_ARM
1493 return cpuinfo_isa.vfpv3 && cpuinfo_isa.fma;
1494 #else
1495 return false;
1496 #endif
1497}
1498
Marat Dukhan6022f802017-09-26 11:56:36 -07001499static inline bool cpuinfo_has_arm_vfpv4_d32(void) {
Marat Dukhanf720d102017-09-26 10:33:47 -07001500 #if CPUINFO_ARCH_ARM64
1501 return true;
1502 #elif CPUINFO_ARCH_ARM
1503 return cpuinfo_isa.vfpv3 && cpuinfo_isa.fma && cpuinfo_isa.d32;
1504 #else
1505 return false;
1506 #endif
1507}
1508
1509static inline bool cpuinfo_has_arm_wmmx(void) {
1510 #if CPUINFO_ARCH_ARM
1511 return cpuinfo_isa.wmmx;
1512 #else
1513 return false;
1514 #endif
1515}
1516
1517static inline bool cpuinfo_has_arm_wmmx2(void) {
1518 #if CPUINFO_ARCH_ARM
1519 return cpuinfo_isa.wmmx2;
1520 #else
1521 return false;
1522 #endif
1523}
1524
1525static inline bool cpuinfo_has_arm_neon(void) {
1526 #if CPUINFO_ARCH_ARM64
1527 return true;
1528 #elif CPUINFO_ARCH_ARM
1529 return cpuinfo_isa.neon;
1530 #else
1531 return false;
1532 #endif
1533}
1534
1535static inline bool cpuinfo_has_arm_neon_fp16(void) {
1536 #if CPUINFO_ARCH_ARM64
1537 return true;
1538 #elif CPUINFO_ARCH_ARM
1539 return cpuinfo_isa.neon && cpuinfo_isa.fp16;
1540 #else
1541 return false;
1542 #endif
1543}
1544
1545static inline bool cpuinfo_has_arm_neon_fma(void) {
1546 #if CPUINFO_ARCH_ARM64
1547 return true;
1548 #elif CPUINFO_ARCH_ARM
1549 return cpuinfo_isa.neon && cpuinfo_isa.fma;
1550 #else
1551 return false;
1552 #endif
1553}
1554
1555static inline bool cpuinfo_has_arm_atomics(void) {
1556 #if CPUINFO_ARCH_ARM64
1557 return cpuinfo_isa.atomics;
1558 #else
1559 return false;
1560 #endif
1561}
1562
1563static inline bool cpuinfo_has_arm_neon_rdm(void) {
Marat Dukhan7abab752018-04-19 22:03:52 -07001564 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
Marat Dukhanf720d102017-09-26 10:33:47 -07001565 return cpuinfo_isa.rdm;
1566 #else
1567 return false;
1568 #endif
1569}
1570
Marat Dukhande2f71e2018-06-11 13:30:21 -07001571static inline bool cpuinfo_has_arm_neon_fp16_arith(void) {
1572 #if CPUINFO_ARCH_ARM
1573 return cpuinfo_isa.neon && cpuinfo_isa.fp16arith;
1574 #elif CPUINFO_ARCH_ARM64
1575 return cpuinfo_isa.fp16arith;
1576 #else
1577 return false;
1578 #endif
1579}
1580
Marat Dukhanf720d102017-09-26 10:33:47 -07001581static inline bool cpuinfo_has_arm_fp16_arith(void) {
Marat Dukhan7abab752018-04-19 22:03:52 -07001582 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
Marat Dukhanf720d102017-09-26 10:33:47 -07001583 return cpuinfo_isa.fp16arith;
1584 #else
1585 return false;
1586 #endif
1587}
1588
1589static inline bool cpuinfo_has_arm_jscvt(void) {
Marat Dukhan7abab752018-04-19 22:03:52 -07001590 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
Marat Dukhanf720d102017-09-26 10:33:47 -07001591 return cpuinfo_isa.jscvt;
1592 #else
1593 return false;
1594 #endif
1595}
1596
1597static inline bool cpuinfo_has_arm_fcma(void) {
Marat Dukhan7abab752018-04-19 22:03:52 -07001598 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
Marat Dukhanf720d102017-09-26 10:33:47 -07001599 return cpuinfo_isa.fcma;
1600 #else
1601 return false;
1602 #endif
1603}
1604
1605static inline bool cpuinfo_has_arm_aes(void) {
1606 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1607 return cpuinfo_isa.aes;
1608 #else
1609 return false;
1610 #endif
1611}
1612
1613static inline bool cpuinfo_has_arm_sha1(void) {
1614 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1615 return cpuinfo_isa.sha1;
1616 #else
1617 return false;
1618 #endif
1619}
1620
1621static inline bool cpuinfo_has_arm_sha2(void) {
1622 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1623 return cpuinfo_isa.sha2;
1624 #else
1625 return false;
1626 #endif
1627}
1628
1629static inline bool cpuinfo_has_arm_pmull(void) {
1630 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1631 return cpuinfo_isa.pmull;
1632 #else
1633 return false;
1634 #endif
1635}
1636
1637static inline bool cpuinfo_has_arm_crc32(void) {
1638 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1639 return cpuinfo_isa.crc32;
1640 #else
1641 return false;
1642 #endif
1643}
1644
Marat Dukhan7b5e4d52018-03-15 23:42:50 -07001645const struct cpuinfo_processor* CPUINFO_ABI cpuinfo_get_processors(void);
1646const struct cpuinfo_core* CPUINFO_ABI cpuinfo_get_cores(void);
Marat Dukhan4d376c32018-03-18 11:36:39 -07001647const struct cpuinfo_cluster* CPUINFO_ABI cpuinfo_get_clusters(void);
Marat Dukhan7b5e4d52018-03-15 23:42:50 -07001648const struct cpuinfo_package* CPUINFO_ABI cpuinfo_get_packages(void);
Marat Dukhan30401972017-09-26 18:35:52 -07001649const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l1i_caches(void);
1650const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l1d_caches(void);
1651const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l2_caches(void);
1652const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l3_caches(void);
1653const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l4_caches(void);
Marat Dukhan3045d4f2017-03-04 01:51:42 -05001654
Marat Dukhan7b5e4d52018-03-15 23:42:50 -07001655const struct cpuinfo_processor* CPUINFO_ABI cpuinfo_get_processor(uint32_t index);
1656const struct cpuinfo_core* CPUINFO_ABI cpuinfo_get_core(uint32_t index);
Marat Dukhan4d376c32018-03-18 11:36:39 -07001657const struct cpuinfo_cluster* CPUINFO_ABI cpuinfo_get_cluster(uint32_t index);
Marat Dukhan7b5e4d52018-03-15 23:42:50 -07001658const struct cpuinfo_package* CPUINFO_ABI cpuinfo_get_package(uint32_t index);
Marat Dukhan30401972017-09-26 18:35:52 -07001659const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l1i_cache(uint32_t index);
1660const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l1d_cache(uint32_t index);
1661const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l2_cache(uint32_t index);
1662const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l3_cache(uint32_t index);
1663const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l4_cache(uint32_t index);
Marat Dukhan3045d4f2017-03-04 01:51:42 -05001664
Marat Dukhan7b5e4d52018-03-15 23:42:50 -07001665uint32_t CPUINFO_ABI cpuinfo_get_processors_count(void);
1666uint32_t CPUINFO_ABI cpuinfo_get_cores_count(void);
Marat Dukhan4d376c32018-03-18 11:36:39 -07001667uint32_t CPUINFO_ABI cpuinfo_get_clusters_count(void);
Marat Dukhan7b5e4d52018-03-15 23:42:50 -07001668uint32_t CPUINFO_ABI cpuinfo_get_packages_count(void);
Marat Dukhan30401972017-09-26 18:35:52 -07001669uint32_t CPUINFO_ABI cpuinfo_get_l1i_caches_count(void);
1670uint32_t CPUINFO_ABI cpuinfo_get_l1d_caches_count(void);
1671uint32_t CPUINFO_ABI cpuinfo_get_l2_caches_count(void);
1672uint32_t CPUINFO_ABI cpuinfo_get_l3_caches_count(void);
1673uint32_t CPUINFO_ABI cpuinfo_get_l4_caches_count(void);
Marat Dukhan8ecad1a2017-05-08 07:21:57 +00001674
Marat Dukhan30401972017-09-26 18:35:52 -07001675const struct cpuinfo_processor* CPUINFO_ABI cpuinfo_get_current_processor(void);
1676const struct cpuinfo_core* CPUINFO_ABI cpuinfo_get_current_core(void);
Marat Dukhan547fa362017-03-03 02:47:26 -05001677
1678#ifdef __cplusplus
1679} /* extern "C" */
1680#endif
1681
1682#endif /* CPUINFO_H */