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 case 0xA5: // Comet Lake H/S
83 case 0xA6: // Comet Lake U/Y
84 return cpuinfo_uarch_sky_lake;
85 case 0x66: // Cannon Lake (Core i3-8121U)
86 return cpuinfo_uarch_palm_cove;
87 case 0x6A: // Ice Lake-DE
88 case 0x6C: // Ice Lake-SP
89 case 0x7D: // Ice Lake-Y
90 case 0x7E: // Ice Lake-U
91 return cpuinfo_uarch_sunny_cove;
92
93 /* Low-power cores */
94 case 0x1C: // Diamondville, Silverthorne, Pineview
95 case 0x26: // Tunnel Creek
96 return cpuinfo_uarch_bonnell;
97 case 0x27: // Medfield
98 case 0x35: // Cloverview
99 case 0x36: // Cedarview, Centerton
100 return cpuinfo_uarch_saltwell;
101 case 0x37: // Bay Trail
102 case 0x4A: // Merrifield
103 case 0x4D: // Avoton, Rangeley
104 case 0x5A: // Moorefield
105 case 0x5D: // SoFIA
106 return cpuinfo_uarch_silvermont;
107 case 0x4C: // Braswell, Cherry Trail
108 case 0x75: // Spreadtrum SC9853I-IA
109 return cpuinfo_uarch_airmont;
110 case 0x5C: // Apollo Lake
111 case 0x5F: // Denverton
112 return cpuinfo_uarch_goldmont;
113 case 0x7A: // Gemini Lake
114 return cpuinfo_uarch_goldmont_plus;
115
116 /* Knights-series cores */
117 case 0x57:
118 return cpuinfo_uarch_knights_landing;
119 case 0x85:
120 return cpuinfo_uarch_knights_mill;
121 }
122 break;
123 case 0x0F:
124 switch (model_info->model) {
125 case 0x00: // Pentium 4 Xeon (Foster)
126 case 0x01: // Pentium 4 Celeron (Willamette-128), Pentium 4 Xeon (Foster, Foster MP)
127 case 0x02: // Pentium 4 (Northwood), Pentium 4 EE (Gallatin), Pentium 4 Celeron (Northwood-128, Northwood-256), Pentium 4 Xeon (Gallatin DP, Prestonia)
128 return cpuinfo_uarch_willamette;
129 break;
130 case 0x03: // Pentium 4 (Prescott), Pentium 4 Xeon (Nocona)
131 case 0x04: // Pentium 4 (Prescott-2M), Pentium 4 EE (Prescott-2M), Pentium D (Smithfield), Celeron D (Prescott-256), Pentium 4 Xeon (Cranford, Irwindale, Paxville)
132 case 0x06: // Pentium 4 (Cedar Mill), Pentium D EE (Presler), Celeron D (Cedar Mill), Pentium 4 Xeon (Dempsey, Tulsa)
133 return cpuinfo_uarch_prescott;
134 }
135 break;
136 }
137 break;
138 case cpuinfo_vendor_amd:
139 switch (model_info->family) {
140 #if CPUINFO_ARCH_X86
141 case 0x5:
142 switch (model_info->model) {
143 case 0x00:
144 case 0x01:
145 case 0x02:
146 return cpuinfo_uarch_k5;
147 case 0x06:
148 case 0x07:
149 case 0x08:
150 case 0x0D:
151 return cpuinfo_uarch_k6;
152 case 0x0A:
153 return cpuinfo_uarch_geode;
154 }
155 break;
156 case 0x6:
157 return cpuinfo_uarch_k7;
158 #endif /* CPUINFO_ARCH_X86 */
159 case 0xF: // Opteron, Athlon 64, Sempron
160 case 0x11: // Turion
161 return cpuinfo_uarch_k8;
162 case 0x10: // Opteron, Phenom, Athlon, Sempron
163 case 0x12: // Llano APU
164 return cpuinfo_uarch_k10;
165 case 0x14:
166 return cpuinfo_uarch_bobcat;
167 case 0x15:
168 switch (model_info->model) {
169 case 0x00: // Engineering samples
170 case 0x01: // Zambezi, Interlagos
171 return cpuinfo_uarch_bulldozer;
172 case 0x02: // Vishera
173 case 0x10: // Trinity
174 case 0x13: // Richland
175 return cpuinfo_uarch_piledriver;
176 case 0x38: // Godavari
177 case 0x30: // Kaveri
178 return cpuinfo_uarch_steamroller;
179 case 0x60: // Carrizo
180 case 0x65: // Bristol Ridge
181 case 0x70: // Stoney Ridge
182 return cpuinfo_uarch_excavator;
183 default:
184 switch (model_info->extended_model) {
185 case 0x0:
186 return cpuinfo_uarch_bulldozer;
187 case 0x1: // No L3 cache
188 case 0x2: // With L3 cache
189 return cpuinfo_uarch_piledriver;
190 case 0x3: // With L3 cache
191 case 0x4: // No L3 cache
192 return cpuinfo_uarch_steamroller;
193 }
194 break;
195 }
196 break;
197 case 0x16:
198 if (model_info->model >= 0x03) {
199 return cpuinfo_uarch_puma;
200 } else {
201 return cpuinfo_uarch_jaguar;
202 }
203 case 0x17:
204 switch (model_info->model) {
205 case 0x01: // 14 nm Naples, Whitehaven, Summit Ridge, Snowy Owl
206 case 0x08: // 12 nm Pinnacle Ridge
207 case 0x11: // 14 nm Raven Ridge, Great Horned Owl
208 case 0x18: // 12 nm Picasso
209 return cpuinfo_uarch_zen;
210 case 0x31: // Rome, Castle Peak
211 case 0x60: // Renoir
212 case 0x68: // Lucienne
213 case 0x71: // Matisse
214 case 0x90: // Van Gogh
215 case 0x98: // Mero
216 return cpuinfo_uarch_zen2;
217 }
218 break;
219 case 0x19:
220 switch (model_info->model) {
221 case 0x01: // Genesis
222 case 0x21: // Vermeer
223 case 0x30: // Badami, Trento
224 case 0x40: // Rembrandt
225 case 0x50: // Cezanne
226 return cpuinfo_uarch_zen3;
227 }
228 break;
229 }
230 break;
231 case cpuinfo_vendor_hygon:
232 switch (model_info->family) {
233 case 0x00:
234 return cpuinfo_uarch_dhyana;
235 }
236 break;
237 default:
238 break;
239 }
240 return cpuinfo_uarch_unknown;
241 }
242