| ... | @@ -58,7 +58,7 @@ pub fn detectNativeCpuAndFeatures(arch: Target.Cpu.Arch, os: Target.Os, query: T | ... | @@ -58,7 +58,7 @@ pub fn detectNativeCpuAndFeatures(arch: Target.Cpu.Arch, os: Target.Os, query: T |
| 58 | detectIntelProcessor(&cpu, family, model, brand_id); | 58 | detectIntelProcessor(&cpu, family, model, brand_id); |
| 59 | }, | 59 | }, |
| 60 | 0x68747541 => { | 60 | 0x68747541 => { |
| 61 | detectAMDProcessor(&cpu, family, model); | 61 | if (detectAMDProcessor(cpu.features, family, model)) |m| cpu.model = m; |
| 62 | }, | 62 | }, |
| 63 | else => {}, | 63 | else => {}, |
| 64 | } | 64 | } |
| ... | @@ -224,97 +224,43 @@ fn detectIntelProcessor(cpu: *Target.Cpu, family: u32, model: u32, brand_id: u32 | ... | @@ -224,97 +224,43 @@ fn detectIntelProcessor(cpu: *Target.Cpu, family: u32, model: u32, brand_id: u32 |
| 224 | } | 224 | } |
| 225 | } | 225 | } |
| 226 | | 226 | |
| 227 | fn detectAMDProcessor(cpu: *Target.Cpu, family: u32, model: u32) void { | 227 | fn detectAMDProcessor(features: Target.Cpu.Feature.Set, family: u32, model: u32) ?*const Target.Cpu.Model { |
| 228 | // AMD's cpuid information is less than optimal for determining a CPU model. | 228 | return switch (family) { |
| 229 | // This is very unscientific, and not necessarily correct. | 229 | 4 => &Target.x86.cpu.i486, |
| 230 | switch (family) { | 230 | 5 => switch (model) { |
| 231 | 4 => { | 231 | 6, 7 => &Target.x86.cpu.k6, |
| 232 | cpu.model = &Target.x86.cpu.i486; | 232 | 8 => &Target.x86.cpu.k6_2, |
| 233 | return; | 233 | 9, 13 => &Target.x86.cpu.k6_3, |
| 234 | }, | 234 | 10 => &Target.x86.cpu.geode, |
| 235 | 5 => { | 235 | else => &Target.x86.cpu.pentium, |
| 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; | | |
| 273 | }, | 236 | }, |
| 274 | 16 => { | 237 | 6 => if (Target.x86.featureSetHas(features, .sse)) |
| 275 | cpu.model = &Target.x86.cpu.amdfam10; | 238 | &Target.x86.cpu.athlon_xp |
| 276 | return; | 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, |
| 277 | }, | 252 | }, |
| 278 | 20 => { | 253 | 22 => &Target.x86.cpu.btver2, |
| 279 | cpu.model = &Target.x86.cpu.btver1; | 254 | 23 => switch (model) { |
| 280 | return; | 255 | 0x30...0x3f, 0x71 => &Target.x86.cpu.znver2, |
| | 256 | else => &Target.x86.cpu.znver1, |
| 281 | }, | 257 | }, |
| 282 | 21 => { | 258 | 25 => switch (model) { |
| 283 | cpu.model = &Target.x86.cpu.bdver1; | 259 | 0x10...0x1f, 0x60...0x6f, 0x70...0x77, 0x78...0x7f, 0xa0...0xaf => &Target.x86.cpu.znver4, |
| 284 | if (model >= 0x60 and model <= 0x7f) { | 260 | else => &Target.x86.cpu.znver3, |
| 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; | | |
| 297 | }, | 261 | }, |
| 298 | 22 => { | 262 | else => null, |
| 299 | cpu.model = &Target.x86.cpu.btver2; | 263 | }; |
| 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 | } | | |
| 318 | } | 264 | } |
| 319 | | 265 | |
| 320 | fn detectNativeFeatures(cpu: *Target.Cpu, os_tag: Target.Os.Tag) void { | 266 | fn detectNativeFeatures(cpu: *Target.Cpu, os_tag: Target.Os.Tag) void { |