1 #include <stdint.h>
2
3 #include <cpuinfo.h>
4 #include <x86/api.h>
5
6
cpuinfo_x86_decode_uarch(enum cpuinfo_vendor vendor,const struct cpuinfo_x86_model_info * model_info)7 enum cpuinfo_uarch cpuinfo_x86_decode_uarch(
8 enum cpuinfo_vendor vendor,
9 const struct cpuinfo_x86_model_info* model_info)
10 {
11 switch (vendor) {
12 case cpuinfo_vendor_intel:
13 switch (model_info->family) {
14 #if CPUINFO_ARCH_X86
15 case 0x05:
16 switch (model_info->model) {
17 case 0x01: // Pentium (60, 66)
18 case 0x02: // Pentium (75, 90, 100, 120, 133, 150, 166, 200)
19 case 0x03: // Pentium OverDrive for Intel486-based systems
20 case 0x04: // Pentium MMX
21 return cpuinfo_uarch_p5;
22 case 0x09:
23 return cpuinfo_uarch_quark;
24 }
25 break;
26 #endif /* CPUINFO_ARCH_X86 */
27 case 0x06:
28 switch (model_info->model) {
29 /* Mainstream cores */
30 #if CPUINFO_ARCH_X86
31 case 0x01: // Pentium Pro
32 case 0x03: // Pentium II (Klamath) and Pentium II Overdrive
33 case 0x05: // Pentium II (Deschutes, Tonga), Pentium II Celeron (Covington), Pentium II Xeon (Drake)
34 case 0x06: // Pentium II (Dixon), Pentium II Celeron (Mendocino)
35 case 0x07: // Pentium III (Katmai), Pentium III Xeon (Tanner)
36 case 0x08: // Pentium III (Coppermine), Pentium II Celeron (Coppermine-128), Pentium III Xeon (Cascades)
37 case 0x0A: // Pentium III Xeon (Cascades-2MB)
38 case 0x0B: // Pentium III (Tualatin), Pentium III Celeron (Tualatin-256)
39 return cpuinfo_uarch_p6;
40 case 0x09: // Pentium M (Banias), Pentium M Celeron (Banias-0, Banias-512)
41 case 0x0D: // Pentium M (Dothan), Pentium M Celeron (Dothan-512, Dothan-1024)
42 case 0x15: // Intel 80579 (Tolapai)
43 return cpuinfo_uarch_dothan;
44 case 0x0E: // Core Solo/Duo (Yonah), Pentium Dual-Core T2xxx (Yonah), Celeron M (Yonah-512, Yonah-1024), Dual-Core Xeon (Sossaman)
45 return cpuinfo_uarch_yonah;
46 #endif /* CPUINFO_ARCH_X86 */
47 case 0x0F: // Core 2 Duo (Conroe, Conroe-2M, Merom), Core 2 Quad (Tigerton), Xeon (Woodcrest, Clovertown, Kentsfield)
48 case 0x16: // Celeron (Conroe-L, Merom-L), Core 2 Duo (Merom)
49 return cpuinfo_uarch_conroe;
50 case 0x17: // Core 2 Duo (Penryn-3M), Core 2 Quad (Yorkfield), Core 2 Extreme (Yorkfield), Xeon (Harpertown), Pentium Dual-Core (Penryn)
51 case 0x1D: // Xeon (Dunnington)
52 return cpuinfo_uarch_penryn;
53 case 0x1A: // Core iX (Bloomfield), Xeon (Gainestown)
54 case 0x1E: // Core iX (Lynnfield, Clarksfield)
55 case 0x1F: // Core iX (Havendale)
56 case 0x2E: // Xeon (Beckton)
57 case 0x25: // Core iX (Clarkdale)
58 case 0x2C: // Core iX (Gulftown), Xeon (Gulftown)
59 case 0x2F: // Xeon (Eagleton)
60 return cpuinfo_uarch_nehalem;
61 case 0x2A: // Core iX (Sandy Bridge)
62 case 0x2D: // Core iX (Sandy Bridge-E), Xeon (Sandy Bridge EP/EX)
63 return cpuinfo_uarch_sandy_bridge;
64 case 0x3A: // Core iX (Ivy Bridge)
65 case 0x3E: // Ivy Bridge-E
66 return cpuinfo_uarch_ivy_bridge;
67 case 0x3C:
68 case 0x3F: // Haswell-E
69 case 0x45: // Haswell ULT
70 case 0x46: // Haswell with eDRAM
71 return cpuinfo_uarch_haswell;
72 case 0x3D: // Broadwell-U
73 case 0x47: // Broadwell-H
74 case 0x4F: // Broadwell-E
75 case 0x56: // Broadwell-DE
76 return cpuinfo_uarch_broadwell;
77 case 0x4E: // Sky Lake Client Y/U
78 case 0x55: // Sky/Cascade/Cooper Lake Server
79 case 0x5E: // Sky Lake Client DT/H/S
80 case 0x8E: // Kaby/Whiskey/Amber/Comet Lake Y/U
81 case 0x9E: // Kaby/Coffee Lake DT/H/S
82 return cpuinfo_uarch_sky_lake;
83 case 0x66: // Cannon Lake (Core i3-8121U)
84 return cpuinfo_uarch_palm_cove;
85 case 0x6A: // Ice Lake-DE
86 case 0x6C: // Ice Lake-SP
87 case 0x7D: // Ice Lake-Y
88 case 0x7E: // Ice Lake-U
89 return cpuinfo_uarch_sunny_cove;
90
91 /* Low-power cores */
92 case 0x1C: // Diamondville, Silverthorne, Pineview
93 case 0x26: // Tunnel Creek
94 return cpuinfo_uarch_bonnell;
95 case 0x27: // Medfield
96 case 0x35: // Cloverview
97 case 0x36: // Cedarview, Centerton
98 return cpuinfo_uarch_saltwell;
99 case 0x37: // Bay Trail
100 case 0x4A: // Merrifield
101 case 0x4D: // Avoton, Rangeley
102 case 0x5A: // Moorefield
103 case 0x5D: // SoFIA
104 return cpuinfo_uarch_silvermont;
105 case 0x4C: // Braswell, Cherry Trail
106 case 0x75: // Spreadtrum SC9853I-IA
107 return cpuinfo_uarch_airmont;
108 case 0x5C: // Apollo Lake
109 case 0x5F: // Denverton
110 return cpuinfo_uarch_goldmont;
111 case 0x7A: // Gemini Lake
112 return cpuinfo_uarch_goldmont_plus;
113 /* Knights-series cores */
114 case 0x57:
115 return cpuinfo_uarch_knights_landing;
116 case 0x85:
117 return cpuinfo_uarch_knights_mill;
118 }
119 break;
120 case 0x0F:
121 switch (model_info->model) {
122 case 0x00: // Pentium 4 Xeon (Foster)
123 case 0x01: // Pentium 4 Celeron (Willamette-128), Pentium 4 Xeon (Foster, Foster MP)
124 case 0x02: // Pentium 4 (Northwood), Pentium 4 EE (Gallatin), Pentium 4 Celeron (Northwood-128, Northwood-256), Pentium 4 Xeon (Gallatin DP, Prestonia)
125 return cpuinfo_uarch_willamette;
126 break;
127 case 0x03: // Pentium 4 (Prescott), Pentium 4 Xeon (Nocona)
128 case 0x04: // Pentium 4 (Prescott-2M), Pentium 4 EE (Prescott-2M), Pentium D (Smithfield), Celeron D (Prescott-256), Pentium 4 Xeon (Cranford, Irwindale, Paxville)
129 case 0x06: // Pentium 4 (Cedar Mill), Pentium D EE (Presler), Celeron D (Cedar Mill), Pentium 4 Xeon (Dempsey, Tulsa)
130 return cpuinfo_uarch_prescott;
131 }
132 break;
133 }
134 break;
135 case cpuinfo_vendor_amd:
136 switch (model_info->family) {
137 #if CPUINFO_ARCH_X86
138 case 0x5:
139 switch (model_info->model) {
140 case 0x00:
141 case 0x01:
142 case 0x02:
143 return cpuinfo_uarch_k5;
144 case 0x06:
145 case 0x07:
146 case 0x08:
147 case 0x0D:
148 return cpuinfo_uarch_k6;
149 case 0x0A:
150 return cpuinfo_uarch_geode;
151 }
152 break;
153 case 0x6:
154 return cpuinfo_uarch_k7;
155 #endif /* CPUINFO_ARCH_X86 */
156 case 0xF: // Opteron, Athlon 64, Sempron
157 case 0x11: // Turion
158 return cpuinfo_uarch_k8;
159 case 0x10: // Opteron, Phenom, Athlon, Sempron
160 case 0x12: // Llano APU
161 return cpuinfo_uarch_k10;
162 case 0x14:
163 return cpuinfo_uarch_bobcat;
164 case 0x15:
165 switch (model_info->model) {
166 case 0x00: // Engineering samples
167 case 0x01: // Zambezi, Interlagos
168 return cpuinfo_uarch_bulldozer;
169 case 0x02: // Vishera
170 case 0x10: // Trinity
171 case 0x13: // Richland
172 return cpuinfo_uarch_piledriver;
173 case 0x38: // Godavari
174 case 0x30: // Kaveri
175 return cpuinfo_uarch_steamroller;
176 case 0x60: // Carrizo
177 case 0x65: // Bristol Ridge
178 case 0x70: // Stoney Ridge
179 return cpuinfo_uarch_excavator;
180 default:
181 switch (model_info->extended_model) {
182 case 0x0:
183 return cpuinfo_uarch_bulldozer;
184 case 0x1: // No L3 cache
185 case 0x2: // With L3 cache
186 return cpuinfo_uarch_piledriver;
187 case 0x3: // With L3 cache
188 case 0x4: // No L3 cache
189 return cpuinfo_uarch_steamroller;
190 }
191 break;
192 }
193 break;
194 case 0x16:
195 if (model_info->model >= 0x03) {
196 return cpuinfo_uarch_puma;
197 } else {
198 return cpuinfo_uarch_jaguar;
199 }
200 case 0x17:
201 switch (model_info->model) {
202 case 0x01: // 14 nm Naples, Whitehaven, Summit Ridge, Snowy Owl
203 case 0x08: // 12 nm Pinnacle Ridge
204 case 0x11: // 14 nm Raven Ridge
205 case 0x18: // 12 nm Picasso
206 return cpuinfo_uarch_zen;
207 case 0x71: // Matisse
208 return cpuinfo_uarch_zen2;
209 }
210 }
211 break;
212 default:
213 break;
214 }
215 return cpuinfo_uarch_unknown;
216 }
217