cpuinfo.h 54 KB

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