authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-10-16 00:32:56+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-10-16 00:33:10+02:00
log1bca53cc20f3b974d811a09addef84a6163c9c92
tree32c4763370c3e0b2d6add04046613e2c3184b9ff
parent7b8fc18c666ba6952ad1571fbed4cc48e81f647d
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.Target: Change Cpu.baseline() to also be able to take OS into consideration.


6 files changed, 17 insertions(+), 16 deletions(-)

lib/compiler/aro/aro/target.zig+2-2
......@@ -709,8 +709,8 @@ pub fn toLLVMTriple(target: std.Target, buf: []u8) []const u8 {
709709test "alignment functions - smoke test" {
710710 var target: std.Target = undefined;
711711 const x86 = std.Target.Cpu.Arch.x86_64;
712 target.cpu = std.Target.Cpu.baseline(x86);
713712 target.os = std.Target.Os.Tag.defaultVersionRange(.linux, x86);
713 target.cpu = std.Target.Cpu.baseline(x86, target.os);
714714 target.abi = std.Target.Abi.default(x86, target.os);
715715
716716 try std.testing.expect(isTlsSupported(target));
......@@ -722,8 +722,8 @@ test "alignment functions - smoke test" {
722722 try std.testing.expect(systemCompiler(target) == .gcc);
723723
724724 const arm = std.Target.Cpu.Arch.arm;
725 target.cpu = std.Target.Cpu.baseline(arm);
726725 target.os = std.Target.Os.Tag.defaultVersionRange(.ios, arm);
726 target.cpu = std.Target.Cpu.baseline(arm, target.os);
727727 target.abi = std.Target.Abi.default(arm, target.os);
728728
729729 try std.testing.expect(!isTlsSupported(target));
lib/std/Target.zig+4-3
......@@ -1669,7 +1669,8 @@ pub const Cpu = struct {
16691669 };
16701670 }
16711671
1672 pub fn baseline(arch: Arch) *const Model {
1672 pub fn baseline(arch: Arch, os: Os) *const Model {
1673 _ = os;
16731674 return switch (arch) {
16741675 .arm, .armeb, .thumb, .thumbeb => &arm.cpu.baseline,
16751676 .hexagon => &hexagon.cpu.hexagonv60, // gcc/clang do not have a generic hexagon model.
......@@ -1688,8 +1689,8 @@ pub const Cpu = struct {
16881689
16891690 /// The "default" set of CPU features for cross-compiling. A conservative set
16901691 /// of features that is expected to be supported on most available hardware.
1691 pub fn baseline(arch: Arch) Cpu {
1692 return Model.baseline(arch).toCpu(arch);
1692 pub fn baseline(arch: Arch, os: Os) Cpu {
1693 return Model.baseline(arch, os).toCpu(arch);
16931694 }
16941695};
16951696
lib/std/Target/Query.zig+5-5
......@@ -6,7 +6,7 @@
66/// `null` means native.
77cpu_arch: ?Target.Cpu.Arch = null,
88
9cpu_model: CpuModel = CpuModel.determined_by_cpu_arch,
9cpu_model: CpuModel = CpuModel.determined_by_arch_os,
1010
1111/// Sparse set of CPU features to add to the set from `cpu_model`.
1212cpu_features_add: Target.Cpu.Feature.Set = Target.Cpu.Feature.Set.empty,
......@@ -48,7 +48,7 @@ pub const CpuModel = union(enum) {
4848
4949 /// If CPU Architecture is native, then the CPU model will be native. Otherwise,
5050 /// it will be baseline.
51 determined_by_cpu_arch,
51 determined_by_arch_os,
5252
5353 explicit: *const Target.Cpu.Model,
5454
......@@ -58,7 +58,7 @@ pub const CpuModel = union(enum) {
5858 const b_tag: Tag = b;
5959 if (a_tag != b_tag) return false;
6060 return switch (a) {
61 .native, .baseline, .determined_by_cpu_arch => true,
61 .native, .baseline, .determined_by_arch_os => true,
6262 .explicit => |a_model| a_model == b.explicit,
6363 };
6464 }
......@@ -349,7 +349,7 @@ test parseVersion {
349349
350350pub fn isNativeCpu(self: Query) bool {
351351 return self.cpu_arch == null and
352 (self.cpu_model == .native or self.cpu_model == .determined_by_cpu_arch) and
352 (self.cpu_model == .native or self.cpu_model == .determined_by_arch_os) and
353353 self.cpu_features_sub.isEmpty() and self.cpu_features_add.isEmpty();
354354}
355355
......@@ -461,7 +461,7 @@ pub fn serializeCpu(q: Query, buffer: *std.ArrayList(u8)) Allocator.Error!void {
461461 .baseline => {
462462 buffer.appendSliceAssumeCapacity("baseline");
463463 },
464 .determined_by_cpu_arch => {
464 .determined_by_arch_os => {
465465 if (q.cpu_arch == null) {
466466 buffer.appendSliceAssumeCapacity("native");
467467 } else {
lib/std/simd.zig+1-1
......@@ -90,7 +90,7 @@ pub fn suggestVectorLength(comptime T: type) ?comptime_int {
9090}
9191
9292test "suggestVectorLengthForCpu works with signed and unsigned values" {
93 comptime var cpu = std.Target.Cpu.baseline(std.Target.Cpu.Arch.x86_64);
93 comptime var cpu = std.Target.Cpu.baseline(std.Target.Cpu.Arch.x86_64, builtin.os);
9494 comptime cpu.features.addFeature(@intFromEnum(std.Target.x86.Feature.avx512f));
9595 comptime cpu.features.populateDependencies(&std.Target.x86.all_features);
9696 const expected_len: usize = switch (builtin.zig_backend) {
lib/std/zig/system.zig+4-4
......@@ -337,14 +337,14 @@ pub fn resolveTargetQuery(query: Target.Query) DetectError!Target {
337337
338338 const cpu = switch (query.cpu_model) {
339339 .native => detectNativeCpuAndFeatures(cpu_arch, os, query),
340 .baseline => Target.Cpu.baseline(cpu_arch),
341 .determined_by_cpu_arch => if (query.cpu_arch == null)
340 .baseline => Target.Cpu.baseline(cpu_arch, os),
341 .determined_by_arch_os => if (query.cpu_arch == null)
342342 detectNativeCpuAndFeatures(cpu_arch, os, query)
343343 else
344 Target.Cpu.baseline(cpu_arch),
344 Target.Cpu.baseline(cpu_arch, os),
345345 .explicit => |model| model.toCpu(cpu_arch),
346346 } orelse backup_cpu_detection: {
347 break :backup_cpu_detection Target.Cpu.baseline(cpu_arch);
347 break :backup_cpu_detection Target.Cpu.baseline(cpu_arch, os);
348348 };
349349 var result = try detectAbiAndDynamicLinker(cpu, os, query);
350350 // For x86, we need to populate some CPU feature flags depending on architecture
src/main.zig+1-1
......@@ -6299,7 +6299,7 @@ fn detectNativeCpuWithLLVM(
62996299 llvm_cpu_name_z: ?[*:0]const u8,
63006300 llvm_cpu_features_opt: ?[*:0]const u8,
63016301) !std.Target.Cpu {
6302 var result = std.Target.Cpu.baseline(arch);
6302 var result = std.Target.Cpu.baseline(arch, builtin.os);
63036303
63046304 if (llvm_cpu_name_z) |cpu_name_z| {
63056305 const llvm_cpu_name = mem.span(cpu_name_z);