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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186
  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. if(support_avx())
  1898. #ifndef NO_AVX2
  1899. return CORE_ZEN;
  1900. #else
  1901. return CORE_SANDYBRIDGE; // Zen is closer in architecture to Sandy Bridge than to Excavator
  1902. #endif
  1903. else
  1904. return CORE_BARCELONA;
  1905. }
  1906. } else {
  1907. return CORE_BARCELONA;
  1908. }
  1909. }
  1910. }
  1911. if (vendor == VENDOR_CENTAUR) {
  1912. switch (family) {
  1913. case 0x6:
  1914. return CORE_NANO;
  1915. break;
  1916. }
  1917. return CORE_VIAC3;
  1918. }
  1919. return CORE_UNKNOWN;
  1920. }
  1921. void get_cpuconfig(void){
  1922. cache_info_t info;
  1923. int features;
  1924. printf("#define %s\n", cpuname[get_cpuname()]);
  1925. if (get_coretype() != CORE_P5) {
  1926. get_cacheinfo(CACHE_INFO_L1_I, &info);
  1927. if (info.size > 0) {
  1928. printf("#define L1_CODE_SIZE %d\n", info.size * 1024);
  1929. printf("#define L1_CODE_ASSOCIATIVE %d\n", info.associative);
  1930. printf("#define L1_CODE_LINESIZE %d\n", info.linesize);
  1931. }
  1932. get_cacheinfo(CACHE_INFO_L1_D, &info);
  1933. if (info.size > 0) {
  1934. printf("#define L1_DATA_SIZE %d\n", info.size * 1024);
  1935. printf("#define L1_DATA_ASSOCIATIVE %d\n", info.associative);
  1936. printf("#define L1_DATA_LINESIZE %d\n", info.linesize);
  1937. }
  1938. get_cacheinfo(CACHE_INFO_L2, &info);
  1939. if (info.size > 0) {
  1940. printf("#define L2_SIZE %d\n", info.size * 1024);
  1941. printf("#define L2_ASSOCIATIVE %d\n", info.associative);
  1942. printf("#define L2_LINESIZE %d\n", info.linesize);
  1943. } else {
  1944. //fall back for some virtual machines.
  1945. printf("#define L2_SIZE 1048576\n");
  1946. printf("#define L2_ASSOCIATIVE 6\n");
  1947. printf("#define L2_LINESIZE 64\n");
  1948. }
  1949. get_cacheinfo(CACHE_INFO_L3, &info);
  1950. if (info.size > 0) {
  1951. printf("#define L3_SIZE %d\n", info.size * 1024);
  1952. printf("#define L3_ASSOCIATIVE %d\n", info.associative);
  1953. printf("#define L3_LINESIZE %d\n", info.linesize);
  1954. }
  1955. get_cacheinfo(CACHE_INFO_L1_ITB, &info);
  1956. if (info.size > 0) {
  1957. printf("#define ITB_SIZE %d\n", info.size * 1024);
  1958. printf("#define ITB_ASSOCIATIVE %d\n", info.associative);
  1959. printf("#define ITB_ENTRIES %d\n", info.linesize);
  1960. }
  1961. get_cacheinfo(CACHE_INFO_L1_DTB, &info);
  1962. if (info.size > 0) {
  1963. printf("#define DTB_SIZE %d\n", info.size * 1024);
  1964. printf("#define DTB_ASSOCIATIVE %d\n", info.associative);
  1965. printf("#define DTB_DEFAULT_ENTRIES %d\n", info.linesize);
  1966. } else {
  1967. //fall back for some virtual machines.
  1968. printf("#define DTB_DEFAULT_ENTRIES 32\n");
  1969. }
  1970. features = get_cputype(GET_FEATURE);
  1971. if (features & HAVE_CMOV ) printf("#define HAVE_CMOV\n");
  1972. if (features & HAVE_MMX ) printf("#define HAVE_MMX\n");
  1973. if (features & HAVE_SSE ) printf("#define HAVE_SSE\n");
  1974. if (features & HAVE_SSE2 ) printf("#define HAVE_SSE2\n");
  1975. if (features & HAVE_SSE3 ) printf("#define HAVE_SSE3\n");
  1976. if (features & HAVE_SSSE3) printf("#define HAVE_SSSE3\n");
  1977. if (features & HAVE_SSE4_1) printf("#define HAVE_SSE4_1\n");
  1978. if (features & HAVE_SSE4_2) printf("#define HAVE_SSE4_2\n");
  1979. if (features & HAVE_SSE4A) printf("#define HAVE_SSE4A\n");
  1980. if (features & HAVE_SSE5 ) printf("#define HAVE_SSSE5\n");
  1981. if (features & HAVE_AVX ) printf("#define HAVE_AVX\n");
  1982. if (features & HAVE_3DNOWEX) printf("#define HAVE_3DNOWEX\n");
  1983. if (features & HAVE_3DNOW) printf("#define HAVE_3DNOW\n");
  1984. if (features & HAVE_FMA4 ) printf("#define HAVE_FMA4\n");
  1985. if (features & HAVE_FMA3 ) printf("#define HAVE_FMA3\n");
  1986. if (features & HAVE_CFLUSH) printf("#define HAVE_CFLUSH\n");
  1987. if (features & HAVE_HIT) printf("#define HAVE_HIT 1\n");
  1988. if (features & HAVE_MISALIGNSSE) printf("#define HAVE_MISALIGNSSE\n");
  1989. if (features & HAVE_128BITFPU) printf("#define HAVE_128BITFPU\n");
  1990. if (features & HAVE_FASTMOVU) printf("#define HAVE_FASTMOVU\n");
  1991. printf("#define NUM_SHAREDCACHE %d\n", get_cputype(GET_NUMSHARE) + 1);
  1992. printf("#define NUM_CORES %d\n", get_cputype(GET_NUMCORES) + 1);
  1993. features = get_coretype();
  1994. if (features > 0) printf("#define CORE_%s\n", corename[features]);
  1995. } else {
  1996. printf("#define DTB_DEFAULT_ENTRIES 16\n");
  1997. printf("#define L1_CODE_SIZE 8192\n");
  1998. printf("#define L1_DATA_SIZE 8192\n");
  1999. printf("#define L2_SIZE 0\n");
  2000. }
  2001. }
  2002. void get_architecture(void){
  2003. #ifndef __64BIT__
  2004. printf("X86");
  2005. #else
  2006. printf("X86_64");
  2007. #endif
  2008. }
  2009. void get_subarchitecture(void){
  2010. printf("%s", get_cpunamechar());
  2011. }
  2012. void get_subdirname(void){
  2013. #ifndef __64BIT__
  2014. printf("x86");
  2015. #else
  2016. printf("x86_64");
  2017. #endif
  2018. }
  2019. char *get_corename(void){
  2020. return corename[get_coretype()];
  2021. }
  2022. void get_libname(void){
  2023. printf("%s", corename_lower[get_coretype()]);
  2024. }
  2025. /* This if for Makefile */
  2026. void get_sse(void){
  2027. int features;
  2028. features = get_cputype(GET_FEATURE);
  2029. if (features & HAVE_MMX ) printf("HAVE_MMX=1\n");
  2030. if (features & HAVE_SSE ) printf("HAVE_SSE=1\n");
  2031. if (features & HAVE_SSE2 ) printf("HAVE_SSE2=1\n");
  2032. if (features & HAVE_SSE3 ) printf("HAVE_SSE3=1\n");
  2033. if (features & HAVE_SSSE3) printf("HAVE_SSSE3=1\n");
  2034. if (features & HAVE_SSE4_1) printf("HAVE_SSE4_1=1\n");
  2035. if (features & HAVE_SSE4_2) printf("HAVE_SSE4_2=1\n");
  2036. if (features & HAVE_SSE4A) printf("HAVE_SSE4A=1\n");
  2037. if (features & HAVE_SSE5 ) printf("HAVE_SSSE5=1\n");
  2038. if (features & HAVE_AVX ) printf("HAVE_AVX=1\n");
  2039. if (features & HAVE_3DNOWEX) printf("HAVE_3DNOWEX=1\n");
  2040. if (features & HAVE_3DNOW) printf("HAVE_3DNOW=1\n");
  2041. if (features & HAVE_FMA4 ) printf("HAVE_FMA4=1\n");
  2042. if (features & HAVE_FMA3 ) printf("HAVE_FMA3=1\n");
  2043. }