@revizly/sharp-libvips-dev 1.0.12 → 1.0.14

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