diff options
| -rw-r--r-- | lib/std/special/compiler_rt/clzsi2_test.zig | 20 | ||||
| -rw-r--r-- | lib/std/special/compiler_rt/truncXfYf2.zig | 5 |
2 files changed, 18 insertions, 7 deletions
diff --git a/lib/std/special/compiler_rt/clzsi2_test.zig b/lib/std/special/compiler_rt/clzsi2_test.zig index 7d07b3e9c1..9ad5d3afe7 100644 --- a/lib/std/special/compiler_rt/clzsi2_test.zig +++ b/lib/std/special/compiler_rt/clzsi2_test.zig @@ -1,13 +1,21 @@ +const builtin = @import("builtin"); const clz = @import("count0bits.zig"); const testing = @import("std").testing; fn test__clzsi2(a: u32, expected: i32) !void { - // XXX At high optimization levels this test may be horribly miscompiled if - // one of the naked implementations is selected. - var nakedClzsi2 = clz.__clzsi2; - var actualClzsi2 = @ptrCast(fn (a: i32) callconv(.C) i32, nakedClzsi2); - var x = @bitCast(i32, a); - var result = actualClzsi2(x); + const nakedClzsi2 = clz.__clzsi2; + const fnProto = fn (a: i32) callconv(.C) i32; + const fnProtoPtr = switch (builtin.zig_backend) { + .stage1 => fnProto, + else => *const fnProto, + }; + const fn_ptr = switch (builtin.zig_backend) { + .stage1 => nakedClzsi2, + else => &nakedClzsi2, + }; + const actualClzsi2 = @ptrCast(fnProtoPtr, fn_ptr); + const x = @bitCast(i32, a); + const result = actualClzsi2(x); try testing.expectEqual(expected, result); } diff --git a/lib/std/special/compiler_rt/truncXfYf2.zig b/lib/std/special/compiler_rt/truncXfYf2.zig index fea1aeb60a..bf324269a6 100644 --- a/lib/std/special/compiler_rt/truncXfYf2.zig +++ b/lib/std/special/compiler_rt/truncXfYf2.zig @@ -4,6 +4,8 @@ const native_arch = builtin.cpu.arch; // AArch64 is the only ABI (at the moment) to support f16 arguments without the // need for extending them to wider fp types. +// TODO remove this; do this type selection in the language rather than +// here in compiler-rt. pub const F16T = if (native_arch.isAARCH64()) f16 else u16; pub fn __truncsfhf2(a: f32) callconv(.C) F16T { @@ -140,7 +142,8 @@ inline fn truncXfYf2(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t } } - const result: dst_rep_t align(@alignOf(dst_t)) = absResult | @truncate(dst_rep_t, sign >> @intCast(SrcShift, srcBits - dstBits)); + const result: dst_rep_t align(@alignOf(dst_t)) = absResult | + @truncate(dst_rep_t, sign >> @intCast(SrcShift, srcBits - dstBits)); return @bitCast(dst_t, result); } |
