Coverage Report

Created: 2024-05-04 12:45

/proc/self/cwd/external/cpuinfo/include/cpuinfo.h
Line
Count
Source (jump to first uncovered line)
1
#pragma once
2
#ifndef CPUINFO_H
3
#define CPUINFO_H
4
5
#ifndef __cplusplus
6
  #include <stdbool.h>
7
#endif
8
9
#ifdef __APPLE__
10
  #include <TargetConditionals.h>
11
#endif
12
13
#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(__asmjs__)
38
  #define CPUINFO_ARCH_ASMJS 1
39
#endif
40
41
#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
49
#if defined(__riscv)
50
  #if (__riscv_xlen == 32)
51
    #define CPUINFO_ARCH_RISCV32 1
52
  #elif (__riscv_xlen == 64)
53
    #define CPUINFO_ARCH_RISCV64 1
54
  #endif
55
#endif
56
57
/* Define other architecture-specific macros as 0 */
58
59
#ifndef CPUINFO_ARCH_X86
60
  #define CPUINFO_ARCH_X86 0
61
#endif
62
63
#ifndef CPUINFO_ARCH_X86_64
64
  #define CPUINFO_ARCH_X86_64 0
65
#endif
66
67
#ifndef CPUINFO_ARCH_ARM
68
  #define CPUINFO_ARCH_ARM 0
69
#endif
70
71
#ifndef CPUINFO_ARCH_ARM64
72
  #define CPUINFO_ARCH_ARM64 0
73
#endif
74
75
#ifndef CPUINFO_ARCH_PPC64
76
  #define CPUINFO_ARCH_PPC64 0
77
#endif
78
79
#ifndef CPUINFO_ARCH_ASMJS
80
  #define CPUINFO_ARCH_ASMJS 0
81
#endif
82
83
#ifndef CPUINFO_ARCH_WASM
84
  #define CPUINFO_ARCH_WASM 0
85
#endif
86
87
#ifndef CPUINFO_ARCH_WASMSIMD
88
  #define CPUINFO_ARCH_WASMSIMD 0
89
#endif
90
91
#ifndef CPUINFO_ARCH_RISCV32
92
  #define CPUINFO_ARCH_RISCV32 0
93
#endif
94
95
#ifndef CPUINFO_ARCH_RISCV64
96
  #define CPUINFO_ARCH_RISCV64 0
97
#endif
98
99
#if CPUINFO_ARCH_X86 && defined(_MSC_VER)
100
  #define CPUINFO_ABI __cdecl
101
#elif CPUINFO_ARCH_X86 && defined(__GNUC__)
102
  #define CPUINFO_ABI __attribute__((__cdecl__))
103
#else
104
  #define CPUINFO_ABI
105
#endif
106
107
#define CPUINFO_CACHE_UNIFIED          0x00000001
108
#define CPUINFO_CACHE_INCLUSIVE        0x00000002
109
#define CPUINFO_CACHE_COMPLEX_INDEXING 0x00000004
110
111
struct cpuinfo_cache {
112
  /** Cache size in bytes */
113
  uint32_t size;
114
  /** Number of ways of associativity */
115
  uint32_t associativity;
116
  /** Number of sets */
117
  uint32_t sets;
118
  /** Number of partitions */
119
  uint32_t partitions;
120
  /** Line size in bytes */
121
  uint32_t line_size;
122
  /**
123
   * Binary characteristics of the cache (unified cache, inclusive cache, cache with complex indexing).
124
   *
125
   * @see CPUINFO_CACHE_UNIFIED, CPUINFO_CACHE_INCLUSIVE, CPUINFO_CACHE_COMPLEX_INDEXING
126
   */
127
  uint32_t flags;
128
  /** Index of the first logical processor that shares this cache */
129
  uint32_t processor_start;
130
  /** Number of logical processors that share this cache */
131
  uint32_t processor_count;
132
};
133
134
struct cpuinfo_trace_cache {
135
  uint32_t uops;
136
  uint32_t associativity;
137
};
138
139
#define CPUINFO_PAGE_SIZE_4KB  0x1000
140
#define CPUINFO_PAGE_SIZE_1MB  0x100000
141
#define CPUINFO_PAGE_SIZE_2MB  0x200000
142
#define CPUINFO_PAGE_SIZE_4MB  0x400000
143
#define CPUINFO_PAGE_SIZE_16MB 0x1000000
144
#define CPUINFO_PAGE_SIZE_1GB  0x40000000
145
146
struct cpuinfo_tlb {
147
  uint32_t entries;
148
  uint32_t associativity;
149
  uint64_t pages;
150
};
151
152
/** Vendor of processor core design */
153
enum cpuinfo_vendor {
154
  /** Processor vendor is not known to the library, or the library failed to get vendor information from the OS. */
155
  cpuinfo_vendor_unknown = 0,
156
157
  /* Active vendors of modern CPUs */
158
159
  /**
160
   * Intel Corporation. Vendor of x86, x86-64, IA64, and ARM processor microarchitectures.
161
   *
162
   * Sold its ARM design subsidiary in 2006. The last ARM processor design was released in 2004.
163
   */
164
  cpuinfo_vendor_intel    = 1,
165
  /** Advanced Micro Devices, Inc. Vendor of x86 and x86-64 processor microarchitectures. */
166
  cpuinfo_vendor_amd      = 2,
167
  /** ARM Holdings plc. Vendor of ARM and ARM64 processor microarchitectures. */
168
  cpuinfo_vendor_arm      = 3,
169
  /** Qualcomm Incorporated. Vendor of ARM and ARM64 processor microarchitectures. */
170
  cpuinfo_vendor_qualcomm = 4,
171
  /** Apple Inc. Vendor of ARM and ARM64 processor microarchitectures. */
172
  cpuinfo_vendor_apple    = 5,
173
  /** Samsung Electronics Co., Ltd. Vendir if ARM64 processor microarchitectures. */
174
  cpuinfo_vendor_samsung  = 6,
175
  /** Nvidia Corporation. Vendor of ARM64-compatible processor microarchitectures. */
176
  cpuinfo_vendor_nvidia   = 7,
177
  /** MIPS Technologies, Inc. Vendor of MIPS processor microarchitectures. */
178
  cpuinfo_vendor_mips     = 8,
179
  /** International Business Machines Corporation. Vendor of PowerPC processor microarchitectures. */
180
  cpuinfo_vendor_ibm      = 9,
181
  /** Ingenic Semiconductor. Vendor of MIPS processor microarchitectures. */
182
  cpuinfo_vendor_ingenic  = 10,
183
  /**
184
   * VIA Technologies, Inc. Vendor of x86 and x86-64 processor microarchitectures.
185
   *
186
   * Processors are designed by Centaur Technology, a subsidiary of VIA Technologies.
187
   */
188
  cpuinfo_vendor_via      = 11,
189
  /** Cavium, Inc. Vendor of ARM64 processor microarchitectures. */
190
  cpuinfo_vendor_cavium   = 12,
191
  /** Broadcom, Inc. Vendor of ARM processor microarchitectures. */
192
  cpuinfo_vendor_broadcom = 13,
193
  /** Applied Micro Circuits Corporation (APM). Vendor of ARM64 processor microarchitectures. */
194
  cpuinfo_vendor_apm      = 14,
195
  /**
196
   * Huawei Technologies Co., Ltd. Vendor of ARM64 processor microarchitectures.
197
   *
198
   * Processors are designed by HiSilicon, a subsidiary of Huawei.
199
   */
200
  cpuinfo_vendor_huawei   = 15,
201
  /**
202
   * Hygon (Chengdu Haiguang Integrated Circuit Design Co., Ltd), Vendor of x86-64 processor microarchitectures.
203
   *
204
   * Processors are variants of AMD cores.
205
   */
206
  cpuinfo_vendor_hygon    = 16,
207
  /** SiFive, Inc. Vendor of RISC-V processor microarchitectures. */
208
  cpuinfo_vendor_sifive   = 17,
209
210
  /* Active vendors of embedded CPUs */
211
212
  /** Texas Instruments Inc. Vendor of ARM processor microarchitectures. */
213
  cpuinfo_vendor_texas_instruments = 30,
214
  /** Marvell Technology Group Ltd. Vendor of ARM processor microarchitectures. */
215
  cpuinfo_vendor_marvell           = 31,
216
  /** RDC Semiconductor Co., Ltd. Vendor of x86 processor microarchitectures. */
217
  cpuinfo_vendor_rdc               = 32,
218
  /** DM&P Electronics Inc. Vendor of x86 processor microarchitectures. */
219
  cpuinfo_vendor_dmp               = 33,
220
  /** Motorola, Inc. Vendor of PowerPC and ARM processor microarchitectures. */
221
  cpuinfo_vendor_motorola          = 34,
222
223
  /* Defunct CPU vendors */
224
225
  /**
226
   * Transmeta Corporation. Vendor of x86 processor microarchitectures.
227
   *
228
   * Now defunct. The last processor design was released in 2004.
229
   * Transmeta processors implemented VLIW ISA and used binary translation to execute x86 code.
230
   */
231
  cpuinfo_vendor_transmeta = 50,
232
  /**
233
   * Cyrix Corporation. Vendor of x86 processor microarchitectures.
234
   *
235
   * Now defunct. The last processor design was released in 1996.
236
   */
237
  cpuinfo_vendor_cyrix     = 51,
238
  /**
239
   * Rise Technology. Vendor of x86 processor microarchitectures.
240
   *
241
   * Now defunct. The last processor design was released in 1999.
242
   */
243
  cpuinfo_vendor_rise      = 52,
244
  /**
245
   * National Semiconductor. Vendor of x86 processor microarchitectures.
246
   *
247
   * Sold its x86 design subsidiary in 1999. The last processor design was released in 1998.
248
   */
249
  cpuinfo_vendor_nsc       = 53,
250
  /**
251
   * Silicon Integrated Systems. Vendor of x86 processor microarchitectures.
252
   *
253
   * Sold its x86 design subsidiary in 2001. The last processor design was released in 2001.
254
   */
255
  cpuinfo_vendor_sis       = 54,
256
  /**
257
   * NexGen. Vendor of x86 processor microarchitectures.
258
   *
259
   * Now defunct. The last processor design was released in 1994.
260
   * NexGen designed the first x86 microarchitecture which decomposed x86 instructions into simple microoperations.
261
   */
262
  cpuinfo_vendor_nexgen    = 55,
263
  /**
264
   * United Microelectronics Corporation. Vendor of x86 processor microarchitectures.
265
   *
266
   * Ceased x86 in the early 1990s. The last processor design was released in 1991.
267
   * Designed U5C and U5D processors. Both are 486 level.
268
   */
269
  cpuinfo_vendor_umc       = 56,
270
  /**
271
   * Digital Equipment Corporation. Vendor of ARM processor microarchitecture.
272
   *
273
   * Sold its ARM designs in 1997. The last processor design was released in 1997.
274
   */
275
  cpuinfo_vendor_dec       = 57,
276
};
277
278
/**
279
 * Processor microarchitecture
280
 *
281
 * Processors with different microarchitectures often have different instruction performance characteristics,
282
 * and may have dramatically different pipeline organization.
283
 */
