aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-01-18 18:22:11 -0500
committerGitHub <noreply@github.com>2025-01-18 18:22:11 -0500
commita5d2aaa936dc74b85d7cf6695e6a7627d7a645d2 (patch)
treeaff47a0d59ae8ed164cbdd794eac8ac3301b9f96 /lib
parent128658038d26a75dd1a52f82fc65fba3e91bba9e (diff)
parent515c97065a5352448747fbaf1f5ea43173a4457a (diff)
downloadzig-a5d2aaa936dc74b85d7cf6695e6a7627d7a645d2.tar.gz
zig-a5d2aaa936dc74b85d7cf6695e6a7627d7a645d2.zip
Merge pull request #22526 from alexrp/cpu-feature-hacks
`std.zig.system`: Move CPU feature hacks after ABI detection.
Diffstat (limited to 'lib')
-rw-r--r--lib/compiler_rt/memcpy.zig28
-rw-r--r--lib/std/zig/system.zig32
2 files changed, 20 insertions, 40 deletions
diff --git a/lib/compiler_rt/memcpy.zig b/lib/compiler_rt/memcpy.zig
index c540e81638..614bcc7182 100644
--- a/lib/compiler_rt/memcpy.zig
+++ b/lib/compiler_rt/memcpy.zig
@@ -9,36 +9,12 @@ comptime {
}
}
-const llvm_cannot_lower = switch (builtin.cpu.arch) {
- .arm, .armeb, .thumb, .thumbeb => builtin.zig_backend == .stage2_llvm,
- else => false,
-};
-
fn memcpy(noalias opt_dest: ?[*]u8, noalias opt_src: ?[*]const u8, len: usize) callconv(.C) ?[*]u8 {
- if (llvm_cannot_lower) {
- for (0..len) |i| opt_dest.?[i] = opt_src.?[i];
- return opt_dest;
- } else {
- return memmove(opt_dest, opt_src, len);
- }
+ return memmove(opt_dest, opt_src, len);
}
-/// A port of https://github.com/facebook/folly/blob/1c8bc50e88804e2a7361a57cd9b551dd10f6c5fd/folly/memcpy.S
fn memmove(opt_dest: ?[*]u8, opt_src: ?[*]const u8, len: usize) callconv(.C) ?[*]u8 {
- if (llvm_cannot_lower) {
- if (@intFromPtr(opt_dest) < @intFromPtr(opt_src)) {
- for (0..len) |i| opt_dest.?[i] = opt_src.?[i];
- return opt_dest;
- } else {
- var index = len;
- while (index != 0) {
- index -= 1;
- opt_dest.?[index] = opt_src.?[index];
- }
- return opt_dest;
- }
- }
-
+ // a port of https://github.com/facebook/folly/blob/1c8bc50e88804e2a7361a57cd9b551dd10f6c5fd/folly/memcpy.S
if (len == 0) {
@branchHint(.unlikely);
return opt_dest;
diff --git a/lib/std/zig/system.zig b/lib/std/zig/system.zig
index f57bb44d72..68182366e8 100644
--- a/lib/std/zig/system.zig
+++ b/lib/std/zig/system.zig
@@ -399,22 +399,26 @@ pub fn resolveTargetQuery(query: Target.Query) DetectError!Target {
query.cpu_features_sub,
);
- if (cpu.arch == .hexagon) {
- // Both LLVM and LLD have broken support for the small data area. Yet LLVM has the feature
- // on by default for all Hexagon CPUs. Clang sort of solves this by defaulting the `-gpsize`
- // command line parameter for the Hexagon backend to 0, so that no constants get placed in
- // the SDA. (This of course breaks down if the user passes `-G <n>` to Clang...) We can't do
- // the `-gpsize` hack because we can have multiple concurrent LLVM emit jobs, and command
- // line options in LLVM are shared globally. So just force this feature off. Lovely stuff.
- cpu.features.removeFeature(@intFromEnum(Target.hexagon.Feature.small_data));
- }
+ var result = try detectAbiAndDynamicLinker(cpu, os, query);
- // https://github.com/llvm/llvm-project/issues/105978
- if (cpu.arch.isArm() and query_abi.floatAbi() == .soft) {
- cpu.features.removeFeature(@intFromEnum(Target.arm.Feature.vfp2));
- }
+ // These CPU feature hacks have to come after ABI detection.
+ {
+ if (result.cpu.arch == .hexagon) {
+ // Both LLVM and LLD have broken support for the small data area. Yet LLVM has the
+ // feature on by default for all Hexagon CPUs. Clang sort of solves this by defaulting
+ // the `-gpsize` command line parameter for the Hexagon backend to 0, so that no
+ // constants get placed in the SDA. (This of course breaks down if the user passes
+ // `-G <n>` to Clang...) We can't do the `-gpsize` hack because we can have multiple
+ // concurrent LLVM emit jobs, and command line options in LLVM are shared globally. So
+ // just force this feature off. Lovely stuff.
+ result.cpu.features.removeFeature(@intFromEnum(Target.hexagon.Feature.small_data));
+ }
- var result = try detectAbiAndDynamicLinker(cpu, os, query);
+ // https://github.com/llvm/llvm-project/issues/105978
+ if (result.cpu.arch.isArm() and result.abi.floatAbi() == .soft) {
+ result.cpu.features.removeFeature(@intFromEnum(Target.arm.Feature.vfp2));
+ }
+ }
// It's possible that we detect the native ABI, but fail to detect the OS version or were told
// to use the default OS version range. In that case, while we can't determine the exact native