authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-09-17 07:43:43+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-09-17 15:27:52+02:00
logedad096b772d58bc39d227b0ba4d13b641ca99e6
treed0847c1f3793a1c69e6e93bcde35cd5b1c938f96
parent055064a37a24b0150b6c7ae426a8f2279819e7de
signature Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.zig.system: remove some pointless parameters being passed around


3 files changed, 11 insertions(+), 19 deletions(-)

lib/std/zig/system.zig+5-5
...@@ -374,10 +374,10 @@ pub fn resolveTargetQuery(io: Io, query: Target.Query) DetectError!Target {...@@ -374,10 +374,10 @@ pub fn resolveTargetQuery(io: Io, query: Target.Query) DetectError!Target {
374 }374 }
375375
376 var cpu = switch (query.cpu_model) {376 var cpu = switch (query.cpu_model) {
377 .native => detectNativeCpuAndFeatures(io, query_cpu_arch, os, query),377 .native => detectNativeCpuAndFeatures(io, query_cpu_arch),
378 .baseline => Target.Cpu.baseline(query_cpu_arch, os),378 .baseline => Target.Cpu.baseline(query_cpu_arch, os),
379 .determined_by_arch_os => if (query.cpu_arch == null)379 .determined_by_arch_os => if (query.cpu_arch == null)
380 detectNativeCpuAndFeatures(io, query_cpu_arch, os, query)380 detectNativeCpuAndFeatures(io, query_cpu_arch)
381 else381 else
382 Target.Cpu.baseline(query_cpu_arch, os),382 Target.Cpu.baseline(query_cpu_arch, os),
383 .explicit => |model| model.toCpu(query_cpu_arch),383 .explicit => |model| model.toCpu(query_cpu_arch),
...@@ -535,13 +535,13 @@ fn updateCpuFeatures(...@@ -535,13 +535,13 @@ fn updateCpuFeatures(
535 set.removeFeatureSet(sub_set);535 set.removeFeatureSet(sub_set);
536}536}
537537
538fn detectNativeCpuAndFeatures(io: Io, cpu_arch: Target.Cpu.Arch, os: Target.Os, query: Target.Query) ?Target.Cpu {538fn detectNativeCpuAndFeatures(io: Io, cpu_arch: Target.Cpu.Arch) ?Target.Cpu {
539 // Here we switch on a comptime value rather than `cpu_arch`. This is valid because `cpu_arch`,539 // Here we switch on a comptime value rather than `cpu_arch`. This is valid because `cpu_arch`,
540 // although it is a runtime value, is guaranteed to be one of the architectures in the set540 // although it is a runtime value, is guaranteed to be one of the architectures in the set
541 // of the respective switch prong.541 // of the respective switch prong.
542 switch (builtin.cpu.arch) {542 switch (builtin.cpu.arch) {
543 .loongarch32, .loongarch64 => return @import("system/loongarch.zig").detectNativeCpuAndFeatures(cpu_arch, os, query),543 .loongarch32, .loongarch64 => return @import("system/loongarch.zig").detectNativeCpuAndFeatures(cpu_arch),
544 .x86_64, .x86 => return @import("system/x86.zig").detectNativeCpuAndFeatures(cpu_arch, os, query),544 .x86_64, .x86 => return @import("system/x86.zig").detectNativeCpuAndFeatures(cpu_arch),
545 else => {},545 else => {},
546 }546 }
547547
lib/std/zig/system/loongarch.zig+1-8
...@@ -18,14 +18,7 @@ fn setFeature(cpu: *std.Target.Cpu, feature: std.Target.loongarch.Feature, enabl...@@ -18,14 +18,7 @@ fn setFeature(cpu: *std.Target.Cpu, feature: std.Target.loongarch.Feature, enabl
18 if (enabled) cpu.features.addFeature(idx) else cpu.features.removeFeature(idx);18 if (enabled) cpu.features.addFeature(idx) else cpu.features.removeFeature(idx);
19}19}
2020
21pub fn detectNativeCpuAndFeatures(21pub fn detectNativeCpuAndFeatures(arch: std.Target.Cpu.Arch) ?std.Target.Cpu {
22 arch: std.Target.Cpu.Arch,
23 os: std.Target.Os,
24 query: std.Target.Query,
25) ?std.Target.Cpu {
26 _ = os;
27 _ = query;
28
29 const variant: Variant = @fromBackingInt(@intCast(cpucfg(1) & 0b11));22 const variant: Variant = @fromBackingInt(@intCast(cpucfg(1) & 0b11));
3023
31 var cpu: std.Target.Cpu = .{24 var cpu: std.Target.Cpu = .{
lib/std/zig/system/x86.zig+5-6
...@@ -41,8 +41,7 @@ inline fn hasMask(input: u32, mask: u32) bool {...@@ -41,8 +41,7 @@ inline fn hasMask(input: u32, mask: u32) bool {
41 return (input & mask) == mask;41 return (input & mask) == mask;
42}42}
4343
44pub fn detectNativeCpuAndFeatures(arch: Target.Cpu.Arch, os: Target.Os, query: Target.Query) Target.Cpu {44pub fn detectNativeCpuAndFeatures(arch: Target.Cpu.Arch) Target.Cpu {
45 _ = query;
46 var cpu = Target.Cpu{45 var cpu = Target.Cpu{
47 .arch = arch,46 .arch = arch,
48 .model = Target.Cpu.Model.generic(arch),47 .model = Target.Cpu.Model.generic(arch),
...@@ -50,7 +49,7 @@ pub fn detectNativeCpuAndFeatures(arch: Target.Cpu.Arch, os: Target.Os, query: T...@@ -50,7 +49,7 @@ pub fn detectNativeCpuAndFeatures(arch: Target.Cpu.Arch, os: Target.Os, query: T
50 };49 };
5150
52 // First we detect features, to use as hints when detecting CPU Model.51 // First we detect features, to use as hints when detecting CPU Model.
53 detectNativeFeatures(&cpu, os.tag);52 detectNativeFeatures(&cpu);
5453
55 var leaf = cpuid(0, 0);54 var leaf = cpuid(0, 0);
56 const max_leaf = leaf.eax;55 const max_leaf = leaf.eax;
...@@ -90,7 +89,7 @@ pub fn detectNativeCpuAndFeatures(arch: Target.Cpu.Arch, os: Target.Os, query: T...@@ -90,7 +89,7 @@ pub fn detectNativeCpuAndFeatures(arch: Target.Cpu.Arch, os: Target.Os, query: T
90 // Add the CPU model's feature set into the working set, but then89 // Add the CPU model's feature set into the working set, but then
91 // override with actual detected features again.90 // override with actual detected features again.
92 cpu.features.addFeatureSet(cpu.model.features);91 cpu.features.addFeatureSet(cpu.model.features);
93 detectNativeFeatures(&cpu, os.tag);92 detectNativeFeatures(&cpu);
9493
95 cpu.features.populateDependencies(cpu.arch.allFeaturesList());94 cpu.features.populateDependencies(cpu.arch.allFeaturesList());
9695
...@@ -215,7 +214,7 @@ fn detectAmdProcessor(cpu: *const Target.Cpu, family: u32, model: u32) ?*const T...@@ -215,7 +214,7 @@ fn detectAmdProcessor(cpu: *const Target.Cpu, family: u32, model: u32) ?*const T
215 };214 };
216}215}
217216
218fn detectNativeFeatures(cpu: *Target.Cpu, os_tag: Target.Os.Tag) void {217fn detectNativeFeatures(cpu: *Target.Cpu) void {
219 var leaf = cpuid(0, 0);218 var leaf = cpuid(0, 0);
220219
221 const max_level = leaf.eax;220 const max_level = leaf.eax;
...@@ -268,7 +267,7 @@ fn detectNativeFeatures(cpu: *Target.Cpu, os_tag: Target.Os.Tag) void {...@@ -268,7 +267,7 @@ fn detectNativeFeatures(cpu: *Target.Cpu, os_tag: Target.Os.Tag) void {
268 // Darwin lazily saves the AVX512 context on first use: trust that the OS will267 // Darwin lazily saves the AVX512 context on first use: trust that the OS will
269 // save the AVX512 context if we use AVX512 instructions, even if the bit is not268 // save the AVX512 context if we use AVX512 instructions, even if the bit is not
270 // set right now.269 // set right now.
271 const has_avx512_save = if (os_tag.isDarwin())270 const has_avx512_save = if (builtin.target.os.tag.isDarwin())
272 true271 true
273 else272 else
274 xcr0.zmm_hi256 and xcr0.hi16_zmm;273 xcr0.zmm_hi256 and xcr0.hi16_zmm;