cpuinfo.h 47 KB

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