Returns the most bare-bones CPU model that is valid for arch. Note that this function
can return CPU models that are understood by LLVM, but not understood by Clang. If
Clang compatibility is important, consider using baseline instead.
arch: Archpub fn generic(arch: Arch) *const Model {
const S = struct {
const generic_model = Model{
.name = "generic",
.llvm_name = null,
.features = Cpu.Feature.Set.empty,
};
};
return switch (arch) {
.amdgcn => &amdgcn.cpu.gfx600,
.arc => &arc.cpu.generic,
.arm, .armeb, .thumb, .thumbeb => &arm.cpu.generic,
.aarch64, .aarch64_be => &aarch64.cpu.generic,
.avr => &avr.cpu.avr1,
.bpfel, .bpfeb => &bpf.cpu.generic,
.csky => &csky.cpu.generic,
.hexagon => &hexagon.cpu.generic,
.lanai => &lanai.cpu.generic,
.loongarch32 => &loongarch.cpu.generic_la32,
.loongarch64 => &loongarch.cpu.generic_la64,
.m68k => &m68k.cpu.generic,
.mips, .mipsel => &mips.cpu.mips32,
.mips64, .mips64el => &mips.cpu.mips64,
.msp430 => &msp430.cpu.generic,
.powerpc, .powerpcle => &powerpc.cpu.ppc,
.powerpc64, .powerpc64le => &powerpc.cpu.ppc64,
.propeller => &propeller.cpu.p1,
.riscv32 => &riscv.cpu.generic_rv32,
.riscv64 => &riscv.cpu.generic_rv64,
.spirv, .spirv32, .spirv64 => &spirv.cpu.generic,
.sparc => &sparc.cpu.generic,
.sparc64 => &sparc.cpu.v9, // 64-bit SPARC needs v9 as the baseline
.s390x => &s390x.cpu.generic,
.x86 => &x86.cpu.i386,
.x86_64 => &x86.cpu.x86_64,
.nvptx, .nvptx64 => &nvptx.cpu.sm_20,
.ve => &ve.cpu.generic,
.wasm32, .wasm64 => &wasm.cpu.mvp,
.xcore => &xcore.cpu.generic,
.xtensa => &xtensa.cpu.generic,
.kalimba,
=> &S.generic_model,
};
}Returns a conservative CPU model for arch that is expected to be compatible with the
vast majority of hardware available. This function is guaranteed to return CPU models
that are understood by both LLVM and Clang, unlike generic.
For certain os values, this function will additionally bump the baseline higher than
the baseline would be for arch in isolation; for example, for aarch64-macos, the
baseline is considered to be apple_m1. To avoid this behavior entirely, pass
Os.Tag.freestanding.
pub fn baseline(arch: Arch, os: Os) *const Model {
return switch (arch) {
.amdgcn => &amdgcn.cpu.gfx906,
.arm, .armeb, .thumb, .thumbeb => &arm.cpu.baseline,
.aarch64 => switch (os.tag) {
.driverkit, .macos => &aarch64.cpu.apple_m1,
.ios, .tvos => &aarch64.cpu.apple_a7,
.visionos => &aarch64.cpu.apple_m2,
.watchos => &aarch64.cpu.apple_s4,
else => generic(arch),
},
.avr => &avr.cpu.avr2,
.bpfel, .bpfeb => &bpf.cpu.v1,
.csky => &csky.cpu.ck810, // gcc/clang do not have a generic csky model.
.hexagon => &hexagon.cpu.hexagonv60, // gcc/clang do not have a generic hexagon model.
.lanai => &lanai.cpu.v11, // clang does not have a generic lanai model.
.loongarch64 => &loongarch.cpu.loongarch64,
.m68k => &m68k.cpu.M68000,
.mips, .mipsel => &mips.cpu.mips32r2,
.mips64, .mips64el => &mips.cpu.mips64r2,
.msp430 => &msp430.cpu.msp430,
.nvptx, .nvptx64 => &nvptx.cpu.sm_52,
.powerpc64le => &powerpc.cpu.ppc64le,
.riscv32 => &riscv.cpu.baseline_rv32,
.riscv64 => &riscv.cpu.baseline_rv64,
.s390x => &s390x.cpu.arch8, // gcc/clang do not have a generic s390x model.
.sparc => &sparc.cpu.v9, // glibc does not work with 'plain' v8.
.x86 => &x86.cpu.pentium4,
.x86_64 => switch (os.tag) {
.driverkit => &x86.cpu.nehalem,
.ios, .macos, .tvos, .visionos, .watchos => &x86.cpu.core2,
.ps4 => &x86.cpu.btver2,
.ps5 => &x86.cpu.znver2,
else => generic(arch),
},
.xcore => &xcore.cpu.xs1b_generic,
.wasm32, .wasm64 => &wasm.cpu.lime1,
else => generic(arch),
};
}pub const Model = struct {
name: []const u8,
llvm_name: ?[:0]const u8,
features: Feature.Set,
pub fn toCpu(model: *const Model, arch: Arch) Cpu {
var features = model.features;
features.populateDependencies(arch.allFeaturesList());
return .{
.arch = arch,
.model = model,
.features = features,
};
}
/// Returns the most bare-bones CPU model that is valid for `arch`. Note that this function
/// can return CPU models that are understood by LLVM, but *not* understood by Clang. If
/// Clang compatibility is important, consider using `baseline` instead.
pub fn generic(arch: Arch) *const Model {
const S = struct {
const generic_model = Model{
.name = "generic",
.llvm_name = null,
.features = Cpu.Feature.Set.empty,
};
};
return switch (arch) {
.amdgcn => &amdgcn.cpu.gfx600,
.arc => &arc.cpu.generic,
.arm, .armeb, .thumb, .thumbeb => &arm.cpu.generic,
.aarch64, .aarch64_be => &aarch64.cpu.generic,
.avr => &avr.cpu.avr1,
.bpfel, .bpfeb => &bpf.cpu.generic,
.csky => &csky.cpu.generic,
.hexagon => &hexagon.cpu.generic,
.lanai => &lanai.cpu.generic,
.loongarch32 => &loongarch.cpu.generic_la32,
.loongarch64 => &loongarch.cpu.generic_la64,
.m68k => &m68k.cpu.generic,
.mips, .mipsel => &mips.cpu.mips32,
.mips64, .mips64el => &mips.cpu.mips64,
.msp430 => &msp430.cpu.generic,
.powerpc, .powerpcle => &powerpc.cpu.ppc,
.powerpc64, .powerpc64le => &powerpc.cpu.ppc64,
.propeller => &propeller.cpu.p1,
.riscv32 => &riscv.cpu.generic_rv32,
.riscv64 => &riscv.cpu.generic_rv64,
.spirv, .spirv32, .spirv64 => &spirv.cpu.generic,
.sparc => &sparc.cpu.generic,
.sparc64 => &sparc.cpu.v9, // 64-bit SPARC needs v9 as the baseline
.s390x => &s390x.cpu.generic,
.x86 => &x86.cpu.i386,
.x86_64 => &x86.cpu.x86_64,
.nvptx, .nvptx64 => &nvptx.cpu.sm_20,
.ve => &ve.cpu.generic,
.wasm32, .wasm64 => &wasm.cpu.mvp,
.xcore => &xcore.cpu.generic,
.xtensa => &xtensa.cpu.generic,
.kalimba,
=> &S.generic_model,
};
}
/// Returns a conservative CPU model for `arch` that is expected to be compatible with the
/// vast majority of hardware available. This function is guaranteed to return CPU models
/// that are understood by both LLVM and Clang, unlike `generic`.
///
/// For certain `os` values, this function will additionally bump the baseline higher than
/// the baseline would be for `arch` in isolation; for example, for `aarch64-macos`, the
/// baseline is considered to be `apple_m1`. To avoid this behavior entirely, pass
/// `Os.Tag.freestanding`.
pub fn baseline(arch: Arch, os: Os) *const Model {
return switch (arch) {
.amdgcn => &amdgcn.cpu.gfx906,
.arm, .armeb, .thumb, .thumbeb => &arm.cpu.baseline,
.aarch64 => switch (os.tag) {
.driverkit, .macos => &aarch64.cpu.apple_m1,
.ios, .tvos => &aarch64.cpu.apple_a7,
.visionos => &aarch64.cpu.apple_m2,
.watchos => &aarch64.cpu.apple_s4,
else => generic(arch),
},
.avr => &avr.cpu.avr2,
.bpfel, .bpfeb => &bpf.cpu.v1,
.csky => &csky.cpu.ck810, // gcc/clang do not have a generic csky model.
.hexagon => &hexagon.cpu.hexagonv60, // gcc/clang do not have a generic hexagon model.
.lanai => &lanai.cpu.v11, // clang does not have a generic lanai model.
.loongarch64 => &loongarch.cpu.loongarch64,
.m68k => &m68k.cpu.M68000,
.mips, .mipsel => &mips.cpu.mips32r2,
.mips64, .mips64el => &mips.cpu.mips64r2,
.msp430 => &msp430.cpu.msp430,
.nvptx, .nvptx64 => &nvptx.cpu.sm_52,
.powerpc64le => &powerpc.cpu.ppc64le,
.riscv32 => &riscv.cpu.baseline_rv32,
.riscv64 => &riscv.cpu.baseline_rv64,
.s390x => &s390x.cpu.arch8, // gcc/clang do not have a generic s390x model.
.sparc => &sparc.cpu.v9, // glibc does not work with 'plain' v8.
.x86 => &x86.cpu.pentium4,
.x86_64 => switch (os.tag) {
.driverkit => &x86.cpu.nehalem,
.ios, .macos, .tvos, .visionos, .watchos => &x86.cpu.core2,
.ps4 => &x86.cpu.btver2,
.ps5 => &x86.cpu.znver2,
else => generic(arch),
},
.xcore => &xcore.cpu.xs1b_generic,
.wasm32, .wasm64 => &wasm.cpu.lime1,
else => generic(arch),
};
}
}