cpuinfo.h 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956
  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. /** AMD Zen 4 microarchitecture. */
  326. cpuinfo_uarch_zen4 = 0x0020010C,
  327. /** NSC Geode and AMD Geode GX and LX. */
  328. cpuinfo_uarch_geode = 0x00200200,
  329. /** AMD Bobcat mobile microarchitecture. */
  330. cpuinfo_uarch_bobcat = 0x00200201,
  331. /** AMD Jaguar mobile microarchitecture. */
  332. cpuinfo_uarch_jaguar = 0x00200202,
  333. /** AMD Puma mobile microarchitecture. */
  334. cpuinfo_uarch_puma = 0x00200203,
  335. /** ARM7 series. */
  336. cpuinfo_uarch_arm7 = 0x00300100,
  337. /** ARM9 series. */
  338. cpuinfo_uarch_arm9 = 0x00300101,
  339. /** ARM 1136, ARM 1156, ARM 1176, or ARM 11MPCore. */
  340. cpuinfo_uarch_arm11 = 0x00300102,
  341. /** ARM Cortex-A5. */
  342. cpuinfo_uarch_cortex_a5 = 0x00300205,
  343. /** ARM Cortex-A7. */
  344. cpuinfo_uarch_cortex_a7 = 0x00300207,
  345. /** ARM Cortex-A8. */
  346. cpuinfo_uarch_cortex_a8 = 0x00300208,
  347. /** ARM Cortex-A9. */
  348. cpuinfo_uarch_cortex_a9 = 0x00300209,
  349. /** ARM Cortex-A12. */
  350. cpuinfo_uarch_cortex_a12 = 0x00300212,
  351. /** ARM Cortex-A15. */
  352. cpuinfo_uarch_cortex_a15 = 0x00300215,
  353. /** ARM Cortex-A17. */
  354. cpuinfo_uarch_cortex_a17 = 0x00300217,
  355. /** ARM Cortex-A32. */
  356. cpuinfo_uarch_cortex_a32 = 0x00300332,
  357. /** ARM Cortex-A35. */
  358. cpuinfo_uarch_cortex_a35 = 0x00300335,
  359. /** ARM Cortex-A53. */
  360. cpuinfo_uarch_cortex_a53 = 0x00300353,
  361. /** ARM Cortex-A55 revision 0 (restricted dual-issue capabilities compared to revision 1+). */
  362. cpuinfo_uarch_cortex_a55r0 = 0x00300354,
  363. /** ARM Cortex-A55. */
  364. cpuinfo_uarch_cortex_a55 = 0x00300355,
  365. /** ARM Cortex-A57. */
  366. cpuinfo_uarch_cortex_a57 = 0x00300357,
  367. /** ARM Cortex-A65. */
  368. cpuinfo_uarch_cortex_a65 = 0x00300365,
  369. /** ARM Cortex-A72. */
  370. cpuinfo_uarch_cortex_a72 = 0x00300372,
  371. /** ARM Cortex-A73. */
  372. cpuinfo_uarch_cortex_a73 = 0x00300373,
  373. /** ARM Cortex-A75. */
  374. cpuinfo_uarch_cortex_a75 = 0x00300375,
  375. /** ARM Cortex-A76. */
  376. cpuinfo_uarch_cortex_a76 = 0x00300376,
  377. /** ARM Cortex-A77. */
  378. cpuinfo_uarch_cortex_a77 = 0x00300377,
  379. /** ARM Cortex-A78. */
  380. cpuinfo_uarch_cortex_a78 = 0x00300378,
  381. /** ARM Neoverse N1. */
  382. cpuinfo_uarch_neoverse_n1 = 0x00300400,
  383. /** ARM Neoverse E1. */
  384. cpuinfo_uarch_neoverse_e1 = 0x00300401,
  385. /** ARM Neoverse V1. */
  386. cpuinfo_uarch_neoverse_v1 = 0x00300402,
  387. /** ARM Neoverse N2. */
  388. cpuinfo_uarch_neoverse_n2 = 0x00300403,
  389. /** ARM Neoverse V2. */
  390. cpuinfo_uarch_neoverse_v2 = 0x00300404,
  391. /** ARM Cortex-X1. */
  392. cpuinfo_uarch_cortex_x1 = 0x00300501,
  393. /** ARM Cortex-X2. */
  394. cpuinfo_uarch_cortex_x2 = 0x00300502,
  395. /** ARM Cortex-X3. */
  396. cpuinfo_uarch_cortex_x3 = 0x00300503,
  397. /** ARM Cortex-A510. */
  398. cpuinfo_uarch_cortex_a510 = 0x00300551,
  399. /** ARM Cortex-A710. */
  400. cpuinfo_uarch_cortex_a710 = 0x00300571,
  401. /** ARM Cortex-A715. */
  402. cpuinfo_uarch_cortex_a715 = 0x00300572,
  403. /** Qualcomm Scorpion. */
  404. cpuinfo_uarch_scorpion = 0x00400100,
  405. /** Qualcomm Krait. */
  406. cpuinfo_uarch_krait = 0x00400101,
  407. /** Qualcomm Kryo. */
  408. cpuinfo_uarch_kryo = 0x00400102,
  409. /** Qualcomm Falkor. */
  410. cpuinfo_uarch_falkor = 0x00400103,
  411. /** Qualcomm Saphira. */
  412. cpuinfo_uarch_saphira = 0x00400104,
  413. /** Nvidia Denver. */
  414. cpuinfo_uarch_denver = 0x00500100,
  415. /** Nvidia Denver 2. */
  416. cpuinfo_uarch_denver2 = 0x00500101,
  417. /** Nvidia Carmel. */
  418. cpuinfo_uarch_carmel = 0x00500102,
  419. /** Samsung Exynos M1 (Exynos 8890 big cores). */
  420. cpuinfo_uarch_exynos_m1 = 0x00600100,
  421. /** Samsung Exynos M2 (Exynos 8895 big cores). */
  422. cpuinfo_uarch_exynos_m2 = 0x00600101,
  423. /** Samsung Exynos M3 (Exynos 9810 big cores). */
  424. cpuinfo_uarch_exynos_m3 = 0x00600102,
  425. /** Samsung Exynos M4 (Exynos 9820 big cores). */
  426. cpuinfo_uarch_exynos_m4 = 0x00600103,
  427. /** Samsung Exynos M5 (Exynos 9830 big cores). */
  428. cpuinfo_uarch_exynos_m5 = 0x00600104,
  429. /* Deprecated synonym for Cortex-A76 */
  430. cpuinfo_uarch_cortex_a76ae = 0x00300376,
  431. /* Deprecated names for Exynos. */
  432. cpuinfo_uarch_mongoose_m1 = 0x00600100,
  433. cpuinfo_uarch_mongoose_m2 = 0x00600101,
  434. cpuinfo_uarch_meerkat_m3 = 0x00600102,
  435. cpuinfo_uarch_meerkat_m4 = 0x00600103,
  436. /** Apple A6 and A6X processors. */
  437. cpuinfo_uarch_swift = 0x00700100,
  438. /** Apple A7 processor. */
  439. cpuinfo_uarch_cyclone = 0x00700101,
  440. /** Apple A8 and A8X processor. */
  441. cpuinfo_uarch_typhoon = 0x00700102,
  442. /** Apple A9 and A9X processor. */
  443. cpuinfo_uarch_twister = 0x00700103,
  444. /** Apple A10 and A10X processor. */
  445. cpuinfo_uarch_hurricane = 0x00700104,
  446. /** Apple A11 processor (big cores). */
  447. cpuinfo_uarch_monsoon = 0x00700105,
  448. /** Apple A11 processor (little cores). */
  449. cpuinfo_uarch_mistral = 0x00700106,
  450. /** Apple A12 processor (big cores). */
  451. cpuinfo_uarch_vortex = 0x00700107,
  452. /** Apple A12 processor (little cores). */
  453. cpuinfo_uarch_tempest = 0x00700108,
  454. /** Apple A13 processor (big cores). */
  455. cpuinfo_uarch_lightning = 0x00700109,
  456. /** Apple A13 processor (little cores). */
  457. cpuinfo_uarch_thunder = 0x0070010A,
  458. /** Apple A14 / M1 processor (big cores). */
  459. cpuinfo_uarch_firestorm = 0x0070010B,
  460. /** Apple A14 / M1 processor (little cores). */
  461. cpuinfo_uarch_icestorm = 0x0070010C,
  462. /** Apple A15 / M2 processor (big cores). */
  463. cpuinfo_uarch_avalanche = 0x0070010D,
  464. /** Apple A15 / M2 processor (little cores). */
  465. cpuinfo_uarch_blizzard = 0x0070010E,
  466. /** Cavium ThunderX. */
  467. cpuinfo_uarch_thunderx = 0x00800100,
  468. /** Cavium ThunderX2 (originally Broadcom Vulkan). */
  469. cpuinfo_uarch_thunderx2 = 0x00800200,
  470. /** Marvell PJ4. */
  471. cpuinfo_uarch_pj4 = 0x00900100,
  472. /** Broadcom Brahma B15. */
  473. cpuinfo_uarch_brahma_b15 = 0x00A00100,
  474. /** Broadcom Brahma B53. */
  475. cpuinfo_uarch_brahma_b53 = 0x00A00101,
  476. /** Applied Micro X-Gene. */
  477. cpuinfo_uarch_xgene = 0x00B00100,
  478. /* Hygon Dhyana (a modification of AMD Zen for Chinese market). */
  479. cpuinfo_uarch_dhyana = 0x01000100,
  480. /** HiSilicon TaiShan v110 (Huawei Kunpeng 920 series processors). */
  481. cpuinfo_uarch_taishan_v110 = 0x00C00100,
  482. };
  483. struct cpuinfo_processor {
  484. /** SMT (hyperthread) ID within a core */
  485. uint32_t smt_id;
  486. /** Core containing this logical processor */
  487. const struct cpuinfo_core* core;
  488. /** Cluster of cores containing this logical processor */
  489. const struct cpuinfo_cluster* cluster;
  490. /** Physical package containing this logical processor */
  491. const struct cpuinfo_package* package;
  492. #if defined(__linux__)
  493. /**
  494. * Linux-specific ID for the logical processor:
  495. * - Linux kernel exposes information about this logical processor in /sys/devices/system/cpu/cpu<linux_id>/
  496. * - Bit <linux_id> in the cpu_set_t identifies this logical processor
  497. */
  498. int linux_id;
  499. #endif
  500. #if defined(_WIN32) || defined(__CYGWIN__)
  501. /** Windows-specific ID for the group containing the logical processor. */
  502. uint16_t windows_group_id;
  503. /**
  504. * Windows-specific ID of the logical processor within its group:
  505. * - Bit <windows_processor_id> in the KAFFINITY mask identifies this logical processor within its group.
  506. */
  507. uint16_t windows_processor_id;
  508. #endif
  509. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  510. /** APIC ID (unique x86-specific ID of the logical processor) */
  511. uint32_t apic_id;
  512. #endif
  513. struct {
  514. /** Level 1 instruction cache */
  515. const struct cpuinfo_cache* l1i;
  516. /** Level 1 data cache */
  517. const struct cpuinfo_cache* l1d;
  518. /** Level 2 unified or data cache */
  519. const struct cpuinfo_cache* l2;
  520. /** Level 3 unified or data cache */
  521. const struct cpuinfo_cache* l3;
  522. /** Level 4 unified or data cache */
  523. const struct cpuinfo_cache* l4;
  524. } cache;
  525. };
  526. struct cpuinfo_core {
  527. /** Index of the first logical processor on this core. */
  528. uint32_t processor_start;
  529. /** Number of logical processors on this core */
  530. uint32_t processor_count;
  531. /** Core ID within a package */
  532. uint32_t core_id;
  533. /** Cluster containing this core */
  534. const struct cpuinfo_cluster* cluster;
  535. /** Physical package containing this core. */
  536. const struct cpuinfo_package* package;
  537. /** Vendor of the CPU microarchitecture for this core */
  538. enum cpuinfo_vendor vendor;
  539. /** CPU microarchitecture for this core */
  540. enum cpuinfo_uarch uarch;
  541. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  542. /** Value of CPUID leaf 1 EAX register for this core */
  543. uint32_t cpuid;
  544. #elif CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
  545. /** Value of Main ID Register (MIDR) for this core */
  546. uint32_t midr;
  547. #endif
  548. /** Clock rate (non-Turbo) of the core, in Hz */
  549. uint64_t frequency;
  550. };
  551. struct cpuinfo_cluster {
  552. /** Index of the first logical processor in the cluster */
  553. uint32_t processor_start;
  554. /** Number of logical processors in the cluster */
  555. uint32_t processor_count;
  556. /** Index of the first core in the cluster */
  557. uint32_t core_start;
  558. /** Number of cores on the cluster */
  559. uint32_t core_count;
  560. /** Cluster ID within a package */
  561. uint32_t cluster_id;
  562. /** Physical package containing the cluster */
  563. const struct cpuinfo_package* package;
  564. /** CPU microarchitecture vendor of the cores in the cluster */
  565. enum cpuinfo_vendor vendor;
  566. /** CPU microarchitecture of the cores in the cluster */
  567. enum cpuinfo_uarch uarch;
  568. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  569. /** Value of CPUID leaf 1 EAX register of the cores in the cluster */
  570. uint32_t cpuid;
  571. #elif CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
  572. /** Value of Main ID Register (MIDR) of the cores in the cluster */
  573. uint32_t midr;
  574. #endif
  575. /** Clock rate (non-Turbo) of the cores in the cluster, in Hz */
  576. uint64_t frequency;
  577. };
  578. #define CPUINFO_PACKAGE_NAME_MAX 48
  579. struct cpuinfo_package {
  580. /** SoC or processor chip model name */
  581. char name[CPUINFO_PACKAGE_NAME_MAX];
  582. /** Index of the first logical processor on this physical package */
  583. uint32_t processor_start;
  584. /** Number of logical processors on this physical package */
  585. uint32_t processor_count;
  586. /** Index of the first core on this physical package */
  587. uint32_t core_start;
  588. /** Number of cores on this physical package */
  589. uint32_t core_count;
  590. /** Index of the first cluster of cores on this physical package */
  591. uint32_t cluster_start;
  592. /** Number of clusters of cores on this physical package */
  593. uint32_t cluster_count;
  594. };
  595. struct cpuinfo_uarch_info {
  596. /** Type of CPU microarchitecture */
  597. enum cpuinfo_uarch uarch;
  598. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  599. /** Value of CPUID leaf 1 EAX register for the microarchitecture */
  600. uint32_t cpuid;
  601. #elif CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
  602. /** Value of Main ID Register (MIDR) for the microarchitecture */
  603. uint32_t midr;
  604. #endif
  605. /** Number of logical processors with the microarchitecture */
  606. uint32_t processor_count;
  607. /** Number of cores with the microarchitecture */
  608. uint32_t core_count;
  609. };
  610. #ifdef __cplusplus
  611. extern "C" {
  612. #endif
  613. bool CPUINFO_ABI cpuinfo_initialize(void);
  614. void CPUINFO_ABI cpuinfo_deinitialize(void);
  615. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  616. /* This structure is not a part of stable API. Use cpuinfo_has_x86_* functions instead. */
  617. struct cpuinfo_x86_isa {
  618. #if CPUINFO_ARCH_X86
  619. bool rdtsc;
  620. #endif
  621. bool rdtscp;
  622. bool rdpid;
  623. bool sysenter;
  624. #if CPUINFO_ARCH_X86
  625. bool syscall;
  626. #endif
  627. bool msr;
  628. bool clzero;
  629. bool clflush;
  630. bool clflushopt;
  631. bool mwait;
  632. bool mwaitx;
  633. #if CPUINFO_ARCH_X86
  634. bool emmx;
  635. #endif
  636. bool fxsave;
  637. bool xsave;
  638. #if CPUINFO_ARCH_X86
  639. bool fpu;
  640. bool mmx;
  641. bool mmx_plus;
  642. #endif
  643. bool three_d_now;
  644. bool three_d_now_plus;
  645. #if CPUINFO_ARCH_X86
  646. bool three_d_now_geode;
  647. #endif
  648. bool prefetch;
  649. bool prefetchw;
  650. bool prefetchwt1;
  651. #if CPUINFO_ARCH_X86
  652. bool daz;
  653. bool sse;
  654. bool sse2;
  655. #endif
  656. bool sse3;
  657. bool ssse3;
  658. bool sse4_1;
  659. bool sse4_2;
  660. bool sse4a;
  661. bool misaligned_sse;
  662. bool avx;
  663. bool avxvnni;
  664. bool fma3;
  665. bool fma4;
  666. bool xop;
  667. bool f16c;
  668. bool avx2;
  669. bool avx512f;
  670. bool avx512pf;
  671. bool avx512er;
  672. bool avx512cd;
  673. bool avx512dq;
  674. bool avx512bw;
  675. bool avx512vl;
  676. bool avx512ifma;
  677. bool avx512vbmi;
  678. bool avx512vbmi2;
  679. bool avx512bitalg;
  680. bool avx512vpopcntdq;
  681. bool avx512vnni;
  682. bool avx512bf16;
  683. bool avx512fp16;
  684. bool avx512vp2intersect;
  685. bool avx512_4vnniw;
  686. bool avx512_4fmaps;
  687. bool hle;
  688. bool rtm;
  689. bool xtest;
  690. bool mpx;
  691. #if CPUINFO_ARCH_X86
  692. bool cmov;
  693. bool cmpxchg8b;
  694. #endif
  695. bool cmpxchg16b;
  696. bool clwb;
  697. bool movbe;
  698. #if CPUINFO_ARCH_X86_64
  699. bool lahf_sahf;
  700. #endif
  701. bool fs_gs_base;
  702. bool lzcnt;
  703. bool popcnt;
  704. bool tbm;
  705. bool bmi;
  706. bool bmi2;
  707. bool adx;
  708. bool aes;
  709. bool vaes;
  710. bool pclmulqdq;
  711. bool vpclmulqdq;
  712. bool gfni;
  713. bool rdrand;
  714. bool rdseed;
  715. bool sha;
  716. bool rng;
  717. bool ace;
  718. bool ace2;
  719. bool phe;
  720. bool pmm;
  721. bool lwp;
  722. };
  723. extern struct cpuinfo_x86_isa cpuinfo_isa;
  724. #endif
  725. static inline bool cpuinfo_has_x86_rdtsc(void) {
  726. #if CPUINFO_ARCH_X86_64
  727. return true;
  728. #elif CPUINFO_ARCH_X86
  729. #if defined(__ANDROID__)
  730. return true;
  731. #else
  732. return cpuinfo_isa.rdtsc;
  733. #endif
  734. #else
  735. return false;
  736. #endif
  737. }
  738. static inline bool cpuinfo_has_x86_rdtscp(void) {
  739. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  740. return cpuinfo_isa.rdtscp;
  741. #else
  742. return false;
  743. #endif
  744. }
  745. static inline bool cpuinfo_has_x86_rdpid(void) {
  746. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  747. return cpuinfo_isa.rdpid;
  748. #else
  749. return false;
  750. #endif
  751. }
  752. static inline bool cpuinfo_has_x86_clzero(void) {
  753. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  754. return cpuinfo_isa.clzero;
  755. #else
  756. return false;
  757. #endif
  758. }
  759. static inline bool cpuinfo_has_x86_mwait(void) {
  760. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  761. return cpuinfo_isa.mwait;
  762. #else
  763. return false;
  764. #endif
  765. }
  766. static inline bool cpuinfo_has_x86_mwaitx(void) {
  767. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  768. return cpuinfo_isa.mwaitx;
  769. #else
  770. return false;
  771. #endif
  772. }
  773. static inline bool cpuinfo_has_x86_fxsave(void) {
  774. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  775. return cpuinfo_isa.fxsave;
  776. #else
  777. return false;
  778. #endif
  779. }
  780. static inline bool cpuinfo_has_x86_xsave(void) {
  781. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  782. return cpuinfo_isa.xsave;
  783. #else
  784. return false;
  785. #endif
  786. }
  787. static inline bool cpuinfo_has_x86_fpu(void) {
  788. #if CPUINFO_ARCH_X86_64
  789. return true;
  790. #elif CPUINFO_ARCH_X86
  791. #if defined(__ANDROID__)
  792. return true;
  793. #else
  794. return cpuinfo_isa.fpu;
  795. #endif
  796. #else
  797. return false;
  798. #endif
  799. }
  800. static inline bool cpuinfo_has_x86_mmx(void) {
  801. #if CPUINFO_ARCH_X86_64
  802. return true;
  803. #elif CPUINFO_ARCH_X86
  804. #if defined(__ANDROID__)
  805. return true;
  806. #else
  807. return cpuinfo_isa.mmx;
  808. #endif
  809. #else
  810. return false;
  811. #endif
  812. }
  813. static inline bool cpuinfo_has_x86_mmx_plus(void) {
  814. #if CPUINFO_ARCH_X86_64
  815. return true;
  816. #elif CPUINFO_ARCH_X86
  817. #if defined(__ANDROID__)
  818. return true;
  819. #else
  820. return cpuinfo_isa.mmx_plus;
  821. #endif
  822. #else
  823. return false;
  824. #endif
  825. }
  826. static inline bool cpuinfo_has_x86_3dnow(void) {
  827. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  828. return cpuinfo_isa.three_d_now;
  829. #else
  830. return false;
  831. #endif
  832. }
  833. static inline bool cpuinfo_has_x86_3dnow_plus(void) {
  834. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  835. return cpuinfo_isa.three_d_now_plus;
  836. #else
  837. return false;
  838. #endif
  839. }
  840. static inline bool cpuinfo_has_x86_3dnow_geode(void) {
  841. #if CPUINFO_ARCH_X86_64
  842. return false;
  843. #elif CPUINFO_ARCH_X86
  844. #if defined(__ANDROID__)
  845. return false;
  846. #else
  847. return cpuinfo_isa.three_d_now_geode;
  848. #endif
  849. #else
  850. return false;
  851. #endif
  852. }
  853. static inline bool cpuinfo_has_x86_prefetch(void) {
  854. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  855. return cpuinfo_isa.prefetch;
  856. #else
  857. return false;
  858. #endif
  859. }
  860. static inline bool cpuinfo_has_x86_prefetchw(void) {
  861. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  862. return cpuinfo_isa.prefetchw;
  863. #else
  864. return false;
  865. #endif
  866. }
  867. static inline bool cpuinfo_has_x86_prefetchwt1(void) {
  868. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  869. return cpuinfo_isa.prefetchwt1;
  870. #else
  871. return false;
  872. #endif
  873. }
  874. static inline bool cpuinfo_has_x86_daz(void) {
  875. #if CPUINFO_ARCH_X86_64
  876. return true;
  877. #elif CPUINFO_ARCH_X86
  878. #if defined(__ANDROID__)
  879. return true;
  880. #else
  881. return cpuinfo_isa.daz;
  882. #endif
  883. #else
  884. return false;
  885. #endif
  886. }
  887. static inline bool cpuinfo_has_x86_sse(void) {
  888. #if CPUINFO_ARCH_X86_64
  889. return true;
  890. #elif CPUINFO_ARCH_X86
  891. #if defined(__ANDROID__)
  892. return true;
  893. #else
  894. return cpuinfo_isa.sse;
  895. #endif
  896. #else
  897. return false;
  898. #endif
  899. }
  900. static inline bool cpuinfo_has_x86_sse2(void) {
  901. #if CPUINFO_ARCH_X86_64
  902. return true;
  903. #elif CPUINFO_ARCH_X86
  904. #if defined(__ANDROID__)
  905. return true;
  906. #else
  907. return cpuinfo_isa.sse2;
  908. #endif
  909. #else
  910. return false;
  911. #endif
  912. }
  913. static inline bool cpuinfo_has_x86_sse3(void) {
  914. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  915. #if defined(__ANDROID__)
  916. return true;
  917. #else
  918. return cpuinfo_isa.sse3;
  919. #endif
  920. #else
  921. return false;
  922. #endif
  923. }
  924. static inline bool cpuinfo_has_x86_ssse3(void) {
  925. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  926. #if defined(__ANDROID__)
  927. return true;
  928. #else
  929. return cpuinfo_isa.ssse3;
  930. #endif
  931. #else
  932. return false;
  933. #endif
  934. }
  935. static inline bool cpuinfo_has_x86_sse4_1(void) {
  936. #if CPUINFO_ARCH_X86_64
  937. #if defined(__ANDROID__)
  938. return true;
  939. #else
  940. return cpuinfo_isa.sse4_1;
  941. #endif
  942. #elif CPUINFO_ARCH_X86
  943. return cpuinfo_isa.sse4_1;
  944. #else
  945. return false;
  946. #endif
  947. }
  948. static inline bool cpuinfo_has_x86_sse4_2(void) {
  949. #if CPUINFO_ARCH_X86_64
  950. #if defined(__ANDROID__)
  951. return true;
  952. #else
  953. return cpuinfo_isa.sse4_2;
  954. #endif
  955. #elif CPUINFO_ARCH_X86
  956. return cpuinfo_isa.sse4_2;
  957. #else
  958. return false;
  959. #endif
  960. }
  961. static inline bool cpuinfo_has_x86_sse4a(void) {
  962. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  963. return cpuinfo_isa.sse4a;
  964. #else
  965. return false;
  966. #endif
  967. }
  968. static inline bool cpuinfo_has_x86_misaligned_sse(void) {
  969. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  970. return cpuinfo_isa.misaligned_sse;
  971. #else
  972. return false;
  973. #endif
  974. }
  975. static inline bool cpuinfo_has_x86_avx(void) {
  976. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  977. return cpuinfo_isa.avx;
  978. #else
  979. return false;
  980. #endif
  981. }
  982. static inline bool cpuinfo_has_x86_avxvnni(void) {
  983. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  984. return cpuinfo_isa.avxvnni;
  985. #else
  986. return false;
  987. #endif
  988. }
  989. static inline bool cpuinfo_has_x86_fma3(void) {
  990. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  991. return cpuinfo_isa.fma3;
  992. #else
  993. return false;
  994. #endif
  995. }
  996. static inline bool cpuinfo_has_x86_fma4(void) {
  997. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  998. return cpuinfo_isa.fma4;
  999. #else
  1000. return false;
  1001. #endif
  1002. }
  1003. static inline bool cpuinfo_has_x86_xop(void) {
  1004. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1005. return cpuinfo_isa.xop;
  1006. #else
  1007. return false;
  1008. #endif
  1009. }
  1010. static inline bool cpuinfo_has_x86_f16c(void) {
  1011. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1012. return cpuinfo_isa.f16c;
  1013. #else
  1014. return false;
  1015. #endif
  1016. }
  1017. static inline bool cpuinfo_has_x86_avx2(void) {
  1018. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1019. return cpuinfo_isa.avx2;
  1020. #else
  1021. return false;
  1022. #endif
  1023. }
  1024. static inline bool cpuinfo_has_x86_avx512f(void) {
  1025. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1026. return cpuinfo_isa.avx512f;
  1027. #else
  1028. return false;
  1029. #endif
  1030. }
  1031. static inline bool cpuinfo_has_x86_avx512pf(void) {
  1032. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1033. return cpuinfo_isa.avx512pf;
  1034. #else
  1035. return false;
  1036. #endif
  1037. }
  1038. static inline bool cpuinfo_has_x86_avx512er(void) {
  1039. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1040. return cpuinfo_isa.avx512er;
  1041. #else
  1042. return false;
  1043. #endif
  1044. }
  1045. static inline bool cpuinfo_has_x86_avx512cd(void) {
  1046. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1047. return cpuinfo_isa.avx512cd;
  1048. #else
  1049. return false;
  1050. #endif
  1051. }
  1052. static inline bool cpuinfo_has_x86_avx512dq(void) {
  1053. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1054. return cpuinfo_isa.avx512dq;
  1055. #else
  1056. return false;
  1057. #endif
  1058. }
  1059. static inline bool cpuinfo_has_x86_avx512bw(void) {
  1060. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1061. return cpuinfo_isa.avx512bw;
  1062. #else
  1063. return false;
  1064. #endif
  1065. }
  1066. static inline bool cpuinfo_has_x86_avx512vl(void) {
  1067. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1068. return cpuinfo_isa.avx512vl;
  1069. #else
  1070. return false;
  1071. #endif
  1072. }
  1073. static inline bool cpuinfo_has_x86_avx512ifma(void) {
  1074. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1075. return cpuinfo_isa.avx512ifma;
  1076. #else
  1077. return false;
  1078. #endif
  1079. }
  1080. static inline bool cpuinfo_has_x86_avx512vbmi(void) {
  1081. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1082. return cpuinfo_isa.avx512vbmi;
  1083. #else
  1084. return false;
  1085. #endif
  1086. }
  1087. static inline bool cpuinfo_has_x86_avx512vbmi2(void) {
  1088. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1089. return cpuinfo_isa.avx512vbmi2;
  1090. #else
  1091. return false;
  1092. #endif
  1093. }
  1094. static inline bool cpuinfo_has_x86_avx512bitalg(void) {
  1095. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1096. return cpuinfo_isa.avx512bitalg;
  1097. #else
  1098. return false;
  1099. #endif
  1100. }
  1101. static inline bool cpuinfo_has_x86_avx512vpopcntdq(void) {
  1102. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1103. return cpuinfo_isa.avx512vpopcntdq;
  1104. #else
  1105. return false;
  1106. #endif
  1107. }
  1108. static inline bool cpuinfo_has_x86_avx512vnni(void) {
  1109. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1110. return cpuinfo_isa.avx512vnni;
  1111. #else
  1112. return false;
  1113. #endif
  1114. }
  1115. static inline bool cpuinfo_has_x86_avx512bf16(void) {
  1116. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1117. return cpuinfo_isa.avx512bf16;
  1118. #else
  1119. return false;
  1120. #endif
  1121. }
  1122. static inline bool cpuinfo_has_x86_avx512fp16(void) {
  1123. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1124. return cpuinfo_isa.avx512fp16;
  1125. #else
  1126. return false;
  1127. #endif
  1128. }
  1129. static inline bool cpuinfo_has_x86_avx512vp2intersect(void) {
  1130. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1131. return cpuinfo_isa.avx512vp2intersect;
  1132. #else
  1133. return false;
  1134. #endif
  1135. }
  1136. static inline bool cpuinfo_has_x86_avx512_4vnniw(void) {
  1137. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1138. return cpuinfo_isa.avx512_4vnniw;
  1139. #else
  1140. return false;
  1141. #endif
  1142. }
  1143. static inline bool cpuinfo_has_x86_avx512_4fmaps(void) {
  1144. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1145. return cpuinfo_isa.avx512_4fmaps;
  1146. #else
  1147. return false;
  1148. #endif
  1149. }
  1150. static inline bool cpuinfo_has_x86_hle(void) {
  1151. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1152. return cpuinfo_isa.hle;
  1153. #else
  1154. return false;
  1155. #endif
  1156. }
  1157. static inline bool cpuinfo_has_x86_rtm(void) {
  1158. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1159. return cpuinfo_isa.rtm;
  1160. #else
  1161. return false;
  1162. #endif
  1163. }
  1164. static inline bool cpuinfo_has_x86_xtest(void) {
  1165. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1166. return cpuinfo_isa.xtest;
  1167. #else
  1168. return false;
  1169. #endif
  1170. }
  1171. static inline bool cpuinfo_has_x86_mpx(void) {
  1172. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1173. return cpuinfo_isa.mpx;
  1174. #else
  1175. return false;
  1176. #endif
  1177. }
  1178. static inline bool cpuinfo_has_x86_cmov(void) {
  1179. #if CPUINFO_ARCH_X86_64
  1180. return true;
  1181. #elif CPUINFO_ARCH_X86
  1182. return cpuinfo_isa.cmov;
  1183. #else
  1184. return false;
  1185. #endif
  1186. }
  1187. static inline bool cpuinfo_has_x86_cmpxchg8b(void) {
  1188. #if CPUINFO_ARCH_X86_64
  1189. return true;
  1190. #elif CPUINFO_ARCH_X86
  1191. return cpuinfo_isa.cmpxchg8b;
  1192. #else
  1193. return false;
  1194. #endif
  1195. }
  1196. static inline bool cpuinfo_has_x86_cmpxchg16b(void) {
  1197. #if CPUINFO_ARCH_X86_64
  1198. return cpuinfo_isa.cmpxchg16b;
  1199. #else
  1200. return false;
  1201. #endif
  1202. }
  1203. static inline bool cpuinfo_has_x86_clwb(void) {
  1204. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1205. return cpuinfo_isa.clwb;
  1206. #else
  1207. return false;
  1208. #endif
  1209. }
  1210. static inline bool cpuinfo_has_x86_movbe(void) {
  1211. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1212. return cpuinfo_isa.movbe;
  1213. #else
  1214. return false;
  1215. #endif
  1216. }
  1217. static inline bool cpuinfo_has_x86_lahf_sahf(void) {
  1218. #if CPUINFO_ARCH_X86
  1219. return true;
  1220. #elif CPUINFO_ARCH_X86_64
  1221. return cpuinfo_isa.lahf_sahf;
  1222. #else
  1223. return false;
  1224. #endif
  1225. }
  1226. static inline bool cpuinfo_has_x86_lzcnt(void) {
  1227. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1228. return cpuinfo_isa.lzcnt;
  1229. #else
  1230. return false;
  1231. #endif
  1232. }
  1233. static inline bool cpuinfo_has_x86_popcnt(void) {
  1234. #if CPUINFO_ARCH_X86_64
  1235. #if defined(__ANDROID__)
  1236. return true;
  1237. #else
  1238. return cpuinfo_isa.popcnt;
  1239. #endif
  1240. #elif CPUINFO_ARCH_X86
  1241. return cpuinfo_isa.popcnt;
  1242. #else
  1243. return false;
  1244. #endif
  1245. }
  1246. static inline bool cpuinfo_has_x86_tbm(void) {
  1247. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1248. return cpuinfo_isa.tbm;
  1249. #else
  1250. return false;
  1251. #endif
  1252. }
  1253. static inline bool cpuinfo_has_x86_bmi(void) {
  1254. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1255. return cpuinfo_isa.bmi;
  1256. #else
  1257. return false;
  1258. #endif
  1259. }
  1260. static inline bool cpuinfo_has_x86_bmi2(void) {
  1261. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1262. return cpuinfo_isa.bmi2;
  1263. #else
  1264. return false;
  1265. #endif
  1266. }
  1267. static inline bool cpuinfo_has_x86_adx(void) {
  1268. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1269. return cpuinfo_isa.adx;
  1270. #else
  1271. return false;
  1272. #endif
  1273. }
  1274. static inline bool cpuinfo_has_x86_aes(void) {
  1275. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1276. return cpuinfo_isa.aes;
  1277. #else
  1278. return false;
  1279. #endif
  1280. }
  1281. static inline bool cpuinfo_has_x86_vaes(void) {
  1282. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1283. return cpuinfo_isa.vaes;
  1284. #else
  1285. return false;
  1286. #endif
  1287. }
  1288. static inline bool cpuinfo_has_x86_pclmulqdq(void) {
  1289. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1290. return cpuinfo_isa.pclmulqdq;
  1291. #else
  1292. return false;
  1293. #endif
  1294. }
  1295. static inline bool cpuinfo_has_x86_vpclmulqdq(void) {
  1296. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1297. return cpuinfo_isa.vpclmulqdq;
  1298. #else
  1299. return false;
  1300. #endif
  1301. }
  1302. static inline bool cpuinfo_has_x86_gfni(void) {
  1303. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1304. return cpuinfo_isa.gfni;
  1305. #else
  1306. return false;
  1307. #endif
  1308. }
  1309. static inline bool cpuinfo_has_x86_rdrand(void) {
  1310. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1311. return cpuinfo_isa.rdrand;
  1312. #else
  1313. return false;
  1314. #endif
  1315. }
  1316. static inline bool cpuinfo_has_x86_rdseed(void) {
  1317. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1318. return cpuinfo_isa.rdseed;
  1319. #else
  1320. return false;
  1321. #endif
  1322. }
  1323. static inline bool cpuinfo_has_x86_sha(void) {
  1324. #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
  1325. return cpuinfo_isa.sha;
  1326. #else
  1327. return false;
  1328. #endif
  1329. }
  1330. #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
  1331. /* This structure is not a part of stable API. Use cpuinfo_has_arm_* functions instead. */
  1332. struct cpuinfo_arm_isa {
  1333. #if CPUINFO_ARCH_ARM
  1334. bool thumb;
  1335. bool thumb2;
  1336. bool thumbee;
  1337. bool jazelle;
  1338. bool armv5e;
  1339. bool armv6;
  1340. bool armv6k;
  1341. bool armv7;
  1342. bool armv7mp;
  1343. bool armv8;
  1344. bool idiv;
  1345. bool vfpv2;
  1346. bool vfpv3;
  1347. bool d32;
  1348. bool fp16;
  1349. bool fma;
  1350. bool wmmx;
  1351. bool wmmx2;
  1352. bool neon;
  1353. #endif
  1354. #if CPUINFO_ARCH_ARM64
  1355. bool atomics;
  1356. bool bf16;
  1357. bool sve;
  1358. bool sve2;
  1359. bool i8mm;
  1360. #endif
  1361. bool rdm;
  1362. bool fp16arith;
  1363. bool dot;
  1364. bool jscvt;
  1365. bool fcma;
  1366. bool fhm;
  1367. bool aes;
  1368. bool sha1;
  1369. bool sha2;
  1370. bool pmull;
  1371. bool crc32;
  1372. };
  1373. extern struct cpuinfo_arm_isa cpuinfo_isa;
  1374. #endif
  1375. static inline bool cpuinfo_has_arm_thumb(void) {
  1376. #if CPUINFO_ARCH_ARM
  1377. return cpuinfo_isa.thumb;
  1378. #else
  1379. return false;
  1380. #endif
  1381. }
  1382. static inline bool cpuinfo_has_arm_thumb2(void) {
  1383. #if CPUINFO_ARCH_ARM
  1384. return cpuinfo_isa.thumb2;
  1385. #else
  1386. return false;
  1387. #endif
  1388. }
  1389. static inline bool cpuinfo_has_arm_v5e(void) {
  1390. #if CPUINFO_ARCH_ARM
  1391. return cpuinfo_isa.armv5e;
  1392. #else
  1393. return false;
  1394. #endif
  1395. }
  1396. static inline bool cpuinfo_has_arm_v6(void) {
  1397. #if CPUINFO_ARCH_ARM
  1398. return cpuinfo_isa.armv6;
  1399. #else
  1400. return false;
  1401. #endif
  1402. }
  1403. static inline bool cpuinfo_has_arm_v6k(void) {
  1404. #if CPUINFO_ARCH_ARM
  1405. return cpuinfo_isa.armv6k;
  1406. #else
  1407. return false;
  1408. #endif
  1409. }
  1410. static inline bool cpuinfo_has_arm_v7(void) {
  1411. #if CPUINFO_ARCH_ARM
  1412. return cpuinfo_isa.armv7;
  1413. #else
  1414. return false;
  1415. #endif
  1416. }
  1417. static inline bool cpuinfo_has_arm_v7mp(void) {
  1418. #if CPUINFO_ARCH_ARM
  1419. return cpuinfo_isa.armv7mp;
  1420. #else
  1421. return false;
  1422. #endif
  1423. }
  1424. static inline bool cpuinfo_has_arm_v8(void) {
  1425. #if CPUINFO_ARCH_ARM64
  1426. return true;
  1427. #elif CPUINFO_ARCH_ARM
  1428. return cpuinfo_isa.armv8;
  1429. #else
  1430. return false;
  1431. #endif
  1432. }
  1433. static inline bool cpuinfo_has_arm_idiv(void) {
  1434. #if CPUINFO_ARCH_ARM64
  1435. return true;
  1436. #elif CPUINFO_ARCH_ARM
  1437. return cpuinfo_isa.idiv;
  1438. #else
  1439. return false;
  1440. #endif
  1441. }
  1442. static inline bool cpuinfo_has_arm_vfpv2(void) {
  1443. #if CPUINFO_ARCH_ARM
  1444. return cpuinfo_isa.vfpv2;
  1445. #else
  1446. return false;
  1447. #endif
  1448. }
  1449. static inline bool cpuinfo_has_arm_vfpv3(void) {
  1450. #if CPUINFO_ARCH_ARM64
  1451. return true;
  1452. #elif CPUINFO_ARCH_ARM
  1453. return cpuinfo_isa.vfpv3;
  1454. #else
  1455. return false;
  1456. #endif
  1457. }
  1458. static inline bool cpuinfo_has_arm_vfpv3_d32(void) {
  1459. #if CPUINFO_ARCH_ARM64
  1460. return true;
  1461. #elif CPUINFO_ARCH_ARM
  1462. return cpuinfo_isa.vfpv3 && cpuinfo_isa.d32;
  1463. #else
  1464. return false;
  1465. #endif
  1466. }
  1467. static inline bool cpuinfo_has_arm_vfpv3_fp16(void) {
  1468. #if CPUINFO_ARCH_ARM64
  1469. return true;
  1470. #elif CPUINFO_ARCH_ARM
  1471. return cpuinfo_isa.vfpv3 && cpuinfo_isa.fp16;
  1472. #else
  1473. return false;
  1474. #endif
  1475. }
  1476. static inline bool cpuinfo_has_arm_vfpv3_fp16_d32(void) {
  1477. #if CPUINFO_ARCH_ARM64
  1478. return true;
  1479. #elif CPUINFO_ARCH_ARM
  1480. return cpuinfo_isa.vfpv3 && cpuinfo_isa.fp16 && cpuinfo_isa.d32;
  1481. #else
  1482. return false;
  1483. #endif
  1484. }
  1485. static inline bool cpuinfo_has_arm_vfpv4(void) {
  1486. #if CPUINFO_ARCH_ARM64
  1487. return true;
  1488. #elif CPUINFO_ARCH_ARM
  1489. return cpuinfo_isa.vfpv3 && cpuinfo_isa.fma;
  1490. #else
  1491. return false;
  1492. #endif
  1493. }
  1494. static inline bool cpuinfo_has_arm_vfpv4_d32(void) {
  1495. #if CPUINFO_ARCH_ARM64
  1496. return true;
  1497. #elif CPUINFO_ARCH_ARM
  1498. return cpuinfo_isa.vfpv3 && cpuinfo_isa.fma && cpuinfo_isa.d32;
  1499. #else
  1500. return false;
  1501. #endif
  1502. }
  1503. static inline bool cpuinfo_has_arm_fp16_arith(void) {
  1504. #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
  1505. return cpuinfo_isa.fp16arith;
  1506. #else
  1507. return false;
  1508. #endif
  1509. }
  1510. static inline bool cpuinfo_has_arm_bf16(void) {
  1511. #if CPUINFO_ARCH_ARM64
  1512. return cpuinfo_isa.bf16;
  1513. #else
  1514. return false;
  1515. #endif
  1516. }
  1517. static inline bool cpuinfo_has_arm_wmmx(void) {
  1518. #if CPUINFO_ARCH_ARM
  1519. return cpuinfo_isa.wmmx;
  1520. #else
  1521. return false;
  1522. #endif
  1523. }
  1524. static inline bool cpuinfo_has_arm_wmmx2(void) {
  1525. #if CPUINFO_ARCH_ARM
  1526. return cpuinfo_isa.wmmx2;
  1527. #else
  1528. return false;
  1529. #endif
  1530. }
  1531. static inline bool cpuinfo_has_arm_neon(void) {
  1532. #if CPUINFO_ARCH_ARM64
  1533. return true;
  1534. #elif CPUINFO_ARCH_ARM
  1535. return cpuinfo_isa.neon;
  1536. #else
  1537. return false;
  1538. #endif
  1539. }
  1540. static inline bool cpuinfo_has_arm_neon_fp16(void) {
  1541. #if CPUINFO_ARCH_ARM64
  1542. return true;
  1543. #elif CPUINFO_ARCH_ARM
  1544. return cpuinfo_isa.neon && cpuinfo_isa.fp16;
  1545. #else
  1546. return false;
  1547. #endif
  1548. }
  1549. static inline bool cpuinfo_has_arm_neon_fma(void) {
  1550. #if CPUINFO_ARCH_ARM64
  1551. return true;
  1552. #elif CPUINFO_ARCH_ARM
  1553. return cpuinfo_isa.neon && cpuinfo_isa.fma;
  1554. #else
  1555. return false;
  1556. #endif
  1557. }
  1558. static inline bool cpuinfo_has_arm_neon_v8(void) {
  1559. #if CPUINFO_ARCH_ARM64
  1560. return true;
  1561. #elif CPUINFO_ARCH_ARM
  1562. return cpuinfo_isa.neon && cpuinfo_isa.armv8;
  1563. #else
  1564. return false;
  1565. #endif
  1566. }
  1567. static inline bool cpuinfo_has_arm_atomics(void) {
  1568. #if CPUINFO_ARCH_ARM64
  1569. return cpuinfo_isa.atomics;
  1570. #else
  1571. return false;
  1572. #endif
  1573. }
  1574. static inline bool cpuinfo_has_arm_neon_rdm(void) {
  1575. #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
  1576. return cpuinfo_isa.rdm;
  1577. #else
  1578. return false;
  1579. #endif
  1580. }
  1581. static inline bool cpuinfo_has_arm_neon_fp16_arith(void) {
  1582. #if CPUINFO_ARCH_ARM
  1583. return cpuinfo_isa.neon && cpuinfo_isa.fp16arith;
  1584. #elif CPUINFO_ARCH_ARM64
  1585. return cpuinfo_isa.fp16arith;
  1586. #else
  1587. return false;
  1588. #endif
  1589. }
  1590. static inline bool cpuinfo_has_arm_fhm(void) {
  1591. #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
  1592. return cpuinfo_isa.fhm;
  1593. #else
  1594. return false;
  1595. #endif
  1596. }
  1597. static inline bool cpuinfo_has_arm_neon_dot(void) {
  1598. #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
  1599. return cpuinfo_isa.dot;
  1600. #else
  1601. return false;
  1602. #endif
  1603. }
  1604. static inline bool cpuinfo_has_arm_neon_bf16(void) {
  1605. #if CPUINFO_ARCH_ARM64
  1606. return cpuinfo_isa.bf16;
  1607. #else
  1608. return false;
  1609. #endif
  1610. }
  1611. static inline bool cpuinfo_has_arm_jscvt(void) {
  1612. #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
  1613. return cpuinfo_isa.jscvt;
  1614. #else
  1615. return false;
  1616. #endif
  1617. }
  1618. static inline bool cpuinfo_has_arm_fcma(void) {
  1619. #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
  1620. return cpuinfo_isa.fcma;
  1621. #else
  1622. return false;
  1623. #endif
  1624. }
  1625. static inline bool cpuinfo_has_arm_i8mm(void) {
  1626. #if CPUINFO_ARCH_ARM64
  1627. return cpuinfo_isa.i8mm;
  1628. #else
  1629. return false;
  1630. #endif
  1631. }
  1632. static inline bool cpuinfo_has_arm_aes(void) {
  1633. #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
  1634. return cpuinfo_isa.aes;
  1635. #else
  1636. return false;
  1637. #endif
  1638. }
  1639. static inline bool cpuinfo_has_arm_sha1(void) {
  1640. #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
  1641. return cpuinfo_isa.sha1;
  1642. #else
  1643. return false;
  1644. #endif
  1645. }
  1646. static inline bool cpuinfo_has_arm_sha2(void) {
  1647. #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
  1648. return cpuinfo_isa.sha2;
  1649. #else
  1650. return false;
  1651. #endif
  1652. }
  1653. static inline bool cpuinfo_has_arm_pmull(void) {
  1654. #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
  1655. return cpuinfo_isa.pmull;
  1656. #else
  1657. return false;
  1658. #endif
  1659. }
  1660. static inline bool cpuinfo_has_arm_crc32(void) {
  1661. #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
  1662. return cpuinfo_isa.crc32;
  1663. #else
  1664. return false;
  1665. #endif
  1666. }
  1667. static inline bool cpuinfo_has_arm_sve(void) {
  1668. #if CPUINFO_ARCH_ARM64
  1669. return cpuinfo_isa.sve;
  1670. #else
  1671. return false;
  1672. #endif
  1673. }
  1674. static inline bool cpuinfo_has_arm_sve_bf16(void) {
  1675. #if CPUINFO_ARCH_ARM64
  1676. return cpuinfo_isa.sve && cpuinfo_isa.bf16;
  1677. #else
  1678. return false;
  1679. #endif
  1680. }
  1681. static inline bool cpuinfo_has_arm_sve2(void) {
  1682. #if CPUINFO_ARCH_ARM64
  1683. return cpuinfo_isa.sve2;
  1684. #else
  1685. return false;
  1686. #endif
  1687. }
  1688. const struct cpuinfo_processor* CPUINFO_ABI cpuinfo_get_processors(void);
  1689. const struct cpuinfo_core* CPUINFO_ABI cpuinfo_get_cores(void);
  1690. const struct cpuinfo_cluster* CPUINFO_ABI cpuinfo_get_clusters(void);
  1691. const struct cpuinfo_package* CPUINFO_ABI cpuinfo_get_packages(void);
  1692. const struct cpuinfo_uarch_info* CPUINFO_ABI cpuinfo_get_uarchs(void);
  1693. const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l1i_caches(void);
  1694. const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l1d_caches(void);
  1695. const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l2_caches(void);
  1696. const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l3_caches(void);
  1697. const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l4_caches(void);
  1698. const struct cpuinfo_processor* CPUINFO_ABI cpuinfo_get_processor(uint32_t index);
  1699. const struct cpuinfo_core* CPUINFO_ABI cpuinfo_get_core(uint32_t index);
  1700. const struct cpuinfo_cluster* CPUINFO_ABI cpuinfo_get_cluster(uint32_t index);
  1701. const struct cpuinfo_package* CPUINFO_ABI cpuinfo_get_package(uint32_t index);
  1702. const struct cpuinfo_uarch_info* CPUINFO_ABI cpuinfo_get_uarch(uint32_t index);
  1703. const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l1i_cache(uint32_t index);
  1704. const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l1d_cache(uint32_t index);
  1705. const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l2_cache(uint32_t index);
  1706. const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l3_cache(uint32_t index);
  1707. const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l4_cache(uint32_t index);
  1708. uint32_t CPUINFO_ABI cpuinfo_get_processors_count(void);
  1709. uint32_t CPUINFO_ABI cpuinfo_get_cores_count(void);
  1710. uint32_t CPUINFO_ABI cpuinfo_get_clusters_count(void);
  1711. uint32_t CPUINFO_ABI cpuinfo_get_packages_count(void);
  1712. uint32_t CPUINFO_ABI cpuinfo_get_uarchs_count(void);
  1713. uint32_t CPUINFO_ABI cpuinfo_get_l1i_caches_count(void);
  1714. uint32_t CPUINFO_ABI cpuinfo_get_l1d_caches_count(void);
  1715. uint32_t CPUINFO_ABI cpuinfo_get_l2_caches_count(void);
  1716. uint32_t CPUINFO_ABI cpuinfo_get_l3_caches_count(void);
  1717. uint32_t CPUINFO_ABI cpuinfo_get_l4_caches_count(void);
  1718. /**
  1719. * Returns upper bound on cache size.
  1720. */
  1721. uint32_t CPUINFO_ABI cpuinfo_get_max_cache_size(void);
  1722. /**
  1723. * Identify the logical processor that executes the current thread.
  1724. *
  1725. * There is no guarantee that the thread will stay on the same logical processor for any time.
  1726. * Callers should treat the result as only a hint, and be prepared to handle NULL return value.
  1727. */
  1728. const struct cpuinfo_processor* CPUINFO_ABI cpuinfo_get_current_processor(void);
  1729. /**
  1730. * Identify the core that executes the current thread.
  1731. *
  1732. * There is no guarantee that the thread will stay on the same core for any time.
  1733. * Callers should treat the result as only a hint, and be prepared to handle NULL return value.
  1734. */
  1735. const struct cpuinfo_core* CPUINFO_ABI cpuinfo_get_current_core(void);
  1736. /**
  1737. * Identify the microarchitecture index of the core that executes the current thread.
  1738. * If the system does not support such identification, the function returns 0.
  1739. *
  1740. * There is no guarantee that the thread will stay on the same type of core for any time.
  1741. * Callers should treat the result as only a hint.
  1742. */
  1743. uint32_t CPUINFO_ABI cpuinfo_get_current_uarch_index(void);
  1744. /**
  1745. * Identify the microarchitecture index of the core that executes the current thread.
  1746. * If the system does not support such identification, the function returns the user-specified default value.
  1747. *
  1748. * There is no guarantee that the thread will stay on the same type of core for any time.
  1749. * Callers should treat the result as only a hint.
  1750. */
  1751. uint32_t CPUINFO_ABI cpuinfo_get_current_uarch_index_with_default(uint32_t default_uarch_index);
  1752. #ifdef __cplusplus
  1753. } /* extern "C" */
  1754. #endif
  1755. #endif /* CPUINFO_H */