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

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