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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453
  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. break;
  903. }
  904. }
  905. break;
  906. case 0x7:
  907. return CPUTYPE_ITANIUM;
  908. case 0xf:
  909. switch (exfamily) {
  910. case 0 :
  911. return CPUTYPE_PENTIUM4;
  912. case 1 :
  913. return CPUTYPE_ITANIUM;
  914. }
  915. break;
  916. }
  917. return CPUTYPE_INTEL_UNKNOWN;
  918. }
  919. if (vendor == VENDOR_AMD){
  920. switch (family) {
  921. case 0x4:
  922. return CPUTYPE_AMD5X86;
  923. case 0x5:
  924. return CPUTYPE_AMDK6;
  925. case 0x6:
  926. return CPUTYPE_ATHLON;
  927. case 0xf:
  928. switch (exfamily) {
  929. case 0:
  930. case 2:
  931. return CPUTYPE_OPTERON;
  932. case 1:
  933. case 10:
  934. return CPUTYPE_BARCELONA;
  935. }
  936. break;
  937. }
  938. return CPUTYPE_AMD_UNKNOWN;
  939. }
  940. if (vendor == VENDOR_CYRIX){
  941. switch (family) {
  942. case 0x4:
  943. return CPUTYPE_CYRIX5X86;
  944. case 0x5:
  945. return CPUTYPE_CYRIXM1;
  946. case 0x6:
  947. return CPUTYPE_CYRIXM2;
  948. }
  949. return CPUTYPE_CYRIX_UNKNOWN;
  950. }
  951. if (vendor == VENDOR_NEXGEN){
  952. switch (family) {
  953. case 0x5:
  954. return CPUTYPE_NEXGENNX586;
  955. }
  956. return CPUTYPE_NEXGEN_UNKNOWN;
  957. }
  958. if (vendor == VENDOR_CENTAUR){
  959. switch (family) {
  960. case 0x5:
  961. return CPUTYPE_CENTAURC6;
  962. break;
  963. case 0x6:
  964. return CPUTYPE_NANO;
  965. break;
  966. }
  967. return CPUTYPE_VIAC3;
  968. }
  969. if (vendor == VENDOR_RISE){
  970. switch (family) {
  971. case 0x5:
  972. return CPUTYPE_RISEMP6;
  973. }
  974. return CPUTYPE_RISE_UNKNOWN;
  975. }
  976. if (vendor == VENDOR_SIS){
  977. switch (family) {
  978. case 0x5:
  979. return CPUTYPE_SYS55X;
  980. }
  981. return CPUTYPE_SIS_UNKNOWN;
  982. }
  983. if (vendor == VENDOR_TRANSMETA){
  984. switch (family) {
  985. case 0x5:
  986. return CPUTYPE_CRUSOETM3X;
  987. }
  988. return CPUTYPE_TRANSMETA_UNKNOWN;
  989. }
  990. if (vendor == VENDOR_NSC){
  991. switch (family) {
  992. case 0x5:
  993. return CPUTYPE_NSGEODE;
  994. }
  995. return CPUTYPE_NSC_UNKNOWN;
  996. }
  997. return CPUTYPE_UNKNOWN;
  998. }
  999. static char *cpuname[] = {
  1000. "UNKNOWN",
  1001. "INTEL_UNKNOWN",
  1002. "UMC_UNKNOWN",
  1003. "AMD_UNKNOWN",
  1004. "CYRIX_UNKNOWN",
  1005. "NEXGEN_UNKNOWN",
  1006. "CENTAUR_UNKNOWN",
  1007. "RISE_UNKNOWN",
  1008. "SIS_UNKNOWN",
  1009. "TRANSMETA_UNKNOWN",
  1010. "NSC_UNKNOWN",
  1011. "80386",
  1012. "80486",
  1013. "PENTIUM",
  1014. "PENTIUM2",
  1015. "PENTIUM3",
  1016. "PENTIUMM",
  1017. "PENTIUM4",
  1018. "CORE2",
  1019. "PENRYN",
  1020. "DUNNINGTON",
  1021. "NEHALEM",
  1022. "ATOM",
  1023. "ITANIUM",
  1024. "ITANIUM2",
  1025. "5X86",
  1026. "K6",
  1027. "ATHLON",
  1028. "DURON",
  1029. "OPTERON",
  1030. "BARCELONA",
  1031. "SHANGHAI",
  1032. "ISTANBUL",
  1033. "CYRIX5X86",
  1034. "CYRIXM1",
  1035. "CYRIXM2",
  1036. "NEXGENNX586",
  1037. "CENTAURC6",
  1038. "RISEMP6",
  1039. "SYS55X",
  1040. "TM3X00",
  1041. "NSGEODE",
  1042. "VIAC3",
  1043. "NANO",
  1044. };
  1045. static char *lowercpuname[] = {
  1046. "unknown",
  1047. "intel_unknown",
  1048. "umc_unknown",
  1049. "amd_unknown",
  1050. "cyrix_unknown",
  1051. "nexgen_unknown",
  1052. "centaur_unknown",
  1053. "rise_unknown",
  1054. "sis_unknown",
  1055. "transmeta_unknown",
  1056. "nsc_unknown",
  1057. "80386",
  1058. "80486",
  1059. "pentium",
  1060. "pentium2",
  1061. "pentium3",
  1062. "pentiumm",
  1063. "pentium4",
  1064. "core2",
  1065. "penryn",
  1066. "dunnington",
  1067. "nehalem",
  1068. "atom",
  1069. "itanium",
  1070. "itanium2",
  1071. "5x86",
  1072. "k6",
  1073. "athlon",
  1074. "duron",
  1075. "opteron",
  1076. "barcelona",
  1077. "shanghai",
  1078. "istanbul",
  1079. "cyrix5x86",
  1080. "cyrixm1",
  1081. "cyrixm2",
  1082. "nexgennx586",
  1083. "centaurc6",
  1084. "risemp6",
  1085. "sys55x",
  1086. "tms3x00",
  1087. "nsgeode",
  1088. "nano",
  1089. };
  1090. static char *corename[] = {
  1091. "UNKOWN",
  1092. "80486",
  1093. "P5",
  1094. "P6",
  1095. "KATMAI",
  1096. "COPPERMINE",
  1097. "NORTHWOOD",
  1098. "PRESCOTT",
  1099. "BANIAS",
  1100. "ATHLON",
  1101. "OPTERON",
  1102. "BARCELONA",
  1103. "VIAC3",
  1104. "YONAH",
  1105. "CORE2",
  1106. "PENRYN",
  1107. "DUNNINGTON",
  1108. "NEHALEM",
  1109. "ATOM",
  1110. "NANO",
  1111. };
  1112. static char *corename_lower[] = {
  1113. "unknown",
  1114. "80486",
  1115. "p5",
  1116. "p6",
  1117. "katmai",
  1118. "coppermine",
  1119. "northwood",
  1120. "prescott",
  1121. "banias",
  1122. "athlon",
  1123. "opteron",
  1124. "barcelona",
  1125. "viac3",
  1126. "yonah",
  1127. "core2",
  1128. "penryn",
  1129. "dunnington",
  1130. "nehalem",
  1131. "atom",
  1132. "nano",
  1133. };
  1134. char *get_cpunamechar(void){
  1135. return cpuname[get_cpuname()];
  1136. }
  1137. char *get_lower_cpunamechar(void){
  1138. return lowercpuname[get_cpuname()];
  1139. }
  1140. int get_coretype(void){
  1141. int family, exfamily, model, exmodel, vendor;
  1142. if (!have_cpuid()) return CORE_80486;
  1143. family = get_cputype(GET_FAMILY);
  1144. exfamily = get_cputype(GET_EXFAMILY);
  1145. model = get_cputype(GET_MODEL);
  1146. exmodel = get_cputype(GET_EXMODEL);
  1147. vendor = get_vendor();
  1148. if (vendor == VENDOR_INTEL){
  1149. switch (family) {
  1150. case 4:
  1151. return CORE_80486;
  1152. case 5:
  1153. return CORE_P5;
  1154. case 6:
  1155. switch (exmodel) {
  1156. case 0:
  1157. switch (model) {
  1158. case 0:
  1159. case 1:
  1160. case 2:
  1161. case 3:
  1162. case 4:
  1163. case 5:
  1164. case 6:
  1165. return CORE_P6;
  1166. case 7:
  1167. return CORE_KATMAI;
  1168. case 8:
  1169. case 10:
  1170. case 11:
  1171. return CORE_COPPERMINE;
  1172. case 9:
  1173. case 13:
  1174. case 14:
  1175. return CORE_BANIAS;
  1176. case 15:
  1177. return CORE_CORE2;
  1178. }
  1179. break;
  1180. case 1:
  1181. switch (model) {
  1182. case 6:
  1183. return CORE_CORE2;
  1184. case 7:
  1185. return CORE_PENRYN;
  1186. case 10:
  1187. case 11:
  1188. case 14:
  1189. case 15:
  1190. return CORE_NEHALEM;
  1191. case 12:
  1192. return CORE_ATOM;
  1193. case 13:
  1194. return CORE_DUNNINGTON;
  1195. break;
  1196. }
  1197. }
  1198. case 15:
  1199. if (model <= 0x2) return CORE_NORTHWOOD;
  1200. return CORE_PRESCOTT;
  1201. }
  1202. }
  1203. if (vendor == VENDOR_AMD){
  1204. if (family <= 0x5) return CORE_80486;
  1205. if (family <= 0xe) return CORE_ATHLON;
  1206. if (family == 0xf){
  1207. if ((exfamily == 0) || (exfamily == 2)) return CORE_OPTERON; else return CORE_BARCELONA;
  1208. }
  1209. }
  1210. if (vendor == VENDOR_CENTAUR) {
  1211. switch (family) {
  1212. case 0x6:
  1213. return CORE_NANO;
  1214. break;
  1215. }
  1216. return CORE_VIAC3;
  1217. }
  1218. return CORE_UNKNOWN;
  1219. }
  1220. void get_cpuconfig(void){
  1221. cache_info_t info;
  1222. int features;
  1223. printf("#define %s\n", cpuname[get_cpuname()]);
  1224. if (get_coretype() != CORE_P5) {
  1225. get_cacheinfo(CACHE_INFO_L1_I, &info);
  1226. if (info.size > 0) {
  1227. printf("#define L1_CODE_SIZE %d\n", info.size * 1024);
  1228. printf("#define L1_CODE_ASSOCIATIVE %d\n", info.associative);
  1229. printf("#define L1_CODE_LINESIZE %d\n", info.linesize);
  1230. }
  1231. get_cacheinfo(CACHE_INFO_L1_D, &info);
  1232. if (info.size > 0) {
  1233. printf("#define L1_DATA_SIZE %d\n", info.size * 1024);
  1234. printf("#define L1_DATA_ASSOCIATIVE %d\n", info.associative);
  1235. printf("#define L1_DATA_LINESIZE %d\n", info.linesize);
  1236. }
  1237. get_cacheinfo(CACHE_INFO_L2, &info);
  1238. if (info.size > 0) {
  1239. printf("#define L2_SIZE %d\n", info.size * 1024);
  1240. printf("#define L2_ASSOCIATIVE %d\n", info.associative);
  1241. printf("#define L2_LINESIZE %d\n", info.linesize);
  1242. }
  1243. get_cacheinfo(CACHE_INFO_L3, &info);
  1244. if (info.size > 0) {
  1245. printf("#define L3_SIZE %d\n", info.size * 1024);
  1246. printf("#define L3_ASSOCIATIVE %d\n", info.associative);
  1247. printf("#define L3_LINESIZE %d\n", info.linesize);
  1248. }
  1249. get_cacheinfo(CACHE_INFO_L1_ITB, &info);
  1250. if (info.size > 0) {
  1251. printf("#define ITB_SIZE %d\n", info.size * 1024);
  1252. printf("#define ITB_ASSOCIATIVE %d\n", info.associative);
  1253. printf("#define ITB_ENTRIES %d\n", info.linesize);
  1254. }
  1255. get_cacheinfo(CACHE_INFO_L1_DTB, &info);
  1256. if (info.size > 0) {
  1257. printf("#define DTB_SIZE %d\n", info.size * 1024);
  1258. printf("#define DTB_ASSOCIATIVE %d\n", info.associative);
  1259. printf("#define DTB_ENTRIES %d\n", info.linesize);
  1260. }
  1261. features = get_cputype(GET_FEATURE);
  1262. if (features & HAVE_CMOV ) printf("#define HAVE_CMOV\n");
  1263. if (features & HAVE_MMX ) printf("#define HAVE_MMX\n");
  1264. if (features & HAVE_SSE ) printf("#define HAVE_SSE\n");
  1265. if (features & HAVE_SSE2 ) printf("#define HAVE_SSE2\n");
  1266. if (features & HAVE_SSE3 ) printf("#define HAVE_SSE3\n");
  1267. if (features & HAVE_SSSE3) printf("#define HAVE_SSSE3\n");
  1268. if (features & HAVE_SSE4_1) printf("#define HAVE_SSE4_1\n");
  1269. if (features & HAVE_SSE4_2) printf("#define HAVE_SSE4_2\n");
  1270. if (features & HAVE_SSE4A) printf("#define HAVE_SSE4A\n");
  1271. if (features & HAVE_SSE5 ) printf("#define HAVE_SSSE5\n");
  1272. if (features & HAVE_3DNOWEX) printf("#define HAVE_3DNOWEX\n");
  1273. if (features & HAVE_3DNOW) printf("#define HAVE_3DNOW\n");
  1274. if (features & HAVE_CFLUSH) printf("#define HAVE_CFLUSH\n");
  1275. if (features & HAVE_HIT) printf("#define HAVE_HIT 1\n");
  1276. if (features & HAVE_MISALIGNSSE) printf("#define HAVE_MISALIGNSSE\n");
  1277. if (features & HAVE_128BITFPU) printf("#define HAVE_128BITFPU\n");
  1278. if (features & HAVE_FASTMOVU) printf("#define HAVE_FASTMOVU\n");
  1279. printf("#define NUM_SHAREDCACHE %d\n", get_cputype(GET_NUMSHARE) + 1);
  1280. printf("#define NUM_CORES %d\n", get_cputype(GET_NUMCORES) + 1);
  1281. features = get_coretype();
  1282. if (features > 0) printf("#define CORE_%s\n", corename[features]);
  1283. } else {
  1284. printf("#define DTB_ENTRIES 16\n");
  1285. printf("#define L1_CODE_SIZE 8192\n");
  1286. printf("#define L1_DATA_SIZE 8192\n");
  1287. printf("#define L2_SIZE 0\n");
  1288. }
  1289. }
  1290. void get_architecture(void){
  1291. #ifndef __64BIT__
  1292. printf("X86");
  1293. #else
  1294. printf("X86_64");
  1295. #endif
  1296. }
  1297. void get_subarchitecture(void){
  1298. printf("%s", get_cpunamechar());
  1299. }
  1300. void get_subdirname(void){
  1301. #ifndef __64BIT__
  1302. printf("x86");
  1303. #else
  1304. printf("x86_64");
  1305. #endif
  1306. }
  1307. char *get_corename(void){
  1308. return corename[get_coretype()];
  1309. }
  1310. void get_libname(void){
  1311. printf("%s", corename_lower[get_coretype()]);
  1312. }
  1313. /* This if for Makefile */
  1314. void get_sse(void){
  1315. int features;
  1316. features = get_cputype(GET_FEATURE);
  1317. if (features & HAVE_MMX ) printf("HAVE_MMX=1\n");
  1318. if (features & HAVE_SSE ) printf("HAVE_SSE=1\n");
  1319. if (features & HAVE_SSE2 ) printf("HAVE_SSE2=1\n");
  1320. if (features & HAVE_SSE3 ) printf("HAVE_SSE3=1\n");
  1321. if (features & HAVE_SSSE3) printf("HAVE_SSSE3=1\n");
  1322. if (features & HAVE_SSE4_1) printf("HAVE_SSE4_1=1\n");
  1323. if (features & HAVE_SSE4_2) printf("HAVE_SSE4_2=1\n");
  1324. if (features & HAVE_SSE4A) printf("HAVE_SSE4A=1\n");
  1325. if (features & HAVE_SSE5 ) printf("HAVE_SSSE5=1\n");
  1326. if (features & HAVE_3DNOWEX) printf("HAVE_3DNOWEX=1\n");
  1327. if (features & HAVE_3DNOW) printf("HAVE_3DNOW=1\n");
  1328. }

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

Contributors (1)