You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

cpuid_x86.c 61 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585
  1. //{
  2. /*********************************************************************/
  3. /* Copyright 2009, 2010 The University of Texas at Austin. */
  4. /* All rights reserved. */
  5. /* */
  6. /* Redistribution and use in source and binary forms, with or */
  7. /* without modification, are permitted provided that the following */
  8. /* conditions are met: */
  9. /* */
  10. /* 1. Redistributions of source code must retain the above */
  11. /* copyright notice, this list of conditions and the following */
  12. /* disclaimer. */
  13. /* */
  14. /* 2. Redistributions in binary form must reproduce the above */
  15. /* copyright notice, this list of conditions and the following */
  16. /* disclaimer in the documentation and/or other materials */
  17. /* provided with the distribution. */
  18. /* */
  19. /* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */
  20. /* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */
  21. /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
  22. /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
  23. /* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */
  24. /* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */
  25. /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
  26. /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */
  27. /* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */
  28. /* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
  29. /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
  30. /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */
  31. /* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
  32. /* POSSIBILITY OF SUCH DAMAGE. */
  33. /* */
  34. /* The views and conclusions contained in the software and */
  35. /* documentation are those of the authors and should not be */
  36. /* interpreted as representing official policies, either expressed */
  37. /* or implied, of The University of Texas at Austin. */
  38. /*********************************************************************/
  39. #include <stdio.h>
  40. #include <string.h>
  41. #include "cpuid.h"
  42. #if defined(_MSC_VER) && !defined(__clang__)
  43. #define C_INLINE __inline
  44. #else
  45. #define C_INLINE inline
  46. #endif
  47. /*
  48. #ifdef NO_AVX
  49. #define CPUTYPE_HASWELL CPUTYPE_NEHALEM
  50. #define CORE_HASWELL CORE_NEHALEM
  51. #define CPUTYPE_SKYLAKEX CPUTYPE_NEHALEM
  52. #define CORE_SKYLAKEX CORE_NEHALEM
  53. #define CPUTYPE_SANDYBRIDGE CPUTYPE_NEHALEM
  54. #define CORE_SANDYBRIDGE CORE_NEHALEM
  55. #define CPUTYPE_BULLDOZER CPUTYPE_BARCELONA
  56. #define CORE_BULLDOZER CORE_BARCELONA
  57. #define CPUTYPE_PILEDRIVER CPUTYPE_BARCELONA
  58. #define CORE_PILEDRIVER CORE_BARCELONA
  59. #endif
  60. */
  61. #if defined(_MSC_VER) && !defined(__clang__)
  62. void cpuid(int op, int *eax, int *ebx, int *ecx, int *edx)
  63. {
  64. int cpuInfo[4] = {-1};
  65. __cpuid(cpuInfo, op);
  66. *eax = cpuInfo[0];
  67. *ebx = cpuInfo[1];
  68. *ecx = cpuInfo[2];
  69. *edx = cpuInfo[3];
  70. }
  71. void cpuid_count(int op, int count, int *eax, int *ebx, int *ecx, int *edx)
  72. {
  73. int cpuInfo[4] = {-1};
  74. __cpuidex(cpuInfo, op, count);
  75. *eax = cpuInfo[0];
  76. *ebx = cpuInfo[1];
  77. *ecx = cpuInfo[2];
  78. *edx = cpuInfo[3];
  79. }
  80. #else
  81. #ifndef CPUIDEMU
  82. #if defined(__APPLE__) && defined(__i386__)
  83. void cpuid(int op, int *eax, int *ebx, int *ecx, int *edx);
  84. void cpuid_count(int op, int count, int *eax, int *ebx, int *ecx, int *edx);
  85. #else
  86. static C_INLINE void cpuid(int op, int *eax, int *ebx, int *ecx, int *edx){
  87. #if defined(__i386__) && defined(__PIC__)
  88. __asm__ __volatile__
  89. ("mov %%ebx, %%edi;"
  90. "cpuid;"
  91. "xchgl %%ebx, %%edi;"
  92. : "=a" (*eax), "=D" (*ebx), "=c" (*ecx), "=d" (*edx) : "a" (op), "c" (0) : "cc");
  93. #else
  94. __asm__ __volatile__
  95. ("cpuid": "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) : "a" (op) , "c" (0) : "cc");
  96. #endif
  97. }
  98. static C_INLINE void cpuid_count(int op, int count ,int *eax, int *ebx, int *ecx, int *edx){
  99. #if defined(__i386__) && defined(__PIC__)
  100. __asm__ __volatile__
  101. ("mov %%ebx, %%edi;"
  102. "cpuid;"
  103. "xchgl %%ebx, %%edi;"
  104. : "=a" (*eax), "=D" (*ebx), "=c" (*ecx), "=d" (*edx) : "0" (op), "2" (count) : "cc");
  105. #else
  106. __asm__ __volatile__
  107. ("cpuid": "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) : "0" (op), "2" (count) : "cc");
  108. #endif
  109. }
  110. #endif
  111. #else
  112. typedef struct {
  113. unsigned int id, a, b, c, d;
  114. } idlist_t;
  115. typedef struct {
  116. char *vendor;
  117. char *name;
  118. int start, stop;
  119. } vendor_t;
  120. extern idlist_t idlist[];
  121. extern vendor_t vendor[];
  122. static int cv = VENDOR;
  123. void cpuid(unsigned int op, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx){
  124. static int current = 0;
  125. int start = vendor[cv].start;
  126. int stop = vendor[cv].stop;
  127. int count = stop - start;
  128. if ((current < start) || (current > stop)) current = start;
  129. while ((count > 0) && (idlist[current].id != op)) {
  130. current ++;
  131. if (current > stop) current = start;
  132. count --;
  133. }
  134. *eax = idlist[current].a;
  135. *ebx = idlist[current].b;
  136. *ecx = idlist[current].c;
  137. *edx = idlist[current].d;
  138. }
  139. void cpuid_count (unsigned int op, unsigned int count, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx) {
  140. return cpuid (op, eax, ebx, ecx, edx);
  141. }
  142. #endif
  143. #endif // _MSC_VER
  144. static C_INLINE int have_cpuid(void){
  145. int eax, ebx, ecx, edx;
  146. cpuid(0, &eax, &ebx, &ecx, &edx);
  147. return eax;
  148. }
  149. static C_INLINE int have_excpuid(void){
  150. int eax, ebx, ecx, edx;
  151. cpuid(0x80000000, &eax, &ebx, &ecx, &edx);
  152. return eax & 0xffff;
  153. }
  154. #ifndef NO_AVX
  155. static C_INLINE void xgetbv(int op, int * eax, int * edx){
  156. //Use binary code for xgetbv
  157. #if defined(_MSC_VER) && !defined(__clang__)
  158. *eax = __xgetbv(op);
  159. #else
  160. __asm__ __volatile__
  161. (".byte 0x0f, 0x01, 0xd0": "=a" (*eax), "=d" (*edx) : "c" (op) : "cc");
  162. #endif
  163. }
  164. #endif
  165. int support_avx(){
  166. #ifndef NO_AVX
  167. int eax, ebx, ecx, edx;
  168. int ret=0;
  169. cpuid(1, &eax, &ebx, &ecx, &edx);
  170. if ((ecx & (1 << 28)) != 0 && (ecx & (1 << 27)) != 0 && (ecx & (1 << 26)) != 0){
  171. xgetbv(0, &eax, &edx);
  172. if((eax & 6) == 6){
  173. ret=1; //OS supports saving xmm and ymm registers (6 = (1<<1) | (1<<2))
  174. }
  175. }
  176. return ret;
  177. #else
  178. return 0;
  179. #endif
  180. }
  181. int support_avx2(){
  182. #ifndef NO_AVX2
  183. int eax, ebx, ecx=0, edx;
  184. int ret=0;
  185. if (!support_avx())
  186. return 0;
  187. cpuid(7, &eax, &ebx, &ecx, &edx);
  188. if((ebx & (1<<5)) != 0)
  189. ret=1; //CPU supports AVX2
  190. return ret;
  191. #else
  192. return 0;
  193. #endif
  194. }
  195. int support_avx512(){
  196. #if !defined(NO_AVX) && !defined(NO_AVX512)
  197. int eax, ebx, ecx, edx;
  198. int ret=0;
  199. if (!support_avx())
  200. return 0;
  201. cpuid(7, &eax, &ebx, &ecx, &edx);
  202. if((ebx & (1<<5)) == 0){
  203. ret=0; //cpu does not have avx2 flag
  204. }
  205. if((ebx & (1<<31)) != 0){ //AVX512VL flag
  206. xgetbv(0, &eax, &edx);
  207. if((eax & 0xe0) == 0xe0)
  208. ret=1; //OS supports saving zmm registers
  209. }
  210. return ret;
  211. #else
  212. return 0;
  213. #endif
  214. }
  215. int support_avx512_bf16(){
  216. #if !defined(NO_AVX) && !defined(NO_AVX512)
  217. int eax, ebx, ecx, edx;
  218. int ret=0;
  219. if (!support_avx512())
  220. return 0;
  221. cpuid_count(7, 1, &eax, &ebx, &ecx, &edx);
  222. if((eax & 32) == 32){
  223. ret=1; // CPUID.7.1:EAX[bit 5] indicates whether avx512_bf16 supported or not
  224. }
  225. return ret;
  226. #else
  227. return 0;
  228. #endif
  229. }
  230. #define BIT_AMX_TILE 0x01000000
  231. #define BIT_AMX_BF16 0x00400000
  232. #define BIT_AMX_ENBD 0x00060000
  233. int support_amx_bf16() {
  234. #if !defined(NO_AVX) && !defined(NO_AVX512)
  235. int eax, ebx, ecx, edx;
  236. int ret=0;
  237. if (!support_avx512())
  238. return 0;
  239. // CPUID.7.0:EDX indicates AMX support
  240. cpuid_count(7, 0, &eax, &ebx, &ecx, &edx);
  241. if ((edx & BIT_AMX_TILE) && (edx & BIT_AMX_BF16)) {
  242. // CPUID.D.0:EAX[17:18] indicates AMX enabled
  243. cpuid_count(0xd, 0, &eax, &ebx, &ecx, &edx);
  244. if ((eax & BIT_AMX_ENBD) == BIT_AMX_ENBD)
  245. ret = 1;
  246. }
  247. return ret;
  248. #else
  249. return 0;
  250. #endif
  251. }
  252. int get_vendor(void){
  253. int eax, ebx, ecx, edx;
  254. char vendor[13];
  255. cpuid(0, &eax, &ebx, &ecx, &edx);
  256. *(int *)(&vendor[0]) = ebx;
  257. *(int *)(&vendor[4]) = edx;
  258. *(int *)(&vendor[8]) = ecx;
  259. vendor[12] = (char)0;
  260. if (!strcmp(vendor, "GenuineIntel")) return VENDOR_INTEL;
  261. if (!strcmp(vendor, " UMC UMC UMC")) return VENDOR_UMC;
  262. if (!strcmp(vendor, "AuthenticAMD")) return VENDOR_AMD;
  263. if (!strcmp(vendor, "CyrixInstead")) return VENDOR_CYRIX;
  264. if (!strcmp(vendor, "NexGenDriven")) return VENDOR_NEXGEN;
  265. if (!strcmp(vendor, "CentaurHauls")) return VENDOR_CENTAUR;
  266. if (!strcmp(vendor, " Shanghai ")) return VENDOR_ZHAOXIN;
  267. if (!strcmp(vendor, "RiseRiseRise")) return VENDOR_RISE;
  268. if (!strcmp(vendor, " SiS SiS SiS")) return VENDOR_SIS;
  269. if (!strcmp(vendor, "GenuineTMx86")) return VENDOR_TRANSMETA;
  270. if (!strcmp(vendor, "Geode by NSC")) return VENDOR_NSC;
  271. if (!strcmp(vendor, "HygonGenuine")) return VENDOR_HYGON;
  272. if ((eax == 0) || ((eax & 0x500) != 0)) return VENDOR_INTEL;
  273. return VENDOR_UNKNOWN;
  274. }
  275. int get_cputype(int gettype){
  276. int eax, ebx, ecx, edx;
  277. int extend_family, family;
  278. int extend_model, model;
  279. int type, stepping;
  280. int feature = 0;
  281. cpuid(1, &eax, &ebx, &ecx, &edx);
  282. switch (gettype) {
  283. case GET_EXFAMILY :
  284. return BITMASK(eax, 20, 0xff);
  285. case GET_EXMODEL :
  286. return BITMASK(eax, 16, 0x0f);
  287. case GET_TYPE :
  288. return BITMASK(eax, 12, 0x03);
  289. case GET_FAMILY :
  290. return BITMASK(eax, 8, 0x0f);
  291. case GET_MODEL :
  292. return BITMASK(eax, 4, 0x0f);
  293. case GET_APICID :
  294. return BITMASK(ebx, 24, 0x0f);
  295. case GET_LCOUNT :
  296. return BITMASK(ebx, 16, 0x0f);
  297. case GET_CHUNKS :
  298. return BITMASK(ebx, 8, 0x0f);
  299. case GET_STEPPING :
  300. return BITMASK(eax, 0, 0x0f);
  301. case GET_BLANDID :
  302. return BITMASK(ebx, 0, 0xff);
  303. case GET_NUMSHARE :
  304. if (have_cpuid() < 4) return 0;
  305. cpuid(4, &eax, &ebx, &ecx, &edx);
  306. return BITMASK(eax, 14, 0xfff);
  307. case GET_NUMCORES :
  308. if (have_cpuid() < 4) return 0;
  309. cpuid(4, &eax, &ebx, &ecx, &edx);
  310. return BITMASK(eax, 26, 0x3f);
  311. case GET_FEATURE :
  312. if ((edx & (1 << 3)) != 0) feature |= HAVE_PSE;
  313. if ((edx & (1 << 15)) != 0) feature |= HAVE_CMOV;
  314. if ((edx & (1 << 19)) != 0) feature |= HAVE_CFLUSH;
  315. if ((edx & (1 << 23)) != 0) feature |= HAVE_MMX;
  316. if ((edx & (1 << 25)) != 0) feature |= HAVE_SSE;
  317. if ((edx & (1 << 26)) != 0) feature |= HAVE_SSE2;
  318. if ((edx & (1 << 27)) != 0) {
  319. if (BITMASK(ebx, 16, 0x0f) > 0) feature |= HAVE_HIT;
  320. }
  321. if ((ecx & (1 << 0)) != 0) feature |= HAVE_SSE3;
  322. if ((ecx & (1 << 9)) != 0) feature |= HAVE_SSSE3;
  323. if ((ecx & (1 << 19)) != 0) feature |= HAVE_SSE4_1;
  324. if ((ecx & (1 << 20)) != 0) feature |= HAVE_SSE4_2;
  325. #ifndef NO_AVX
  326. if (support_avx()) feature |= HAVE_AVX;
  327. if (support_avx2()) feature |= HAVE_AVX2;
  328. if (support_avx512()) feature |= HAVE_AVX512VL;
  329. if (support_avx512_bf16()) feature |= HAVE_AVX512BF16;
  330. if (support_amx_bf16()) feature |= HAVE_AMXBF16;
  331. if ((ecx & (1 << 12)) != 0) feature |= HAVE_FMA3;
  332. #endif
  333. if (have_excpuid() >= 0x01) {
  334. cpuid(0x80000001, &eax, &ebx, &ecx, &edx);
  335. if ((ecx & (1 << 6)) != 0) feature |= HAVE_SSE4A;
  336. if ((ecx & (1 << 7)) != 0) feature |= HAVE_MISALIGNSSE;
  337. #ifndef NO_AVX
  338. if ((ecx & (1 << 16)) != 0) feature |= HAVE_FMA4;
  339. #endif
  340. if ((edx & (1 << 30)) != 0) feature |= HAVE_3DNOWEX;
  341. if ((edx & (1 << 31)) != 0) feature |= HAVE_3DNOW;
  342. }
  343. if (have_excpuid() >= 0x1a) {
  344. cpuid(0x8000001a, &eax, &ebx, &ecx, &edx);
  345. if ((eax & (1 << 0)) != 0) feature |= HAVE_128BITFPU;
  346. if ((eax & (1 << 1)) != 0) feature |= HAVE_FASTMOVU;
  347. }
  348. }
  349. return feature;
  350. }
  351. int get_cacheinfo(int type, cache_info_t *cacheinfo){
  352. int eax, ebx, ecx, edx, cpuid_level;
  353. int info[15];
  354. int i;
  355. cache_info_t LC1, LD1, L2, L3,
  356. ITB, DTB, LITB, LDTB,
  357. L2ITB, L2DTB, L2LITB, L2LDTB;
  358. LC1.size = 0; LC1.associative = 0; LC1.linesize = 0; LC1.shared = 0;
  359. LD1.size = 0; LD1.associative = 0; LD1.linesize = 0; LD1.shared = 0;
  360. L2.size = 0; L2.associative = 0; L2.linesize = 0; L2.shared = 0;
  361. L3.size = 0; L3.associative = 0; L3.linesize = 0; L3.shared = 0;
  362. ITB.size = 0; ITB.associative = 0; ITB.linesize = 0; ITB.shared = 0;
  363. DTB.size = 0; DTB.associative = 0; DTB.linesize = 0; DTB.shared = 0;
  364. LITB.size = 0; LITB.associative = 0; LITB.linesize = 0; LITB.shared = 0;
  365. LDTB.size = 0; LDTB.associative = 0; LDTB.linesize = 0; LDTB.shared = 0;
  366. L2ITB.size = 0; L2ITB.associative = 0; L2ITB.linesize = 0; L2ITB.shared = 0;
  367. L2DTB.size = 0; L2DTB.associative = 0; L2DTB.linesize = 0; L2DTB.shared = 0;
  368. L2LITB.size = 0; L2LITB.associative = 0; L2LITB.linesize = 0; L2LITB.shared = 0;
  369. L2LDTB.size = 0; L2LDTB.associative = 0; L2LDTB.linesize = 0; L2LDTB.shared = 0;
  370. cpuid(0, &cpuid_level, &ebx, &ecx, &edx);
  371. if (cpuid_level > 1) {
  372. int numcalls =0 ;
  373. cpuid(2, &eax, &ebx, &ecx, &edx);
  374. numcalls = BITMASK(eax, 0, 0xff); //FIXME some systems may require repeated calls to read all entries
  375. info[ 0] = BITMASK(eax, 8, 0xff);
  376. info[ 1] = BITMASK(eax, 16, 0xff);
  377. info[ 2] = BITMASK(eax, 24, 0xff);
  378. info[ 3] = BITMASK(ebx, 0, 0xff);
  379. info[ 4] = BITMASK(ebx, 8, 0xff);
  380. info[ 5] = BITMASK(ebx, 16, 0xff);
  381. info[ 6] = BITMASK(ebx, 24, 0xff);
  382. info[ 7] = BITMASK(ecx, 0, 0xff);
  383. info[ 8] = BITMASK(ecx, 8, 0xff);
  384. info[ 9] = BITMASK(ecx, 16, 0xff);
  385. info[10] = BITMASK(ecx, 24, 0xff);
  386. info[11] = BITMASK(edx, 0, 0xff);
  387. info[12] = BITMASK(edx, 8, 0xff);
  388. info[13] = BITMASK(edx, 16, 0xff);
  389. info[14] = BITMASK(edx, 24, 0xff);
  390. for (i = 0; i < 15; i++){
  391. switch (info[i]){
  392. /* This table is from http://www.sandpile.org/ia32/cpuid.htm */
  393. case 0x01 :
  394. ITB.size = 4;
  395. ITB.associative = 4;
  396. ITB.linesize = 32;
  397. break;
  398. case 0x02 :
  399. LITB.size = 4096;
  400. LITB.associative = 0;
  401. LITB.linesize = 2;
  402. break;
  403. case 0x03 :
  404. DTB.size = 4;
  405. DTB.associative = 4;
  406. DTB.linesize = 64;
  407. break;
  408. case 0x04 :
  409. LDTB.size = 4096;
  410. LDTB.associative = 4;
  411. LDTB.linesize = 8;
  412. break;
  413. case 0x05 :
  414. LDTB.size = 4096;
  415. LDTB.associative = 4;
  416. LDTB.linesize = 32;
  417. break;
  418. case 0x06 :
  419. LC1.size = 8;
  420. LC1.associative = 4;
  421. LC1.linesize = 32;
  422. break;
  423. case 0x08 :
  424. LC1.size = 16;
  425. LC1.associative = 4;
  426. LC1.linesize = 32;
  427. break;
  428. case 0x09 :
  429. LC1.size = 32;
  430. LC1.associative = 4;
  431. LC1.linesize = 64;
  432. break;
  433. case 0x0a :
  434. LD1.size = 8;
  435. LD1.associative = 2;
  436. LD1.linesize = 32;
  437. break;
  438. case 0x0c :
  439. LD1.size = 16;
  440. LD1.associative = 4;
  441. LD1.linesize = 32;
  442. break;
  443. case 0x0d :
  444. LD1.size = 16;
  445. LD1.associative = 4;
  446. LD1.linesize = 64;
  447. break;
  448. case 0x0e :
  449. LD1.size = 24;
  450. LD1.associative = 6;
  451. LD1.linesize = 64;
  452. break;
  453. case 0x10 :
  454. LD1.size = 16;
  455. LD1.associative = 4;
  456. LD1.linesize = 32;
  457. break;
  458. case 0x15 :
  459. LC1.size = 16;
  460. LC1.associative = 4;
  461. LC1.linesize = 32;
  462. break;
  463. case 0x1a :
  464. L2.size = 96;
  465. L2.associative = 6;
  466. L2.linesize = 64;
  467. break;
  468. case 0x21 :
  469. L2.size = 256;
  470. L2.associative = 8;
  471. L2.linesize = 64;
  472. break;
  473. case 0x22 :
  474. L3.size = 512;
  475. L3.associative = 4;
  476. L3.linesize = 64;
  477. break;
  478. case 0x23 :
  479. L3.size = 1024;
  480. L3.associative = 8;
  481. L3.linesize = 64;
  482. break;
  483. case 0x25 :
  484. L3.size = 2048;
  485. L3.associative = 8;
  486. L3.linesize = 64;
  487. break;
  488. case 0x29 :
  489. L3.size = 4096;
  490. L3.associative = 8;
  491. L3.linesize = 64;
  492. break;
  493. case 0x2c :
  494. LD1.size = 32;
  495. LD1.associative = 8;
  496. LD1.linesize = 64;
  497. break;
  498. case 0x30 :
  499. LC1.size = 32;
  500. LC1.associative = 8;
  501. LC1.linesize = 64;
  502. break;
  503. case 0x39 :
  504. L2.size = 128;
  505. L2.associative = 4;
  506. L2.linesize = 64;
  507. break;
  508. case 0x3a :
  509. L2.size = 192;
  510. L2.associative = 6;
  511. L2.linesize = 64;
  512. break;
  513. case 0x3b :
  514. L2.size = 128;
  515. L2.associative = 2;
  516. L2.linesize = 64;
  517. break;
  518. case 0x3c :
  519. L2.size = 256;
  520. L2.associative = 4;
  521. L2.linesize = 64;
  522. break;
  523. case 0x3d :
  524. L2.size = 384;
  525. L2.associative = 6;
  526. L2.linesize = 64;
  527. break;
  528. case 0x3e :
  529. L2.size = 512;
  530. L2.associative = 4;
  531. L2.linesize = 64;
  532. break;
  533. case 0x41 :
  534. L2.size = 128;
  535. L2.associative = 4;
  536. L2.linesize = 32;
  537. break;
  538. case 0x42 :
  539. L2.size = 256;
  540. L2.associative = 4;
  541. L2.linesize = 32;
  542. break;
  543. case 0x43 :
  544. L2.size = 512;
  545. L2.associative = 4;
  546. L2.linesize = 32;
  547. break;
  548. case 0x44 :
  549. L2.size = 1024;
  550. L2.associative = 4;
  551. L2.linesize = 32;
  552. break;
  553. case 0x45 :
  554. L2.size = 2048;
  555. L2.associative = 4;
  556. L2.linesize = 32;
  557. break;
  558. case 0x46 :
  559. L3.size = 4096;
  560. L3.associative = 4;
  561. L3.linesize = 64;
  562. break;
  563. case 0x47 :
  564. L3.size = 8192;
  565. L3.associative = 8;
  566. L3.linesize = 64;
  567. break;
  568. case 0x48 :
  569. L2.size = 3184;
  570. L2.associative = 12;
  571. L2.linesize = 64;
  572. break;
  573. case 0x49 :
  574. if ((get_cputype(GET_FAMILY) == 0x0f) && (get_cputype(GET_MODEL) == 0x06)) {
  575. L3.size = 4096;
  576. L3.associative = 16;
  577. L3.linesize = 64;
  578. } else {
  579. L2.size = 4096;
  580. L2.associative = 16;
  581. L2.linesize = 64;
  582. }
  583. break;
  584. case 0x4a :
  585. L3.size = 6144;
  586. L3.associative = 12;
  587. L3.linesize = 64;
  588. break;
  589. case 0x4b :
  590. L3.size = 8192;
  591. L3.associative = 16;
  592. L3.linesize = 64;
  593. break;
  594. case 0x4c :
  595. L3.size = 12280;
  596. L3.associative = 12;
  597. L3.linesize = 64;
  598. break;
  599. case 0x4d :
  600. L3.size = 16384;
  601. L3.associative = 16;
  602. L3.linesize = 64;
  603. break;
  604. case 0x4e :
  605. L2.size = 6144;
  606. L2.associative = 24;
  607. L2.linesize = 64;
  608. break;
  609. case 0x4f :
  610. ITB.size = 4;
  611. ITB.associative = 0;
  612. ITB.linesize = 32;
  613. break;
  614. case 0x50 :
  615. ITB.size = 4;
  616. ITB.associative = 0;
  617. ITB.linesize = 64;
  618. LITB.size = 4096;
  619. LITB.associative = 0;
  620. LITB.linesize = 64;
  621. LITB.shared = 1;
  622. break;
  623. case 0x51 :
  624. ITB.size = 4;
  625. ITB.associative = 0;
  626. ITB.linesize = 128;
  627. LITB.size = 4096;
  628. LITB.associative = 0;
  629. LITB.linesize = 128;
  630. LITB.shared = 1;
  631. break;
  632. case 0x52 :
  633. ITB.size = 4;
  634. ITB.associative = 0;
  635. ITB.linesize = 256;
  636. LITB.size = 4096;
  637. LITB.associative = 0;
  638. LITB.linesize = 256;
  639. LITB.shared = 1;
  640. break;
  641. case 0x55 :
  642. LITB.size = 4096;
  643. LITB.associative = 0;
  644. LITB.linesize = 7;
  645. LITB.shared = 1;
  646. break;
  647. case 0x56 :
  648. LDTB.size = 4096;
  649. LDTB.associative = 4;
  650. LDTB.linesize = 16;
  651. break;
  652. case 0x57 :
  653. LDTB.size = 4096;
  654. LDTB.associative = 4;
  655. LDTB.linesize = 16;
  656. break;
  657. case 0x5b :
  658. DTB.size = 4;
  659. DTB.associative = 0;
  660. DTB.linesize = 64;
  661. LDTB.size = 4096;
  662. LDTB.associative = 0;
  663. LDTB.linesize = 64;
  664. LDTB.shared = 1;
  665. break;
  666. case 0x5c :
  667. DTB.size = 4;
  668. DTB.associative = 0;
  669. DTB.linesize = 128;
  670. LDTB.size = 4096;
  671. LDTB.associative = 0;
  672. LDTB.linesize = 128;
  673. LDTB.shared = 1;
  674. break;
  675. case 0x5d :
  676. DTB.size = 4;
  677. DTB.associative = 0;
  678. DTB.linesize = 256;
  679. LDTB.size = 4096;
  680. LDTB.associative = 0;
  681. LDTB.linesize = 256;
  682. LDTB.shared = 1;
  683. break;
  684. case 0x60 :
  685. LD1.size = 16;
  686. LD1.associative = 8;
  687. LD1.linesize = 64;
  688. break;
  689. case 0x63 :
  690. DTB.size = 2048;
  691. DTB.associative = 4;
  692. DTB.linesize = 32;
  693. LDTB.size = 4096;
  694. LDTB.associative= 4;
  695. LDTB.linesize = 32;
  696. break;
  697. case 0x66 :
  698. LD1.size = 8;
  699. LD1.associative = 4;
  700. LD1.linesize = 64;
  701. break;
  702. case 0x67 :
  703. LD1.size = 16;
  704. LD1.associative = 4;
  705. LD1.linesize = 64;
  706. break;
  707. case 0x68 :
  708. LD1.size = 32;
  709. LD1.associative = 4;
  710. LD1.linesize = 64;
  711. break;
  712. case 0x70 :
  713. LC1.size = 12;
  714. LC1.associative = 8;
  715. break;
  716. case 0x71 :
  717. LC1.size = 16;
  718. LC1.associative = 8;
  719. break;
  720. case 0x72 :
  721. LC1.size = 32;
  722. LC1.associative = 8;
  723. break;
  724. case 0x73 :
  725. LC1.size = 64;
  726. LC1.associative = 8;
  727. break;
  728. case 0x76 :
  729. ITB.size = 2048;
  730. ITB.associative = 0;
  731. ITB.linesize = 8;
  732. LITB.size = 4096;
  733. LITB.associative= 0;
  734. LITB.linesize = 8;
  735. break;
  736. case 0x77 :
  737. LC1.size = 16;
  738. LC1.associative = 4;
  739. LC1.linesize = 64;
  740. break;
  741. case 0x78 :
  742. L2.size = 1024;
  743. L2.associative = 4;
  744. L2.linesize = 64;
  745. break;
  746. case 0x79 :
  747. L2.size = 128;
  748. L2.associative = 8;
  749. L2.linesize = 64;
  750. break;
  751. case 0x7a :
  752. L2.size = 256;
  753. L2.associative = 8;
  754. L2.linesize = 64;
  755. break;
  756. case 0x7b :
  757. L2.size = 512;
  758. L2.associative = 8;
  759. L2.linesize = 64;
  760. break;
  761. case 0x7c :
  762. L2.size = 1024;
  763. L2.associative = 8;
  764. L2.linesize = 64;
  765. break;
  766. case 0x7d :
  767. L2.size = 2048;
  768. L2.associative = 8;
  769. L2.linesize = 64;
  770. break;
  771. case 0x7e :
  772. L2.size = 256;
  773. L2.associative = 8;
  774. L2.linesize = 128;
  775. break;
  776. case 0x7f :
  777. L2.size = 512;
  778. L2.associative = 2;
  779. L2.linesize = 64;
  780. break;
  781. case 0x81 :
  782. L2.size = 128;
  783. L2.associative = 8;
  784. L2.linesize = 32;
  785. break;
  786. case 0x82 :
  787. L2.size = 256;
  788. L2.associative = 8;
  789. L2.linesize = 32;
  790. break;
  791. case 0x83 :
  792. L2.size = 512;
  793. L2.associative = 8;
  794. L2.linesize = 32;
  795. break;
  796. case 0x84 :
  797. L2.size = 1024;
  798. L2.associative = 8;
  799. L2.linesize = 32;
  800. break;
  801. case 0x85 :
  802. L2.size = 2048;
  803. L2.associative = 8;
  804. L2.linesize = 32;
  805. break;
  806. case 0x86 :
  807. L2.size = 512;
  808. L2.associative = 4;
  809. L2.linesize = 64;
  810. break;
  811. case 0x87 :
  812. L2.size = 1024;
  813. L2.associative = 8;
  814. L2.linesize = 64;
  815. break;
  816. case 0x88 :
  817. L3.size = 2048;
  818. L3.associative = 4;
  819. L3.linesize = 64;
  820. break;
  821. case 0x89 :
  822. L3.size = 4096;
  823. L3.associative = 4;
  824. L3.linesize = 64;
  825. break;
  826. case 0x8a :
  827. L3.size = 8192;
  828. L3.associative = 4;
  829. L3.linesize = 64;
  830. break;
  831. case 0x8d :
  832. L3.size = 3096;
  833. L3.associative = 12;
  834. L3.linesize = 128;
  835. break;
  836. case 0x90 :
  837. ITB.size = 4;
  838. ITB.associative = 0;
  839. ITB.linesize = 64;
  840. break;
  841. case 0x96 :
  842. DTB.size = 4;
  843. DTB.associative = 0;
  844. DTB.linesize = 32;
  845. break;
  846. case 0x9b :
  847. L2DTB.size = 4;
  848. L2DTB.associative = 0;
  849. L2DTB.linesize = 96;
  850. break;
  851. case 0xb0 :
  852. ITB.size = 4;
  853. ITB.associative = 4;
  854. ITB.linesize = 128;
  855. break;
  856. case 0xb1 :
  857. LITB.size = 4096;
  858. LITB.associative = 4;
  859. LITB.linesize = 4;
  860. break;
  861. case 0xb2 :
  862. ITB.size = 4;
  863. ITB.associative = 4;
  864. ITB.linesize = 64;
  865. break;
  866. case 0xb3 :
  867. DTB.size = 4;
  868. DTB.associative = 4;
  869. DTB.linesize = 128;
  870. break;
  871. case 0xb4 :
  872. DTB.size = 4;
  873. DTB.associative = 4;
  874. DTB.linesize = 256;
  875. break;
  876. case 0xba :
  877. DTB.size = 4;
  878. DTB.associative = 4;
  879. DTB.linesize = 64;
  880. break;
  881. case 0xd0 :
  882. L3.size = 512;
  883. L3.associative = 4;
  884. L3.linesize = 64;
  885. break;
  886. case 0xd1 :
  887. L3.size = 1024;
  888. L3.associative = 4;
  889. L3.linesize = 64;
  890. break;
  891. case 0xd2 :
  892. L3.size = 2048;
  893. L3.associative = 4;
  894. L3.linesize = 64;
  895. break;
  896. case 0xd6 :
  897. L3.size = 1024;
  898. L3.associative = 8;
  899. L3.linesize = 64;
  900. break;
  901. case 0xd7 :
  902. L3.size = 2048;
  903. L3.associative = 8;
  904. L3.linesize = 64;
  905. break;
  906. case 0xd8 :
  907. L3.size = 4096;
  908. L3.associative = 8;
  909. L3.linesize = 64;
  910. break;
  911. case 0xdc :
  912. L3.size = 2048;
  913. L3.associative = 12;
  914. L3.linesize = 64;
  915. break;
  916. case 0xdd :
  917. L3.size = 4096;
  918. L3.associative = 12;
  919. L3.linesize = 64;
  920. break;
  921. case 0xde :
  922. L3.size = 8192;
  923. L3.associative = 12;
  924. L3.linesize = 64;
  925. break;
  926. case 0xe2 :
  927. L3.size = 2048;
  928. L3.associative = 16;
  929. L3.linesize = 64;
  930. break;
  931. case 0xe3 :
  932. L3.size = 4096;
  933. L3.associative = 16;
  934. L3.linesize = 64;
  935. break;
  936. case 0xe4 :
  937. L3.size = 8192;
  938. L3.associative = 16;
  939. L3.linesize = 64;
  940. break;
  941. }
  942. }
  943. }
  944. if (get_vendor() == VENDOR_INTEL) {
  945. if(LD1.size<=0 || LC1.size<=0){
  946. //If we didn't detect L1 correctly before,
  947. int count;
  948. for (count=0;count <4;count++) {
  949. cpuid_count(4, count, &eax, &ebx, &ecx, &edx);
  950. switch (eax &0x1f) {
  951. case 0:
  952. continue;
  953. case 1:
  954. case 3:
  955. {
  956. switch ((eax >>5) &0x07)
  957. {
  958. case 1:
  959. {
  960. // fprintf(stderr,"L1 data cache...\n");
  961. int sets = ecx+1;
  962. int lines = (ebx & 0x0fff) +1;
  963. ebx>>=12;
  964. int part = (ebx&0x03ff)+1;
  965. ebx >>=10;
  966. int assoc = (ebx&0x03ff)+1;
  967. LD1.size = (assoc*part*lines*sets)/1024;
  968. LD1.associative = assoc;
  969. LD1.linesize= lines;
  970. break;
  971. }
  972. default:
  973. break;
  974. }
  975. break;
  976. }
  977. case 2:
  978. {
  979. switch ((eax >>5) &0x07)
  980. {
  981. case 1:
  982. {
  983. // fprintf(stderr,"L1 instruction cache...\n");
  984. int sets = ecx+1;
  985. int lines = (ebx & 0x0fff) +1;
  986. ebx>>=12;
  987. int part = (ebx&0x03ff)+1;
  988. ebx >>=10;
  989. int assoc = (ebx&0x03ff)+1;
  990. LC1.size = (assoc*part*lines*sets)/1024;
  991. LC1.associative = assoc;
  992. LC1.linesize= lines;
  993. break;
  994. }
  995. default:
  996. break;
  997. }
  998. break;
  999. }
  1000. default:
  1001. break;
  1002. }
  1003. }
  1004. }
  1005. cpuid(0x80000000, &cpuid_level, &ebx, &ecx, &edx);
  1006. if (cpuid_level >= 0x80000006) {
  1007. if(L2.size<=0){
  1008. //If we didn't detect L2 correctly before,
  1009. cpuid(0x80000006, &eax, &ebx, &ecx, &edx);
  1010. L2.size = BITMASK(ecx, 16, 0xffff);
  1011. L2.associative = BITMASK(ecx, 12, 0x0f);
  1012. switch (L2.associative){
  1013. case 0x06:
  1014. L2.associative = 8;
  1015. break;
  1016. case 0x08:
  1017. L2.associative = 16;
  1018. break;
  1019. }
  1020. L2.linesize = BITMASK(ecx, 0, 0xff);
  1021. }
  1022. }
  1023. }
  1024. if ((get_vendor() == VENDOR_AMD) ||
  1025. (get_vendor() == VENDOR_HYGON) ||
  1026. (get_vendor() == VENDOR_CENTAUR) ||
  1027. (get_vendor() == VENDOR_ZHAOXIN)) {
  1028. cpuid(0x80000005, &eax, &ebx, &ecx, &edx);
  1029. LDTB.size = 4096;
  1030. LDTB.associative = BITMASK(eax, 24, 0xff);
  1031. if (LDTB.associative == 0xff) LDTB.associative = 0;
  1032. LDTB.linesize = BITMASK(eax, 16, 0xff);
  1033. LITB.size = 4096;
  1034. LITB.associative = BITMASK(eax, 8, 0xff);
  1035. if (LITB.associative == 0xff) LITB.associative = 0;
  1036. LITB.linesize = BITMASK(eax, 0, 0xff);
  1037. DTB.size = 4;
  1038. DTB.associative = BITMASK(ebx, 24, 0xff);
  1039. if (DTB.associative == 0xff) DTB.associative = 0;
  1040. DTB.linesize = BITMASK(ebx, 16, 0xff);
  1041. ITB.size = 4;
  1042. ITB.associative = BITMASK(ebx, 8, 0xff);
  1043. if (ITB.associative == 0xff) ITB.associative = 0;
  1044. ITB.linesize = BITMASK(ebx, 0, 0xff);
  1045. LD1.size = BITMASK(ecx, 24, 0xff);
  1046. LD1.associative = BITMASK(ecx, 16, 0xff);
  1047. if (LD1.associative == 0xff) LD1.associative = 0;
  1048. LD1.linesize = BITMASK(ecx, 0, 0xff);
  1049. LC1.size = BITMASK(ecx, 24, 0xff);
  1050. LC1.associative = BITMASK(ecx, 16, 0xff);
  1051. if (LC1.associative == 0xff) LC1.associative = 0;
  1052. LC1.linesize = BITMASK(ecx, 0, 0xff);
  1053. cpuid(0x80000006, &eax, &ebx, &ecx, &edx);
  1054. L2LDTB.size = 4096;
  1055. L2LDTB.associative = BITMASK(eax, 24, 0xff);
  1056. if (L2LDTB.associative == 0xff) L2LDTB.associative = 0;
  1057. L2LDTB.linesize = BITMASK(eax, 16, 0xff);
  1058. L2LITB.size = 4096;
  1059. L2LITB.associative = BITMASK(eax, 8, 0xff);
  1060. if (L2LITB.associative == 0xff) L2LITB.associative = 0;
  1061. L2LITB.linesize = BITMASK(eax, 0, 0xff);
  1062. L2DTB.size = 4;
  1063. L2DTB.associative = BITMASK(ebx, 24, 0xff);
  1064. if (L2DTB.associative == 0xff) L2DTB.associative = 0;
  1065. L2DTB.linesize = BITMASK(ebx, 16, 0xff);
  1066. L2ITB.size = 4;
  1067. L2ITB.associative = BITMASK(ebx, 8, 0xff);
  1068. if (L2ITB.associative == 0xff) L2ITB.associative = 0;
  1069. L2ITB.linesize = BITMASK(ebx, 0, 0xff);
  1070. if(L2.size <= 0){
  1071. //If we didn't detect L2 correctly before,
  1072. L2.size = BITMASK(ecx, 16, 0xffff);
  1073. L2.associative = BITMASK(ecx, 12, 0xf);
  1074. switch (L2.associative){
  1075. case 0x06:
  1076. L2.associative = 8;
  1077. break;
  1078. case 0x08:
  1079. L2.associative = 16;
  1080. break;
  1081. }
  1082. if (L2.associative == 0xff) L2.associative = 0;
  1083. L2.linesize = BITMASK(ecx, 0, 0xff);
  1084. }
  1085. L3.size = BITMASK(edx, 18, 0x3fff) * 512;
  1086. L3.associative = BITMASK(edx, 12, 0xf);
  1087. if (L3.associative == 0xff) L2.associative = 0;
  1088. L3.linesize = BITMASK(edx, 0, 0xff);
  1089. }
  1090. switch (type) {
  1091. case CACHE_INFO_L1_I :
  1092. *cacheinfo = LC1;
  1093. break;
  1094. case CACHE_INFO_L1_D :
  1095. *cacheinfo = LD1;
  1096. break;
  1097. case CACHE_INFO_L2 :
  1098. *cacheinfo = L2;
  1099. break;
  1100. case CACHE_INFO_L3 :
  1101. *cacheinfo = L3;
  1102. break;
  1103. case CACHE_INFO_L1_DTB :
  1104. *cacheinfo = DTB;
  1105. break;
  1106. case CACHE_INFO_L1_ITB :
  1107. *cacheinfo = ITB;
  1108. break;
  1109. case CACHE_INFO_L1_LDTB :
  1110. *cacheinfo = LDTB;
  1111. break;
  1112. case CACHE_INFO_L1_LITB :
  1113. *cacheinfo = LITB;
  1114. break;
  1115. case CACHE_INFO_L2_DTB :
  1116. *cacheinfo = L2DTB;
  1117. break;
  1118. case CACHE_INFO_L2_ITB :
  1119. *cacheinfo = L2ITB;
  1120. break;
  1121. case CACHE_INFO_L2_LDTB :
  1122. *cacheinfo = L2LDTB;
  1123. break;
  1124. case CACHE_INFO_L2_LITB :
  1125. *cacheinfo = L2LITB;
  1126. break;
  1127. }
  1128. return 0;
  1129. }
  1130. int get_cpuname(void){
  1131. int family, exfamily, model, vendor, exmodel, stepping;
  1132. if (!have_cpuid()) return CPUTYPE_80386;
  1133. family = get_cputype(GET_FAMILY);
  1134. exfamily = get_cputype(GET_EXFAMILY);
  1135. model = get_cputype(GET_MODEL);
  1136. exmodel = get_cputype(GET_EXMODEL);
  1137. stepping = get_cputype(GET_STEPPING);
  1138. vendor = get_vendor();
  1139. if (vendor == VENDOR_INTEL){
  1140. switch (family) {
  1141. case 0x4:
  1142. return CPUTYPE_80486;
  1143. case 0x5:
  1144. return CPUTYPE_PENTIUM;
  1145. case 0x6:
  1146. switch (exmodel) {
  1147. case 0:
  1148. switch (model) {
  1149. case 1:
  1150. case 3:
  1151. case 5:
  1152. case 6:
  1153. #if defined(__x86_64__) || defined(__amd64__)
  1154. return CPUTYPE_CORE2;
  1155. #else
  1156. return CPUTYPE_PENTIUM2;
  1157. #endif
  1158. case 7:
  1159. case 8:
  1160. case 10:
  1161. case 11:
  1162. return CPUTYPE_PENTIUM3;
  1163. case 9:
  1164. case 13:
  1165. case 14:
  1166. return CPUTYPE_PENTIUMM;
  1167. case 15:
  1168. return CPUTYPE_CORE2;
  1169. }
  1170. break;
  1171. case 1: // family 6 exmodel 1
  1172. switch (model) {
  1173. case 6:
  1174. return CPUTYPE_CORE2;
  1175. case 7:
  1176. return CPUTYPE_PENRYN;
  1177. case 10:
  1178. case 11:
  1179. case 14:
  1180. case 15:
  1181. return CPUTYPE_NEHALEM;
  1182. case 12:
  1183. return CPUTYPE_ATOM;
  1184. case 13:
  1185. return CPUTYPE_DUNNINGTON;
  1186. }
  1187. break;
  1188. case 2: // family 6 exmodel 2
  1189. switch (model) {
  1190. case 5:
  1191. //Intel Core (Clarkdale) / Core (Arrandale)
  1192. // Pentium (Clarkdale) / Pentium Mobile (Arrandale)
  1193. // Xeon (Clarkdale), 32nm
  1194. return CPUTYPE_NEHALEM;
  1195. case 10:
  1196. //Intel Core i5-2000 /i7-2000 (Sandy Bridge)
  1197. if(support_avx())
  1198. return CPUTYPE_SANDYBRIDGE;
  1199. else
  1200. return CPUTYPE_NEHALEM; //OS doesn't support AVX
  1201. case 12:
  1202. //Xeon Processor 5600 (Westmere-EP)
  1203. return CPUTYPE_NEHALEM;
  1204. case 13:
  1205. //Intel Core i7-3000 / Xeon E5 (Sandy Bridge)
  1206. if(support_avx())
  1207. return CPUTYPE_SANDYBRIDGE;
  1208. else
  1209. return CPUTYPE_NEHALEM;
  1210. case 14:
  1211. // Xeon E7540
  1212. case 15:
  1213. //Xeon Processor E7 (Westmere-EX)
  1214. return CPUTYPE_NEHALEM;
  1215. }
  1216. break;
  1217. case 3: // family 6 exmodel 3
  1218. switch (model) {
  1219. case 7:
  1220. // Bay Trail
  1221. return CPUTYPE_ATOM;
  1222. case 10:
  1223. case 14:
  1224. // Ivy Bridge
  1225. if(support_avx())
  1226. return CPUTYPE_SANDYBRIDGE;
  1227. else
  1228. return CPUTYPE_NEHALEM;
  1229. case 12:
  1230. case 15:
  1231. if(support_avx2())
  1232. return CPUTYPE_HASWELL;
  1233. if(support_avx())
  1234. return CPUTYPE_SANDYBRIDGE;
  1235. else
  1236. return CPUTYPE_NEHALEM;
  1237. case 13:
  1238. //Broadwell
  1239. if(support_avx2())
  1240. return CPUTYPE_HASWELL;
  1241. if(support_avx())
  1242. return CPUTYPE_SANDYBRIDGE;
  1243. else
  1244. return CPUTYPE_NEHALEM;
  1245. }
  1246. break;
  1247. case 4: // family 6 exmodel 4
  1248. switch (model) {
  1249. case 5:
  1250. case 6:
  1251. if(support_avx2())
  1252. return CPUTYPE_HASWELL;
  1253. if(support_avx())
  1254. return CPUTYPE_SANDYBRIDGE;
  1255. else
  1256. return CPUTYPE_NEHALEM;
  1257. case 7:
  1258. case 15:
  1259. //Broadwell
  1260. if(support_avx2())
  1261. return CPUTYPE_HASWELL;
  1262. if(support_avx())
  1263. return CPUTYPE_SANDYBRIDGE;
  1264. else
  1265. return CPUTYPE_NEHALEM;
  1266. case 14:
  1267. //Skylake
  1268. if(support_avx2())
  1269. return CPUTYPE_HASWELL;
  1270. if(support_avx())
  1271. return CPUTYPE_SANDYBRIDGE;
  1272. else
  1273. return CPUTYPE_NEHALEM;
  1274. case 12:
  1275. // Braswell
  1276. case 13:
  1277. // Avoton
  1278. return CPUTYPE_NEHALEM;
  1279. }
  1280. break;
  1281. case 5: // family 6 exmodel 5
  1282. switch (model) {
  1283. case 6:
  1284. //Broadwell
  1285. if(support_avx2())
  1286. return CPUTYPE_HASWELL;
  1287. if(support_avx())
  1288. return CPUTYPE_SANDYBRIDGE;
  1289. else
  1290. return CPUTYPE_NEHALEM;
  1291. case 5:
  1292. // Skylake X
  1293. if(support_avx512_bf16())
  1294. return CPUTYPE_COOPERLAKE;
  1295. if(support_avx512())
  1296. return CPUTYPE_SKYLAKEX;
  1297. if(support_avx2())
  1298. return CPUTYPE_HASWELL;
  1299. if(support_avx())
  1300. return CPUTYPE_SANDYBRIDGE;
  1301. else
  1302. return CPUTYPE_NEHALEM;
  1303. case 14:
  1304. // Skylake
  1305. if(support_avx2())
  1306. return CPUTYPE_HASWELL;
  1307. if(support_avx())
  1308. return CPUTYPE_SANDYBRIDGE;
  1309. else
  1310. return CPUTYPE_NEHALEM;
  1311. case 7:
  1312. // Xeon Phi Knights Landing
  1313. if(support_avx2())
  1314. return CPUTYPE_HASWELL;
  1315. if(support_avx())
  1316. return CPUTYPE_SANDYBRIDGE;
  1317. else
  1318. return CPUTYPE_NEHALEM;
  1319. case 12:
  1320. // Apollo Lake
  1321. case 15:
  1322. // Denverton
  1323. return CPUTYPE_NEHALEM;
  1324. }
  1325. break;
  1326. case 6: // family 6 exmodel 6
  1327. switch (model) {
  1328. case 6: // Cannon Lake
  1329. if(support_avx512())
  1330. return CPUTYPE_SKYLAKEX;
  1331. if(support_avx2())
  1332. return CPUTYPE_HASWELL;
  1333. if(support_avx())
  1334. return CPUTYPE_SANDYBRIDGE;
  1335. else
  1336. return CPUTYPE_NEHALEM;
  1337. case 10: // Ice Lake SP
  1338. if(support_avx512_bf16())
  1339. return CPUTYPE_COOPERLAKE;
  1340. if(support_avx512())
  1341. return CPUTYPE_SKYLAKEX;
  1342. if(support_avx2())
  1343. return CPUTYPE_HASWELL;
  1344. if(support_avx())
  1345. return CPUTYPE_SANDYBRIDGE;
  1346. else
  1347. return CPUTYPE_NEHALEM;
  1348. }
  1349. break;
  1350. case 7: // family 6 exmodel 7
  1351. switch (model) {
  1352. case 10: // Goldmont Plus
  1353. return CPUTYPE_NEHALEM;
  1354. case 14: // Ice Lake
  1355. if(support_avx512())
  1356. return CPUTYPE_SKYLAKEX;
  1357. if(support_avx2())
  1358. return CPUTYPE_HASWELL;
  1359. if(support_avx())
  1360. return CPUTYPE_SANDYBRIDGE;
  1361. else
  1362. return CPUTYPE_NEHALEM;
  1363. }
  1364. break;
  1365. case 8:
  1366. switch (model) {
  1367. case 12: // Tiger Lake
  1368. case 13: // Tiger Lake (11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz)
  1369. if(support_avx512())
  1370. return CPUTYPE_SKYLAKEX;
  1371. if(support_avx2())
  1372. return CPUTYPE_HASWELL;
  1373. if(support_avx())
  1374. return CPUTYPE_SANDYBRIDGE;
  1375. else
  1376. return CPUTYPE_NEHALEM;
  1377. case 14: // Kaby Lake and refreshes
  1378. if(support_avx2())
  1379. return CPUTYPE_HASWELL;
  1380. if(support_avx())
  1381. return CPUTYPE_SANDYBRIDGE;
  1382. else
  1383. return CPUTYPE_NEHALEM;
  1384. case 15: // Sapphire Rapids
  1385. if(support_avx512_bf16())
  1386. return CPUTYPE_COOPERLAKE;
  1387. if(support_avx512())
  1388. return CPUTYPE_SKYLAKEX;
  1389. if(support_avx2())
  1390. return CPUTYPE_HASWELL;
  1391. if(support_avx())
  1392. return CPUTYPE_SANDYBRIDGE;
  1393. else
  1394. return CPUTYPE_NEHALEM;
  1395. }
  1396. break;
  1397. case 9:
  1398. switch (model) {
  1399. case 7: // Alder Lake desktop
  1400. case 10: // Alder Lake mobile
  1401. if(support_avx2())
  1402. return CPUTYPE_HASWELL;
  1403. if(support_avx())
  1404. return CPUTYPE_SANDYBRIDGE;
  1405. else
  1406. return CPUTYPE_NEHALEM;
  1407. case 13: // Ice Lake NNPI
  1408. if(support_avx512())
  1409. return CPUTYPE_SKYLAKEX;
  1410. if(support_avx2())
  1411. return CPUTYPE_HASWELL;
  1412. if(support_avx())
  1413. return CPUTYPE_SANDYBRIDGE;
  1414. else
  1415. return CPUTYPE_NEHALEM;
  1416. case 14: // Kaby Lake and refreshes
  1417. if(support_avx2())
  1418. return CPUTYPE_HASWELL;
  1419. if(support_avx())
  1420. return CPUTYPE_SANDYBRIDGE;
  1421. else
  1422. return CPUTYPE_NEHALEM;
  1423. }
  1424. break;
  1425. case 10: //family 6 exmodel 10
  1426. switch (model) {
  1427. case 5: // Comet Lake H and S
  1428. case 6: // Comet Lake U
  1429. if(support_avx2())
  1430. return CPUTYPE_HASWELL;
  1431. if(support_avx())
  1432. return CPUTYPE_SANDYBRIDGE;
  1433. else
  1434. return CPUTYPE_NEHALEM;
  1435. case 7: // Rocket Lake
  1436. if(support_avx512())
  1437. return CPUTYPE_SKYLAKEX;
  1438. if(support_avx2())
  1439. return CPUTYPE_HASWELL;
  1440. if(support_avx())
  1441. return CPUTYPE_SANDYBRIDGE;
  1442. else
  1443. return CPUTYPE_NEHALEM;
  1444. }
  1445. break;
  1446. }
  1447. break;
  1448. case 0x7:
  1449. return CPUTYPE_ITANIUM;
  1450. case 0xf:
  1451. switch (exfamily) {
  1452. case 0 :
  1453. return CPUTYPE_PENTIUM4;
  1454. case 1 :
  1455. return CPUTYPE_ITANIUM;
  1456. }
  1457. break;
  1458. }
  1459. return CPUTYPE_INTEL_UNKNOWN;
  1460. }
  1461. if (vendor == VENDOR_AMD){
  1462. switch (family) {
  1463. case 0x4:
  1464. return CPUTYPE_AMD5X86;
  1465. case 0x5:
  1466. return CPUTYPE_AMDK6;
  1467. case 0x6:
  1468. #if defined(__x86_64__) || defined(__amd64__)
  1469. return CPUTYPE_BARCELONA;
  1470. #else
  1471. return CPUTYPE_ATHLON;
  1472. #endif
  1473. case 0xf:
  1474. switch (exfamily) {
  1475. case 0:
  1476. case 2:
  1477. return CPUTYPE_OPTERON;
  1478. case 1:
  1479. case 3:
  1480. // case 7:
  1481. // case 10:
  1482. return CPUTYPE_BARCELONA;
  1483. case 5:
  1484. case 7:
  1485. return CPUTYPE_BOBCAT;
  1486. case 6:
  1487. switch (model) {
  1488. case 1:
  1489. //AMD Bulldozer Opteron 6200 / Opteron 4200 / AMD FX-Series
  1490. if(support_avx())
  1491. return CPUTYPE_BULLDOZER;
  1492. else
  1493. return CPUTYPE_BARCELONA; //OS don't support AVX.
  1494. case 2: //AMD Piledriver
  1495. case 3: //AMD Richland
  1496. if(support_avx())
  1497. return CPUTYPE_PILEDRIVER;
  1498. else
  1499. return CPUTYPE_BARCELONA; //OS don't support AVX.
  1500. case 5: // New EXCAVATOR CPUS
  1501. if(support_avx())
  1502. return CPUTYPE_EXCAVATOR;
  1503. else
  1504. return CPUTYPE_BARCELONA; //OS don't support AVX.
  1505. case 0:
  1506. case 8:
  1507. switch(exmodel){
  1508. case 1: //AMD Trinity
  1509. if(support_avx())
  1510. return CPUTYPE_PILEDRIVER;
  1511. else
  1512. return CPUTYPE_BARCELONA; //OS don't support AVX.
  1513. case 3:
  1514. if(support_avx())
  1515. return CPUTYPE_STEAMROLLER;
  1516. else
  1517. return CPUTYPE_BARCELONA; //OS don't support AVX.
  1518. case 6:
  1519. if(support_avx())
  1520. return CPUTYPE_EXCAVATOR;
  1521. else
  1522. return CPUTYPE_BARCELONA; //OS don't support AVX.
  1523. }
  1524. break;
  1525. }
  1526. break;
  1527. case 8:
  1528. switch (model) {
  1529. case 1:
  1530. // AMD Ryzen
  1531. case 8:
  1532. // AMD Ryzen2
  1533. default:
  1534. // Matisse/Renoir and other recent Ryzen2
  1535. if(support_avx())
  1536. #ifndef NO_AVX2
  1537. return CPUTYPE_ZEN;
  1538. #else
  1539. return CPUTYPE_SANDYBRIDGE; // Zen is closer in architecture to Sandy Bridge than to Excavator
  1540. #endif
  1541. else
  1542. return CPUTYPE_BARCELONA;
  1543. }
  1544. break;
  1545. case 10: // Zen3
  1546. if(support_avx())
  1547. #ifndef NO_AVX2
  1548. return CPUTYPE_ZEN;
  1549. #else
  1550. return CPUTYPE_SANDYBRIDGE; // Zen is closer in architecture to Sandy Bridge than to Excavator
  1551. #endif
  1552. else
  1553. return CPUTYPE_BARCELONA;
  1554. }
  1555. break;
  1556. }
  1557. return CPUTYPE_AMD_UNKNOWN;
  1558. }
  1559. if (vendor == VENDOR_HYGON){
  1560. switch (family) {
  1561. case 0xf:
  1562. switch (exfamily) {
  1563. case 9:
  1564. //Hygon Dhyana
  1565. if(support_avx())
  1566. #ifndef NO_AVX2
  1567. return CPUTYPE_ZEN;
  1568. #else
  1569. return CPUTYPE_SANDYBRIDGE; // closer in architecture to Sandy Bridge than to Excavator
  1570. #endif
  1571. else
  1572. return CPUTYPE_BARCELONA;
  1573. }
  1574. break;
  1575. }
  1576. return CPUTYPE_HYGON_UNKNOWN;
  1577. }
  1578. if (vendor == VENDOR_CYRIX){
  1579. switch (family) {
  1580. case 0x4:
  1581. return CPUTYPE_CYRIX5X86;
  1582. case 0x5:
  1583. return CPUTYPE_CYRIXM1;
  1584. case 0x6:
  1585. return CPUTYPE_CYRIXM2;
  1586. }
  1587. return CPUTYPE_CYRIX_UNKNOWN;
  1588. }
  1589. if (vendor == VENDOR_NEXGEN){
  1590. switch (family) {
  1591. case 0x5:
  1592. return CPUTYPE_NEXGENNX586;
  1593. }
  1594. return CPUTYPE_NEXGEN_UNKNOWN;
  1595. }
  1596. if (vendor == VENDOR_CENTAUR){
  1597. switch (family) {
  1598. case 0x5:
  1599. return CPUTYPE_CENTAURC6;
  1600. case 0x6:
  1601. if (model == 0xf && stepping < 0xe)
  1602. return CPUTYPE_NANO;
  1603. return CPUTYPE_NEHALEM;
  1604. default:
  1605. if (family >= 0x7)
  1606. return CPUTYPE_NEHALEM;
  1607. else
  1608. return CPUTYPE_VIAC3;
  1609. }
  1610. }
  1611. if (vendor == VENDOR_ZHAOXIN){
  1612. return CPUTYPE_NEHALEM;
  1613. }
  1614. if (vendor == VENDOR_RISE){
  1615. switch (family) {
  1616. case 0x5:
  1617. return CPUTYPE_RISEMP6;
  1618. }
  1619. return CPUTYPE_RISE_UNKNOWN;
  1620. }
  1621. if (vendor == VENDOR_SIS){
  1622. switch (family) {
  1623. case 0x5:
  1624. return CPUTYPE_SYS55X;
  1625. }
  1626. return CPUTYPE_SIS_UNKNOWN;
  1627. }
  1628. if (vendor == VENDOR_TRANSMETA){
  1629. switch (family) {
  1630. case 0x5:
  1631. return CPUTYPE_CRUSOETM3X;
  1632. }
  1633. return CPUTYPE_TRANSMETA_UNKNOWN;
  1634. }
  1635. if (vendor == VENDOR_NSC){
  1636. switch (family) {
  1637. case 0x5:
  1638. return CPUTYPE_NSGEODE;
  1639. }
  1640. return CPUTYPE_NSC_UNKNOWN;
  1641. }
  1642. return CPUTYPE_UNKNOWN;
  1643. }
  1644. static char *cpuname[] = {
  1645. "UNKNOWN",
  1646. "INTEL_UNKNOWN",
  1647. "UMC_UNKNOWN",
  1648. "AMD_UNKNOWN",
  1649. "CYRIX_UNKNOWN",
  1650. "NEXGEN_UNKNOWN",
  1651. "CENTAUR_UNKNOWN",
  1652. "RISE_UNKNOWN",
  1653. "SIS_UNKNOWN",
  1654. "TRANSMETA_UNKNOWN",
  1655. "NSC_UNKNOWN",
  1656. "80386",
  1657. "80486",
  1658. "PENTIUM",
  1659. "PENTIUM2",
  1660. "PENTIUM3",
  1661. "PENTIUMM",
  1662. "PENTIUM4",
  1663. "CORE2",
  1664. "PENRYN",
  1665. "DUNNINGTON",
  1666. "NEHALEM",
  1667. "ATOM",
  1668. "ITANIUM",
  1669. "ITANIUM2",
  1670. "5X86",
  1671. "K6",
  1672. "ATHLON",
  1673. "DURON",
  1674. "OPTERON",
  1675. "BARCELONA",
  1676. "SHANGHAI",
  1677. "ISTANBUL",
  1678. "CYRIX5X86",
  1679. "CYRIXM1",
  1680. "CYRIXM2",
  1681. "NEXGENNX586",
  1682. "CENTAURC6",
  1683. "RISEMP6",
  1684. "SYS55X",
  1685. "TM3X00",
  1686. "NSGEODE",
  1687. "VIAC3",
  1688. "NANO",
  1689. "SANDYBRIDGE",
  1690. "BOBCAT",
  1691. "BULLDOZER",
  1692. "PILEDRIVER",
  1693. "HASWELL",
  1694. "STEAMROLLER",
  1695. "EXCAVATOR",
  1696. "ZEN",
  1697. "SKYLAKEX",
  1698. "DHYANA",
  1699. "COOPERLAKE"
  1700. };
  1701. static char *lowercpuname[] = {
  1702. "unknown",
  1703. "intel_unknown",
  1704. "umc_unknown",
  1705. "amd_unknown",
  1706. "cyrix_unknown",
  1707. "nexgen_unknown",
  1708. "centaur_unknown",
  1709. "rise_unknown",
  1710. "sis_unknown",
  1711. "transmeta_unknown",
  1712. "nsc_unknown",
  1713. "80386",
  1714. "80486",
  1715. "pentium",
  1716. "pentium2",
  1717. "pentium3",
  1718. "pentiumm",
  1719. "pentium4",
  1720. "core2",
  1721. "penryn",
  1722. "dunnington",
  1723. "nehalem",
  1724. "atom",
  1725. "itanium",
  1726. "itanium2",
  1727. "5x86",
  1728. "k6",
  1729. "athlon",
  1730. "duron",
  1731. "opteron",
  1732. "barcelona",
  1733. "shanghai",
  1734. "istanbul",
  1735. "cyrix5x86",
  1736. "cyrixm1",
  1737. "cyrixm2",
  1738. "nexgennx586",
  1739. "centaurc6",
  1740. "risemp6",
  1741. "sys55x",
  1742. "tms3x00",
  1743. "nsgeode",
  1744. "nano",
  1745. "sandybridge",
  1746. "bobcat",
  1747. "bulldozer",
  1748. "piledriver",
  1749. "haswell",
  1750. "steamroller",
  1751. "excavator",
  1752. "zen",
  1753. "skylakex",
  1754. "dhyana",
  1755. "cooperlake"
  1756. };
  1757. static char *corename[] = {
  1758. "UNKNOWN",
  1759. "80486",
  1760. "P5",
  1761. "P6",
  1762. "KATMAI",
  1763. "COPPERMINE",
  1764. "NORTHWOOD",
  1765. "PRESCOTT",
  1766. "BANIAS",
  1767. "ATHLON",
  1768. "OPTERON",
  1769. "BARCELONA",
  1770. "VIAC3",
  1771. "YONAH",
  1772. "CORE2",
  1773. "PENRYN",
  1774. "DUNNINGTON",
  1775. "NEHALEM",
  1776. "ATOM",
  1777. "NANO",
  1778. "SANDYBRIDGE",
  1779. "BOBCAT",
  1780. "BULLDOZER",
  1781. "PILEDRIVER",
  1782. "HASWELL",
  1783. "STEAMROLLER",
  1784. "EXCAVATOR",
  1785. "ZEN",
  1786. "SKYLAKEX",
  1787. "DHYANA",
  1788. "COOPERLAKE"
  1789. };
  1790. static char *corename_lower[] = {
  1791. "unknown",
  1792. "80486",
  1793. "p5",
  1794. "p6",
  1795. "katmai",
  1796. "coppermine",
  1797. "northwood",
  1798. "prescott",
  1799. "banias",
  1800. "athlon",
  1801. "opteron",
  1802. "barcelona",
  1803. "viac3",
  1804. "yonah",
  1805. "core2",
  1806. "penryn",
  1807. "dunnington",
  1808. "nehalem",
  1809. "atom",
  1810. "nano",
  1811. "sandybridge",
  1812. "bobcat",
  1813. "bulldozer",
  1814. "piledriver",
  1815. "haswell",
  1816. "steamroller",
  1817. "excavator",
  1818. "zen",
  1819. "skylakex",
  1820. "dhyana",
  1821. "cooperlake"
  1822. };
  1823. char *get_cpunamechar(void){
  1824. return cpuname[get_cpuname()];
  1825. }
  1826. char *get_lower_cpunamechar(void){
  1827. return lowercpuname[get_cpuname()];
  1828. }
  1829. int get_coretype(void){
  1830. int family, exfamily, model, exmodel, vendor, stepping;
  1831. if (!have_cpuid()) return CORE_80486;
  1832. family = get_cputype(GET_FAMILY);
  1833. exfamily = get_cputype(GET_EXFAMILY);
  1834. model = get_cputype(GET_MODEL);
  1835. exmodel = get_cputype(GET_EXMODEL);
  1836. stepping = get_cputype(GET_STEPPING);
  1837. vendor = get_vendor();
  1838. if (vendor == VENDOR_INTEL){
  1839. switch (family) {
  1840. case 4:
  1841. return CORE_80486;
  1842. case 5:
  1843. return CORE_P5;
  1844. case 6:
  1845. switch (exmodel) {
  1846. case 0:
  1847. switch (model) {
  1848. case 0:
  1849. case 1:
  1850. case 2:
  1851. case 3:
  1852. case 4:
  1853. case 5:
  1854. case 6:
  1855. #if defined(__x86_64__) || defined(__amd64__)
  1856. return CORE_CORE2;
  1857. #else
  1858. return CORE_P6;
  1859. #endif
  1860. case 7:
  1861. return CORE_KATMAI;
  1862. case 8:
  1863. case 10:
  1864. case 11:
  1865. return CORE_COPPERMINE;
  1866. case 9:
  1867. case 13:
  1868. case 14:
  1869. return CORE_BANIAS;
  1870. case 15:
  1871. return CORE_CORE2;
  1872. }
  1873. break;
  1874. case 1:
  1875. switch (model) {
  1876. case 6:
  1877. return CORE_CORE2;
  1878. case 7:
  1879. return CORE_PENRYN;
  1880. case 10:
  1881. case 11:
  1882. case 14:
  1883. case 15:
  1884. return CORE_NEHALEM;
  1885. case 12:
  1886. return CORE_ATOM;
  1887. case 13:
  1888. return CORE_DUNNINGTON;
  1889. }
  1890. break;
  1891. case 2:
  1892. switch (model) {
  1893. case 5:
  1894. //Intel Core (Clarkdale) / Core (Arrandale)
  1895. // Pentium (Clarkdale) / Pentium Mobile (Arrandale)
  1896. // Xeon (Clarkdale), 32nm
  1897. return CORE_NEHALEM;
  1898. case 10:
  1899. //Intel Core i5-2000 /i7-2000 (Sandy Bridge)
  1900. if(support_avx())
  1901. return CORE_SANDYBRIDGE;
  1902. else
  1903. return CORE_NEHALEM; //OS doesn't support AVX
  1904. case 12:
  1905. //Xeon Processor 5600 (Westmere-EP)
  1906. return CORE_NEHALEM;
  1907. case 13:
  1908. //Intel Core i7-3000 / Xeon E5 (Sandy Bridge)
  1909. if(support_avx())
  1910. return CORE_SANDYBRIDGE;
  1911. else
  1912. return CORE_NEHALEM; //OS doesn't support AVX
  1913. case 14:
  1914. //Xeon E7540
  1915. case 15:
  1916. //Xeon Processor E7 (Westmere-EX)
  1917. return CORE_NEHALEM;
  1918. }
  1919. break;
  1920. case 3:
  1921. switch (model) {
  1922. case 7:
  1923. return CORE_ATOM;
  1924. case 10:
  1925. case 14:
  1926. if(support_avx())
  1927. return CORE_SANDYBRIDGE;
  1928. else
  1929. return CORE_NEHALEM; //OS doesn't support AVX
  1930. case 12:
  1931. case 15:
  1932. if(support_avx())
  1933. #ifndef NO_AVX2
  1934. return CORE_HASWELL;
  1935. #else
  1936. return CORE_SANDYBRIDGE;
  1937. #endif
  1938. else
  1939. return CORE_NEHALEM;
  1940. case 13:
  1941. //broadwell
  1942. if(support_avx())
  1943. #ifndef NO_AVX2
  1944. return CORE_HASWELL;
  1945. #else
  1946. return CORE_SANDYBRIDGE;
  1947. #endif
  1948. else
  1949. return CORE_NEHALEM;
  1950. }
  1951. break;
  1952. case 4:
  1953. switch (model) {
  1954. case 5:
  1955. case 6:
  1956. if(support_avx())
  1957. #ifndef NO_AVX2
  1958. return CORE_HASWELL;
  1959. #else
  1960. return CORE_SANDYBRIDGE;
  1961. #endif
  1962. else
  1963. return CORE_NEHALEM;
  1964. case 7:
  1965. case 15:
  1966. //broadwell
  1967. if(support_avx())
  1968. #ifndef NO_AVX2
  1969. return CORE_HASWELL;
  1970. #else
  1971. return CORE_SANDYBRIDGE;
  1972. #endif
  1973. else
  1974. return CORE_NEHALEM;
  1975. case 14:
  1976. //Skylake
  1977. if(support_avx())
  1978. #ifndef NO_AVX2
  1979. return CORE_HASWELL;
  1980. #else
  1981. return CORE_SANDYBRIDGE;
  1982. #endif
  1983. else
  1984. return CORE_NEHALEM;
  1985. case 12:
  1986. // Braswell
  1987. case 13:
  1988. // Avoton
  1989. return CORE_NEHALEM;
  1990. }
  1991. break;
  1992. case 5:
  1993. switch (model) {
  1994. case 6:
  1995. //broadwell
  1996. if(support_avx())
  1997. #ifndef NO_AVX2
  1998. return CORE_HASWELL;
  1999. #else
  2000. return CORE_SANDYBRIDGE;
  2001. #endif
  2002. else
  2003. return CORE_NEHALEM;
  2004. case 5:
  2005. // Skylake X
  2006. #ifndef NO_AVX512
  2007. if(support_avx512_bf16())
  2008. return CORE_COOPERLAKE;
  2009. return CORE_SKYLAKEX;
  2010. #else
  2011. if(support_avx())
  2012. #ifndef NO_AVX2
  2013. return CORE_HASWELL;
  2014. #else
  2015. return CORE_SANDYBRIDGE;
  2016. #endif
  2017. else
  2018. return CORE_NEHALEM;
  2019. #endif
  2020. case 14:
  2021. // Skylake
  2022. if(support_avx())
  2023. #ifndef NO_AVX2
  2024. return CORE_HASWELL;
  2025. #else
  2026. return CORE_SANDYBRIDGE;
  2027. #endif
  2028. else
  2029. return CORE_NEHALEM;
  2030. case 7:
  2031. // Phi Knights Landing
  2032. if(support_avx())
  2033. #ifndef NO_AVX2
  2034. return CORE_HASWELL;
  2035. #else
  2036. return CORE_SANDYBRIDGE;
  2037. #endif
  2038. else
  2039. return CORE_NEHALEM;
  2040. case 12:
  2041. // Apollo Lake
  2042. return CORE_NEHALEM;
  2043. }
  2044. break;
  2045. case 6:
  2046. if (model == 6)
  2047. #ifndef NO_AVX512
  2048. return CORE_SKYLAKEX;
  2049. #else
  2050. if(support_avx())
  2051. #ifndef NO_AVX2
  2052. return CORE_HASWELL;
  2053. #else
  2054. return CORE_SANDYBRIDGE;
  2055. #endif
  2056. else
  2057. return CORE_NEHALEM;
  2058. #endif
  2059. if (model == 10 || model == 12)
  2060. #ifndef NO_AVX512
  2061. if(support_avx512_bf16())
  2062. return CORE_COOPERLAKE;
  2063. return CORE_SKYLAKEX;
  2064. #else
  2065. if(support_avx())
  2066. #ifndef NO_AVX2
  2067. return CORE_HASWELL;
  2068. #else
  2069. return CORE_SANDYBRIDGE;
  2070. #endif
  2071. else
  2072. return CORE_NEHALEM;
  2073. #endif
  2074. break;
  2075. case 7:
  2076. if (model == 10)
  2077. return CORE_NEHALEM;
  2078. if (model == 13 || model == 14) // Ice Lake
  2079. #ifndef NO_AVX512
  2080. return CORE_SKYLAKEX;
  2081. #else
  2082. if(support_avx())
  2083. #ifndef NO_AVX2
  2084. return CORE_HASWELL;
  2085. #else
  2086. return CORE_SANDYBRIDGE;
  2087. #endif
  2088. else
  2089. return CORE_NEHALEM;
  2090. #endif
  2091. break;
  2092. case 8:
  2093. if (model == 12 || model == 13) { // Tiger Lake
  2094. if(support_avx512())
  2095. return CORE_SKYLAKEX;
  2096. if(support_avx2())
  2097. return CORE_HASWELL;
  2098. if(support_avx())
  2099. return CORE_SANDYBRIDGE;
  2100. else
  2101. return CORE_NEHALEM;
  2102. }
  2103. if (model == 14) { // Kaby Lake mobile
  2104. if(support_avx())
  2105. #ifndef NO_AVX2
  2106. return CORE_HASWELL;
  2107. #else
  2108. return CORE_SANDYBRIDGE;
  2109. #endif
  2110. else
  2111. return CORE_NEHALEM;
  2112. }
  2113. if (model == 15) { // Sapphire Rapids
  2114. if(support_avx512_bf16())
  2115. return CPUTYPE_COOPERLAKE;
  2116. if(support_avx512())
  2117. return CPUTYPE_SKYLAKEX;
  2118. if(support_avx2())
  2119. return CPUTYPE_HASWELL;
  2120. if(support_avx())
  2121. return CPUTYPE_SANDYBRIDGE;
  2122. else
  2123. return CPUTYPE_NEHALEM;
  2124. }
  2125. break;
  2126. case 9:
  2127. if (model == 7 || model == 10) { // Alder Lake
  2128. if(support_avx2())
  2129. return CORE_HASWELL;
  2130. if(support_avx())
  2131. return CORE_SANDYBRIDGE;
  2132. else
  2133. return CORE_NEHALEM;
  2134. }
  2135. if (model == 13) { // Ice Lake NNPI
  2136. if(support_avx512())
  2137. return CORE_SKYLAKEX;
  2138. if(support_avx2())
  2139. return CORE_HASWELL;
  2140. if(support_avx())
  2141. return CORE_SANDYBRIDGE;
  2142. else
  2143. return CORE_NEHALEM;
  2144. }
  2145. if (model == 14) { // Kaby Lake desktop
  2146. if(support_avx())
  2147. #ifndef NO_AVX2
  2148. return CORE_HASWELL;
  2149. #else
  2150. return CORE_SANDYBRIDGE;
  2151. #endif
  2152. else
  2153. return CORE_NEHALEM;
  2154. }
  2155. break;
  2156. case 10:
  2157. switch (model) {
  2158. case 5: // Comet Lake H and S
  2159. case 6: // Comet Lake U
  2160. if(support_avx())
  2161. #ifndef NO_AVX2
  2162. return CORE_HASWELL;
  2163. #else
  2164. return CORE_SANDYBRIDGE;
  2165. #endif
  2166. else
  2167. return CORE_NEHALEM;
  2168. case 7:// Rocket Lake
  2169. #ifndef NO_AVX512
  2170. if(support_avx512())
  2171. return CORE_SKYLAKEX;
  2172. #endif
  2173. #ifndef NO_AVX2
  2174. if(support_avx2())
  2175. return CORE_HASWELL;
  2176. #endif
  2177. if(support_avx())
  2178. return CORE_SANDYBRIDGE;
  2179. else
  2180. return CORE_NEHALEM;
  2181. }
  2182. case 15:
  2183. if (model <= 0x2) return CORE_NORTHWOOD;
  2184. else return CORE_PRESCOTT;
  2185. }
  2186. }
  2187. }
  2188. if (vendor == VENDOR_AMD){
  2189. if (family <= 0x5) return CORE_80486;
  2190. #if defined(__x86_64__) || defined(__amd64__)
  2191. if (family <= 0xe) return CORE_BARCELONA;
  2192. #else
  2193. if (family <= 0xe) return CORE_ATHLON;
  2194. #endif
  2195. if (family == 0xf){
  2196. if ((exfamily == 0) || (exfamily == 2)) return CORE_OPTERON;
  2197. else if (exfamily == 5) return CORE_BOBCAT;
  2198. else if (exfamily == 6) {
  2199. switch (model) {
  2200. case 1:
  2201. //AMD Bulldozer Opteron 6200 / Opteron 4200 / AMD FX-Series
  2202. if(support_avx())
  2203. return CORE_BULLDOZER;
  2204. else
  2205. return CORE_BARCELONA; //OS don't support AVX.
  2206. case 2: //AMD Piledriver
  2207. case 3: //AMD Richland
  2208. if(support_avx())
  2209. return CORE_PILEDRIVER;
  2210. else
  2211. return CORE_BARCELONA; //OS don't support AVX.
  2212. case 5: // New EXCAVATOR
  2213. if(support_avx())
  2214. return CORE_EXCAVATOR;
  2215. else
  2216. return CORE_BARCELONA; //OS don't support AVX.
  2217. case 0:
  2218. case 8:
  2219. switch(exmodel){
  2220. case 1: //AMD Trinity
  2221. if(support_avx())
  2222. return CORE_PILEDRIVER;
  2223. else
  2224. return CORE_BARCELONA; //OS don't support AVX.
  2225. case 3:
  2226. if(support_avx())
  2227. return CORE_STEAMROLLER;
  2228. else
  2229. return CORE_BARCELONA; //OS don't support AVX.
  2230. case 6:
  2231. if(support_avx())
  2232. return CORE_EXCAVATOR;
  2233. else
  2234. return CORE_BARCELONA; //OS don't support AVX.
  2235. }
  2236. break;
  2237. }
  2238. } else if (exfamily == 8 || exfamily == 10) {
  2239. switch (model) {
  2240. case 1:
  2241. // AMD Ryzen
  2242. case 8:
  2243. // Ryzen 2
  2244. default:
  2245. // Matisse,Renoir Ryzen2 models
  2246. if(support_avx())
  2247. #ifndef NO_AVX2
  2248. return CORE_ZEN;
  2249. #else
  2250. return CORE_SANDYBRIDGE; // Zen is closer in architecture to Sandy Bridge than to Excavator
  2251. #endif
  2252. else
  2253. return CORE_BARCELONA;
  2254. }
  2255. } else {
  2256. return CORE_BARCELONA;
  2257. }
  2258. }
  2259. }
  2260. if (vendor == VENDOR_HYGON){
  2261. if (family == 0xf){
  2262. if (exfamily == 9) {
  2263. if(support_avx())
  2264. #ifndef NO_AVX2
  2265. return CORE_ZEN;
  2266. #else
  2267. return CORE_SANDYBRIDGE; // closer in architecture to Sandy Bridge than to Excavator
  2268. #endif
  2269. else
  2270. return CORE_BARCELONA;
  2271. } else {
  2272. return CORE_BARCELONA;
  2273. }
  2274. }
  2275. }
  2276. if (vendor == VENDOR_CENTAUR) {
  2277. switch (family) {
  2278. case 0x6:
  2279. if (model == 0xf && stepping < 0xe)
  2280. return CORE_NANO;
  2281. return CORE_NEHALEM;
  2282. default:
  2283. if (family >= 0x7)
  2284. return CORE_NEHALEM;
  2285. else
  2286. return CORE_VIAC3;
  2287. }
  2288. }
  2289. if (vendor == VENDOR_ZHAOXIN) {
  2290. return CORE_NEHALEM;
  2291. }
  2292. return CORE_UNKNOWN;
  2293. }
  2294. void get_cpuconfig(void){
  2295. cache_info_t info;
  2296. int features;
  2297. printf("#define %s\n", cpuname[get_cpuname()]);
  2298. if (get_coretype() != CORE_P5) {
  2299. get_cacheinfo(CACHE_INFO_L1_I, &info);
  2300. if (info.size > 0) {
  2301. printf("#define L1_CODE_SIZE %d\n", info.size * 1024);
  2302. printf("#define L1_CODE_ASSOCIATIVE %d\n", info.associative);
  2303. printf("#define L1_CODE_LINESIZE %d\n", info.linesize);
  2304. }
  2305. get_cacheinfo(CACHE_INFO_L1_D, &info);
  2306. if (info.size > 0) {
  2307. printf("#define L1_DATA_SIZE %d\n", info.size * 1024);
  2308. printf("#define L1_DATA_ASSOCIATIVE %d\n", info.associative);
  2309. printf("#define L1_DATA_LINESIZE %d\n", info.linesize);
  2310. }
  2311. get_cacheinfo(CACHE_INFO_L2, &info);
  2312. if (info.size > 0) {
  2313. printf("#define L2_SIZE %d\n", info.size * 1024);
  2314. printf("#define L2_ASSOCIATIVE %d\n", info.associative);
  2315. printf("#define L2_LINESIZE %d\n", info.linesize);
  2316. } else {
  2317. //fall back for some virtual machines.
  2318. printf("#define L2_SIZE 1048576\n");
  2319. printf("#define L2_ASSOCIATIVE 6\n");
  2320. printf("#define L2_LINESIZE 64\n");
  2321. }
  2322. get_cacheinfo(CACHE_INFO_L3, &info);
  2323. if (info.size > 0) {
  2324. printf("#define L3_SIZE %d\n", info.size * 1024);
  2325. printf("#define L3_ASSOCIATIVE %d\n", info.associative);
  2326. printf("#define L3_LINESIZE %d\n", info.linesize);
  2327. }
  2328. get_cacheinfo(CACHE_INFO_L1_ITB, &info);
  2329. if (info.size > 0) {
  2330. printf("#define ITB_SIZE %d\n", info.size * 1024);
  2331. printf("#define ITB_ASSOCIATIVE %d\n", info.associative);
  2332. printf("#define ITB_ENTRIES %d\n", info.linesize);
  2333. }
  2334. get_cacheinfo(CACHE_INFO_L1_DTB, &info);
  2335. if (info.size > 0) {
  2336. printf("#define DTB_SIZE %d\n", info.size * 1024);
  2337. printf("#define DTB_ASSOCIATIVE %d\n", info.associative);
  2338. printf("#define DTB_DEFAULT_ENTRIES %d\n", info.linesize);
  2339. } else {
  2340. //fall back for some virtual machines.
  2341. printf("#define DTB_DEFAULT_ENTRIES 32\n");
  2342. }
  2343. features = get_cputype(GET_FEATURE);
  2344. if (features & HAVE_CMOV ) printf("#define HAVE_CMOV\n");
  2345. if (features & HAVE_MMX ) printf("#define HAVE_MMX\n");
  2346. if (features & HAVE_SSE ) printf("#define HAVE_SSE\n");
  2347. if (features & HAVE_SSE2 ) printf("#define HAVE_SSE2\n");
  2348. if (features & HAVE_SSE3 ) printf("#define HAVE_SSE3\n");
  2349. if (features & HAVE_SSSE3) printf("#define HAVE_SSSE3\n");
  2350. if (features & HAVE_SSE4_1) printf("#define HAVE_SSE4_1\n");
  2351. if (features & HAVE_SSE4_2) printf("#define HAVE_SSE4_2\n");
  2352. if (features & HAVE_SSE4A) printf("#define HAVE_SSE4A\n");
  2353. if (features & HAVE_SSE5 ) printf("#define HAVE_SSSE5\n");
  2354. if (features & HAVE_AVX ) printf("#define HAVE_AVX\n");
  2355. if (features & HAVE_AVX2 ) printf("#define HAVE_AVX2\n");
  2356. if (features & HAVE_AVX512VL ) printf("#define HAVE_AVX512VL\n");
  2357. if (features & HAVE_AVX512BF16 ) printf("#define HAVE_AVX512BF16\n");
  2358. if (features & HAVE_AMXBF16 ) printf("#define HAVE_AMXBF16\n");
  2359. if (features & HAVE_3DNOWEX) printf("#define HAVE_3DNOWEX\n");
  2360. if (features & HAVE_3DNOW) printf("#define HAVE_3DNOW\n");
  2361. if (features & HAVE_FMA4 ) printf("#define HAVE_FMA4\n");
  2362. if (features & HAVE_FMA3 ) printf("#define HAVE_FMA3\n");
  2363. if (features & HAVE_CFLUSH) printf("#define HAVE_CFLUSH\n");
  2364. if (features & HAVE_HIT) printf("#define HAVE_HIT 1\n");
  2365. if (features & HAVE_MISALIGNSSE) printf("#define HAVE_MISALIGNSSE\n");
  2366. if (features & HAVE_128BITFPU) printf("#define HAVE_128BITFPU\n");
  2367. if (features & HAVE_FASTMOVU) printf("#define HAVE_FASTMOVU\n");
  2368. printf("#define NUM_SHAREDCACHE %d\n", get_cputype(GET_NUMSHARE) + 1);
  2369. printf("#define NUM_CORES %d\n", get_cputype(GET_NUMCORES) + 1);
  2370. features = get_coretype();
  2371. if (features > 0) printf("#define CORE_%s\n", corename[features]);
  2372. } else {
  2373. printf("#define DTB_DEFAULT_ENTRIES 16\n");
  2374. printf("#define L1_CODE_SIZE 8192\n");
  2375. printf("#define L1_DATA_SIZE 8192\n");
  2376. printf("#define L2_SIZE 0\n");
  2377. }
  2378. }
  2379. void get_architecture(void){
  2380. #ifndef __64BIT__
  2381. printf("X86");
  2382. #else
  2383. printf("X86_64");
  2384. #endif
  2385. }
  2386. void get_subarchitecture(void){
  2387. printf("%s", get_cpunamechar());
  2388. }
  2389. void get_subdirname(void){
  2390. #ifndef __64BIT__
  2391. printf("x86");
  2392. #else
  2393. printf("x86_64");
  2394. #endif
  2395. }
  2396. char *get_corename(void){
  2397. return corename[get_coretype()];
  2398. }
  2399. void get_libname(void){
  2400. printf("%s", corename_lower[get_coretype()]);
  2401. }
  2402. /* This if for Makefile */
  2403. void get_sse(void){
  2404. int features;
  2405. features = get_cputype(GET_FEATURE);
  2406. if (features & HAVE_MMX ) printf("HAVE_MMX=1\n");
  2407. if (features & HAVE_SSE ) printf("HAVE_SSE=1\n");
  2408. if (features & HAVE_SSE2 ) printf("HAVE_SSE2=1\n");
  2409. if (features & HAVE_SSE3 ) printf("HAVE_SSE3=1\n");
  2410. if (features & HAVE_SSSE3) printf("HAVE_SSSE3=1\n");
  2411. if (features & HAVE_SSE4_1) printf("HAVE_SSE4_1=1\n");
  2412. if (features & HAVE_SSE4_2) printf("HAVE_SSE4_2=1\n");
  2413. if (features & HAVE_SSE4A) printf("HAVE_SSE4A=1\n");
  2414. if (features & HAVE_SSE5 ) printf("HAVE_SSSE5=1\n");
  2415. if (features & HAVE_AVX ) printf("HAVE_AVX=1\n");
  2416. if (features & HAVE_AVX2 ) printf("HAVE_AVX2=1\n");
  2417. if (features & HAVE_AVX512VL ) printf("HAVE_AVX512VL=1\n");
  2418. if (features & HAVE_AVX512BF16 ) printf("HAVE_AVX512BF16=1\n");
  2419. if (features & HAVE_AMXBF16 ) printf("HAVE_AMXBF16=1\n");
  2420. if (features & HAVE_3DNOWEX) printf("HAVE_3DNOWEX=1\n");
  2421. if (features & HAVE_3DNOW) printf("HAVE_3DNOW=1\n");
  2422. if (features & HAVE_FMA4 ) printf("HAVE_FMA4=1\n");
  2423. if (features & HAVE_FMA3 ) printf("HAVE_FMA3=1\n");
  2424. }
  2425. //}