From d97981f6fd4e98506404de4259230dc157cc50dd Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sun, 11 Apr 2021 18:38:04 +0200 Subject: [PATCH 1/4] std: Make a test-case independent of the target endianness --- test/stage1/behavior/cast.zig | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/stage1/behavior/cast.zig b/test/stage1/behavior/cast.zig index 6fa44085e0..94ba2636b7 100644 --- a/test/stage1/behavior/cast.zig +++ b/test/stage1/behavior/cast.zig @@ -17,14 +17,15 @@ test "integer literal to pointer cast" { } test "pointer reinterpret const float to int" { - // https://github.com/ziglang/zig/issues/3345 - if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest; - + // The hex representation is 0x3fe3333333333303. const float: f64 = 5.99999999999994648725e-01; const float_ptr = &float; const int_ptr = @ptrCast(*const i32, float_ptr); const int_val = int_ptr.*; - expect(int_val == 858993411); + if (std.builtin.endian == .Little) + expect(int_val == 0x33333303) + else + expect(int_val == 0x3fe33333); } test "implicitly cast indirect pointer to maybe-indirect pointer" { From 9bebdc77d66369fc7cf6c1de7c9559fdd0c2c561 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sun, 11 Apr 2021 18:40:08 +0200 Subject: [PATCH 2/4] std: Fix TLS definitions for 32bit PowerPC targets Correct some silly errors and add the missing piece to set the thread pointer (r2). --- lib/std/os/linux/tls.zig | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/std/os/linux/tls.zig b/lib/std/os/linux/tls.zig index 614f5b4395..757e77bff3 100644 --- a/lib/std/os/linux/tls.zig +++ b/lib/std/os/linux/tls.zig @@ -69,7 +69,7 @@ const tls_tcb_size = switch (builtin.arch) { // Controls if the TP points to the end of the TCB instead of its beginning const tls_tp_points_past_tcb = switch (builtin.arch) { - .riscv32, .riscv64, .mips, .mipsel, .powerpc64, .powerpc64le => true, + .riscv32, .riscv64, .mips, .mipsel, .powerpc, .powerpc64, .powerpc64le => true, else => false, }; @@ -165,7 +165,14 @@ pub fn setThreadPointer(addr: usize) void { const rc = std.os.linux.syscall1(.set_thread_area, addr); assert(rc == 0); }, - .powerpc, .powerpc64, .powerpc64le => { + .powerpc => { + asm volatile ( + \\ mr 2, %[addr] + : + : [addr] "r" (addr) + ); + }, + .powerpc64, .powerpc64le => { asm volatile ( \\ mr 13, %[addr] : From 8d94dc625b34832af0e85c16fe4d64ee19c2e74e Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sun, 11 Apr 2021 18:41:10 +0200 Subject: [PATCH 3/4] compiler-rt: Introduce PowerPC-specific f128 helpers For historical reasons IEEE f128 ops use `kf` instead of `tf` in their names, there's no functional change. --- lib/std/special/compiler_rt.zig | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib/std/special/compiler_rt.zig b/lib/std/special/compiler_rt.zig index 4f12d21957..3a7457a4fd 100644 --- a/lib/std/special/compiler_rt.zig +++ b/lib/std/special/compiler_rt.zig @@ -296,6 +296,33 @@ comptime { @export(@import("compiler_rt/sparc.zig")._Qp_qtod, .{ .name = "_Qp_qtod", .linkage = linkage }); } + if (builtin.arch == .powerpc or builtin.arch.isPPC64()) { + @export(@import("compiler_rt/addXf3.zig").__addtf3, .{ .name = "__addkf3", .linkage = linkage }); + @export(@import("compiler_rt/addXf3.zig").__subtf3, .{ .name = "__subkf3", .linkage = linkage }); + @export(@import("compiler_rt/mulXf3.zig").__multf3, .{ .name = "__mulkf3", .linkage = linkage }); + @export(@import("compiler_rt/divtf3.zig").__divtf3, .{ .name = "__divkf3", .linkage = linkage }); + @export(@import("compiler_rt/extendXfYf2.zig").__extendsftf2, .{ .name = "__extendsfkf2", .linkage = linkage }); + @export(@import("compiler_rt/extendXfYf2.zig").__extenddftf2, .{ .name = "__extenddfkf2", .linkage = linkage }); + @export(@import("compiler_rt/truncXfYf2.zig").__trunctfsf2, .{ .name = "__trunckfsf2", .linkage = linkage }); + @export(@import("compiler_rt/truncXfYf2.zig").__trunctfdf2, .{ .name = "__trunckfdf2", .linkage = linkage }); + @export(@import("compiler_rt/fixtfdi.zig").__fixtfdi, .{ .name = "__fixkfdi", .linkage = linkage }); + @export(@import("compiler_rt/fixtfsi.zig").__fixtfsi, .{ .name = "__fixkfsi", .linkage = linkage }); + @export(@import("compiler_rt/fixunstfsi.zig").__fixunstfsi, .{ .name = "__fixunskfsi", .linkage = linkage }); + @export(@import("compiler_rt/fixunstfdi.zig").__fixunstfdi, .{ .name = "__fixunskfdi", .linkage = linkage }); + @export(@import("compiler_rt/floatsiXf.zig").__floatsitf, .{ .name = "__floatsikf", .linkage = linkage }); + @export(@import("compiler_rt/floatditf.zig").__floatditf, .{ .name = "__floatdikf", .linkage = linkage }); + @export(@import("compiler_rt/floatunditf.zig").__floatunditf, .{ .name = "__floatundikf", .linkage = linkage }); + @export(@import("compiler_rt/floatunsitf.zig").__floatunsitf, .{ .name = "__floatunsikf", .linkage = linkage }); + + @export(@import("compiler_rt/compareXf2.zig").__letf2, .{ .name = "__eqkf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__letf2, .{ .name = "__nekf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__getf2, .{ .name = "__gekf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__letf2, .{ .name = "__ltkf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__letf2, .{ .name = "__lekf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__getf2, .{ .name = "__gtkf2", .linkage = linkage }); + @export(@import("compiler_rt/compareXf2.zig").__unordtf2, .{ .name = "__unordkf2", .linkage = linkage }); + } + if (builtin.os.tag == .windows) { // Default stack-probe functions emitted by LLVM if (is_mingw) { From 44f8ce690ddd406fc1a9caa63d9c0741f4afb3a0 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sun, 11 Apr 2021 21:27:39 +0200 Subject: [PATCH 4/4] std: Fix typo in sqrt implementation The code initializes twice `t` instead of `t1`, leaving the latter uninitialized. The problem manifested itself by corrupting the LSBs of the result in unpredictable ways. --- lib/std/special/c.zig | 2 +- test/stage1/behavior/bugs/920.zig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/std/special/c.zig b/lib/std/special/c.zig index 51cbafc133..f24bedd262 100644 --- a/lib/std/special/c.zig +++ b/lib/std/special/c.zig @@ -874,7 +874,7 @@ export fn sqrt(x: f64) f64 { r = sign; while (r != 0) { - t = s1 +% r; + t1 = s1 +% r; t = s0; if (t < ix0 or (t == ix0 and t1 <= ix1)) { s1 = t1 +% r; diff --git a/test/stage1/behavior/bugs/920.zig b/test/stage1/behavior/bugs/920.zig index 10c002f6ba..72854956a1 100644 --- a/test/stage1/behavior/bugs/920.zig +++ b/test/stage1/behavior/bugs/920.zig @@ -60,6 +60,6 @@ test "bug 920 fixed" { }; for (NormalDist1.f) |_, i| { - std.testing.expect(NormalDist1.f[i] == NormalDist.f[i]); + std.testing.expectEqual(NormalDist1.f[i], NormalDist.f[i]); } }