feature. See also
. The project being documented here (as the example) is the Zig library itself.
x86.detectNativeCpuAndFeatures
pub fn detectNativeCpuAndFeatures(arch: Target.Cpu.Arch, os: Target.Os, query: Target.Query) Target.Cpu
File
Code
pub fn detectNativeCpuAndFeatures(arch: Target.Cpu.Arch, os: Target.Os, query: Target.Query) Target.Cpu {
_ = query;
var cpu = Target.Cpu{
.arch = arch,
.model = Target.Cpu.Model.generic(arch),
.features = Target.Cpu.Feature.Set.empty,
};
detectNativeFeatures(&cpu, os.tag);
var leaf = cpuid(0, 0);
const max_leaf = leaf.eax;
const vendor = leaf.ebx;
if (max_leaf > 0) {
leaf = cpuid(0x1, 0);
const brand_id = leaf.ebx & 0xff;
var family = (leaf.eax >> 8) & 0xf;
var model = (leaf.eax >> 4) & 0xf;
if (family == 6 or family == 0xf) {
if (family == 0xf) {
family += (leaf.eax >> 20) & 0xff;
}
model += ((leaf.eax >> 16) & 0xf) << 4;
}
switch (vendor) {
0x756e6547 => {
detectIntelProcessor(&cpu, family, model, brand_id);
},
0x68747541 => {
if (detectAMDProcessor(cpu, family, model)) |m| cpu.model = m;
},
else => {},
}
}
// override with actual detected features again.
cpu.features.addFeatureSet(cpu.model.features);
detectNativeFeatures(&cpu, os.tag);
cpu.features.populateDependencies(cpu.arch.allFeaturesList());
return cpu;
}