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

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