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

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