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 63 kB

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