You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

cpuid_x86.c 50 kB

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