| author | |
| committer | |
| log | ecd5878b74940852e8a63154aba165047bca0e0a |
| tree | 543bdd9ac090d7e4051892f00cf1cbb5b716a070 |
| parent | 1efc9c149c8310802a1fb9bb15024079e033ef5e |
| parent | a2c466220c13392e85f4910316883d5042ec248c |
| signature |
`std.Target`: Make `Cpu.baseline()` take OS into consideration and pick a better CPU for Apple targets6 files changed, 23 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 { |
| 709 | 709 | test "alignment functions - smoke test" { |
| 710 | 710 | var target: std.Target = undefined; |
| 711 | 711 | const x86 = std.Target.Cpu.Arch.x86_64; |
| 712 | target.cpu = std.Target.Cpu.baseline(x86); | |
| 713 | 712 | target.os = std.Target.Os.Tag.defaultVersionRange(.linux, x86); |
| 713 | target.cpu = std.Target.Cpu.baseline(x86, target.os); | |
| 714 | 714 | target.abi = std.Target.Abi.default(x86, target.os); |
| 715 | 715 | |
| 716 | 716 | try std.testing.expect(isTlsSupported(target)); |
| ... | ... | @@ -722,8 +722,8 @@ test "alignment functions - smoke test" { |
| 722 | 722 | try std.testing.expect(systemCompiler(target) == .gcc); |
| 723 | 723 | |
| 724 | 724 | const arm = std.Target.Cpu.Arch.arm; |
| 725 | target.cpu = std.Target.Cpu.baseline(arm); | |
| 726 | 725 | target.os = std.Target.Os.Tag.defaultVersionRange(.ios, arm); |
| 726 | target.cpu = std.Target.Cpu.baseline(arm, target.os); | |
| 727 | 727 | target.abi = std.Target.Abi.default(arm, target.os); |
| 728 | 728 | |
| 729 | 729 | try std.testing.expect(!isTlsSupported(target)); |
lib/std/Target.zig+10-3| ... | ... | @@ -1669,9 +1669,16 @@ pub const Cpu = struct { |
| 1669 | 1669 | }; |
| 1670 | 1670 | } |
| 1671 | 1671 | |
| 1672 | pub fn baseline(arch: Arch) *const Model { | |
| 1672 | pub fn baseline(arch: Arch, os: Os) *const Model { | |
| 1673 | 1673 | return switch (arch) { |
| 1674 | 1674 | .arm, .armeb, .thumb, .thumbeb => &arm.cpu.baseline, |
| 1675 | .aarch64 => switch (os.tag) { | |
| 1676 | .bridgeos, .driverkit, .macos => &aarch64.cpu.apple_m1, | |
| 1677 | .ios, .tvos => &aarch64.cpu.apple_a7, | |
| 1678 | .visionos => &aarch64.cpu.apple_m2, | |
| 1679 | .watchos => &aarch64.cpu.apple_s4, | |
| 1680 | else => generic(arch), | |
| 1681 | }, | |
| 1675 | 1682 | .hexagon => &hexagon.cpu.hexagonv60, // gcc/clang do not have a generic hexagon model. |
| 1676 | 1683 | .riscv32 => &riscv.cpu.baseline_rv32, |
| 1677 | 1684 | .riscv64 => &riscv.cpu.baseline_rv64, |
| ... | ... | @@ -1688,8 +1695,8 @@ pub const Cpu = struct { |
| 1688 | 1695 | |
| 1689 | 1696 | /// The "default" set of CPU features for cross-compiling. A conservative set |
| 1690 | 1697 | /// 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); | |
| 1698 | pub fn baseline(arch: Arch, os: Os) Cpu { | |
| 1699 | return Model.baseline(arch, os).toCpu(arch); | |
| 1693 | 1700 | } |
| 1694 | 1701 | }; |
| 1695 | 1702 |
lib/std/Target/Query.zig+5-5| ... | ... | @@ -6,7 +6,7 @@ |
| 6 | 6 | /// `null` means native. |
| 7 | 7 | cpu_arch: ?Target.Cpu.Arch = null, |
| 8 | 8 | |
| 9 | cpu_model: CpuModel = CpuModel.determined_by_cpu_arch, | |
| 9 | cpu_model: CpuModel = CpuModel.determined_by_arch_os, | |
| 10 | 10 | |
| 11 | 11 | /// Sparse set of CPU features to add to the set from `cpu_model`. |
| 12 | 12 | cpu_features_add: Target.Cpu.Feature.Set = Target.Cpu.Feature.Set.empty, |
| ... | ... | @@ -48,7 +48,7 @@ pub const CpuModel = union(enum) { |
| 48 | 48 | |
| 49 | 49 | /// If CPU Architecture is native, then the CPU model will be native. Otherwise, |
| 50 | 50 | /// it will be baseline. |
| 51 | determined_by_cpu_arch, | |
| 51 | determined_by_arch_os, | |
| 52 | 52 | |
| 53 | 53 | explicit: *const Target.Cpu.Model, |
| 54 | 54 | |
| ... | ... | @@ -58,7 +58,7 @@ pub const CpuModel = union(enum) { |
| 58 | 58 | const b_tag: Tag = b; |
| 59 | 59 | if (a_tag != b_tag) return false; |
| 60 | 60 | return switch (a) { |
| 61 | .native, .baseline, .determined_by_cpu_arch => true, | |
| 61 | .native, .baseline, .determined_by_arch_os => true, | |
| 62 | 62 | .explicit => |a_model| a_model == b.explicit, |
| 63 | 63 | }; |
| 64 | 64 | } |
| ... | ... | @@ -349,7 +349,7 @@ test parseVersion { |
| 349 | 349 | |
| 350 | 350 | pub fn isNativeCpu(self: Query) bool { |
| 351 | 351 | 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 | |
| 353 | 353 | self.cpu_features_sub.isEmpty() and self.cpu_features_add.isEmpty(); |
| 354 | 354 | } |
| 355 | 355 | |
| ... | ... | @@ -461,7 +461,7 @@ pub fn serializeCpu(q: Query, buffer: *std.ArrayList(u8)) Allocator.Error!void { |
| 461 | 461 | .baseline => { |
| 462 | 462 | buffer.appendSliceAssumeCapacity("baseline"); |
| 463 | 463 | }, |
| 464 | .determined_by_cpu_arch => { | |
| 464 | .determined_by_arch_os => { | |
| 465 | 465 | if (q.cpu_arch == null) { |
| 466 | 466 | buffer.appendSliceAssumeCapacity("native"); |
| 467 | 467 | } else { |
lib/std/simd.zig+1-1| ... | ... | @@ -90,7 +90,7 @@ pub fn suggestVectorLength(comptime T: type) ?comptime_int { |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | test "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); | |
| 94 | 94 | comptime cpu.features.addFeature(@intFromEnum(std.Target.x86.Feature.avx512f)); |
| 95 | 95 | comptime cpu.features.populateDependencies(&std.Target.x86.all_features); |
| 96 | 96 | 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 { |
| 337 | 337 | |
| 338 | 338 | const cpu = switch (query.cpu_model) { |
| 339 | 339 | .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) | |
| 342 | 342 | detectNativeCpuAndFeatures(cpu_arch, os, query) |
| 343 | 343 | else |
| 344 | Target.Cpu.baseline(cpu_arch), | |
| 344 | Target.Cpu.baseline(cpu_arch, os), | |
| 345 | 345 | .explicit => |model| model.toCpu(cpu_arch), |
| 346 | 346 | } 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); | |
| 348 | 348 | }; |
| 349 | 349 | var result = try detectAbiAndDynamicLinker(cpu, os, query); |
| 350 | 350 | // For x86, we need to populate some CPU feature flags depending on architecture |
src/main.zig+1-1| ... | ... | @@ -6299,7 +6299,7 @@ fn detectNativeCpuWithLLVM( |
| 6299 | 6299 | llvm_cpu_name_z: ?[*:0]const u8, |
| 6300 | 6300 | llvm_cpu_features_opt: ?[*:0]const u8, |
| 6301 | 6301 | ) !std.Target.Cpu { |
| 6302 | var result = std.Target.Cpu.baseline(arch); | |
| 6302 | var result = std.Target.Cpu.baseline(arch, builtin.os); | |
| 6303 | 6303 | |
| 6304 | 6304 | if (llvm_cpu_name_z) |cpu_name_z| { |
| 6305 | 6305 | const llvm_cpu_name = mem.span(cpu_name_z); |