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

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