authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-04-28 20:22:23-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-05-08 19:37:29-07:00
log3c21db639269d29a4edde140dea43e5cdf3e9431
treead800bd1abb8ec7e0d13664826ad92413d5792e4
parent78002dbe47c9dec430754c3a3f1d62c1b11df08d

update detectAMDProcessor to detect znver4


1 files changed, 34 insertions(+), 88 deletions(-)

lib/std/zig/system/x86.zig+34-88
......@@ -58,7 +58,7 @@ pub fn detectNativeCpuAndFeatures(arch: Target.Cpu.Arch, os: Target.Os, query: T
5858 detectIntelProcessor(&cpu, family, model, brand_id);
5959 },
6060 0x68747541 => {
61 detectAMDProcessor(&cpu, family, model);
61 if (detectAMDProcessor(cpu.features, family, model)) |m| cpu.model = m;
6262 },
6363 else => {},
6464 }
......@@ -224,97 +224,43 @@ fn detectIntelProcessor(cpu: *Target.Cpu, family: u32, model: u32, brand_id: u32
224224 }
225225}
226226
227fn detectAMDProcessor(cpu: *Target.Cpu, family: u32, model: u32) void {
228 // AMD's cpuid information is less than optimal for determining a CPU model.
229 // This is very unscientific, and not necessarily correct.
230 switch (family) {
231 4 => {
232 cpu.model = &Target.x86.cpu.i486;
233 return;
234 },
235 5 => {
236 cpu.model = &Target.x86.cpu.pentium;
237 switch (model) {
238 6, 7 => {
239 cpu.model = &Target.x86.cpu.k6;
240 return;
241 },
242 8 => {
243 cpu.model = &Target.x86.cpu.k6_2;
244 return;
245 },
246 9, 13 => {
247 cpu.model = &Target.x86.cpu.k6_3;
248 return;
249 },
250 10 => {
251 cpu.model = &Target.x86.cpu.geode;
252 return;
253 },
254 else => {},
255 }
256 return;
257 },
258 6 => {
259 if (Target.x86.featureSetHas(cpu.features, .sse)) {
260 cpu.model = &Target.x86.cpu.athlon_xp;
261 return;
262 }
263 cpu.model = &Target.x86.cpu.athlon;
264 return;
265 },
266 15 => {
267 if (Target.x86.featureSetHas(cpu.features, .sse3)) {
268 cpu.model = &Target.x86.cpu.k8_sse3;
269 return;
270 }
271 cpu.model = &Target.x86.cpu.k8;
272 return;
227fn detectAMDProcessor(features: Target.Cpu.Feature.Set, family: u32, model: u32) ?*const Target.Cpu.Model {
228 return switch (family) {
229 4 => &Target.x86.cpu.i486,
230 5 => switch (model) {
231 6, 7 => &Target.x86.cpu.k6,
232 8 => &Target.x86.cpu.k6_2,
233 9, 13 => &Target.x86.cpu.k6_3,
234 10 => &Target.x86.cpu.geode,
235 else => &Target.x86.cpu.pentium,
273236 },
274 16 => {
275 cpu.model = &Target.x86.cpu.amdfam10;
276 return;
237 6 => if (Target.x86.featureSetHas(features, .sse))
238 &Target.x86.cpu.athlon_xp
239 else
240 &Target.x86.cpu.athlon,
241 15 => if (Target.x86.featureSetHas(features, .sse3))
242 &Target.x86.cpu.k8_sse3
243 else
244 &Target.x86.cpu.k8,
245 16 => &Target.x86.cpu.amdfam10,
246 20 => &Target.x86.cpu.btver1,
247 21 => switch (model) {
248 0x60...0x7f => &Target.x86.cpu.bdver4,
249 0x30...0x3f => &Target.x86.cpu.bdver3,
250 0x02, 0x10...0x1f => &Target.x86.cpu.bdver2,
251 else => &Target.x86.cpu.bdver1,
277252 },
278 20 => {
279 cpu.model = &Target.x86.cpu.btver1;
280 return;
253 22 => &Target.x86.cpu.btver2,
254 23 => switch (model) {
255 0x30...0x3f, 0x71 => &Target.x86.cpu.znver2,
256 else => &Target.x86.cpu.znver1,
281257 },
282 21 => {
283 cpu.model = &Target.x86.cpu.bdver1;
284 if (model >= 0x60 and model <= 0x7f) {
285 cpu.model = &Target.x86.cpu.bdver4;
286 return;
287 }
288 if (model >= 0x30 and model <= 0x3f) {
289 cpu.model = &Target.x86.cpu.bdver3;
290 return;
291 }
292 if ((model >= 0x10 and model <= 0x1f) or model == 0x02) {
293 cpu.model = &Target.x86.cpu.bdver2;
294 return;
295 }
296 return;
258 25 => switch (model) {
259 0x10...0x1f, 0x60...0x6f, 0x70...0x77, 0x78...0x7f, 0xa0...0xaf => &Target.x86.cpu.znver4,
260 else => &Target.x86.cpu.znver3,
297261 },
298 22 => {
299 cpu.model = &Target.x86.cpu.btver2;
300 return;
301 },
302 23 => {
303 cpu.model = &Target.x86.cpu.znver1;
304 if ((model >= 0x30 and model <= 0x3f) or model == 0x71) {
305 cpu.model = &Target.x86.cpu.znver2;
306 return;
307 }
308 return;
309 },
310 25 => {
311 cpu.model = &Target.x86.cpu.znver3;
312 return;
313 },
314 else => {
315 return;
316 },
317 }
262 else => null,
263 };
318264}
319265
320266fn detectNativeFeatures(cpu: *Target.Cpu, os_tag: Target.Os.Tag) void {