284
enum cpuinfo_uarch {
285
  /** Microarchitecture is unknown, or the library failed to get information about the microarchitecture from OS */
286
  cpuinfo_uarch_unknown = 0,
287
288
  /** Pentium and Pentium MMX microarchitecture. */
289
  cpuinfo_uarch_p5    = 0x00100100,
290
  /** Intel Quark microarchitecture. */
291
  cpuinfo_uarch_quark = 0x00100101,
292
293
  /** Pentium Pro, Pentium II, and Pentium III. */
294
  cpuinfo_uarch_p6           = 0x00100200,
295
  /** Pentium M. */
296
  cpuinfo_uarch_dothan       = 0x00100201,
297
  /** Intel Core microarchitecture. */
298
  cpuinfo_uarch_yonah        = 0x00100202,
299
  /** Intel Core 2 microarchitecture on 65 nm process. */
300
  cpuinfo_uarch_conroe       = 0x00100203,
301
  /** Intel Core 2 microarchitecture on 45 nm process. */
302
  cpuinfo_uarch_penryn       = 0x00100204,
303
  /** Intel Nehalem and Westmere microarchitectures (Core i3/i5/i7 1st gen). */
304
  cpuinfo_uarch_nehalem      = 0x00100205,
305
  /** Intel Sandy Bridge microarchitecture (Core i3/i5/i7 2nd gen). */
306
  cpuinfo_uarch_sandy_bridge = 0x00100206,
307
  /** Intel Ivy Bridge microarchitecture (Core i3/i5/i7 3rd gen). */
308
  cpuinfo_uarch_ivy_bridge   = 0x00100207,
309
  /** Intel Haswell microarchitecture (Core i3/i5/i7 4th gen). */
310
  cpuinfo_uarch_haswell      = 0x00100208,
311
  /** Intel Broadwell microarchitecture. */
312
  cpuinfo_uarch_broadwell    = 0x00100209,
313
  /** Intel Sky Lake microarchitecture (14 nm, including Kaby/Coffee/Whiskey/Amber/Comet/Cascade/Cooper Lake). */
314
  cpuinfo_uarch_sky_lake     = 0x0010020A,
315
  /** DEPRECATED (Intel Kaby Lake microarchitecture). */
316
  cpuinfo_uarch_kaby_lake    = 0x0010020A,
317
  /** Intel Palm Cove microarchitecture (10 nm, Cannon Lake). */
318
  cpuinfo_uarch_palm_cove    = 0x0010020B,
319
  /** Intel Sunny Cove microarchitecture (10 nm, Ice Lake). */
320
  cpuinfo_uarch_sunny_cove   = 0x0010020C,
321
322
  /** Pentium 4 with Willamette, Northwood, or Foster cores. */
323
  cpuinfo_uarch_willamette = 0x00100300,
324
  /** Pentium 4 with Prescott and later cores. */
325
  cpuinfo_uarch_prescott   = 0x00100301,
326
327
  /** Intel Atom on 45 nm process. */
328
  cpuinfo_uarch_bonnell       = 0x00100400,
329
  /** Intel Atom on 32 nm process. */
330
  cpuinfo_uarch_saltwell      = 0x00100401,
331
  /** Intel Silvermont microarchitecture (22 nm out-of-order Atom). */
332
  cpuinfo_uarch_silvermont    = 0x00100402,
333
  /** Intel Airmont microarchitecture (14 nm out-of-order Atom). */
334
  cpuinfo_uarch_airmont       = 0x00100403,
335
  /** Intel Goldmont microarchitecture (Denverton, Apollo Lake). */
336
  cpuinfo_uarch_goldmont      = 0x00100404,
337
  /** Intel Goldmont Plus microarchitecture (Gemini Lake). */
338
  cpuinfo_uarch_goldmont_plus = 0x00100405,
339
340
  /** Intel Knights Ferry HPC boards. */
341
  cpuinfo_uarch_knights_ferry   = 0x00100500,
342
  /** Intel Knights Corner HPC boards (aka Xeon Phi). */
343
  cpuinfo_uarch_knights_corner  = 0x00100501,
344
  /** Intel Knights Landing microarchitecture (second-gen MIC). */
345
  cpuinfo_uarch_knights_landing = 0x00100502,
346
  /** Intel Knights Hill microarchitecture (third-gen MIC). */
347
  cpuinfo_uarch_knights_hill    = 0x00100503,
348
  /** Intel Knights Mill Xeon Phi. */
349
  cpuinfo_uarch_knights_mill    = 0x00100504,
350
351
  /** Intel/Marvell XScale series. */
352
  cpuinfo_uarch_xscale = 0x00100600,
353
354
  /** AMD K5. */
355
  cpuinfo_uarch_k5        = 0x00200100,
356
  /** AMD K6 and alike. */
357
  cpuinfo_uarch_k6        = 0x00200101,
358
  /** AMD Athlon and Duron. */
359
  cpuinfo_uarch_k7        = 0x00200102,
360
  /** AMD Athlon 64, Opteron 64. */
361
  cpuinfo_uarch_k8        = 0x00200103,
362
  /** AMD Family 10h (Barcelona, Istambul, Magny-Cours). */
363
  cpuinfo_uarch_k10       = 0x00200104,
364
  /**
365
   * AMD Bulldozer microarchitecture
366
   * Zambezi FX-series CPUs, Zurich, Valencia and Interlagos Opteron CPUs.
367
   */
368
  cpuinfo_uarch_bulldozer = 0x00200105,
369
  /**
370
   * AMD Piledriver microarchitecture
371
   * Vishera FX-series CPUs, Trinity and Richland APUs, Delhi, Seoul, Abu Dhabi Opteron CPUs.
372
   */
373
  cpuinfo_uarch_piledriver  = 0x00200106,
374
  /** AMD Steamroller microarchitecture (Kaveri APUs). */
375
  cpuinfo_uarch_steamroller = 0x00200107,
376
  /** AMD Excavator microarchitecture (Carizzo APUs). */
377
  cpuinfo_uarch_excavator   = 0x00200108,
378
  /** AMD Zen microarchitecture (12/14 nm Ryzen and EPYC CPUs). */
379
  cpuinfo_uarch_zen         = 0x00200109,
380
  /** AMD Zen 2 microarchitecture (7 nm Ryzen and EPYC CPUs). */
381
  cpuinfo_uarch_zen2        = 0x0020010A,
382
  /** AMD Zen 3 microarchitecture. */
383
  cpuinfo_uarch_zen3        = 0x0020010B,
384
  /** AMD Zen 4 microarchitecture. */
385
  cpuinfo_uarch_zen4        = 0x0020010C,
386
387
  /** NSC Geode and AMD Geode GX and LX. */
388
  cpuinfo_uarch_geode  = 0x00200200,
389
  /** AMD Bobcat mobile microarchitecture. */
390
  cpuinfo_uarch_bobcat = 0x00200201,
391
  /** AMD Jaguar mobile microarchitecture. */
392
  cpuinfo_uarch_jaguar = 0x00200202,
393
  /** AMD Puma mobile microarchitecture. */
394
  cpuinfo_uarch_puma   = 0x00200203,
395
396
  /** ARM7 series. */
397
  cpuinfo_uarch_arm7  = 0x00300100,
398
  /** ARM9 series. */
399
  cpuinfo_uarch_arm9  = 0x00300101,
400
  /** ARM 1136, ARM 1156, ARM 1176, or ARM 11MPCore. */
401
  cpuinfo_uarch_arm11 = 0x00300102,
402
403
  /** ARM Cortex-A5. */
404
  cpuinfo_uarch_cortex_a5  = 0x00300205,
405
  /** ARM Cortex-A7. */
406
  cpuinfo_uarch_cortex_a7  = 0x00300207,
407
  /** ARM Cortex-A8. */
408
  cpuinfo_uarch_cortex_a8  = 0x00300208,
409
  /** ARM Cortex-A9. */
410
  cpuinfo_uarch_cortex_a9  = 0x00300209,
411
  /** ARM Cortex-A12. */
412
  cpuinfo_uarch_cortex_a12 = 0x00300212,
413
  /** ARM Cortex-A15. */
414
  cpuinfo_uarch_cortex_a15 = 0x00300215,
415
  /** ARM Cortex-A17. */
416
  cpuinfo_uarch_cortex_a17 = 0x00300217,
417
418
  /** ARM Cortex-A32. */
419
  cpuinfo_uarch_cortex_a32   = 0x00300332,
420
  /** ARM Cortex-A35. */
421
  cpuinfo_uarch_cortex_a35   = 0x00300335,
422
  /** ARM Cortex-A53. */
423
  cpuinfo_uarch_cortex_a53   = 0x00300353,
424
  /** ARM Cortex-A55 revision 0 (restricted dual-issue capabilities compared to revision 1+). */
425
  cpuinfo_uarch_cortex_a55r0 = 0x00300354,
426
  /** ARM Cortex-A55. */
427
  cpuinfo_uarch_cortex_a55   = 0x00300355,
428
  /** ARM Cortex-A57. */
429
  cpuinfo_uarch_cortex_a57   = 0x00300357,
430
  /** ARM Cortex-A65. */
431
  cpuinfo_uarch_cortex_a65   = 0x00300365,
432
  /** ARM Cortex-A72. */
433
  cpuinfo_uarch_cortex_a72   = 0x00300372,
434
  /** ARM Cortex-A73. */
435
  cpuinfo_uarch_cortex_a73   = 0x00300373,
436
  /** ARM Cortex-A75. */
437
  cpuinfo_uarch_cortex_a75   = 0x00300375,
438
  /** ARM Cortex-A76. */
439
  cpuinfo_uarch_cortex_a76   = 0x00300376,
440
  /** ARM Cortex-A77. */
441
  cpuinfo_uarch_cortex_a77   = 0x00300377,
442
  /** ARM Cortex-A78. */
443
  cpuinfo_uarch_cortex_a78   = 0x00300378,
444
445
  /** ARM Neoverse N1. */
446
  cpuinfo_uarch_neoverse_n1  = 0x00300400,
447
  /** ARM Neoverse E1. */
448
  cpuinfo_uarch_neoverse_e1  = 0x00300401,
449
  /** ARM Neoverse V1. */
450
  cpuinfo_uarch_neoverse_v1  = 0x00300402,
451
  /** ARM Neoverse N2. */
452
  cpuinfo_uarch_neoverse_n2  = 0x00300403,
453
  /** ARM Neoverse V2. */
454
  cpuinfo_uarch_neoverse_v2  = 0x00300404,
455
456
  /** ARM Cortex-X1. */
457
  cpuinfo_uarch_cortex_x1    = 0x00300501,
458
  /** ARM Cortex-X2. */
459
  cpuinfo_uarch_cortex_x2    = 0x00300502,
460
  /** ARM Cortex-X3. */
461
  cpuinfo_uarch_cortex_x3    = 0x00300503,
462
463
  /** ARM Cortex-A510. */
464
  cpuinfo_uarch_cortex_a510  = 0x00300551,
465
  /** ARM Cortex-A710. */
466
  cpuinfo_uarch_cortex_a710  = 0x00300571,
467
  /** ARM Cortex-A715. */
468
  cpuinfo_uarch_cortex_a715  = 0x00300572,
469
470
  /** Qualcomm Scorpion. */
471
  cpuinfo_uarch_scorpion = 0x00400100,
472
  /** Qualcomm Krait. */
473
  cpuinfo_uarch_krait    = 0x00400101,
474
  /** Qualcomm Kryo. */
475
  cpuinfo_uarch_kryo     = 0x00400102,
476
  /** Qualcomm Falkor. */
477
  cpuinfo_uarch_falkor   = 0x00400103,
478
  /** Qualcomm Saphira. */
479
  cpuinfo_uarch_saphira  = 0x00400104,
480
481
  /** Nvidia Denver. */
482
  cpuinfo_uarch_denver   = 0x00500100,
483
  /** Nvidia Denver 2. */
484
  cpuinfo_uarch_denver2  = 0x00500101,
485
  /** Nvidia Carmel. */
486
  cpuinfo_uarch_carmel   = 0x00500102,
487
488
  /** Samsung Exynos M1 (Exynos 8890 big cores). */
489
  cpuinfo_uarch_exynos_m1 = 0x00600100,
490
  /** Samsung Exynos M2 (Exynos 8895 big cores). */
491
  cpuinfo_uarch_exynos_m2 = 0x00600101,
492
  /** Samsung Exynos M3 (Exynos 9810 big cores). */
493
  cpuinfo_uarch_exynos_m3  = 0x00600102,
494
  /** Samsung Exynos M4 (Exynos 9820 big cores). */
495
  cpuinfo_uarch_exynos_m4  = 0x00600103,
496
  /** Samsung Exynos M5 (Exynos 9830 big cores). */
497
  cpuinfo_uarch_exynos_m5  = 0x00600104,
498
499
  /* Deprecated synonym for Cortex-A76 */
500
  cpuinfo_uarch_cortex_a76ae = 0x00300376,
501
  /* Deprecated names for Exynos. */
502
  cpuinfo_uarch_mongoose_m1 = 0x00600100,
503
  cpuinfo_uarch_mongoose_m2 = 0x00600101,
504
  cpuinfo_uarch_meerkat_m3  = 0x00600102,
505
  cpuinfo_uarch_meerkat_m4  = 0x00600103,
506
507
  /** Apple A6 and A6X processors. */
508
  cpuinfo_uarch_swift     = 0x00700100,
509
  /** Apple A7 processor. */
510
  cpuinfo_uarch_cyclone   = 0x00700101,
511
  /** Apple A8 and A8X processor. */
512
  cpuinfo_uarch_typhoon   = 0x00700102,
513
  /** Apple A9 and A9X processor. */
514
  cpuinfo_uarch_twister   = 0x00700103,
515
  /** Apple A10 and A10X processor. */
516
  cpuinfo_uarch_hurricane = 0x00700104,
517
  /** Apple A11 processor (big cores). */
518
  cpuinfo_uarch_monsoon   = 0x00700105,
519
  /** Apple A11 processor (little cores). */
520
  cpuinfo_uarch_mistral   = 0x00700106,
521
  /** Apple A12 processor (big cores). */
522
  cpuinfo_uarch_vortex    = 0x00700107,
523
  /** Apple A12 processor (little cores). */
524
  cpuinfo_uarch_tempest   = 0x00700108,
525
  /** Apple A13 processor (big cores). */
526
  cpuinfo_uarch_lightning = 0x00700109,
527
  /** Apple A13 processor (little cores). */
528
  cpuinfo_uarch_thunder   = 0x0070010A,
529
  /** Apple A14 / M1 processor (big cores). */
530
  cpuinfo_uarch_firestorm = 0x0070010B,
531
  /** Apple A14 / M1 processor (little cores). */
532
  cpuinfo_uarch_icestorm  = 0x0070010C,
533
  /** Apple A15 / M2 processor (big cores). */
534
  cpuinfo_uarch_avalanche = 0x0070010D,
535
  /** Apple A15 / M2 processor (little cores). */
536
  cpuinfo_uarch_blizzard  = 0x0070010E,
537
538
  /** Cavium ThunderX. */
539
  cpuinfo_uarch_thunderx = 0x00800100,
540
  /** Cavium ThunderX2 (originally Broadcom Vulkan). */
541
  cpuinfo_uarch_thunderx2 = 0x00800200,
542
543
  /** Marvell PJ4. */
544
  cpuinfo_uarch_pj4 = 0x00900100,
545
546
  /** Broadcom Brahma B15. */
547
  cpuinfo_uarch_brahma_b15 = 0x00A00100,
548
  /** Broadcom Brahma B53. */
549
  cpuinfo_uarch_brahma_b53 = 0x00A00101,
550
551
  /** Applied Micro X-Gene. */
552
  cpuinfo_uarch_xgene = 0x00B00100,
553
554
  /* Hygon Dhyana (a modification of AMD Zen for Chinese market). */
555
  cpuinfo_uarch_dhyana = 0x01000100,
556
557
  /** HiSilicon TaiShan v110 (Huawei Kunpeng 920 series processors). */
558
  cpuinfo_uarch_taishan_v110 = 0x00C00100,
559
};
560
561
struct cpuinfo_processor {
562
  /** SMT (hyperthread) ID within a core */
563
  uint32_t smt_id;
564
  /** Core containing this logical processor */
565
  const struct cpuinfo_core* core;
566
  /** Cluster of cores containing this logical processor */
567
  const struct cpuinfo_cluster* cluster;
568
  /** Physical package containing this logical processor */
569
  const struct cpuinfo_package* package;
570
#if defined(__linux__)
571
  /**
572
   * Linux-specific ID for the logical processor:
573
   * - Linux kernel exposes information about this logical processor in /sys/devices/system/cpu/cpu<linux_id>/
574
   * - Bit <linux_id> in the cpu_set_t identifies this logical processor
575
   */
576
  int linux_id;
577
#endif
578
#if defined(_WIN32) || defined(__CYGWIN__)
579
  /** Windows-specific ID for the group containing the logical processor. */
580
  uint16_t windows_group_id;
581
  /**
582
   * Windows-specific ID of the logical processor within its group:
583
   * - Bit <windows_processor_id> in the KAFFINITY mask identifies this logical processor within its group.
584
   */
585
  uint16_t windows_processor_id;
586
#endif
587
#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
588
  /** APIC ID (unique x86-specific ID of the logical processor) */
589
  uint32_t apic_id;
590
#endif
591
  struct {
592
    /** Level 1 instruction cache */
593
    const struct cpuinfo_cache* l1i;
594
    /** Level 1 data cache */
595
    const struct cpuinfo_cache* l1d;
596
    /** Level 2 unified or data cache */
597
    const struct cpuinfo_cache* l2;
598
    /** Level 3 unified or data cache */
599
    const struct cpuinfo_cache* l3;
600
    /** Level 4 unified or data cache */
601
    const struct cpuinfo_cache* l4;
602
  } cache;
603
};
604
605
struct cpuinfo_core {
606
  /** Index of the first logical processor on this core. */
607
  uint32_t processor_start;
608
  /** Number of logical processors on this core */
609
  uint32_t processor_count;
610
  /** Core ID within a package */
611
  uint32_t core_id;
612
  /** Cluster containing this core */
613
  const struct cpuinfo_cluster* cluster;
614
  /** Physical package containing this core. */
615
  const struct cpuinfo_package* package;
616
  /** Vendor of the CPU microarchitecture for this core */
617
  enum cpuinfo_vendor vendor;
618
  /** CPU microarchitecture for this core */
619
  enum cpuinfo_uarch uarch;
620
#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
621
  /** Value of CPUID leaf 1 EAX register for this core */
622
  uint32_t cpuid;
623
#elif CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
624
  /** Value of Main ID Register (MIDR) for this core */
625
  uint32_t midr;
626
#endif
627
  /** Clock rate (non-Turbo) of the core, in Hz */
628
  uint64_t frequency;
629
};
630
631
struct cpuinfo_cluster {
632
  /** Index of the first logical processor in the cluster */
633
  uint32_t processor_start;
634
  /** Number of logical processors in the cluster */
635
  uint32_t processor_count;
636
  /** Index of the first core in the cluster */
637
  uint32_t core_start;
638
  /** Number of cores on the cluster */
639
  uint32_t core_count;
640
  /** Cluster ID within a package */
641
  uint32_t cluster_id;
642
  /** Physical package containing the cluster */
643
  const struct cpuinfo_package* package;
644
  /** CPU microarchitecture vendor of the cores in the cluster */
645
  enum cpuinfo_vendor vendor;
646
  /** CPU microarchitecture of the cores in the cluster */
647
  enum cpuinfo_uarch uarch;
648
#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
649
  /** Value of CPUID leaf 1 EAX register of the cores in the cluster */
650
  uint32_t cpuid;
651
#elif CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
652
  /** Value of Main ID Register (MIDR) of the cores in the cluster */
653
  uint32_t midr;
654
#endif
655
  /** Clock rate (non-Turbo) of the cores in the cluster, in Hz */
656
  uint64_t frequency;
657
};
658
659
#define CPUINFO_PACKAGE_NAME_MAX 48
660
661
struct cpuinfo_package {
662
  /** SoC or processor chip model name */
663
  char name[CPUINFO_PACKAGE_NAME_MAX];
664
  /** Index of the first logical processor on this physical package */
665
  uint32_t processor_start;
666
  /** Number of logical processors on this physical package */
667
  uint32_t processor_count;
668
  /** Index of the first core on this physical package */
669
  uint32_t core_start;
670
  /** Number of cores on this physical package */
671
  uint32_t core_count;
672
  /** Index of the first cluster of cores on this physical package */
673
  uint32_t cluster_start;
674
  /** Number of clusters of cores on this physical package */
675
  uint32_t cluster_count;
676
};
677
678
struct cpuinfo_uarch_info {
679
  /** Type of CPU microarchitecture */
680
  enum cpuinfo_uarch uarch;
681
#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
682
  /** Value of CPUID leaf 1 EAX register for the microarchitecture */
683
  uint32_t cpuid;
684
#elif CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
685
  /** Value of Main ID Register (MIDR) for the microarchitecture */
686
  uint32_t midr;
687
#endif
688
  /** Number of logical processors with the microarchitecture */
689
  uint32_t processor_count;
690
  /** Number of cores with the microarchitecture */
691
  uint32_t core_count;
692
};
693
694
#ifdef __cplusplus
695
extern "C" {
696
#endif
697
698
bool CPUINFO_ABI cpuinfo_initialize(void);
699
700
void CPUINFO_ABI cpuinfo_deinitialize(void);
701
702
#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
703
  /* This structure is not a part of stable API. Use cpuinfo_has_x86_* functions instead. */
704
  struct cpuinfo_x86_isa {
705
    #if CPUINFO_ARCH_X86
706
      bool rdtsc;
707
    #endif
708
    bool rdtscp;
709
    bool rdpid;
710
    bool sysenter;
711
    #if CPUINFO_ARCH_X86
712
      bool syscall;
713
    #endif
714
    bool msr;
715
    bool clzero;
716
    bool clflush;
717
    bool clflushopt;
718
    bool mwait;
719
    bool mwaitx;
720
    #if CPUINFO_ARCH_X86
721
      bool emmx;
722
    #endif
723
    bool fxsave;
724
    bool xsave;
725
    #if CPUINFO_ARCH_X86
726
      bool fpu;
727
      bool mmx;
728
      bool mmx_plus;
729
    #endif
730
    bool three_d_now;
731
    bool three_d_now_plus;
732
    #if CPUINFO_ARCH_X86
733
      bool three_d_now_geode;
734
    #endif
735
    bool prefetch;
736
    bool prefetchw;
737
    bool prefetchwt1;
738
    #if CPUINFO_ARCH_X86
739
      bool daz;
740
      bool sse;
741
      bool sse2;
742
    #endif
743
    bool sse3;
744
    bool ssse3;
745
    bool sse4_1;
746
    bool sse4_2;
747
    bool sse4a;
748
    bool misaligned_sse;
749
    bool avx;
750
    bool avxvnni;
751
    bool fma3;
752
    bool fma4;
753
    bool xop;
754
    bool f16c;
755
    bool avx2;
756
    bool avx512f;
757
    bool avx512pf;
758
    bool avx512er;
759
    bool avx512cd;
760
    bool avx512dq;
761
    bool avx512bw;
762
    bool avx512vl;
763
    bool avx512ifma;
764
    bool avx512vbmi;
765
    bool avx512vbmi2;
766
    bool avx512bitalg;
767
    bool avx512vpopcntdq;
768
    bool avx512vnni;
769
    bool avx512bf16;
770
    bool avx512fp16;
771
    bool avx512vp2intersect;
772
    bool avx512_4vnniw;
773
    bool avx512_4fmaps;
774
    bool hle;
775
    bool rtm;
776
    bool xtest;
777
    bool mpx;
778
    #if CPUINFO_ARCH_X86
779
      bool cmov;
780
      bool cmpxchg8b;
781
    #endif
782
    bool cmpxchg16b;
783
    bool clwb;
784
    bool movbe;
785
    #if CPUINFO_ARCH_X86_64
786
      bool lahf_sahf;
787
    #endif
788
    bool fs_gs_base;
789
    bool lzcnt;
790
    bool popcnt;
791
    bool tbm;
792
    bool bmi;
793
    bool bmi2;
794
    bool adx;
795
    bool aes;
796
    bool vaes;
797
    bool pclmulqdq;
798
    bool vpclmulqdq;
799
    bool gfni;
800
    bool rdrand;
801
    bool rdseed;
802
    bool sha;
803
    bool rng;
804
    bool ace;
805
    bool ace2;
806
    bool phe;
807
    bool pmm;
808
    bool lwp;
809
  };
810
811
  extern struct cpuinfo_x86_isa cpuinfo_isa;
812
#endif
813
814
0
static inline bool cpuinfo_has_x86_rdtsc(void) {
815
0
  #if CPUINFO_ARCH_X86_64
816
0
    return true;
817
0
  #elif CPUINFO_ARCH_X86
818
0
    #if defined(__ANDROID__)
819
0
      return true;
820
0
    #else
821
0
      return cpuinfo_isa.rdtsc;
822
0
    #endif
823
0
  #else
824
0
    return false;
825
0
  #endif
826
0
}
827
828
0
static inline bool cpuinfo_has_x86_rdtscp(void) {
829
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
830
0
    return cpuinfo_isa.rdtscp;
831
0
  #else
832
0
    return false;
833
0
  #endif
834
0
}
835
836
0
static inline bool cpuinfo_has_x86_rdpid(void) {
837
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
838
0
    return cpuinfo_isa.rdpid;
839
0
  #else
840
0
    return false;
841
0
  #endif
842
0
}
843
844
0
static inline bool cpuinfo_has_x86_clzero(void) {
845
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
846
0
    return cpuinfo_isa.clzero;
847
0
  #else
848
0
    return false;
849
0
  #endif
850
0
}
851
852
0
static inline bool cpuinfo_has_x86_mwait(void) {
853
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
854
0
    return cpuinfo_isa.mwait;
855
0
  #else
856
0
    return false;
857
0
  #endif
858
0
}
859
860
0
static inline bool cpuinfo_has_x86_mwaitx(void) {
861
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
862
0
    return cpuinfo_isa.mwaitx;
863
0
  #else
864
0
    return false;
865
0
  #endif
866
0
}
867
868
0
static inline bool cpuinfo_has_x86_fxsave(void) {
869
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
870
0
    return cpuinfo_isa.fxsave;
871
0
  #else
872
0
    return false;
873
0
  #endif
874
0
}
875
876
0
static inline bool cpuinfo_has_x86_xsave(void) {
877
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
878
0
    return cpuinfo_isa.xsave;
879
0
  #else
880
0
    return false;
881
0
  #endif
882
0
}
883
884
0
static inline bool cpuinfo_has_x86_fpu(void) {
885
0
  #if CPUINFO_ARCH_X86_64
886
0
    return true;
887
0
  #elif CPUINFO_ARCH_X86
888
0
    #if defined(__ANDROID__)
889
0
      return true;
890
0
    #else
891
0
      return cpuinfo_isa.fpu;
892
0
    #endif
893
0
  #else
894
0
    return false;
895
0
  #endif
896
0
}
897
898
0
static inline bool cpuinfo_has_x86_mmx(void) {
899
0
  #if CPUINFO_ARCH_X86_64
900
0
    return true;
901
0
  #elif CPUINFO_ARCH_X86
902
0
    #if defined(__ANDROID__)
903
0
      return true;
904
0
    #else
905
0
      return cpuinfo_isa.mmx;
906
0
    #endif
907
0
  #else
908
0
    return false;
909
0
  #endif
910
0
}
911
912
0
static inline bool cpuinfo_has_x86_mmx_plus(void) {
913
0
  #if CPUINFO_ARCH_X86_64
914
0
    return true;
915
0
  #elif CPUINFO_ARCH_X86
916
0
    #if defined(__ANDROID__)
917
0
      return true;
918
0
    #else
919
0
      return cpuinfo_isa.mmx_plus;
920
0
    #endif
921
0
  #else
922
0
    return false;
923
0
  #endif
924
0
}
925
926
0
static inline bool cpuinfo_has_x86_3dnow(void) {
927
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
928
0
    return cpuinfo_isa.three_d_now;
929
0
  #else
930
0
    return false;
931
0
  #endif
932
0
}
933
934
0
static inline bool cpuinfo_has_x86_3dnow_plus(void) {
935
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
936
0
    return cpuinfo_isa.three_d_now_plus;
937
0
  #else
938
0
    return false;
939
0
  #endif
940
0
}
941
942
0
static inline bool cpuinfo_has_x86_3dnow_geode(void) {
943
0
  #if CPUINFO_ARCH_X86_64
944
0
    return false;
945
0
  #elif CPUINFO_ARCH_X86
946
0
    #if defined(__ANDROID__)
947
0
      return false;
948
0
    #else
949
0
      return cpuinfo_isa.three_d_now_geode;
950
0
    #endif
951
0
  #else
952
0
    return false;
953
0
  #endif
954
0
}
955
956
0
static inline bool cpuinfo_has_x86_prefetch(void) {
957
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
958
0
    return cpuinfo_isa.prefetch;
959
0
  #else
960
0
    return false;
961
0
  #endif
962
0
}
963
964
0
static inline bool cpuinfo_has_x86_prefetchw(void) {
965
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
966
0
    return cpuinfo_isa.prefetchw;
967
0
  #else
968
0
    return false;
969
0
  #endif
970
0
}
971
972
0
static inline bool cpuinfo_has_x86_prefetchwt1(void) {
973
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
974
0
    return cpuinfo_isa.prefetchwt1;
975
0
  #else
976
0
    return false;
977
0
  #endif
978
0
}
979
980
0
static inline bool cpuinfo_has_x86_daz(void) {
981
0
  #if CPUINFO_ARCH_X86_64
982
0
    return true;
983
0
  #elif CPUINFO_ARCH_X86
984
0
    #if defined(__ANDROID__)
985
0
      return true;
986
0
    #else
987
0
      return cpuinfo_isa.daz;
988
0
    #endif
989
0
  #else
990
0
    return false;
991
0
  #endif
992
0
}
993
994
0
static inline bool cpuinfo_has_x86_sse(void) {
995
0
  #if CPUINFO_ARCH_X86_64
996
0
    return true;
997
0
  #elif CPUINFO_ARCH_X86
998
0
    #if defined(__ANDROID__)
999
0
      return true;
1000
0
    #else
1001
0
      return cpuinfo_isa.sse;
1002
0
    #endif
1003
0
  #else
1004
0
    return false;
1005
0
  #endif
1006
0
}
1007
1008
0
static inline bool cpuinfo_has_x86_sse2(void) {
1009
0
  #if CPUINFO_ARCH_X86_64
1010
0
    return true;
1011
0
  #elif CPUINFO_ARCH_X86
1012
0
    #if defined(__ANDROID__)
1013
0
      return true;
1014
0
    #else
1015
0
      return cpuinfo_isa.sse2;
1016
0
    #endif
1017
0
  #else
1018
0
    return false;
1019
0
  #endif
1020
0
}
1021
1022
0
static inline bool cpuinfo_has_x86_sse3(void) {
1023
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1024
0
    #if defined(__ANDROID__)
1025
0
      return true;
1026
0
    #else
1027
0
      return cpuinfo_isa.sse3;
1028
0
    #endif
1029
0
  #else
1030
0
    return false;
1031
0
  #endif
1032
0
}
1033
1034
0
static inline bool cpuinfo_has_x86_ssse3(void) {
1035
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1036
0
    #if defined(__ANDROID__)
1037
0
      return true;
1038
0
    #else
1039
0
      return cpuinfo_isa.ssse3;
1040
0
    #endif
1041
0
  #else
1042
0
    return false;
1043
0
  #endif
1044
0
}
1045
1046
0
static inline bool cpuinfo_has_x86_sse4_1(void) {
1047
0
  #if CPUINFO_ARCH_X86_64
1048
0
    #if defined(__ANDROID__)
1049
0
      return true;
1050
0
    #else
1051
0
      return cpuinfo_isa.sse4_1;
1052
0
    #endif
1053
0
  #elif CPUINFO_ARCH_X86
1054
0
    return cpuinfo_isa.sse4_1;
1055
0
  #else
1056
0
    return false;
1057
0
  #endif
1058
0
}
1059
1060
0
static inline bool cpuinfo_has_x86_sse4_2(void) {
1061
0
  #if CPUINFO_ARCH_X86_64
1062
0
    #if defined(__ANDROID__)
1063
0
      return true;
1064
0
    #else
1065
0
      return cpuinfo_isa.sse4_2;
1066
0
    #endif
1067
0
  #elif CPUINFO_ARCH_X86
1068
0
    return cpuinfo_isa.sse4_2;
1069
0
  #else
1070
0
    return false;
1071
0
  #endif
1072
0
}
1073
1074
0
static inline bool cpuinfo_has_x86_sse4a(void) {
1075
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1076
0
    return cpuinfo_isa.sse4a;
1077
0
  #else
1078
0
    return false;
1079
0
  #endif
1080
0
}
1081
1082
0
static inline bool cpuinfo_has_x86_misaligned_sse(void) {
1083
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1084
0
    return cpuinfo_isa.misaligned_sse;
1085
0
  #else
1086
0
    return false;
1087
0
  #endif
1088
0
}
1089
1090
0
static inline bool cpuinfo_has_x86_avx(void) {
1091
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1092
0
    return cpuinfo_isa.avx;
1093
  #else
1094
    return false;
1095
  #endif
1096
0
}
1097
1098
0
static inline bool cpuinfo_has_x86_avxvnni(void) {
1099
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1100
0
    return cpuinfo_isa.avxvnni;
1101
0
  #else
1102
0
    return false;
1103
0
  #endif
1104
0
}
1105
1106
0
static inline bool cpuinfo_has_x86_fma3(void) {
1107
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1108
0
    return cpuinfo_isa.fma3;
1109
  #else
1110
    return false;
1111
  #endif
1112
0
}
1113
1114
0
static inline bool cpuinfo_has_x86_fma4(void) {
1115
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1116
0
    return cpuinfo_isa.fma4;
1117
0
  #else
1118
0
    return false;
1119
0
  #endif
1120
0
}
1121
1122
0
static inline bool cpuinfo_has_x86_xop(void) {
1123
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1124
0
    return cpuinfo_isa.xop;
1125
0
  #else
1126
0
    return false;
1127
0
  #endif
1128
0
}
1129
1130
0
static inline bool cpuinfo_has_x86_f16c(void) {
1131
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1132
0
    return cpuinfo_isa.f16c;
1133
0
  #else
1134
0
    return false;
1135
0
  #endif
1136
0
}
1137
1138
0
static inline bool cpuinfo_has_x86_avx2(void) {
1139
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1140
0
    return cpuinfo_isa.avx2;
1141
  #else
1142
    return false;
1143
  #endif
1144
0
}
1145
1146
0
static inline bool cpuinfo_has_x86_avx512f(void) {
1147
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1148
0
    return cpuinfo_isa.avx512f;
1149
  #else
1150
    return false;
1151
  #endif
1152
0
}
1153
1154
0
static inline bool cpuinfo_has_x86_avx512pf(void) {
1155
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1156
0
    return cpuinfo_isa.avx512pf;
1157
0
  #else
1158
0
    return false;
1159
0
  #endif
1160
0
}
1161
1162
0
static inline bool cpuinfo_has_x86_avx512er(void) {
1163
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1164
0
    return cpuinfo_isa.avx512er;
1165
0
  #else
1166
0
    return false;
1167
0
  #endif
1168
0
}
1169
1170
0
static inline bool cpuinfo_has_x86_avx512cd(void) {
1171
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1172
0
    return cpuinfo_isa.avx512cd;
1173
  #else
1174
    return false;
1175
  #endif
1176
0
}
1177
1178
0
static inline bool cpuinfo_has_x86_avx512dq(void) {
1179
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1180
0
    return cpuinfo_isa.avx512dq;
1181
  #else
1182
    return false;
1183
  #endif
1184
0
}
1185
1186
0
static inline bool cpuinfo_has_x86_avx512bw(void) {
1187
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1188
0
    return cpuinfo_isa.avx512bw;
1189
  #else
1190
    return false;
1191
  #endif
1192
0
}
1193
1194
0
static inline bool cpuinfo_has_x86_avx512vl(void) {
1195
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1196
0
    return cpuinfo_isa.avx512vl;
1197
  #else
1198
    return false;
1199
  #endif
1200
0
}
1201
1202
0
static inline bool cpuinfo_has_x86_avx512ifma(void) {
1203
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1204
0
    return cpuinfo_isa.avx512ifma;
1205
0
  #else
1206
0
    return false;
1207
0
  #endif
1208
0
}
1209
1210
0
static inline bool cpuinfo_has_x86_avx512vbmi(void) {
1211
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1212
0
    return cpuinfo_isa.avx512vbmi;
1213
0
  #else
1214
0
    return false;
1215
0
  #endif
1216
0
}
1217
1218
0
static inline bool cpuinfo_has_x86_avx512vbmi2(void) {
1219
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1220
0
    return cpuinfo_isa.avx512vbmi2;
1221
0
  #else
1222
0
    return false;
1223
0
  #endif
1224
0
}
1225
1226
0
static inline bool cpuinfo_has_x86_avx512bitalg(void) {
1227
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1228
0
    return cpuinfo_isa.avx512bitalg;
1229
0
  #else
1230
0
    return false;
1231
0
  #endif
1232
0
}
1233
1234
0
static inline bool cpuinfo_has_x86_avx512vpopcntdq(void) {
1235
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1236
0
    return cpuinfo_isa.avx512vpopcntdq;
1237
0
  #else
1238
0
    return false;
1239
0
  #endif
1240
0
}
1241
1242
0
static inline bool cpuinfo_has_x86_avx512vnni(void) {
1243
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1244
0
    return cpuinfo_isa.avx512vnni;
1245
0
  #else
1246
0
    return false;
1247
0
  #endif
1248
0
}
1249
1250
0
static inline bool cpuinfo_has_x86_avx512bf16(void) {
1251
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1252
0
    return cpuinfo_isa.avx512bf16;
1253
0
  #else
1254
0
    return false;
1255
0
  #endif
1256
0
}
1257
1258
0
static inline bool cpuinfo_has_x86_avx512fp16(void) {
1259
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1260
0
    return cpuinfo_isa.avx512fp16;
1261
0
  #else
1262
0
    return false;
1263
0
  #endif
1264
0
}
1265
1266
0
static inline bool cpuinfo_has_x86_avx512vp2intersect(void) {
1267
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1268
0
    return cpuinfo_isa.avx512vp2intersect;
1269
0
  #else
1270
0
    return false;
1271
0
  #endif
1272
0
}
1273
1274
0
static inline bool cpuinfo_has_x86_avx512_4vnniw(void) {
1275
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1276
0
    return cpuinfo_isa.avx512_4vnniw;
1277
0
  #else
1278
0
    return false;
1279
0
  #endif
1280
0
}
1281
1282
0
static inline bool cpuinfo_has_x86_avx512_4fmaps(void) {
1283
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1284
0
    return cpuinfo_isa.avx512_4fmaps;
1285
0
  #else
1286
0
    return false;
1287
0
  #endif
1288
0
}
1289
1290
0
static inline bool cpuinfo_has_x86_hle(void) {
1291
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1292
0
    return cpuinfo_isa.hle;
1293
0
  #else
1294
0
    return false;
1295
0
  #endif
1296
0
}
1297
1298
0
static inline bool cpuinfo_has_x86_rtm(void) {
1299
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1300
0
    return cpuinfo_isa.rtm;
1301
0
  #else
1302
0
    return false;
1303
0
  #endif
1304
0
}
1305
1306
0
static inline bool cpuinfo_has_x86_xtest(void) {
1307
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1308
0
    return cpuinfo_isa.xtest;
1309
0
  #else
1310
0
    return false;
1311
0
  #endif
1312
0
}
1313
1314
0
static inline bool cpuinfo_has_x86_mpx(void) {
1315
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1316
0
    return cpuinfo_isa.mpx;
1317
0
  #else
1318
0
    return false;
1319
0
  #endif
1320
0
}
1321
1322
0
static inline bool cpuinfo_has_x86_cmov(void) {
1323
0
  #if CPUINFO_ARCH_X86_64
1324
0
    return true;
1325
0
  #elif CPUINFO_ARCH_X86
1326
0
    return cpuinfo_isa.cmov;
1327
0
  #else
1328
0
    return false;
1329
0
  #endif
1330
0
}
1331
1332
0
static inline bool cpuinfo_has_x86_cmpxchg8b(void) {
1333
0
  #if CPUINFO_ARCH_X86_64
1334
0
    return true;
1335
0
  #elif CPUINFO_ARCH_X86
1336
0
    return cpuinfo_isa.cmpxchg8b;
1337
0
  #else
1338
0
    return false;
1339
0
  #endif
1340
0
}
1341
1342
0
static inline bool cpuinfo_has_x86_cmpxchg16b(void) {
1343
0
  #if CPUINFO_ARCH_X86_64
1344
0
    return cpuinfo_isa.cmpxchg16b;
1345
0
  #else
1346
0
    return false;
1347
0
  #endif
1348
0
}
1349
1350
0
static inline bool cpuinfo_has_x86_clwb(void) {
1351
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1352
0
    return cpuinfo_isa.clwb;
1353
0
  #else
1354
0
    return false;
1355
0
  #endif
1356
0
}
1357
1358
0
static inline bool cpuinfo_has_x86_movbe(void) {
1359
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1360
0
    return cpuinfo_isa.movbe;
1361
0
  #else
1362
0
    return false;
1363
0
  #endif
1364
0
}
1365
1366
0
static inline bool cpuinfo_has_x86_lahf_sahf(void) {
1367
0
  #if CPUINFO_ARCH_X86
1368
0
    return true;
1369
0
  #elif CPUINFO_ARCH_X86_64
1370
0
    return cpuinfo_isa.lahf_sahf;
1371
0
  #else
1372
0
    return false;
1373
0
  #endif
1374
0
}
1375
1376
0
static inline bool cpuinfo_has_x86_lzcnt(void) {
1377
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1378
0
    return cpuinfo_isa.lzcnt;
1379
0
  #else
1380
0
    return false;
1381
0
  #endif
1382
0
}
1383
1384
0
static inline bool cpuinfo_has_x86_popcnt(void) {
1385
0
  #if CPUINFO_ARCH_X86_64
1386
0
    #if defined(__ANDROID__)
1387
0
      return true;
1388
0
    #else
1389
0
      return cpuinfo_isa.popcnt;
1390
0
    #endif
1391
0
  #elif CPUINFO_ARCH_X86
1392
0
    return cpuinfo_isa.popcnt;
1393
0
  #else
1394
0
    return false;
1395
0
  #endif
1396
0
}
1397
1398
0
static inline bool cpuinfo_has_x86_tbm(void) {
1399
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1400
0
    return cpuinfo_isa.tbm;
1401
0
  #else
1402
0
    return false;
1403
0
  #endif
1404
0
}
1405
1406
0
static inline bool cpuinfo_has_x86_bmi(void) {
1407
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1408
0
    return cpuinfo_isa.bmi;
1409
0
  #else
1410
0
    return false;
1411
0
  #endif
1412
0
}
1413
1414
0
static inline bool cpuinfo_has_x86_bmi2(void) {
1415
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1416
0
    return cpuinfo_isa.bmi2;
1417
0
  #else
1418
0
    return false;
1419
0
  #endif
1420
0
}
1421
1422
0
static inline bool cpuinfo_has_x86_adx(void) {
1423
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1424
0
    return cpuinfo_isa.adx;
1425
0
  #else
1426
0
    return false;
1427
0
  #endif
1428
0
}
1429
1430
0
static inline bool cpuinfo_has_x86_aes(void) {
1431
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1432
0
    return cpuinfo_isa.aes;
1433
0
  #else
1434
0
    return false;
1435
0
  #endif
1436
0
}
1437
1438
0
static inline bool cpuinfo_has_x86_vaes(void) {
1439
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1440
0
    return cpuinfo_isa.vaes;
1441
0
  #else
1442
0
    return false;
1443
0
  #endif
1444
0
}
1445
1446
0
static inline bool cpuinfo_has_x86_pclmulqdq(void) {
1447
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1448
0
    return cpuinfo_isa.pclmulqdq;
1449
0
  #else
1450
0
    return false;
1451
0
  #endif
1452
0
}
1453
1454
0
static inline bool cpuinfo_has_x86_vpclmulqdq(void) {
1455
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1456
0
    return cpuinfo_isa.vpclmulqdq;
1457
0
  #else
1458
0
    return false;
1459
0
  #endif
1460
0
}
1461
1462
0
static inline bool cpuinfo_has_x86_gfni(void) {
1463
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1464
0
    return cpuinfo_isa.gfni;
1465
0
  #else
1466
0
    return false;
1467
0
  #endif
1468
0
}
1469
1470
0
static inline bool cpuinfo_has_x86_rdrand(void) {
1471
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1472
0
    return cpuinfo_isa.rdrand;
1473
0
  #else
1474
0
    return false;
1475
0
  #endif
1476
0
}
1477
1478
0
static inline bool cpuinfo_has_x86_rdseed(void) {
1479
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1480
0
    return cpuinfo_isa.rdseed;
1481
0
  #else
1482
0
    return false;
1483
0
  #endif
1484
0
}
1485
1486
0
static inline bool cpuinfo_has_x86_sha(void) {
1487
0
  #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1488
0
    return cpuinfo_isa.sha;
1489
0
  #else
1490
0
    return false;
1491
0
  #endif
1492
0
}
1493
1494
#if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1495
  /* This structure is not a part of stable API. Use cpuinfo_has_arm_* functions instead. */
1496
  struct cpuinfo_arm_isa {
1497
    #if CPUINFO_ARCH_ARM
1498
      bool thumb;
1499
      bool thumb2;
1500
      bool thumbee;
1501
      bool jazelle;
1502
      bool armv5e;
1503
      bool armv6;
1504
      bool armv6k;
1505
      bool armv7;
1506
      bool armv7mp;
1507
      bool armv8;
1508
      bool idiv;
1509
1510
      bool vfpv2;
1511
      bool vfpv3;
1512
      bool d32;
1513
      bool fp16;
1514
      bool fma;
1515
1516
      bool wmmx;
1517
      bool wmmx2;
1518
      bool neon;
1519
    #endif
1520
    #if CPUINFO_ARCH_ARM64
1521
      bool atomics;
1522
      bool bf16;
1523
      bool sve;
1524
      bool sve2;
1525
      bool i8mm;
1526
    #endif
1527
    bool rdm;
1528
    bool fp16arith;
1529
    bool dot;
1530
    bool jscvt;
1531
    bool fcma;
1532
    bool fhm;
1533
1534
    bool aes;
1535
    bool sha1;
1536
    bool sha2;
1537
    bool pmull;
1538
    bool crc32;
1539
  };
1540
1541
  extern struct cpuinfo_arm_isa cpuinfo_isa;
1542
#endif
1543
1544
0
static inline bool cpuinfo_has_arm_thumb(void) {
1545
0
  #if CPUINFO_ARCH_ARM
1546
0
    return cpuinfo_isa.thumb;
1547
0
  #else
1548
0
    return false;
1549
0
  #endif
1550
0
}
1551
1552
0
static inline bool cpuinfo_has_arm_thumb2(void) {
1553
0
  #if CPUINFO_ARCH_ARM
1554
0
    return cpuinfo_isa.thumb2;
1555
0
  #else
1556
0
    return false;
1557
0
  #endif
1558
0
}
1559
1560
0
static inline bool cpuinfo_has_arm_v5e(void) {
1561
0
  #if CPUINFO_ARCH_ARM
1562
0
    return cpuinfo_isa.armv5e;
1563
0
  #else
1564
0
    return false;
1565
0
  #endif
1566
0
}
1567
1568
0
static inline bool cpuinfo_has_arm_v6(void) {
1569
0
  #if CPUINFO_ARCH_ARM
1570
0
    return cpuinfo_isa.armv6;
1571
0
  #else
1572
0
    return false;
1573
0
  #endif
1574
0
}
1575
1576
0
static inline bool cpuinfo_has_arm_v6k(void) {
1577
0
  #if CPUINFO_ARCH_ARM
1578
0
    return cpuinfo_isa.armv6k;
1579
0
  #else
1580
0
    return false;
1581
0
  #endif
1582
0
}
1583
1584
0
static inline bool cpuinfo_has_arm_v7(void) {
1585
0
  #if CPUINFO_ARCH_ARM
1586
0
    return cpuinfo_isa.armv7;
1587
0
  #else
1588
0
    return false;
1589
0
  #endif
1590
0
}
1591
1592
0
static inline bool cpuinfo_has_arm_v7mp(void) {
1593
0
  #if CPUINFO_ARCH_ARM
1594
0
    return cpuinfo_isa.armv7mp;
1595
0
  #else
1596
0
    return false;
1597
0
  #endif
1598
0
}
1599
1600
0
static inline bool cpuinfo_has_arm_v8(void) {
1601
0
  #if CPUINFO_ARCH_ARM64
1602
0
    return true;
1603
0
  #elif CPUINFO_ARCH_ARM
1604
0
    return cpuinfo_isa.armv8;
1605
0
  #else
1606
0
    return false;
1607
0
  #endif
1608
0
}
1609
1610
0
static inline bool cpuinfo_has_arm_idiv(void) {
1611
0
  #if CPUINFO_ARCH_ARM64
1612
0
    return true;
1613
0
  #elif CPUINFO_ARCH_ARM
1614
0
    return cpuinfo_isa.idiv;
1615
0
  #else
1616
0
    return false;
1617
0
  #endif
1618
0
}
1619
1620
0
static inline bool cpuinfo_has_arm_vfpv2(void) {
1621
0
  #if CPUINFO_ARCH_ARM
1622
0
    return cpuinfo_isa.vfpv2;
1623
0
  #else
1624
0
    return false;
1625
0
  #endif
1626
0
}
1627
1628
0
static inline bool cpuinfo_has_arm_vfpv3(void) {
1629
0
  #if CPUINFO_ARCH_ARM64
1630
0
    return true;
1631
0
  #elif CPUINFO_ARCH_ARM
1632
0
    return cpuinfo_isa.vfpv3;
1633
0
  #else
1634
0
    return false;
1635
0
  #endif
1636
0
}
1637
1638
0
static inline bool cpuinfo_has_arm_vfpv3_d32(void) {
1639
0
  #if CPUINFO_ARCH_ARM64
1640
0
    return true;
1641
0
  #elif CPUINFO_ARCH_ARM
1642
0
    return cpuinfo_isa.vfpv3 && cpuinfo_isa.d32;
1643
0
  #else
1644
0
    return false;
1645
0
  #endif
1646
0
}
1647
1648
0
static inline bool cpuinfo_has_arm_vfpv3_fp16(void) {
1649
0
  #if CPUINFO_ARCH_ARM64
1650
0
    return true;
1651
0
  #elif CPUINFO_ARCH_ARM
1652
0
    return cpuinfo_isa.vfpv3 && cpuinfo_isa.fp16;
1653
0
  #else
1654
0
    return false;
1655
0
  #endif
1656
0
}
1657
1658
0
static inline bool cpuinfo_has_arm_vfpv3_fp16_d32(void) {
1659
0
  #if CPUINFO_ARCH_ARM64
1660
0
    return true;
1661
0
  #elif CPUINFO_ARCH_ARM
1662
0
    return cpuinfo_isa.vfpv3 && cpuinfo_isa.fp16 && cpuinfo_isa.d32;
1663
0
  #else
1664
0
    return false;
1665
0
  #endif
1666
0
}
1667
1668
0
static inline bool cpuinfo_has_arm_vfpv4(void) {
1669
0
  #if CPUINFO_ARCH_ARM64
1670
0
    return true;
1671
0
  #elif CPUINFO_ARCH_ARM
1672
0
    return cpuinfo_isa.vfpv3 && cpuinfo_isa.fma;
1673
0
  #else
1674
0
    return false;
1675
0
  #endif
1676
0
}
1677
1678
0
static inline bool cpuinfo_has_arm_vfpv4_d32(void) {
1679
0
  #if CPUINFO_ARCH_ARM64
1680
0
    return true;
1681
0
  #elif CPUINFO_ARCH_ARM
1682
0
    return cpuinfo_isa.vfpv3 && cpuinfo_isa.fma && cpuinfo_isa.d32;
1683
0
  #else
1684
0
    return false;
1685
0
  #endif
1686
0
}
1687
1688
0
static inline bool cpuinfo_has_arm_fp16_arith(void) {
1689
0
  #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1690
0
    return cpuinfo_isa.fp16arith;
1691
0
  #else
1692
0
    return false;
1693
0
  #endif
1694
0
}
1695
1696
0
static inline bool cpuinfo_has_arm_bf16(void) {
1697
0
  #if CPUINFO_ARCH_ARM64
1698
0
    return cpuinfo_isa.bf16;
1699
0
  #else
1700
0
    return false;
1701
0
  #endif
1702
0
}
1703
1704
0
static inline bool cpuinfo_has_arm_wmmx(void) {
1705
0
  #if CPUINFO_ARCH_ARM
1706
0
    return cpuinfo_isa.wmmx;
1707
0
  #else
1708
0
    return false;
1709
0
  #endif
1710
0
}
1711
1712
0
static inline bool cpuinfo_has_arm_wmmx2(void) {
1713
0
  #if CPUINFO_ARCH_ARM
1714
0
    return cpuinfo_isa.wmmx2;
1715
0
  #else
1716
0
    return false;
1717
0
  #endif
1718
0
}
1719
1720
0
static inline bool cpuinfo_has_arm_neon(void) {
1721
0
  #if CPUINFO_ARCH_ARM64
1722
0
    return true;
1723
0
  #elif CPUINFO_ARCH_ARM
1724
0
    return cpuinfo_isa.neon;
1725
0
  #else
1726
0
    return false;
1727
0
  #endif
1728
0
}
1729
1730
0
static inline bool cpuinfo_has_arm_neon_fp16(void) {
1731
0
  #if CPUINFO_ARCH_ARM64
1732
0
    return true;
1733
0
  #elif CPUINFO_ARCH_ARM
1734
0
    return cpuinfo_isa.neon && cpuinfo_isa.fp16;
1735
0
  #else
1736
0
    return false;
1737
0
  #endif
1738
0
}
1739
1740
0
static inline bool cpuinfo_has_arm_neon_fma(void) {
1741
0
  #if CPUINFO_ARCH_ARM64
1742
0
    return true;
1743
0
  #elif CPUINFO_ARCH_ARM
1744
0
    return cpuinfo_isa.neon && cpuinfo_isa.fma;
1745
0
  #else
1746
0
    return false;
1747
0
  #endif
1748
0
}
1749
1750
0
static inline bool cpuinfo_has_arm_neon_v8(void) {
1751
0
  #if CPUINFO_ARCH_ARM64
1752
0
    return true;
1753
0
  #elif CPUINFO_ARCH_ARM
1754
0
    return cpuinfo_isa.neon && cpuinfo_isa.armv8;
1755
0
  #else
1756
0
    return false;
1757
0
  #endif
1758
0
}
1759
1760
0
static inline bool cpuinfo_has_arm_atomics(void) {
1761
0
  #if CPUINFO_ARCH_ARM64
1762
0
    return cpuinfo_isa.atomics;
1763
0
  #else
1764
0
    return false;
1765
0
  #endif
1766
0
}
1767
1768
0
static inline bool cpuinfo_has_arm_neon_rdm(void) {
1769
0
  #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1770
0
    return cpuinfo_isa.rdm;
1771
0
  #else
1772
0
    return false;
1773
0
  #endif
1774
0
}
1775
1776
0
static inline bool cpuinfo_has_arm_neon_fp16_arith(void) {
1777
0
  #if CPUINFO_ARCH_ARM
1778
0
    return cpuinfo_isa.neon && cpuinfo_isa.fp16arith;
1779
0
  #elif CPUINFO_ARCH_ARM64
1780
0
    return cpuinfo_isa.fp16arith;
1781
0
  #else
1782
0
    return false;
1783
0
  #endif
1784
0
}
1785
1786
0
static inline bool cpuinfo_has_arm_fhm(void) {
1787
0
  #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1788
0
    return cpuinfo_isa.fhm;
1789
0
  #else
1790
0
    return false;
1791
0
  #endif
1792
0
}
1793
1794
0
static inline bool cpuinfo_has_arm_neon_dot(void) {
1795
0
  #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1796
0
    return cpuinfo_isa.dot;
1797
0
  #else
1798
0
    return false;
1799
0
  #endif
1800
0
}
1801
1802
0
static inline bool cpuinfo_has_arm_neon_bf16(void) {
1803
0
  #if CPUINFO_ARCH_ARM64
1804
0
    return cpuinfo_isa.bf16;
1805
0
  #else
1806
0
    return false;
1807
0
  #endif
1808
0
}
1809
1810
0
static inline bool cpuinfo_has_arm_jscvt(void) {
1811
0
  #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1812
0
    return cpuinfo_isa.jscvt;
1813
0
  #else
1814
0
    return false;
1815
0
  #endif
1816
0
}
1817
1818
0
static inline bool cpuinfo_has_arm_fcma(void) {
1819
0
  #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1820
0
    return cpuinfo_isa.fcma;
1821
0
  #else
1822
0
    return false;
1823
0
  #endif
1824
0
}
1825
1826
0
static inline bool cpuinfo_has_arm_i8mm(void) {
1827
0
  #if CPUINFO_ARCH_ARM64
1828
0
    return cpuinfo_isa.i8mm;
1829
0
  #else
1830
0
    return false;
1831
0
  #endif
1832
0
}
1833
1834
0
static inline bool cpuinfo_has_arm_aes(void) {
1835
0
  #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1836
0
    return cpuinfo_isa.aes;
1837
0
  #else
1838
0
    return false;
1839
0
  #endif
1840
0
}
1841
1842
0
static inline bool cpuinfo_has_arm_sha1(void) {
1843
0
  #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1844
0
    return cpuinfo_isa.sha1;
1845
0
  #else
1846
0
    return false;
1847
0
  #endif
1848
0
}
1849
1850
0
static inline bool cpuinfo_has_arm_sha2(void) {
1851
0
  #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1852
0
    return cpuinfo_isa.sha2;
1853
0
  #else
1854
0
    return false;
1855
0
  #endif
1856
0
}
1857
1858
0
static inline bool cpuinfo_has_arm_pmull(void) {
1859
0
  #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1860
0
    return cpuinfo_isa.pmull;
1861
0
  #else
1862
0
    return false;
1863
0
  #endif
1864
0
}
1865
1866
0
static inline bool cpuinfo_has_arm_crc32(void) {
1867
0
  #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1868
0
    return cpuinfo_isa.crc32;
1869
0
  #else
1870
0
    return false;
1871
0
  #endif
1872
0
}
1873
1874
0
static inline bool cpuinfo_has_arm_sve(void) {
1875
0
  #if CPUINFO_ARCH_ARM64
1876
0
    return cpuinfo_isa.sve;
1877
0
  #else
1878
0
    return false;
1879
0
  #endif
1880
0
}
1881
1882
0
static inline bool cpuinfo_has_arm_sve_bf16(void) {
1883
0
  #if CPUINFO_ARCH_ARM64
1884
0
    return cpuinfo_isa.sve && cpuinfo_isa.bf16;
1885
0
  #else
1886
0
    return false;
1887
0
  #endif
1888
0
}
1889
1890
0
static inline bool cpuinfo_has_arm_sve2(void) {
1891
0
  #if CPUINFO_ARCH_ARM64
1892
0
    return cpuinfo_isa.sve2;
1893
0
  #else
1894
0
    return false;
1895
0
  #endif
1896
0
}
1897
1898
#if CPUINFO_ARCH_RISCV32 || CPUINFO_ARCH_RISCV64
1899
  /* This structure is not a part of stable API. Use cpuinfo_has_riscv_* functions instead. */
1900
  struct cpuinfo_riscv_isa {
1901
    /**
1902
     * Keep fields in line with the canonical order as defined by
1903
     * Section 27.11 Subset Naming Convention.
1904
     */
1905
    /* RV32I/64I/128I Base ISA. */
1906
    bool i;
1907
    #if CPUINFO_ARCH_RISCV32
1908
      /* RV32E Base ISA. */
1909
      bool e;
1910
    #endif
1911
    /* Integer Multiply/Divide Extension. */
1912
    bool m;
1913
    /* Atomic Extension. */
1914
    bool a;
1915
    /* Single-Precision Floating-Point Extension. */
1916
    bool f;
1917
    /* Double-Precision Floating-Point Extension. */
1918
    bool d;
1919
    /* Compressed Extension. */
1920
    bool c;
1921
    /* Vector Extension. */
1922
    bool v;
1923
  };
1924
1925
  extern struct cpuinfo_riscv_isa cpuinfo_isa;
1926
#endif
1927
1928
0
static inline bool cpuinfo_has_riscv_i(void) {
1929
0
  #if CPUINFO_ARCH_RISCV32 || CPUINFO_ARCH_RISCV64
1930
0
    return cpuinfo_isa.i;
1931
0
  #else
1932
0
    return false;
1933
0
  #endif
1934
0
}
1935
1936
0
static inline bool cpuinfo_has_riscv_e(void) {
1937
0
  #if CPUINFO_ARCH_RISCV32
1938
0
    return cpuinfo_isa.e;
1939
0
  #else
1940
0
    return false;
1941
0
  #endif
1942
0
}
1943
1944
0
static inline bool cpuinfo_has_riscv_m(void) {
1945
0
  #if CPUINFO_ARCH_RISCV32 || CPUINFO_ARCH_RISCV64
1946
0
    return cpuinfo_isa.m;
1947
0
  #else
1948
0
    return false;
1949
0
  #endif
1950
0
}
1951
1952
0
static inline bool cpuinfo_has_riscv_a(void) {
1953
0
  #if CPUINFO_ARCH_RISCV32 || CPUINFO_ARCH_RISCV64
1954
0
    return cpuinfo_isa.a;
1955
0
  #else
1956
0
    return false;
1957
0
  #endif
1958
0
}
1959
1960
0
static inline bool cpuinfo_has_riscv_f(void) {
1961
0
  #if CPUINFO_ARCH_RISCV32 || CPUINFO_ARCH_RISCV64
1962
0
    return cpuinfo_isa.f;
1963
0
  #else
1964
0
    return false;
1965
0
  #endif
1966
0
}
1967
1968
0
static inline bool cpuinfo_has_riscv_d(void) {
1969
0
  #if CPUINFO_ARCH_RISCV32 || CPUINFO_ARCH_RISCV64
1970
0
    return cpuinfo_isa.d;
1971
0
  #else
1972
0
    return false;
1973
0
  #endif
1974
0
}
1975
1976
0
static inline bool cpuinfo_has_riscv_g(void) {
1977
0
  // The 'G' extension is simply shorthand for 'IMAFD'.
1978
0
  return cpuinfo_has_riscv_i()
1979
0
    && cpuinfo_has_riscv_m()
1980
0
    && cpuinfo_has_riscv_a()
1981
0
    && cpuinfo_has_riscv_f()
1982
0
    && cpuinfo_has_riscv_d();
1983
0
}
1984
1985
0
static inline bool cpuinfo_has_riscv_c(void) {
1986
0
  #if CPUINFO_ARCH_RISCV32 || CPUINFO_ARCH_RISCV64
1987
0
    return cpuinfo_isa.c;
1988
0
  #else
1989
0
    return false;
1990
0
  #endif
1991
0
}
1992
1993
0
static inline bool cpuinfo_has_riscv_v(void) {
1994
0
  #if CPUINFO_ARCH_RISCV32 || CPUINFO_ARCH_RISCV64
1995
0
    return cpuinfo_isa.v;
1996
0
  #else
1997
0
    return false;
1998
0
  #endif
1999
0
}
2000
2001
const struct cpuinfo_processor* CPUINFO_ABI cpuinfo_get_processors(void);
2002
const struct cpuinfo_core* CPUINFO_ABI cpuinfo_get_cores(void);
2003
const struct cpuinfo_cluster* CPUINFO_ABI cpuinfo_get_clusters(void);
2004
const struct cpuinfo_package* CPUINFO_ABI cpuinfo_get_packages(void);
2005
const struct cpuinfo_uarch_info* CPUINFO_ABI cpuinfo_get_uarchs(void);
2006
const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l1i_caches(void);
2007
const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l1d_caches(void);
2008
const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l2_caches(void);
2009
const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l3_caches(void);
2010
const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l4_caches(void);
2011
2012
const struct cpuinfo_processor* CPUINFO_ABI cpuinfo_get_processor(uint32_t index);
2013
const struct cpuinfo_core* CPUINFO_ABI cpuinfo_get_core(uint32_t index);
2014
const struct cpuinfo_cluster* CPUINFO_ABI cpuinfo_get_cluster(uint32_t index);
2015
const struct cpuinfo_package* CPUINFO_ABI cpuinfo_get_package(uint32_t index);
2016
const struct cpuinfo_uarch_info* CPUINFO_ABI cpuinfo_get_uarch(uint32_t index);
2017
const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l1i_cache(uint32_t index);
2018
const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l1d_cache(uint32_t index);
2019
const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l2_cache(uint32_t index);
2020
const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l3_cache(uint32_t index);
2021
const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l4_cache(uint32_t index);
2022
2023
uint32_t CPUINFO_ABI cpuinfo_get_processors_count(void);
2024
uint32_t CPUINFO_ABI cpuinfo_get_cores_count(void);
2025
uint32_t CPUINFO_ABI cpuinfo_get_clusters_count(void);
2026
uint32_t CPUINFO_ABI cpuinfo_get_packages_count(void);
2027
uint32_t CPUINFO_ABI cpuinfo_get_uarchs_count(void);
2028
uint32_t CPUINFO_ABI cpuinfo_get_l1i_caches_count(void);
2029
uint32_t CPUINFO_ABI cpuinfo_get_l1d_caches_count(void);
2030
uint32_t CPUINFO_ABI cpuinfo_get_l2_caches_count(void);
2031
uint32_t CPUINFO_ABI cpuinfo_get_l3_caches_count(void);
2032
uint32_t CPUINFO_ABI cpuinfo_get_l4_caches_count(void);
2033
2034
/**
2035
 * Returns upper bound on cache size.
2036
 */
2037
uint32_t CPUINFO_ABI cpuinfo_get_max_cache_size(void);
2038
2039
/**
2040
 * Identify the logical processor that executes the current thread.
2041
 *
2042
 * There is no guarantee that the thread will stay on the same logical processor for any time.
2043
 * Callers should treat the result as only a hint, and be prepared to handle NULL return value.
2044
 */
2045
const struct cpuinfo_processor* CPUINFO_ABI cpuinfo_get_current_processor(void);
2046
2047
/**
2048
 * Identify the core that executes the current thread.
2049
 *
2050
 * There is no guarantee that the thread will stay on the same core for any time.
2051
 * Callers should treat the result as only a hint, and be prepared to handle NULL return value.
2052
 */
2053
const struct cpuinfo_core* CPUINFO_ABI cpuinfo_get_current_core(void);
2054
2055
/**
2056
 * Identify the microarchitecture index of the core that executes the current thread.
2057
 * If the system does not support such identification, the function returns 0.
2058
 *
2059
 * There is no guarantee that the thread will stay on the same type of core for any time.
2060
 * Callers should treat the result as only a hint.
2061
 */
2062
uint32_t CPUINFO_ABI cpuinfo_get_current_uarch_index(void);
2063
2064
/**
2065
 * Identify the microarchitecture index of the core that executes the current thread.
2066
 * If the system does not support such identification, the function returns the user-specified default value.
2067
 *
2068
 * There is no guarantee that the thread will stay on the same type of core for any time.
2069
 * Callers should treat the result as only a hint.
2070
 */
2071
uint32_t CPUINFO_ABI cpuinfo_get_current_uarch_index_with_default(uint32_t default_uarch_index);
2072
2073
#ifdef __cplusplus
2074
} /* extern "C" */
2075
#endif
2076
2077
#endif /* CPUINFO_H */