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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701
  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(void){
  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(void){
  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(void){
  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(void){
  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(void) {
  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_amx_bf16())
  1388. return CPUTYPE_SAPPHIRERAPIDS;
  1389. if(support_avx512_bf16())
  1390. return CPUTYPE_COOPERLAKE;
  1391. if(support_avx512())
  1392. return CPUTYPE_SKYLAKEX;
  1393. if(support_avx2())
  1394. return CPUTYPE_HASWELL;
  1395. if(support_avx())
  1396. return CPUTYPE_SANDYBRIDGE;
  1397. else
  1398. return CPUTYPE_NEHALEM;
  1399. }
  1400. break;
  1401. case 9:
  1402. switch (model) {
  1403. case 7: // Alder Lake desktop
  1404. case 10: // Alder Lake mobile
  1405. if(support_avx512_bf16())
  1406. return CPUTYPE_COOPERLAKE;
  1407. if(support_avx512())
  1408. return CPUTYPE_SKYLAKEX;
  1409. if(support_avx2())
  1410. return CPUTYPE_HASWELL;
  1411. if(support_avx())
  1412. return CPUTYPE_SANDYBRIDGE;
  1413. else
  1414. return CPUTYPE_NEHALEM;
  1415. case 13: // Ice Lake NNPI
  1416. if(support_avx512())
  1417. return CPUTYPE_SKYLAKEX;
  1418. if(support_avx2())
  1419. return CPUTYPE_HASWELL;
  1420. if(support_avx())
  1421. return CPUTYPE_SANDYBRIDGE;
  1422. else
  1423. return CPUTYPE_NEHALEM;
  1424. case 14: // Kaby Lake and refreshes
  1425. if(support_avx2())
  1426. return CPUTYPE_HASWELL;
  1427. if(support_avx())
  1428. return CPUTYPE_SANDYBRIDGE;
  1429. else
  1430. return CPUTYPE_NEHALEM;
  1431. }
  1432. break;
  1433. case 10: //family 6 exmodel 10
  1434. switch (model) {
  1435. case 5: // Comet Lake H and S
  1436. case 6: // Comet Lake U
  1437. case 10: // Meteor Lake
  1438. if(support_avx2())
  1439. return CPUTYPE_HASWELL;
  1440. if(support_avx())
  1441. return CPUTYPE_SANDYBRIDGE;
  1442. else
  1443. return CPUTYPE_NEHALEM;
  1444. case 0: // Meteor Lake
  1445. case 7: // Rocket Lake
  1446. if(support_avx512())
  1447. return CPUTYPE_SKYLAKEX;
  1448. if(support_avx2())
  1449. return CPUTYPE_HASWELL;
  1450. if(support_avx())
  1451. return CPUTYPE_SANDYBRIDGE;
  1452. else
  1453. return CPUTYPE_NEHALEM;
  1454. }
  1455. break;
  1456. case 11: //family 6 exmodel 11
  1457. switch (model) {
  1458. case 7: // Raptor Lake
  1459. case 10:
  1460. case 15:
  1461. case 14: // Alder Lake N
  1462. if(support_avx2())
  1463. return CPUTYPE_HASWELL;
  1464. if(support_avx())
  1465. return CPUTYPE_SANDYBRIDGE;
  1466. else
  1467. return CPUTYPE_NEHALEM;
  1468. }
  1469. break;
  1470. case 12: //family 6 exmodel 12
  1471. switch (model) {
  1472. case 15:
  1473. if(support_avx512())
  1474. return CPUTYPE_SAPPHIRERAPIDS;
  1475. if(support_avx2())
  1476. return CPUTYPE_HASWELL;
  1477. if(support_avx())
  1478. return CPUTYPE_SANDYBRIDGE;
  1479. else
  1480. return CPUTYPE_NEHALEM;
  1481. }
  1482. break;
  1483. }
  1484. break;
  1485. case 0x7:
  1486. return CPUTYPE_ITANIUM;
  1487. case 0xf:
  1488. switch (exfamily) {
  1489. case 0 :
  1490. return CPUTYPE_PENTIUM4;
  1491. case 1 :
  1492. return CPUTYPE_ITANIUM;
  1493. }
  1494. break;
  1495. }
  1496. return CPUTYPE_INTEL_UNKNOWN;
  1497. }
  1498. if (vendor == VENDOR_AMD){
  1499. switch (family) {
  1500. case 0x4:
  1501. return CPUTYPE_AMD5X86;
  1502. case 0x5:
  1503. return CPUTYPE_AMDK6;
  1504. case 0x6:
  1505. #if defined(__x86_64__) || defined(__amd64__)
  1506. return CPUTYPE_BARCELONA;
  1507. #else
  1508. return CPUTYPE_ATHLON;
  1509. #endif
  1510. case 0xf:
  1511. switch (exfamily) {
  1512. case 0:
  1513. case 2:
  1514. return CPUTYPE_OPTERON;
  1515. case 1:
  1516. case 3:
  1517. // case 7:
  1518. // case 10:
  1519. return CPUTYPE_BARCELONA;
  1520. case 5:
  1521. case 7:
  1522. return CPUTYPE_BOBCAT;
  1523. case 6:
  1524. switch (model) {
  1525. case 1:
  1526. //AMD Bulldozer Opteron 6200 / Opteron 4200 / AMD FX-Series
  1527. if(support_avx())
  1528. return CPUTYPE_BULLDOZER;
  1529. else
  1530. return CPUTYPE_BARCELONA; //OS don't support AVX.
  1531. case 2: //AMD Piledriver
  1532. case 3: //AMD Richland
  1533. if(support_avx())
  1534. return CPUTYPE_PILEDRIVER;
  1535. else
  1536. return CPUTYPE_BARCELONA; //OS don't support AVX.
  1537. case 5: // New EXCAVATOR CPUS
  1538. if(support_avx())
  1539. return CPUTYPE_EXCAVATOR;
  1540. else
  1541. return CPUTYPE_BARCELONA; //OS don't support AVX.
  1542. case 0:
  1543. case 8:
  1544. switch(exmodel){
  1545. case 1: //AMD Trinity
  1546. if(support_avx())
  1547. return CPUTYPE_PILEDRIVER;
  1548. else
  1549. return CPUTYPE_BARCELONA; //OS don't support AVX.
  1550. case 3:
  1551. if(support_avx())
  1552. return CPUTYPE_STEAMROLLER;
  1553. else
  1554. return CPUTYPE_BARCELONA; //OS don't support AVX.
  1555. case 6:
  1556. if(support_avx())
  1557. return CPUTYPE_EXCAVATOR;
  1558. else
  1559. return CPUTYPE_BARCELONA; //OS don't support AVX.
  1560. }
  1561. break;
  1562. }
  1563. break;
  1564. case 8:
  1565. switch (model) {
  1566. case 1:
  1567. // AMD Ryzen
  1568. case 8:
  1569. // AMD Ryzen2
  1570. default:
  1571. // Matisse/Renoir and other recent Ryzen2
  1572. if(support_avx())
  1573. #ifndef NO_AVX2
  1574. return CPUTYPE_ZEN;
  1575. #else
  1576. return CPUTYPE_SANDYBRIDGE; // Zen is closer in architecture to Sandy Bridge than to Excavator
  1577. #endif
  1578. else
  1579. return CPUTYPE_BARCELONA;
  1580. }
  1581. case 10: // Zen3/4
  1582. #ifndef NO_AVX512
  1583. if(support_avx512_bf16())
  1584. return CPUTYPE_COOPERLAKE;
  1585. if(support_avx512())
  1586. return CPUTYPE_SKYLAKEX;
  1587. #endif
  1588. if(support_avx())
  1589. #ifndef NO_AVX2
  1590. return CPUTYPE_ZEN;
  1591. #else
  1592. return CPUTYPE_SANDYBRIDGE; // Zen is closer in architecture to Sandy Bridge than to Excavator
  1593. #endif
  1594. else
  1595. return CPUTYPE_BARCELONA;
  1596. }
  1597. break;
  1598. }
  1599. return CPUTYPE_AMD_UNKNOWN;
  1600. }
  1601. if (vendor == VENDOR_HYGON){
  1602. switch (family) {
  1603. case 0xf:
  1604. switch (exfamily) {
  1605. case 9:
  1606. //Hygon Dhyana
  1607. if(support_avx())
  1608. #ifndef NO_AVX2
  1609. return CPUTYPE_ZEN;
  1610. #else
  1611. return CPUTYPE_SANDYBRIDGE; // closer in architecture to Sandy Bridge than to Excavator
  1612. #endif
  1613. else
  1614. return CPUTYPE_BARCELONA;
  1615. }
  1616. break;
  1617. }
  1618. return CPUTYPE_HYGON_UNKNOWN;
  1619. }
  1620. if (vendor == VENDOR_CYRIX){
  1621. switch (family) {
  1622. case 0x4:
  1623. return CPUTYPE_CYRIX5X86;
  1624. case 0x5:
  1625. return CPUTYPE_CYRIXM1;
  1626. case 0x6:
  1627. return CPUTYPE_CYRIXM2;
  1628. }
  1629. return CPUTYPE_CYRIX_UNKNOWN;
  1630. }
  1631. if (vendor == VENDOR_NEXGEN){
  1632. switch (family) {
  1633. case 0x5:
  1634. return CPUTYPE_NEXGENNX586;
  1635. }
  1636. return CPUTYPE_NEXGEN_UNKNOWN;
  1637. }
  1638. if (vendor == VENDOR_CENTAUR){
  1639. switch (family) {
  1640. case 0x5:
  1641. return CPUTYPE_CENTAURC6;
  1642. case 0x6:
  1643. if (model == 0xf && stepping < 0xe)
  1644. return CPUTYPE_NANO;
  1645. return CPUTYPE_NEHALEM;
  1646. case 0x7:
  1647. switch (exmodel) {
  1648. case 5:
  1649. if (support_avx2())
  1650. return CPUTYPE_ZEN;
  1651. else
  1652. return CPUTYPE_DUNNINGTON;
  1653. default:
  1654. return CPUTYPE_NEHALEM;
  1655. }
  1656. default:
  1657. if (family >= 0x8)
  1658. return CPUTYPE_NEHALEM;
  1659. else
  1660. return CPUTYPE_VIAC3;
  1661. }
  1662. }
  1663. if (vendor == VENDOR_ZHAOXIN){
  1664. switch (family) {
  1665. case 0x7:
  1666. switch (exmodel) {
  1667. case 5:
  1668. if (support_avx2())
  1669. return CPUTYPE_ZEN;
  1670. else
  1671. return CPUTYPE_DUNNINGTON;
  1672. default:
  1673. return CPUTYPE_NEHALEM;
  1674. }
  1675. default:
  1676. return CPUTYPE_NEHALEM;
  1677. }
  1678. }
  1679. if (vendor == VENDOR_RISE){
  1680. switch (family) {
  1681. case 0x5:
  1682. return CPUTYPE_RISEMP6;
  1683. }
  1684. return CPUTYPE_RISE_UNKNOWN;
  1685. }
  1686. if (vendor == VENDOR_SIS){
  1687. switch (family) {
  1688. case 0x5:
  1689. return CPUTYPE_SYS55X;
  1690. }
  1691. return CPUTYPE_SIS_UNKNOWN;
  1692. }
  1693. if (vendor == VENDOR_TRANSMETA){
  1694. switch (family) {
  1695. case 0x5:
  1696. return CPUTYPE_CRUSOETM3X;
  1697. }
  1698. return CPUTYPE_TRANSMETA_UNKNOWN;
  1699. }
  1700. if (vendor == VENDOR_NSC){
  1701. switch (family) {
  1702. case 0x5:
  1703. return CPUTYPE_NSGEODE;
  1704. }
  1705. return CPUTYPE_NSC_UNKNOWN;
  1706. }
  1707. return CPUTYPE_UNKNOWN;
  1708. }
  1709. static char *cpuname[] = {
  1710. "UNKNOWN",
  1711. "INTEL_UNKNOWN",
  1712. "UMC_UNKNOWN",
  1713. "AMD_UNKNOWN",
  1714. "CYRIX_UNKNOWN",
  1715. "NEXGEN_UNKNOWN",
  1716. "CENTAUR_UNKNOWN",
  1717. "RISE_UNKNOWN",
  1718. "SIS_UNKNOWN",
  1719. "TRANSMETA_UNKNOWN",
  1720. "NSC_UNKNOWN",
  1721. "80386",
  1722. "80486",
  1723. "PENTIUM",
  1724. "PENTIUM2",
  1725. "PENTIUM3",
  1726. "PENTIUMM",
  1727. "PENTIUM4",
  1728. "CORE2",
  1729. "PENRYN",
  1730. "DUNNINGTON",
  1731. "NEHALEM",
  1732. "ATOM",
  1733. "ITANIUM",
  1734. "ITANIUM2",
  1735. "5X86",
  1736. "K6",
  1737. "ATHLON",
  1738. "DURON",
  1739. "OPTERON",
  1740. "BARCELONA",
  1741. "SHANGHAI",
  1742. "ISTANBUL",
  1743. "CYRIX5X86",
  1744. "CYRIXM1",
  1745. "CYRIXM2",
  1746. "NEXGENNX586",
  1747. "CENTAURC6",
  1748. "RISEMP6",
  1749. "SYS55X",
  1750. "TM3X00",
  1751. "NSGEODE",
  1752. "VIAC3",
  1753. "NANO",
  1754. "SANDYBRIDGE",
  1755. "BOBCAT",
  1756. "BULLDOZER",
  1757. "PILEDRIVER",
  1758. "HASWELL",
  1759. "STEAMROLLER",
  1760. "EXCAVATOR",
  1761. "ZEN",
  1762. "SKYLAKEX",
  1763. "DHYANA",
  1764. "COOPERLAKE",
  1765. "SAPPHIRERAPIDS",
  1766. };
  1767. static char *lowercpuname[] = {
  1768. "unknown",
  1769. "intel_unknown",
  1770. "umc_unknown",
  1771. "amd_unknown",
  1772. "cyrix_unknown",
  1773. "nexgen_unknown",
  1774. "centaur_unknown",
  1775. "rise_unknown",
  1776. "sis_unknown",
  1777. "transmeta_unknown",
  1778. "nsc_unknown",
  1779. "80386",
  1780. "80486",
  1781. "pentium",
  1782. "pentium2",
  1783. "pentium3",
  1784. "pentiumm",
  1785. "pentium4",
  1786. "core2",
  1787. "penryn",
  1788. "dunnington",
  1789. "nehalem",
  1790. "atom",
  1791. "itanium",
  1792. "itanium2",
  1793. "5x86",
  1794. "k6",
  1795. "athlon",
  1796. "duron",
  1797. "opteron",
  1798. "barcelona",
  1799. "shanghai",
  1800. "istanbul",
  1801. "cyrix5x86",
  1802. "cyrixm1",
  1803. "cyrixm2",
  1804. "nexgennx586",
  1805. "centaurc6",
  1806. "risemp6",
  1807. "sys55x",
  1808. "tms3x00",
  1809. "nsgeode",
  1810. "nano",
  1811. "sandybridge",
  1812. "bobcat",
  1813. "bulldozer",
  1814. "piledriver",
  1815. "haswell",
  1816. "steamroller",
  1817. "excavator",
  1818. "zen",
  1819. "skylakex",
  1820. "dhyana",
  1821. "cooperlake",
  1822. "sapphirerapids",
  1823. };
  1824. static char *corename[] = {
  1825. "UNKNOWN",
  1826. "80486",
  1827. "P5",
  1828. "P6",
  1829. "KATMAI",
  1830. "COPPERMINE",
  1831. "NORTHWOOD",
  1832. "PRESCOTT",
  1833. "BANIAS",
  1834. "ATHLON",
  1835. "OPTERON",
  1836. "BARCELONA",
  1837. "VIAC3",
  1838. "YONAH",
  1839. "CORE2",
  1840. "PENRYN",
  1841. "DUNNINGTON",
  1842. "NEHALEM",
  1843. "ATOM",
  1844. "NANO",
  1845. "SANDYBRIDGE",
  1846. "BOBCAT",
  1847. "BULLDOZER",
  1848. "PILEDRIVER",
  1849. "HASWELL",
  1850. "STEAMROLLER",
  1851. "EXCAVATOR",
  1852. "ZEN",
  1853. "SKYLAKEX",
  1854. "DHYANA",
  1855. "COOPERLAKE",
  1856. "SAPPHIRERAPIDS",
  1857. };
  1858. static char *corename_lower[] = {
  1859. "unknown",
  1860. "80486",
  1861. "p5",
  1862. "p6",
  1863. "katmai",
  1864. "coppermine",
  1865. "northwood",
  1866. "prescott",
  1867. "banias",
  1868. "athlon",
  1869. "opteron",
  1870. "barcelona",
  1871. "viac3",
  1872. "yonah",
  1873. "core2",
  1874. "penryn",
  1875. "dunnington",
  1876. "nehalem",
  1877. "atom",
  1878. "nano",
  1879. "sandybridge",
  1880. "bobcat",
  1881. "bulldozer",
  1882. "piledriver",
  1883. "haswell",
  1884. "steamroller",
  1885. "excavator",
  1886. "zen",
  1887. "skylakex",
  1888. "dhyana",
  1889. "cooperlake",
  1890. "sapphirerapids",
  1891. };
  1892. char *get_cpunamechar(void){
  1893. return cpuname[get_cpuname()];
  1894. }
  1895. char *get_lower_cpunamechar(void){
  1896. return lowercpuname[get_cpuname()];
  1897. }
  1898. int get_coretype(void){
  1899. int family, exfamily, model, exmodel, vendor, stepping;
  1900. if (!have_cpuid()) return CORE_80486;
  1901. family = get_cputype(GET_FAMILY);
  1902. exfamily = get_cputype(GET_EXFAMILY);
  1903. model = get_cputype(GET_MODEL);
  1904. exmodel = get_cputype(GET_EXMODEL);
  1905. stepping = get_cputype(GET_STEPPING);
  1906. vendor = get_vendor();
  1907. if (vendor == VENDOR_INTEL){
  1908. switch (family) {
  1909. case 4:
  1910. return CORE_80486;
  1911. case 5:
  1912. return CORE_P5;
  1913. case 6:
  1914. switch (exmodel) {
  1915. case 0:
  1916. switch (model) {
  1917. case 0:
  1918. case 1:
  1919. case 2:
  1920. case 3:
  1921. case 4:
  1922. case 5:
  1923. case 6:
  1924. #if defined(__x86_64__) || defined(__amd64__)
  1925. return CORE_CORE2;
  1926. #else
  1927. return CORE_P6;
  1928. #endif
  1929. case 7:
  1930. return CORE_KATMAI;
  1931. case 8:
  1932. case 10:
  1933. case 11:
  1934. return CORE_COPPERMINE;
  1935. case 9:
  1936. case 13:
  1937. case 14:
  1938. return CORE_BANIAS;
  1939. case 15:
  1940. return CORE_CORE2;
  1941. }
  1942. break;
  1943. case 1:
  1944. switch (model) {
  1945. case 6:
  1946. return CORE_CORE2;
  1947. case 7:
  1948. return CORE_PENRYN;
  1949. case 10:
  1950. case 11:
  1951. case 14:
  1952. case 15:
  1953. return CORE_NEHALEM;
  1954. case 12:
  1955. return CORE_ATOM;
  1956. case 13:
  1957. return CORE_DUNNINGTON;
  1958. }
  1959. break;
  1960. case 2:
  1961. switch (model) {
  1962. case 5:
  1963. //Intel Core (Clarkdale) / Core (Arrandale)
  1964. // Pentium (Clarkdale) / Pentium Mobile (Arrandale)
  1965. // Xeon (Clarkdale), 32nm
  1966. return CORE_NEHALEM;
  1967. case 10:
  1968. //Intel Core i5-2000 /i7-2000 (Sandy Bridge)
  1969. if(support_avx())
  1970. return CORE_SANDYBRIDGE;
  1971. else
  1972. return CORE_NEHALEM; //OS doesn't support AVX
  1973. case 12:
  1974. //Xeon Processor 5600 (Westmere-EP)
  1975. return CORE_NEHALEM;
  1976. case 13:
  1977. //Intel Core i7-3000 / Xeon E5 (Sandy Bridge)
  1978. if(support_avx())
  1979. return CORE_SANDYBRIDGE;
  1980. else
  1981. return CORE_NEHALEM; //OS doesn't support AVX
  1982. case 14:
  1983. //Xeon E7540
  1984. case 15:
  1985. //Xeon Processor E7 (Westmere-EX)
  1986. return CORE_NEHALEM;
  1987. }
  1988. break;
  1989. case 3:
  1990. switch (model) {
  1991. case 7:
  1992. return CORE_ATOM;
  1993. case 10:
  1994. case 14:
  1995. if(support_avx())
  1996. return CORE_SANDYBRIDGE;
  1997. else
  1998. return CORE_NEHALEM; //OS doesn't support AVX
  1999. case 12:
  2000. case 15:
  2001. if(support_avx())
  2002. #ifndef NO_AVX2
  2003. return CORE_HASWELL;
  2004. #else
  2005. return CORE_SANDYBRIDGE;
  2006. #endif
  2007. else
  2008. return CORE_NEHALEM;
  2009. case 13:
  2010. //broadwell
  2011. if(support_avx())
  2012. #ifndef NO_AVX2
  2013. return CORE_HASWELL;
  2014. #else
  2015. return CORE_SANDYBRIDGE;
  2016. #endif
  2017. else
  2018. return CORE_NEHALEM;
  2019. }
  2020. break;
  2021. case 4:
  2022. switch (model) {
  2023. case 5:
  2024. case 6:
  2025. if(support_avx())
  2026. #ifndef NO_AVX2
  2027. return CORE_HASWELL;
  2028. #else
  2029. return CORE_SANDYBRIDGE;
  2030. #endif
  2031. else
  2032. return CORE_NEHALEM;
  2033. case 7:
  2034. case 15:
  2035. //broadwell
  2036. if(support_avx())
  2037. #ifndef NO_AVX2
  2038. return CORE_HASWELL;
  2039. #else
  2040. return CORE_SANDYBRIDGE;
  2041. #endif
  2042. else
  2043. return CORE_NEHALEM;
  2044. case 14:
  2045. //Skylake
  2046. if(support_avx())
  2047. #ifndef NO_AVX2
  2048. return CORE_HASWELL;
  2049. #else
  2050. return CORE_SANDYBRIDGE;
  2051. #endif
  2052. else
  2053. return CORE_NEHALEM;
  2054. case 12:
  2055. // Braswell
  2056. case 13:
  2057. // Avoton
  2058. return CORE_NEHALEM;
  2059. }
  2060. break;
  2061. case 5:
  2062. switch (model) {
  2063. case 6:
  2064. //broadwell
  2065. if(support_avx())
  2066. #ifndef NO_AVX2
  2067. return CORE_HASWELL;
  2068. #else
  2069. return CORE_SANDYBRIDGE;
  2070. #endif
  2071. else
  2072. return CORE_NEHALEM;
  2073. case 5:
  2074. // Skylake X
  2075. #ifndef NO_AVX512
  2076. if(support_avx512_bf16())
  2077. return CORE_COOPERLAKE;
  2078. return CORE_SKYLAKEX;
  2079. #else
  2080. if(support_avx())
  2081. #ifndef NO_AVX2
  2082. return CORE_HASWELL;
  2083. #else
  2084. return CORE_SANDYBRIDGE;
  2085. #endif
  2086. else
  2087. return CORE_NEHALEM;
  2088. #endif
  2089. case 14:
  2090. // Skylake
  2091. if(support_avx())
  2092. #ifndef NO_AVX2
  2093. return CORE_HASWELL;
  2094. #else
  2095. return CORE_SANDYBRIDGE;
  2096. #endif
  2097. else
  2098. return CORE_NEHALEM;
  2099. case 7:
  2100. // Phi Knights Landing
  2101. if(support_avx())
  2102. #ifndef NO_AVX2
  2103. return CORE_HASWELL;
  2104. #else
  2105. return CORE_SANDYBRIDGE;
  2106. #endif
  2107. else
  2108. return CORE_NEHALEM;
  2109. case 12:
  2110. // Apollo Lake
  2111. return CORE_NEHALEM;
  2112. }
  2113. break;
  2114. case 6:
  2115. if (model == 6)
  2116. #ifndef NO_AVX512
  2117. return CORE_SKYLAKEX;
  2118. #else
  2119. if(support_avx())
  2120. #ifndef NO_AVX2
  2121. return CORE_HASWELL;
  2122. #else
  2123. return CORE_SANDYBRIDGE;
  2124. #endif
  2125. else
  2126. return CORE_NEHALEM;
  2127. #endif
  2128. if (model == 10 || model == 12)
  2129. #ifndef NO_AVX512
  2130. if(support_avx512_bf16())
  2131. return CORE_COOPERLAKE;
  2132. return CORE_SKYLAKEX;
  2133. #else
  2134. if(support_avx())
  2135. #ifndef NO_AVX2
  2136. return CORE_HASWELL;
  2137. #else
  2138. return CORE_SANDYBRIDGE;
  2139. #endif
  2140. else
  2141. return CORE_NEHALEM;
  2142. #endif
  2143. case 7:
  2144. if (model == 10)
  2145. return CORE_NEHALEM;
  2146. if (model == 13 || model == 14) // Ice Lake
  2147. #ifndef NO_AVX512
  2148. return CORE_SKYLAKEX;
  2149. #else
  2150. if(support_avx())
  2151. #ifndef NO_AVX2
  2152. return CORE_HASWELL;
  2153. #else
  2154. return CORE_SANDYBRIDGE;
  2155. #endif
  2156. else
  2157. return CORE_NEHALEM;
  2158. #endif
  2159. break;
  2160. case 8:
  2161. if (model == 12 || model == 13) { // Tiger Lake
  2162. if(support_avx512())
  2163. return CORE_SKYLAKEX;
  2164. if(support_avx2())
  2165. return CORE_HASWELL;
  2166. if(support_avx())
  2167. return CORE_SANDYBRIDGE;
  2168. else
  2169. return CORE_NEHALEM;
  2170. }
  2171. if (model == 14) { // Kaby Lake mobile
  2172. if(support_avx())
  2173. #ifndef NO_AVX2
  2174. return CORE_HASWELL;
  2175. #else
  2176. return CORE_SANDYBRIDGE;
  2177. #endif
  2178. else
  2179. return CORE_NEHALEM;
  2180. }
  2181. if (model == 15) { // Sapphire Rapids
  2182. if(support_amx_bf16())
  2183. return CORE_SAPPHIRERAPIDS;
  2184. if(support_avx512_bf16())
  2185. return CORE_COOPERLAKE;
  2186. if(support_avx512())
  2187. return CORE_SKYLAKEX;
  2188. if(support_avx2())
  2189. return CORE_HASWELL;
  2190. if(support_avx())
  2191. return CORE_SANDYBRIDGE;
  2192. else
  2193. return CORE_NEHALEM;
  2194. }
  2195. break;
  2196. case 9:
  2197. if (model == 7 || model == 10) { // Alder Lake
  2198. if(support_avx2())
  2199. return CORE_HASWELL;
  2200. if(support_avx())
  2201. return CORE_SANDYBRIDGE;
  2202. else
  2203. return CORE_NEHALEM;
  2204. }
  2205. if (model == 13) { // Ice Lake NNPI
  2206. if(support_avx512())
  2207. return CORE_SKYLAKEX;
  2208. if(support_avx2())
  2209. return CORE_HASWELL;
  2210. if(support_avx())
  2211. return CORE_SANDYBRIDGE;
  2212. else
  2213. return CORE_NEHALEM;
  2214. }
  2215. if (model == 14) { // Kaby Lake desktop
  2216. if(support_avx())
  2217. #ifndef NO_AVX2
  2218. return CORE_HASWELL;
  2219. #else
  2220. return CORE_SANDYBRIDGE;
  2221. #endif
  2222. else
  2223. return CORE_NEHALEM;
  2224. }
  2225. break;
  2226. case 10:
  2227. switch (model) {
  2228. case 5: // Comet Lake H and S
  2229. case 6: // Comet Lake U
  2230. if(support_avx())
  2231. #ifndef NO_AVX2
  2232. return CORE_HASWELL;
  2233. #else
  2234. return CORE_SANDYBRIDGE;
  2235. #endif
  2236. else
  2237. return CORE_NEHALEM;
  2238. case 7:// Rocket Lake
  2239. #ifndef NO_AVX512
  2240. if(support_avx512())
  2241. return CORE_SKYLAKEX;
  2242. #endif
  2243. #ifndef NO_AVX2
  2244. if(support_avx2())
  2245. return CORE_HASWELL;
  2246. #endif
  2247. if(support_avx())
  2248. return CORE_SANDYBRIDGE;
  2249. else
  2250. return CORE_NEHALEM;
  2251. }
  2252. case 11:
  2253. switch (model) {
  2254. case 7: // Raptor Lake
  2255. case 10:
  2256. case 15:
  2257. case 14: // Alder Lake N
  2258. #ifndef NO_AVX2
  2259. if(support_avx2())
  2260. return CORE_HASWELL;
  2261. #endif
  2262. if(support_avx())
  2263. return CORE_SANDYBRIDGE;
  2264. else
  2265. return CORE_NEHALEM;
  2266. }
  2267. }
  2268. case 15:
  2269. if (model <= 0x2) return CORE_NORTHWOOD;
  2270. else return CORE_PRESCOTT;
  2271. }
  2272. }
  2273. if (vendor == VENDOR_AMD){
  2274. if (family <= 0x5) return CORE_80486;
  2275. #if defined(__x86_64__) || defined(__amd64__)
  2276. if (family <= 0xe) return CORE_BARCELONA;
  2277. #else
  2278. if (family <= 0xe) return CORE_ATHLON;
  2279. #endif
  2280. if (family == 0xf){
  2281. if ((exfamily == 0) || (exfamily == 2)) return CORE_OPTERON;
  2282. else if (exfamily == 5) return CORE_BOBCAT;
  2283. else if (exfamily == 6) {
  2284. switch (model) {
  2285. case 1:
  2286. //AMD Bulldozer Opteron 6200 / Opteron 4200 / AMD FX-Series
  2287. if(support_avx())
  2288. return CORE_BULLDOZER;
  2289. else
  2290. return CORE_BARCELONA; //OS don't support AVX.
  2291. case 2: //AMD Piledriver
  2292. case 3: //AMD Richland
  2293. if(support_avx())
  2294. return CORE_PILEDRIVER;
  2295. else
  2296. return CORE_BARCELONA; //OS don't support AVX.
  2297. case 5: // New EXCAVATOR
  2298. if(support_avx())
  2299. return CORE_EXCAVATOR;
  2300. else
  2301. return CORE_BARCELONA; //OS don't support AVX.
  2302. case 0:
  2303. case 8:
  2304. switch(exmodel){
  2305. case 1: //AMD Trinity
  2306. if(support_avx())
  2307. return CORE_PILEDRIVER;
  2308. else
  2309. return CORE_BARCELONA; //OS don't support AVX.
  2310. case 3:
  2311. if(support_avx())
  2312. return CORE_STEAMROLLER;
  2313. else
  2314. return CORE_BARCELONA; //OS don't support AVX.
  2315. case 6:
  2316. if(support_avx())
  2317. return CORE_EXCAVATOR;
  2318. else
  2319. return CORE_BARCELONA; //OS don't support AVX.
  2320. }
  2321. break;
  2322. }
  2323. } else if (exfamily == 8 || exfamily == 10) {
  2324. switch (model) {
  2325. case 1:
  2326. // AMD Ryzen
  2327. case 8:
  2328. // Ryzen 2
  2329. default:
  2330. // Matisse,Renoir Ryzen2 models
  2331. #ifndef NO_AVX512
  2332. if(support_avx512_bf16())
  2333. return CORE_COOPERLAKE;
  2334. if(support_avx512())
  2335. return CORE_SKYLAKEX;
  2336. #endif
  2337. if(support_avx())
  2338. #ifndef NO_AVX2
  2339. return CORE_ZEN;
  2340. #else
  2341. return CORE_SANDYBRIDGE; // Zen is closer in architecture to Sandy Bridge than to Excavator
  2342. #endif
  2343. else
  2344. return CORE_BARCELONA;
  2345. }
  2346. } else {
  2347. return CORE_BARCELONA;
  2348. }
  2349. }
  2350. }
  2351. if (vendor == VENDOR_HYGON){
  2352. if (family == 0xf){
  2353. if (exfamily == 9) {
  2354. if(support_avx())
  2355. #ifndef NO_AVX2
  2356. return CORE_ZEN;
  2357. #else
  2358. return CORE_SANDYBRIDGE; // closer in architecture to Sandy Bridge than to Excavator
  2359. #endif
  2360. else
  2361. return CORE_BARCELONA;
  2362. } else {
  2363. return CORE_BARCELONA;
  2364. }
  2365. }
  2366. }
  2367. if (vendor == VENDOR_CENTAUR) {
  2368. switch (family) {
  2369. case 0x6:
  2370. if (model == 0xf && stepping < 0xe)
  2371. return CORE_NANO;
  2372. return CORE_NEHALEM;
  2373. case 0x7:
  2374. switch (exmodel) {
  2375. case 5:
  2376. if (support_avx2())
  2377. return CORE_ZEN;
  2378. else
  2379. return CORE_DUNNINGTON;
  2380. default:
  2381. return CORE_NEHALEM;
  2382. }
  2383. default:
  2384. if (family >= 0x8)
  2385. return CORE_NEHALEM;
  2386. else
  2387. return CORE_VIAC3;
  2388. }
  2389. }
  2390. if (vendor == VENDOR_ZHAOXIN) {
  2391. switch (family) {
  2392. case 0x7:
  2393. switch (exmodel) {
  2394. case 5:
  2395. case 6:
  2396. if (support_avx2())
  2397. return CORE_ZEN;
  2398. else
  2399. return CORE_DUNNINGTON;
  2400. default:
  2401. return CORE_NEHALEM;
  2402. }
  2403. default:
  2404. return CORE_NEHALEM;
  2405. }
  2406. }
  2407. return CORE_UNKNOWN;
  2408. }
  2409. void get_cpuconfig(void){
  2410. cache_info_t info;
  2411. int features;
  2412. printf("#define %s\n", cpuname[get_cpuname()]);
  2413. if (get_coretype() != CORE_P5) {
  2414. get_cacheinfo(CACHE_INFO_L1_I, &info);
  2415. if (info.size > 0) {
  2416. printf("#define L1_CODE_SIZE %d\n", info.size * 1024);
  2417. printf("#define L1_CODE_ASSOCIATIVE %d\n", info.associative);
  2418. printf("#define L1_CODE_LINESIZE %d\n", info.linesize);
  2419. }
  2420. get_cacheinfo(CACHE_INFO_L1_D, &info);
  2421. if (info.size > 0) {
  2422. printf("#define L1_DATA_SIZE %d\n", info.size * 1024);
  2423. printf("#define L1_DATA_ASSOCIATIVE %d\n", info.associative);
  2424. printf("#define L1_DATA_LINESIZE %d\n", info.linesize);
  2425. }
  2426. get_cacheinfo(CACHE_INFO_L2, &info);
  2427. if (info.size > 0) {
  2428. printf("#define L2_SIZE %d\n", info.size * 1024);
  2429. printf("#define L2_ASSOCIATIVE %d\n", info.associative);
  2430. printf("#define L2_LINESIZE %d\n", info.linesize);
  2431. } else {
  2432. //fall back for some virtual machines.
  2433. printf("#define L2_SIZE 1048576\n");
  2434. printf("#define L2_ASSOCIATIVE 6\n");
  2435. printf("#define L2_LINESIZE 64\n");
  2436. }
  2437. get_cacheinfo(CACHE_INFO_L3, &info);
  2438. if (info.size > 0) {
  2439. printf("#define L3_SIZE %d\n", info.size * 1024);
  2440. printf("#define L3_ASSOCIATIVE %d\n", info.associative);
  2441. printf("#define L3_LINESIZE %d\n", info.linesize);
  2442. }
  2443. get_cacheinfo(CACHE_INFO_L1_ITB, &info);
  2444. if (info.size > 0) {
  2445. printf("#define ITB_SIZE %d\n", info.size * 1024);
  2446. printf("#define ITB_ASSOCIATIVE %d\n", info.associative);
  2447. printf("#define ITB_ENTRIES %d\n", info.linesize);
  2448. }
  2449. get_cacheinfo(CACHE_INFO_L1_DTB, &info);
  2450. if (info.size > 0) {
  2451. printf("#define DTB_SIZE %d\n", info.size * 1024);
  2452. printf("#define DTB_ASSOCIATIVE %d\n", info.associative);
  2453. printf("#define DTB_DEFAULT_ENTRIES %d\n", info.linesize);
  2454. } else {
  2455. //fall back for some virtual machines.
  2456. printf("#define DTB_DEFAULT_ENTRIES 32\n");
  2457. }
  2458. features = get_cputype(GET_FEATURE);
  2459. if (features & HAVE_CMOV ) printf("#define HAVE_CMOV\n");
  2460. if (features & HAVE_MMX ) printf("#define HAVE_MMX\n");
  2461. if (features & HAVE_SSE ) printf("#define HAVE_SSE\n");
  2462. if (features & HAVE_SSE2 ) printf("#define HAVE_SSE2\n");
  2463. if (features & HAVE_SSE3 ) printf("#define HAVE_SSE3\n");
  2464. if (features & HAVE_SSSE3) printf("#define HAVE_SSSE3\n");
  2465. if (features & HAVE_SSE4_1) printf("#define HAVE_SSE4_1\n");
  2466. if (features & HAVE_SSE4_2) printf("#define HAVE_SSE4_2\n");
  2467. if (features & HAVE_SSE4A) printf("#define HAVE_SSE4A\n");
  2468. if (features & HAVE_SSE5 ) printf("#define HAVE_SSSE5\n");
  2469. if (features & HAVE_AVX ) printf("#define HAVE_AVX\n");
  2470. if (features & HAVE_AVX2 ) printf("#define HAVE_AVX2\n");
  2471. if (features & HAVE_AVX512VL ) printf("#define HAVE_AVX512VL\n");
  2472. if (features & HAVE_AVX512BF16 ) printf("#define HAVE_AVX512BF16\n");
  2473. if (features & HAVE_AMXBF16 ) printf("#define HAVE_AMXBF16\n");
  2474. if (features & HAVE_3DNOWEX) printf("#define HAVE_3DNOWEX\n");
  2475. if (features & HAVE_3DNOW) printf("#define HAVE_3DNOW\n");
  2476. if (features & HAVE_FMA4 ) printf("#define HAVE_FMA4\n");
  2477. if (features & HAVE_FMA3 ) printf("#define HAVE_FMA3\n");
  2478. if (features & HAVE_CFLUSH) printf("#define HAVE_CFLUSH\n");
  2479. if (features & HAVE_HIT) printf("#define HAVE_HIT 1\n");
  2480. if (features & HAVE_MISALIGNSSE) printf("#define HAVE_MISALIGNSSE\n");
  2481. if (features & HAVE_128BITFPU) printf("#define HAVE_128BITFPU\n");
  2482. if (features & HAVE_FASTMOVU) printf("#define HAVE_FASTMOVU\n");
  2483. printf("#define NUM_SHAREDCACHE %d\n", get_cputype(GET_NUMSHARE) + 1);
  2484. printf("#define NUM_CORES %d\n", get_cputype(GET_NUMCORES) + 1);
  2485. features = get_coretype();
  2486. if (features > 0) printf("#define CORE_%s\n", corename[features]);
  2487. } else {
  2488. printf("#define DTB_DEFAULT_ENTRIES 16\n");
  2489. printf("#define L1_CODE_SIZE 8192\n");
  2490. printf("#define L1_DATA_SIZE 8192\n");
  2491. printf("#define L2_SIZE 0\n");
  2492. }
  2493. }
  2494. void get_architecture(void){
  2495. #ifndef __64BIT__
  2496. printf("X86");
  2497. #else
  2498. printf("X86_64");
  2499. #endif
  2500. }
  2501. void get_subarchitecture(void){
  2502. printf("%s", get_cpunamechar());
  2503. }
  2504. void get_subdirname(void){
  2505. #ifndef __64BIT__
  2506. printf("x86");
  2507. #else
  2508. printf("x86_64");
  2509. #endif
  2510. }
  2511. char *get_corename(void){
  2512. return corename[get_coretype()];
  2513. }
  2514. void get_libname(void){
  2515. printf("%s", corename_lower[get_coretype()]);
  2516. }
  2517. /* This if for Makefile */
  2518. void get_sse(void){
  2519. int features;
  2520. features = get_cputype(GET_FEATURE);
  2521. if (features & HAVE_MMX ) printf("HAVE_MMX=1\n");
  2522. if (features & HAVE_SSE ) printf("HAVE_SSE=1\n");
  2523. if (features & HAVE_SSE2 ) printf("HAVE_SSE2=1\n");
  2524. if (features & HAVE_SSE3 ) printf("HAVE_SSE3=1\n");
  2525. if (features & HAVE_SSSE3) printf("HAVE_SSSE3=1\n");
  2526. if (features & HAVE_SSE4_1) printf("HAVE_SSE4_1=1\n");
  2527. if (features & HAVE_SSE4_2) printf("HAVE_SSE4_2=1\n");
  2528. if (features & HAVE_SSE4A) printf("HAVE_SSE4A=1\n");
  2529. if (features & HAVE_SSE5 ) printf("HAVE_SSSE5=1\n");
  2530. if (features & HAVE_AVX ) printf("HAVE_AVX=1\n");
  2531. if (features & HAVE_AVX2 ) printf("HAVE_AVX2=1\n");
  2532. if (features & HAVE_AVX512VL ) printf("HAVE_AVX512VL=1\n");
  2533. if (features & HAVE_AVX512BF16 ) printf("HAVE_AVX512BF16=1\n");
  2534. if (features & HAVE_AMXBF16 ) printf("HAVE_AMXBF16=1\n");
  2535. if (features & HAVE_3DNOWEX) printf("HAVE_3DNOWEX=1\n");
  2536. if (features & HAVE_3DNOW) printf("HAVE_3DNOW=1\n");
  2537. if (features & HAVE_FMA4 ) printf("HAVE_FMA4=1\n");
  2538. if (features & HAVE_FMA3 ) printf("HAVE_FMA3=1\n");
  2539. }
  2540. //}