authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-09-06 10:40:09+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-09-06 10:40:09+02:00
log6bee34ee56ab0fd6da1903924efa8816494ba3f6
tree0e1d009d281b712c76381e9123ba937a36f4cb4a
parent71a7185ebb777e04f668590358079fb1f08da3e8
signature Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.zig.system.openbsd: implement riscv CPU model detection


1 files changed, 21 insertions(+), 0 deletions(-)

lib/std/zig/system/openbsd.zig+21
...@@ -132,11 +132,32 @@ const powerpc = struct {...@@ -132,11 +132,32 @@ const powerpc = struct {
132 }132 }
133};133};
134134
135const riscv = struct {
136 const models = .{
137 .{ "SiFive U5", &std.Target.riscv.cpu.sifive_u54 },
138 .{ "SiFive U7", &std.Target.riscv.cpu.sifive_u74 },
139 .{ "SpacemiT X60", &std.Target.riscv.cpu.spacemit_x60 },
140 .{ "SpacemiT X100", &std.Target.riscv.cpu.spacemit_x100 },
141 };
142
143 fn detectNativeCpu(arch: std.Target.Cpu.Arch) ?std.Target.Cpu {
144 var buf: [64:0]u8 = undefined;
145 const name = hwModelName(&buf) orelse return null;
146
147 inline for (models) |pair| {
148 if (std.mem.startsWith(u8, name, pair[0])) return pair[1].toCpu(arch);
149 }
150
151 return null;
152 }
153};
154
135pub fn detectNativeCpuAndFeatures() ?std.Target.Cpu {155pub fn detectNativeCpuAndFeatures() ?std.Target.Cpu {
136 return switch (native_arch) {156 return switch (native_arch) {
137 .aarch64 => aarch64.detectNativeCpuAndFeatures(native_arch),157 .aarch64 => aarch64.detectNativeCpuAndFeatures(native_arch),
138 .arm => arm.detectNativeCpu(native_arch),158 .arm => arm.detectNativeCpu(native_arch),
139 .powerpc, .powerpc64 => powerpc.detectNativeCpu(native_arch),159 .powerpc, .powerpc64 => powerpc.detectNativeCpu(native_arch),
160 .riscv64 => riscv.detectNativeCpu(native_arch),
140 else => null,161 else => null,
141 };162 };
142}163}