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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473
  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. #ifndef CPUIDEMU
  42. #if defined(__APPLE__) && defined(__i386__)
  43. void cpuid(int op, int *eax, int *ebx, int *ecx, int *edx);
  44. #else
  45. static inline void cpuid(int op, int *eax, int *ebx, int *ecx, int *edx){
  46. __asm__ __volatile__
  47. ("cpuid": "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) : "a" (op) : "cc");
  48. }
  49. #endif
  50. #else
  51. typedef struct {
  52. unsigned int id, a, b, c, d;
  53. } idlist_t;
  54. typedef struct {
  55. char *vendor;
  56. char *name;
  57. int start, stop;
  58. } vendor_t;
  59. extern idlist_t idlist[];
  60. extern vendor_t vendor[];
  61. static int cv = VENDOR;
  62. void cpuid(unsigned int op, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx){
  63. static int current = 0;
  64. int start = vendor[cv].start;
  65. int stop = vendor[cv].stop;
  66. int count = stop - start;
  67. if ((current < start) || (current > stop)) current = start;
  68. while ((count > 0) && (idlist[current].id != op)) {
  69. current ++;
  70. if (current > stop) current = start;
  71. count --;
  72. }
  73. *eax = idlist[current].a;
  74. *ebx = idlist[current].b;
  75. *ecx = idlist[current].c;
  76. *edx = idlist[current].d;
  77. }
  78. #endif
  79. static inline int have_cpuid(void){
  80. int eax, ebx, ecx, edx;
  81. cpuid(0, &eax, &ebx, &ecx, &edx);
  82. return eax;
  83. }
  84. static inline int have_excpuid(void){
  85. int eax, ebx, ecx, edx;
  86. cpuid(0x80000000, &eax, &ebx, &ecx, &edx);
  87. return eax & 0xffff;
  88. }
  89. int get_vendor(void){
  90. int eax, ebx, ecx, edx;
  91. char vendor[13];
  92. cpuid(0, &eax, &ebx, &ecx, &edx);
  93. *(int *)(&vendor[0]) = ebx;
  94. *(int *)(&vendor[4]) = edx;
  95. *(int *)(&vendor[8]) = ecx;
  96. vendor[12] = (char)0;
  97. if (!strcmp(vendor, "GenuineIntel")) return VENDOR_INTEL;
  98. if (!strcmp(vendor, " UMC UMC UMC")) return VENDOR_UMC;
  99. if (!strcmp(vendor, "AuthenticAMD")) return VENDOR_AMD;
  100. if (!strcmp(vendor, "CyrixInstead")) return VENDOR_CYRIX;
  101. if (!strcmp(vendor, "NexGenDriven")) return VENDOR_NEXGEN;
  102. if (!strcmp(vendor, "CentaurHauls")) return VENDOR_CENTAUR;
  103. if (!strcmp(vendor, "RiseRiseRise")) return VENDOR_RISE;
  104. if (!strcmp(vendor, " SiS SiS SiS")) return VENDOR_SIS;
  105. if (!strcmp(vendor, "GenuineTMx86")) return VENDOR_TRANSMETA;
  106. if (!strcmp(vendor, "Geode by NSC")) return VENDOR_NSC;
  107. if ((eax == 0) || ((eax & 0x500) != 0)) return VENDOR_INTEL;
  108. return VENDOR_UNKNOWN;
  109. }
  110. int get_cputype(int gettype){
  111. int eax, ebx, ecx, edx;
  112. int extend_family, family;
  113. int extend_model, model;
  114. int type, stepping;
  115. int feature = 0;
  116. cpuid(1, &eax, &ebx, &ecx, &edx);
  117. switch (gettype) {
  118. case GET_EXFAMILY :
  119. return BITMASK(eax, 20, 0xff);
  120. case GET_EXMODEL :
  121. return BITMASK(eax, 16, 0x0f);
  122. case GET_TYPE :
  123. return BITMASK(eax, 12, 0x03);
  124. case GET_FAMILY :
  125. return BITMASK(eax, 8, 0x0f);
  126. case GET_MODEL :
  127. return BITMASK(eax, 4, 0x0f);
  128. case GET_APICID :
  129. return BITMASK(ebx, 24, 0x0f);
  130. case GET_LCOUNT :
  131. return BITMASK(ebx, 16, 0x0f);
  132. case GET_CHUNKS :
  133. return BITMASK(ebx, 8, 0x0f);
  134. case GET_STEPPING :
  135. return BITMASK(eax, 0, 0x0f);
  136. case GET_BLANDID :
  137. return BITMASK(ebx, 0, 0xff);
  138. case GET_NUMSHARE :
  139. if (have_cpuid() < 4) return 0;
  140. cpuid(4, &eax, &ebx, &ecx, &edx);
  141. return BITMASK(eax, 14, 0xfff);
  142. case GET_NUMCORES :
  143. if (have_cpuid() < 4) return 0;
  144. cpuid(4, &eax, &ebx, &ecx, &edx);
  145. return BITMASK(eax, 26, 0x3f);
  146. case GET_FEATURE :
  147. if ((edx & (1 << 3)) != 0) feature |= HAVE_PSE;
  148. if ((edx & (1 << 15)) != 0) feature |= HAVE_CMOV;
  149. if ((edx & (1 << 19)) != 0) feature |= HAVE_CFLUSH;
  150. if ((edx & (1 << 23)) != 0) feature |= HAVE_MMX;
  151. if ((edx & (1 << 25)) != 0) feature |= HAVE_SSE;
  152. if ((edx & (1 << 26)) != 0) feature |= HAVE_SSE2;
  153. if ((edx & (1 << 27)) != 0) {
  154. if (BITMASK(ebx, 16, 0x0f) > 0) feature |= HAVE_HIT;
  155. }
  156. if ((ecx & (1 << 0)) != 0) feature |= HAVE_SSE3;
  157. if ((ecx & (1 << 9)) != 0) feature |= HAVE_SSSE3;
  158. if ((ecx & (1 << 19)) != 0) feature |= HAVE_SSE4_1;
  159. if ((ecx & (1 << 20)) != 0) feature |= HAVE_SSE4_2;
  160. if (have_excpuid() >= 0x01) {
  161. cpuid(0x80000001, &eax, &ebx, &ecx, &edx);
  162. if ((ecx & (1 << 6)) != 0) feature |= HAVE_SSE4A;
  163. if ((ecx & (1 << 7)) != 0) feature |= HAVE_MISALIGNSSE;
  164. if ((edx & (1 << 30)) != 0) feature |= HAVE_3DNOWEX;
  165. if ((edx & (1 << 31)) != 0) feature |= HAVE_3DNOW;
  166. }
  167. if (have_excpuid() >= 0x1a) {
  168. cpuid(0x8000001a, &eax, &ebx, &ecx, &edx);
  169. if ((eax & (1 << 0)) != 0) feature |= HAVE_128BITFPU;
  170. if ((eax & (1 << 1)) != 0) feature |= HAVE_FASTMOVU;
  171. }
  172. }
  173. return feature;
  174. }
  175. int get_cacheinfo(int type, cache_info_t *cacheinfo){
  176. int eax, ebx, ecx, edx, cpuid_level;
  177. int info[15];
  178. int i;
  179. cache_info_t LC1, LD1, L2, L3,
  180. ITB, DTB, LITB, LDTB,
  181. L2ITB, L2DTB, L2LITB, L2LDTB;
  182. LC1.size = 0; LC1.associative = 0; LC1.linesize = 0; LC1.shared = 0;
  183. LD1.size = 0; LD1.associative = 0; LD1.linesize = 0; LD1.shared = 0;
  184. L2.size = 0; L2.associative = 0; L2.linesize = 0; L2.shared = 0;
  185. L3.size = 0; L3.associative = 0; L3.linesize = 0; L3.shared = 0;
  186. ITB.size = 0; ITB.associative = 0; ITB.linesize = 0; ITB.shared = 0;
  187. DTB.size = 0; DTB.associative = 0; DTB.linesize = 0; DTB.shared = 0;
  188. LITB.size = 0; LITB.associative = 0; LITB.linesize = 0; LITB.shared = 0;
  189. LDTB.size = 0; LDTB.associative = 0; LDTB.linesize = 0; LDTB.shared = 0;
  190. L2ITB.size = 0; L2ITB.associative = 0; L2ITB.linesize = 0; L2ITB.shared = 0;
  191. L2DTB.size = 0; L2DTB.associative = 0; L2DTB.linesize = 0; L2DTB.shared = 0;
  192. L2LITB.size = 0; L2LITB.associative = 0; L2LITB.linesize = 0; L2LITB.shared = 0;
  193. L2LDTB.size = 0; L2LDTB.associative = 0; L2LDTB.linesize = 0; L2LDTB.shared = 0;
  194. cpuid(0, &cpuid_level, &ebx, &ecx, &edx);
  195. if (cpuid_level > 1) {
  196. cpuid(2, &eax, &ebx, &ecx, &edx);
  197. info[ 0] = BITMASK(eax, 8, 0xff);
  198. info[ 1] = BITMASK(eax, 16, 0xff);
  199. info[ 2] = BITMASK(eax, 24, 0xff);
  200. info[ 3] = BITMASK(ebx, 0, 0xff);
  201. info[ 4] = BITMASK(ebx, 8, 0xff);
  202. info[ 5] = BITMASK(ebx, 16, 0xff);
  203. info[ 6] = BITMASK(ebx, 24, 0xff);
  204. info[ 7] = BITMASK(ecx, 0, 0xff);
  205. info[ 8] = BITMASK(ecx, 8, 0xff);
  206. info[ 9] = BITMASK(ecx, 16, 0xff);
  207. info[10] = BITMASK(ecx, 24, 0xff);
  208. info[11] = BITMASK(edx, 0, 0xff);
  209. info[12] = BITMASK(edx, 8, 0xff);
  210. info[13] = BITMASK(edx, 16, 0xff);
  211. info[14] = BITMASK(edx, 24, 0xff);
  212. for (i = 0; i < 15; i++){
  213. switch (info[i]){
  214. /* This table is from http://www.sandpile.org/ia32/cpuid.htm */
  215. case 0x01 :
  216. ITB.size = 4;
  217. ITB.associative = 4;
  218. ITB.linesize = 32;
  219. break;
  220. case 0x02 :
  221. LITB.size = 4096;
  222. LITB.associative = 0;
  223. LITB.linesize = 2;
  224. break;
  225. case 0x03 :
  226. DTB.size = 4;
  227. DTB.associative = 4;
  228. DTB.linesize = 64;
  229. break;
  230. case 0x04 :
  231. LDTB.size = 4096;
  232. LDTB.associative = 4;
  233. LDTB.linesize = 8;
  234. break;
  235. case 0x05 :
  236. LDTB.size = 4096;
  237. LDTB.associative = 4;
  238. LDTB.linesize = 32;
  239. break;
  240. case 0x06 :
  241. LC1.size = 8;
  242. LC1.associative = 4;
  243. LC1.linesize = 32;
  244. break;
  245. case 0x08 :
  246. LC1.size = 16;
  247. LC1.associative = 4;
  248. LC1.linesize = 32;
  249. break;
  250. case 0x09 :
  251. LC1.size = 32;
  252. LC1.associative = 4;
  253. LC1.linesize = 64;
  254. break;
  255. case 0x0a :
  256. LD1.size = 8;
  257. LD1.associative = 2;
  258. LD1.linesize = 32;
  259. break;
  260. case 0x0c :
  261. LD1.size = 16;
  262. LD1.associative = 4;
  263. LD1.linesize = 32;
  264. break;
  265. case 0x0d :
  266. LD1.size = 16;
  267. LD1.associative = 4;
  268. LD1.linesize = 64;
  269. break;
  270. case 0x0e :
  271. LD1.size = 24;
  272. LD1.associative = 6;
  273. LD1.linesize = 64;
  274. break;
  275. case 0x10 :
  276. LD1.size = 16;
  277. LD1.associative = 4;
  278. LD1.linesize = 32;
  279. break;
  280. case 0x15 :
  281. LC1.size = 16;
  282. LC1.associative = 4;
  283. LC1.linesize = 32;
  284. break;
  285. case 0x1a :
  286. L2.size = 96;
  287. L2.associative = 6;
  288. L2.linesize = 64;
  289. break;
  290. case 0x21 :
  291. L2.size = 256;
  292. L2.associative = 8;
  293. L2.linesize = 64;
  294. break;
  295. case 0x22 :
  296. L3.size = 512;
  297. L3.associative = 4;
  298. L3.linesize = 64;
  299. break;
  300. case 0x23 :
  301. L3.size = 1024;
  302. L3.associative = 8;
  303. L3.linesize = 64;
  304. break;
  305. case 0x25 :
  306. L3.size = 2048;
  307. L3.associative = 8;
  308. L3.linesize = 64;
  309. break;
  310. case 0x29 :
  311. L3.size = 4096;
  312. L3.associative = 8;
  313. L3.linesize = 64;
  314. break;
  315. case 0x2c :
  316. LD1.size = 32;
  317. LD1.associative = 8;
  318. LD1.linesize = 64;
  319. break;
  320. case 0x30 :
  321. LC1.size = 32;
  322. LC1.associative = 8;
  323. LC1.linesize = 64;
  324. break;
  325. case 0x39 :
  326. L2.size = 128;
  327. L2.associative = 4;
  328. L2.linesize = 64;
  329. break;
  330. case 0x3a :
  331. L2.size = 192;
  332. L2.associative = 6;
  333. L2.linesize = 64;
  334. break;
  335. case 0x3b :
  336. L2.size = 128;
  337. L2.associative = 2;
  338. L2.linesize = 64;
  339. break;
  340. case 0x3c :
  341. L2.size = 256;
  342. L2.associative = 4;
  343. L2.linesize = 64;
  344. break;
  345. case 0x3d :
  346. L2.size = 384;
  347. L2.associative = 6;
  348. L2.linesize = 64;
  349. break;
  350. case 0x3e :
  351. L2.size = 512;
  352. L2.associative = 4;
  353. L2.linesize = 64;
  354. break;
  355. case 0x41 :
  356. L2.size = 128;
  357. L2.associative = 4;
  358. L2.linesize = 32;
  359. break;
  360. case 0x42 :
  361. L2.size = 256;
  362. L2.associative = 4;
  363. L2.linesize = 32;
  364. break;
  365. case 0x43 :
  366. L2.size = 512;
  367. L2.associative = 4;
  368. L2.linesize = 32;
  369. break;
  370. case 0x44 :
  371. L2.size = 1024;
  372. L2.associative = 4;
  373. L2.linesize = 32;
  374. break;
  375. case 0x45 :
  376. L2.size = 2048;
  377. L2.associative = 4;
  378. L2.linesize = 32;
  379. break;
  380. case 0x46 :
  381. L3.size = 4096;
  382. L3.associative = 4;
  383. L3.linesize = 64;
  384. break;
  385. case 0x47 :
  386. L3.size = 8192;
  387. L3.associative = 8;
  388. L3.linesize = 64;
  389. break;
  390. case 0x48 :
  391. L2.size = 3184;
  392. L2.associative = 12;
  393. L2.linesize = 64;
  394. break;
  395. case 0x49 :
  396. if ((get_cputype(GET_FAMILY) == 0x0f) && (get_cputype(GET_MODEL) == 0x06)) {
  397. L3.size = 4096;
  398. L3.associative = 16;
  399. L3.linesize = 64;
  400. } else {
  401. L2.size = 4096;
  402. L2.associative = 16;
  403. L2.linesize = 64;
  404. }
  405. break;
  406. case 0x4a :
  407. L3.size = 6144;
  408. L3.associative = 12;
  409. L3.linesize = 64;
  410. break;
  411. case 0x4b :
  412. L3.size = 8192;
  413. L3.associative = 16;
  414. L3.linesize = 64;
  415. break;
  416. case 0x4c :
  417. L3.size = 12280;
  418. L3.associative = 12;
  419. L3.linesize = 64;
  420. break;
  421. case 0x4d :
  422. L3.size = 16384;
  423. L3.associative = 16;
  424. L3.linesize = 64;
  425. break;
  426. case 0x4e :
  427. L2.size = 6144;
  428. L2.associative = 24;
  429. L2.linesize = 64;
  430. break;
  431. case 0x4f :
  432. ITB.size = 4;
  433. ITB.associative = 0;
  434. ITB.linesize = 32;
  435. break;
  436. case 0x50 :
  437. ITB.size = 4;
  438. ITB.associative = 0;
  439. ITB.linesize = 64;
  440. LITB.size = 4096;
  441. LITB.associative = 0;
  442. LITB.linesize = 64;
  443. LITB.shared = 1;
  444. break;
  445. case 0x51 :
  446. ITB.size = 4;
  447. ITB.associative = 0;
  448. ITB.linesize = 128;
  449. LITB.size = 4096;
  450. LITB.associative = 0;
  451. LITB.linesize = 128;
  452. LITB.shared = 1;
  453. break;
  454. case 0x52 :
  455. ITB.size = 4;
  456. ITB.associative = 0;
  457. ITB.linesize = 256;
  458. LITB.size = 4096;
  459. LITB.associative = 0;
  460. LITB.linesize = 256;
  461. LITB.shared = 1;
  462. break;
  463. case 0x55 :
  464. LITB.size = 4096;
  465. LITB.associative = 0;
  466. LITB.linesize = 7;
  467. LITB.shared = 1;
  468. break;
  469. case 0x56 :
  470. LDTB.size = 4096;
  471. LDTB.associative = 4;
  472. LDTB.linesize = 16;
  473. break;
  474. case 0x57 :
  475. LDTB.size = 4096;
  476. LDTB.associative = 4;
  477. LDTB.linesize = 16;
  478. break;
  479. case 0x5b :
  480. DTB.size = 4;
  481. DTB.associative = 0;
  482. DTB.linesize = 64;
  483. LDTB.size = 4096;
  484. LDTB.associative = 0;
  485. LDTB.linesize = 64;
  486. LDTB.shared = 1;
  487. break;
  488. case 0x5c :
  489. DTB.size = 4;
  490. DTB.associative = 0;
  491. DTB.linesize = 128;
  492. LDTB.size = 4096;
  493. LDTB.associative = 0;
  494. LDTB.linesize = 128;
  495. LDTB.shared = 1;
  496. break;
  497. case 0x5d :
  498. DTB.size = 4;
  499. DTB.associative = 0;
  500. DTB.linesize = 256;
  501. LDTB.size = 4096;
  502. LDTB.associative = 0;
  503. LDTB.linesize = 256;
  504. LDTB.shared = 1;
  505. break;
  506. case 0x60 :
  507. LD1.size = 16;
  508. LD1.associative = 8;
  509. LD1.linesize = 64;
  510. break;
  511. case 0x66 :
  512. LD1.size = 8;
  513. LD1.associative = 4;
  514. LD1.linesize = 64;
  515. break;
  516. case 0x67 :
  517. LD1.size = 16;
  518. LD1.associative = 4;
  519. LD1.linesize = 64;
  520. break;
  521. case 0x68 :
  522. LD1.size = 32;
  523. LD1.associative = 4;
  524. LD1.linesize = 64;
  525. break;
  526. case 0x70 :
  527. LC1.size = 12;
  528. LC1.associative = 8;
  529. break;
  530. case 0x71 :
  531. LC1.size = 16;
  532. LC1.associative = 8;
  533. break;
  534. case 0x72 :
  535. LC1.size = 32;
  536. LC1.associative = 8;
  537. break;
  538. case 0x73 :
  539. LC1.size = 64;
  540. LC1.associative = 8;
  541. break;
  542. case 0x77 :
  543. LC1.size = 16;
  544. LC1.associative = 4;
  545. LC1.linesize = 64;
  546. break;
  547. case 0x78 :
  548. L2.size = 1024;
  549. L2.associative = 4;
  550. L2.linesize = 64;
  551. break;
  552. case 0x79 :
  553. L2.size = 128;
  554. L2.associative = 8;
  555. L2.linesize = 64;
  556. break;
  557. case 0x7a :
  558. L2.size = 256;
  559. L2.associative = 8;
  560. L2.linesize = 64;
  561. break;
  562. case 0x7b :
  563. L2.size = 512;
  564. L2.associative = 8;
  565. L2.linesize = 64;
  566. break;
  567. case 0x7c :
  568. L2.size = 1024;
  569. L2.associative = 8;
  570. L2.linesize = 64;
  571. break;
  572. case 0x7d :
  573. L2.size = 2048;
  574. L2.associative = 8;
  575. L2.linesize = 64;
  576. break;
  577. case 0x7e :
  578. L2.size = 256;
  579. L2.associative = 8;
  580. L2.linesize = 128;
  581. break;
  582. case 0x7f :
  583. L2.size = 512;
  584. L2.associative = 2;
  585. L2.linesize = 64;
  586. break;
  587. case 0x81 :
  588. L2.size = 128;
  589. L2.associative = 8;
  590. L2.linesize = 32;
  591. break;
  592. case 0x82 :
  593. L2.size = 256;
  594. L2.associative = 8;
  595. L2.linesize = 32;
  596. break;
  597. case 0x83 :
  598. L2.size = 512;
  599. L2.associative = 8;
  600. L2.linesize = 32;
  601. break;
  602. case 0x84 :
  603. L2.size = 1024;
  604. L2.associative = 8;
  605. L2.linesize = 32;
  606. break;
  607. case 0x85 :
  608. L2.size = 2048;
  609. L2.associative = 8;
  610. L2.linesize = 32;
  611. break;
  612. case 0x86 :
  613. L2.size = 512;
  614. L2.associative = 4;
  615. L2.linesize = 64;
  616. break;
  617. case 0x87 :
  618. L2.size = 1024;
  619. L2.associative = 8;
  620. L2.linesize = 64;
  621. break;
  622. case 0x88 :
  623. L3.size = 2048;
  624. L3.associative = 4;
  625. L3.linesize = 64;
  626. break;
  627. case 0x89 :
  628. L3.size = 4096;
  629. L3.associative = 4;
  630. L3.linesize = 64;
  631. break;
  632. case 0x8a :
  633. L3.size = 8192;
  634. L3.associative = 4;
  635. L3.linesize = 64;
  636. break;
  637. case 0x8d :
  638. L3.size = 3096;
  639. L3.associative = 12;
  640. L3.linesize = 128;
  641. break;
  642. case 0x90 :
  643. ITB.size = 4;
  644. ITB.associative = 0;
  645. ITB.linesize = 64;
  646. break;
  647. case 0x96 :
  648. DTB.size = 4;
  649. DTB.associative = 0;
  650. DTB.linesize = 32;
  651. break;
  652. case 0x9b :
  653. L2DTB.size = 4;
  654. L2DTB.associative = 0;
  655. L2DTB.linesize = 96;
  656. break;
  657. case 0xb0 :
  658. ITB.size = 4;
  659. ITB.associative = 4;
  660. ITB.linesize = 128;
  661. break;
  662. case 0xb1 :
  663. LITB.size = 4096;
  664. LITB.associative = 4;
  665. LITB.linesize = 4;
  666. break;
  667. case 0xb2 :
  668. ITB.size = 4;
  669. ITB.associative = 4;
  670. ITB.linesize = 64;
  671. break;
  672. case 0xb3 :
  673. DTB.size = 4;
  674. DTB.associative = 4;
  675. DTB.linesize = 128;
  676. break;
  677. case 0xb4 :
  678. DTB.size = 4;
  679. DTB.associative = 4;
  680. DTB.linesize = 256;
  681. break;
  682. case 0xba :
  683. DTB.size = 4;
  684. DTB.associative = 4;
  685. DTB.linesize = 64;
  686. break;
  687. case 0xd0 :
  688. L3.size = 512;
  689. L3.associative = 4;
  690. L3.linesize = 64;
  691. break;
  692. case 0xd1 :
  693. L3.size = 1024;
  694. L3.associative = 4;
  695. L3.linesize = 64;
  696. break;
  697. case 0xd2 :
  698. L3.size = 2048;
  699. L3.associative = 4;
  700. L3.linesize = 64;
  701. break;
  702. case 0xd6 :
  703. L3.size = 1024;
  704. L3.associative = 8;
  705. L3.linesize = 64;
  706. break;
  707. case 0xd7 :
  708. L3.size = 2048;
  709. L3.associative = 8;
  710. L3.linesize = 64;
  711. break;
  712. case 0xd8 :
  713. L3.size = 4096;
  714. L3.associative = 8;
  715. L3.linesize = 64;
  716. break;
  717. case 0xdc :
  718. L3.size = 2048;
  719. L3.associative = 12;
  720. L3.linesize = 64;
  721. break;
  722. case 0xdd :
  723. L3.size = 4096;
  724. L3.associative = 12;
  725. L3.linesize = 64;
  726. break;
  727. case 0xde :
  728. L3.size = 8192;
  729. L3.associative = 12;
  730. L3.linesize = 64;
  731. break;
  732. case 0xe2 :
  733. L3.size = 2048;
  734. L3.associative = 16;
  735. L3.linesize = 64;
  736. break;
  737. case 0xe3 :
  738. L3.size = 4096;
  739. L3.associative = 16;
  740. L3.linesize = 64;
  741. break;
  742. case 0xe4 :
  743. L3.size = 8192;
  744. L3.associative = 16;
  745. L3.linesize = 64;
  746. break;
  747. }
  748. }
  749. }
  750. if (get_vendor() == VENDOR_INTEL) {
  751. cpuid(0x80000000, &cpuid_level, &ebx, &ecx, &edx);
  752. if (cpuid_level >= 0x80000006) {
  753. cpuid(0x80000006, &eax, &ebx, &ecx, &edx);
  754. L2.size = BITMASK(ecx, 16, 0xffff);
  755. L2.associative = BITMASK(ecx, 12, 0x0f);
  756. L2.linesize = BITMASK(ecx, 0, 0xff);
  757. }
  758. }
  759. if ((get_vendor() == VENDOR_AMD) || (get_vendor() == VENDOR_CENTAUR)) {
  760. cpuid(0x80000005, &eax, &ebx, &ecx, &edx);
  761. LDTB.size = 4096;
  762. LDTB.associative = BITMASK(eax, 24, 0xff);
  763. if (LDTB.associative == 0xff) LDTB.associative = 0;
  764. LDTB.linesize = BITMASK(eax, 16, 0xff);
  765. LITB.size = 4096;
  766. LITB.associative = BITMASK(eax, 8, 0xff);
  767. if (LITB.associative == 0xff) LITB.associative = 0;
  768. LITB.linesize = BITMASK(eax, 0, 0xff);
  769. DTB.size = 4;
  770. DTB.associative = BITMASK(ebx, 24, 0xff);
  771. if (DTB.associative == 0xff) DTB.associative = 0;
  772. DTB.linesize = BITMASK(ebx, 16, 0xff);
  773. ITB.size = 4;
  774. ITB.associative = BITMASK(ebx, 8, 0xff);
  775. if (ITB.associative == 0xff) ITB.associative = 0;
  776. ITB.linesize = BITMASK(ebx, 0, 0xff);
  777. LD1.size = BITMASK(ecx, 24, 0xff);
  778. LD1.associative = BITMASK(ecx, 16, 0xff);
  779. if (LD1.associative == 0xff) LD1.associative = 0;
  780. LD1.linesize = BITMASK(ecx, 0, 0xff);
  781. LC1.size = BITMASK(ecx, 24, 0xff);
  782. LC1.associative = BITMASK(ecx, 16, 0xff);
  783. if (LC1.associative == 0xff) LC1.associative = 0;
  784. LC1.linesize = BITMASK(ecx, 0, 0xff);
  785. cpuid(0x80000006, &eax, &ebx, &ecx, &edx);
  786. L2LDTB.size = 4096;
  787. L2LDTB.associative = BITMASK(eax, 24, 0xff);
  788. if (L2LDTB.associative == 0xff) L2LDTB.associative = 0;
  789. L2LDTB.linesize = BITMASK(eax, 16, 0xff);
  790. L2LITB.size = 4096;
  791. L2LITB.associative = BITMASK(eax, 8, 0xff);
  792. if (L2LITB.associative == 0xff) L2LITB.associative = 0;
  793. L2LITB.linesize = BITMASK(eax, 0, 0xff);
  794. L2DTB.size = 4;
  795. L2DTB.associative = BITMASK(ebx, 24, 0xff);
  796. if (L2DTB.associative == 0xff) L2DTB.associative = 0;
  797. L2DTB.linesize = BITMASK(ebx, 16, 0xff);
  798. L2ITB.size = 4;
  799. L2ITB.associative = BITMASK(ebx, 8, 0xff);
  800. if (L2ITB.associative == 0xff) L2ITB.associative = 0;
  801. L2ITB.linesize = BITMASK(ebx, 0, 0xff);
  802. L2.size = BITMASK(ecx, 16, 0xffff);
  803. L2.associative = BITMASK(ecx, 12, 0xf);
  804. if (L2.associative == 0xff) L2.associative = 0;
  805. L2.linesize = BITMASK(ecx, 0, 0xff);
  806. L3.size = BITMASK(edx, 18, 0x3fff) * 512;
  807. L3.associative = BITMASK(edx, 12, 0xf);
  808. if (L3.associative == 0xff) L2.associative = 0;
  809. L3.linesize = BITMASK(edx, 0, 0xff);
  810. }
  811. switch (type) {
  812. case CACHE_INFO_L1_I :
  813. *cacheinfo = LC1;
  814. break;
  815. case CACHE_INFO_L1_D :
  816. *cacheinfo = LD1;
  817. break;
  818. case CACHE_INFO_L2 :
  819. *cacheinfo = L2;
  820. break;
  821. case CACHE_INFO_L3 :
  822. *cacheinfo = L3;
  823. break;
  824. case CACHE_INFO_L1_DTB :
  825. *cacheinfo = DTB;
  826. break;
  827. case CACHE_INFO_L1_ITB :
  828. *cacheinfo = ITB;
  829. break;
  830. case CACHE_INFO_L1_LDTB :
  831. *cacheinfo = LDTB;
  832. break;
  833. case CACHE_INFO_L1_LITB :
  834. *cacheinfo = LITB;
  835. break;
  836. case CACHE_INFO_L2_DTB :
  837. *cacheinfo = L2DTB;
  838. break;
  839. case CACHE_INFO_L2_ITB :
  840. *cacheinfo = L2ITB;
  841. break;
  842. case CACHE_INFO_L2_LDTB :
  843. *cacheinfo = L2LDTB;
  844. break;
  845. case CACHE_INFO_L2_LITB :
  846. *cacheinfo = L2LITB;
  847. break;
  848. }
  849. return 0;
  850. }
  851. int get_cpuname(void){
  852. int family, exfamily, model, vendor, exmodel;
  853. if (!have_cpuid()) return CPUTYPE_80386;
  854. family = get_cputype(GET_FAMILY);
  855. exfamily = get_cputype(GET_EXFAMILY);
  856. model = get_cputype(GET_MODEL);
  857. exmodel = get_cputype(GET_EXMODEL);
  858. vendor = get_vendor();
  859. if (vendor == VENDOR_INTEL){
  860. switch (family) {
  861. case 0x4:
  862. return CPUTYPE_80486;
  863. case 0x5:
  864. return CPUTYPE_PENTIUM;
  865. case 0x6:
  866. switch (exmodel) {
  867. case 0:
  868. switch (model) {
  869. case 1:
  870. case 3:
  871. case 5:
  872. case 6:
  873. return CPUTYPE_PENTIUM2;
  874. case 7:
  875. case 8:
  876. case 10:
  877. case 11:
  878. return CPUTYPE_PENTIUM3;
  879. case 9:
  880. case 13:
  881. case 14:
  882. return CPUTYPE_PENTIUMM;
  883. case 15:
  884. return CPUTYPE_CORE2;
  885. }
  886. break;
  887. case 1:
  888. switch (model) {
  889. case 6:
  890. return CPUTYPE_CORE2;
  891. case 7:
  892. return CPUTYPE_PENRYN;
  893. case 10:
  894. case 11:
  895. case 14:
  896. case 15:
  897. return CPUTYPE_NEHALEM;
  898. case 12:
  899. return CPUTYPE_ATOM;
  900. case 13:
  901. return CPUTYPE_DUNNINGTON;
  902. }
  903. break;
  904. case 2:
  905. switch (model) {
  906. case 5:
  907. //Intel Core (Clarkdale) / Core (Arrandale)
  908. // Pentium (Clarkdale) / Pentium Mobile (Arrandale)
  909. // Xeon (Clarkdale), 32nm
  910. return CPUTYPE_NEHALEM;
  911. case 12:
  912. //Xeon Processor 5600 (Westmere-EP)
  913. return CPUTYPE_NEHALEM;
  914. }
  915. break;
  916. }
  917. break;
  918. case 0x7:
  919. return CPUTYPE_ITANIUM;
  920. case 0xf:
  921. switch (exfamily) {
  922. case 0 :
  923. return CPUTYPE_PENTIUM4;
  924. case 1 :
  925. return CPUTYPE_ITANIUM;
  926. }
  927. break;
  928. }
  929. return CPUTYPE_INTEL_UNKNOWN;
  930. }
  931. if (vendor == VENDOR_AMD){
  932. switch (family) {
  933. case 0x4:
  934. return CPUTYPE_AMD5X86;
  935. case 0x5:
  936. return CPUTYPE_AMDK6;
  937. case 0x6:
  938. return CPUTYPE_ATHLON;
  939. case 0xf:
  940. switch (exfamily) {
  941. case 0:
  942. case 2:
  943. return CPUTYPE_OPTERON;
  944. case 1:
  945. case 10:
  946. return CPUTYPE_BARCELONA;
  947. }
  948. break;
  949. }
  950. return CPUTYPE_AMD_UNKNOWN;
  951. }
  952. if (vendor == VENDOR_CYRIX){
  953. switch (family) {
  954. case 0x4:
  955. return CPUTYPE_CYRIX5X86;
  956. case 0x5:
  957. return CPUTYPE_CYRIXM1;
  958. case 0x6:
  959. return CPUTYPE_CYRIXM2;
  960. }
  961. return CPUTYPE_CYRIX_UNKNOWN;
  962. }
  963. if (vendor == VENDOR_NEXGEN){
  964. switch (family) {
  965. case 0x5:
  966. return CPUTYPE_NEXGENNX586;
  967. }
  968. return CPUTYPE_NEXGEN_UNKNOWN;
  969. }
  970. if (vendor == VENDOR_CENTAUR){
  971. switch (family) {
  972. case 0x5:
  973. return CPUTYPE_CENTAURC6;
  974. break;
  975. case 0x6:
  976. return CPUTYPE_NANO;
  977. break;
  978. }
  979. return CPUTYPE_VIAC3;
  980. }
  981. if (vendor == VENDOR_RISE){
  982. switch (family) {
  983. case 0x5:
  984. return CPUTYPE_RISEMP6;
  985. }
  986. return CPUTYPE_RISE_UNKNOWN;
  987. }
  988. if (vendor == VENDOR_SIS){
  989. switch (family) {
  990. case 0x5:
  991. return CPUTYPE_SYS55X;
  992. }
  993. return CPUTYPE_SIS_UNKNOWN;
  994. }
  995. if (vendor == VENDOR_TRANSMETA){
  996. switch (family) {
  997. case 0x5:
  998. return CPUTYPE_CRUSOETM3X;
  999. }
  1000. return CPUTYPE_TRANSMETA_UNKNOWN;
  1001. }
  1002. if (vendor == VENDOR_NSC){
  1003. switch (family) {
  1004. case 0x5:
  1005. return CPUTYPE_NSGEODE;
  1006. }
  1007. return CPUTYPE_NSC_UNKNOWN;
  1008. }
  1009. return CPUTYPE_UNKNOWN;
  1010. }
  1011. static char *cpuname[] = {
  1012. "UNKNOWN",
  1013. "INTEL_UNKNOWN",
  1014. "UMC_UNKNOWN",
  1015. "AMD_UNKNOWN",
  1016. "CYRIX_UNKNOWN",
  1017. "NEXGEN_UNKNOWN",
  1018. "CENTAUR_UNKNOWN",
  1019. "RISE_UNKNOWN",
  1020. "SIS_UNKNOWN",
  1021. "TRANSMETA_UNKNOWN",
  1022. "NSC_UNKNOWN",
  1023. "80386",
  1024. "80486",
  1025. "PENTIUM",
  1026. "PENTIUM2",
  1027. "PENTIUM3",
  1028. "PENTIUMM",
  1029. "PENTIUM4",
  1030. "CORE2",
  1031. "PENRYN",
  1032. "DUNNINGTON",
  1033. "NEHALEM",
  1034. "ATOM",
  1035. "ITANIUM",
  1036. "ITANIUM2",
  1037. "5X86",
  1038. "K6",
  1039. "ATHLON",
  1040. "DURON",
  1041. "OPTERON",
  1042. "BARCELONA",
  1043. "SHANGHAI",
  1044. "ISTANBUL",
  1045. "CYRIX5X86",
  1046. "CYRIXM1",
  1047. "CYRIXM2",
  1048. "NEXGENNX586",
  1049. "CENTAURC6",
  1050. "RISEMP6",
  1051. "SYS55X",
  1052. "TM3X00",
  1053. "NSGEODE",
  1054. "VIAC3",
  1055. "NANO",
  1056. };
  1057. static char *lowercpuname[] = {
  1058. "unknown",
  1059. "intel_unknown",
  1060. "umc_unknown",
  1061. "amd_unknown",
  1062. "cyrix_unknown",
  1063. "nexgen_unknown",
  1064. "centaur_unknown",
  1065. "rise_unknown",
  1066. "sis_unknown",
  1067. "transmeta_unknown",
  1068. "nsc_unknown",
  1069. "80386",
  1070. "80486",
  1071. "pentium",
  1072. "pentium2",
  1073. "pentium3",
  1074. "pentiumm",
  1075. "pentium4",
  1076. "core2",
  1077. "penryn",
  1078. "dunnington",
  1079. "nehalem",
  1080. "atom",
  1081. "itanium",
  1082. "itanium2",
  1083. "5x86",
  1084. "k6",
  1085. "athlon",
  1086. "duron",
  1087. "opteron",
  1088. "barcelona",
  1089. "shanghai",
  1090. "istanbul",
  1091. "cyrix5x86",
  1092. "cyrixm1",
  1093. "cyrixm2",
  1094. "nexgennx586",
  1095. "centaurc6",
  1096. "risemp6",
  1097. "sys55x",
  1098. "tms3x00",
  1099. "nsgeode",
  1100. "nano",
  1101. };
  1102. static char *corename[] = {
  1103. "UNKOWN",
  1104. "80486",
  1105. "P5",
  1106. "P6",
  1107. "KATMAI",
  1108. "COPPERMINE",
  1109. "NORTHWOOD",
  1110. "PRESCOTT",
  1111. "BANIAS",
  1112. "ATHLON",
  1113. "OPTERON",
  1114. "BARCELONA",
  1115. "VIAC3",
  1116. "YONAH",
  1117. "CORE2",
  1118. "PENRYN",
  1119. "DUNNINGTON",
  1120. "NEHALEM",
  1121. "ATOM",
  1122. "NANO",
  1123. };
  1124. static char *corename_lower[] = {
  1125. "unknown",
  1126. "80486",
  1127. "p5",
  1128. "p6",
  1129. "katmai",
  1130. "coppermine",
  1131. "northwood",
  1132. "prescott",
  1133. "banias",
  1134. "athlon",
  1135. "opteron",
  1136. "barcelona",
  1137. "viac3",
  1138. "yonah",
  1139. "core2",
  1140. "penryn",
  1141. "dunnington",
  1142. "nehalem",
  1143. "atom",
  1144. "nano",
  1145. };
  1146. char *get_cpunamechar(void){
  1147. return cpuname[get_cpuname()];
  1148. }
  1149. char *get_lower_cpunamechar(void){
  1150. return lowercpuname[get_cpuname()];
  1151. }
  1152. int get_coretype(void){
  1153. int family, exfamily, model, exmodel, vendor;
  1154. if (!have_cpuid()) return CORE_80486;
  1155. family = get_cputype(GET_FAMILY);
  1156. exfamily = get_cputype(GET_EXFAMILY);
  1157. model = get_cputype(GET_MODEL);
  1158. exmodel = get_cputype(GET_EXMODEL);
  1159. vendor = get_vendor();
  1160. if (vendor == VENDOR_INTEL){
  1161. switch (family) {
  1162. case 4:
  1163. return CORE_80486;
  1164. case 5:
  1165. return CORE_P5;
  1166. case 6:
  1167. switch (exmodel) {
  1168. case 0:
  1169. switch (model) {
  1170. case 0:
  1171. case 1:
  1172. case 2:
  1173. case 3:
  1174. case 4:
  1175. case 5:
  1176. case 6:
  1177. return CORE_P6;
  1178. case 7:
  1179. return CORE_KATMAI;
  1180. case 8:
  1181. case 10:
  1182. case 11:
  1183. return CORE_COPPERMINE;
  1184. case 9:
  1185. case 13:
  1186. case 14:
  1187. return CORE_BANIAS;
  1188. case 15:
  1189. return CORE_CORE2;
  1190. }
  1191. break;
  1192. case 1:
  1193. switch (model) {
  1194. case 6:
  1195. return CORE_CORE2;
  1196. case 7:
  1197. return CORE_PENRYN;
  1198. case 10:
  1199. case 11:
  1200. case 14:
  1201. case 15:
  1202. return CORE_NEHALEM;
  1203. case 12:
  1204. return CORE_ATOM;
  1205. case 13:
  1206. return CORE_DUNNINGTON;
  1207. }
  1208. break;
  1209. case 2:
  1210. switch (model) {
  1211. case 12:
  1212. //Xeon Processor 5600 (Westmere-EP)
  1213. return CORE_NEHALEM;
  1214. }
  1215. break;
  1216. }
  1217. case 15:
  1218. if (model <= 0x2) return CORE_NORTHWOOD;
  1219. return CORE_PRESCOTT;
  1220. }
  1221. }
  1222. if (vendor == VENDOR_AMD){
  1223. if (family <= 0x5) return CORE_80486;
  1224. if (family <= 0xe) return CORE_ATHLON;
  1225. if (family == 0xf){
  1226. if ((exfamily == 0) || (exfamily == 2)) return CORE_OPTERON; else return CORE_BARCELONA;
  1227. }
  1228. }
  1229. if (vendor == VENDOR_CENTAUR) {
  1230. switch (family) {
  1231. case 0x6:
  1232. return CORE_NANO;
  1233. break;
  1234. }
  1235. return CORE_VIAC3;
  1236. }
  1237. return CORE_UNKNOWN;
  1238. }
  1239. void get_cpuconfig(void){
  1240. cache_info_t info;
  1241. int features;
  1242. printf("#define %s\n", cpuname[get_cpuname()]);
  1243. if (get_coretype() != CORE_P5) {
  1244. get_cacheinfo(CACHE_INFO_L1_I, &info);
  1245. if (info.size > 0) {
  1246. printf("#define L1_CODE_SIZE %d\n", info.size * 1024);
  1247. printf("#define L1_CODE_ASSOCIATIVE %d\n", info.associative);
  1248. printf("#define L1_CODE_LINESIZE %d\n", info.linesize);
  1249. }
  1250. get_cacheinfo(CACHE_INFO_L1_D, &info);
  1251. if (info.size > 0) {
  1252. printf("#define L1_DATA_SIZE %d\n", info.size * 1024);
  1253. printf("#define L1_DATA_ASSOCIATIVE %d\n", info.associative);
  1254. printf("#define L1_DATA_LINESIZE %d\n", info.linesize);
  1255. }
  1256. get_cacheinfo(CACHE_INFO_L2, &info);
  1257. if (info.size > 0) {
  1258. printf("#define L2_SIZE %d\n", info.size * 1024);
  1259. printf("#define L2_ASSOCIATIVE %d\n", info.associative);
  1260. printf("#define L2_LINESIZE %d\n", info.linesize);
  1261. }
  1262. get_cacheinfo(CACHE_INFO_L3, &info);
  1263. if (info.size > 0) {
  1264. printf("#define L3_SIZE %d\n", info.size * 1024);
  1265. printf("#define L3_ASSOCIATIVE %d\n", info.associative);
  1266. printf("#define L3_LINESIZE %d\n", info.linesize);
  1267. }
  1268. get_cacheinfo(CACHE_INFO_L1_ITB, &info);
  1269. if (info.size > 0) {
  1270. printf("#define ITB_SIZE %d\n", info.size * 1024);
  1271. printf("#define ITB_ASSOCIATIVE %d\n", info.associative);
  1272. printf("#define ITB_ENTRIES %d\n", info.linesize);
  1273. }
  1274. get_cacheinfo(CACHE_INFO_L1_DTB, &info);
  1275. if (info.size > 0) {
  1276. printf("#define DTB_SIZE %d\n", info.size * 1024);
  1277. printf("#define DTB_ASSOCIATIVE %d\n", info.associative);
  1278. printf("#define DTB_ENTRIES %d\n", info.linesize);
  1279. }
  1280. features = get_cputype(GET_FEATURE);
  1281. if (features & HAVE_CMOV ) printf("#define HAVE_CMOV\n");
  1282. if (features & HAVE_MMX ) printf("#define HAVE_MMX\n");
  1283. if (features & HAVE_SSE ) printf("#define HAVE_SSE\n");
  1284. if (features & HAVE_SSE2 ) printf("#define HAVE_SSE2\n");
  1285. if (features & HAVE_SSE3 ) printf("#define HAVE_SSE3\n");
  1286. if (features & HAVE_SSSE3) printf("#define HAVE_SSSE3\n");
  1287. if (features & HAVE_SSE4_1) printf("#define HAVE_SSE4_1\n");
  1288. if (features & HAVE_SSE4_2) printf("#define HAVE_SSE4_2\n");
  1289. if (features & HAVE_SSE4A) printf("#define HAVE_SSE4A\n");
  1290. if (features & HAVE_SSE5 ) printf("#define HAVE_SSSE5\n");
  1291. if (features & HAVE_3DNOWEX) printf("#define HAVE_3DNOWEX\n");
  1292. if (features & HAVE_3DNOW) printf("#define HAVE_3DNOW\n");
  1293. if (features & HAVE_CFLUSH) printf("#define HAVE_CFLUSH\n");
  1294. if (features & HAVE_HIT) printf("#define HAVE_HIT 1\n");
  1295. if (features & HAVE_MISALIGNSSE) printf("#define HAVE_MISALIGNSSE\n");
  1296. if (features & HAVE_128BITFPU) printf("#define HAVE_128BITFPU\n");
  1297. if (features & HAVE_FASTMOVU) printf("#define HAVE_FASTMOVU\n");
  1298. printf("#define NUM_SHAREDCACHE %d\n", get_cputype(GET_NUMSHARE) + 1);
  1299. printf("#define NUM_CORES %d\n", get_cputype(GET_NUMCORES) + 1);
  1300. features = get_coretype();
  1301. if (features > 0) printf("#define CORE_%s\n", corename[features]);
  1302. } else {
  1303. printf("#define DTB_ENTRIES 16\n");
  1304. printf("#define L1_CODE_SIZE 8192\n");
  1305. printf("#define L1_DATA_SIZE 8192\n");
  1306. printf("#define L2_SIZE 0\n");
  1307. }
  1308. }
  1309. void get_architecture(void){
  1310. #ifndef __64BIT__
  1311. printf("X86");
  1312. #else
  1313. printf("X86_64");
  1314. #endif
  1315. }
  1316. void get_subarchitecture(void){
  1317. printf("%s", get_cpunamechar());
  1318. }
  1319. void get_subdirname(void){
  1320. #ifndef __64BIT__
  1321. printf("x86");
  1322. #else
  1323. printf("x86_64");
  1324. #endif
  1325. }
  1326. char *get_corename(void){
  1327. return corename[get_coretype()];
  1328. }
  1329. void get_libname(void){
  1330. printf("%s", corename_lower[get_coretype()]);
  1331. }
  1332. /* This if for Makefile */
  1333. void get_sse(void){
  1334. int features;
  1335. features = get_cputype(GET_FEATURE);
  1336. if (features & HAVE_MMX ) printf("HAVE_MMX=1\n");
  1337. if (features & HAVE_SSE ) printf("HAVE_SSE=1\n");
  1338. if (features & HAVE_SSE2 ) printf("HAVE_SSE2=1\n");
  1339. if (features & HAVE_SSE3 ) printf("HAVE_SSE3=1\n");
  1340. if (features & HAVE_SSSE3) printf("HAVE_SSSE3=1\n");
  1341. if (features & HAVE_SSE4_1) printf("HAVE_SSE4_1=1\n");
  1342. if (features & HAVE_SSE4_2) printf("HAVE_SSE4_2=1\n");
  1343. if (features & HAVE_SSE4A) printf("HAVE_SSE4A=1\n");
  1344. if (features & HAVE_SSE5 ) printf("HAVE_SSSE5=1\n");
  1345. if (features & HAVE_3DNOWEX) printf("HAVE_3DNOWEX=1\n");
  1346. if (features & HAVE_3DNOW) printf("HAVE_3DNOW=1\n");
  1347. }

OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version.