authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-04-28 17:11:14-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-04-28 17:11:14-07:00
log18d6523888ef08bc66eb808075d13c5e00b8fcf4
tree0cc67106566871a471eeb930619cbfaed84361f5
parentc5e847744c82953d44189a2c7094c8257fdf5b09

compiler-rt: upgrade to stage2 fn ptr semantics


2 files changed, 18 insertions(+), 7 deletions(-)

lib/std/special/compiler_rt/clzsi2_test.zig+14-6
...@@ -1,13 +1,21 @@...@@ -1,13 +1,21 @@
1const builtin = @import("builtin");
1const clz = @import("count0bits.zig");2const clz = @import("count0bits.zig");
2const testing = @import("std").testing;3const testing = @import("std").testing;
34
4fn test__clzsi2(a: u32, expected: i32) !void {5fn test__clzsi2(a: u32, expected: i32) !void {
5 // XXX At high optimization levels this test may be horribly miscompiled if6 const nakedClzsi2 = clz.__clzsi2;
6 // one of the naked implementations is selected.7 const fnProto = fn (a: i32) callconv(.C) i32;
7 var nakedClzsi2 = clz.__clzsi2;8 const fnProtoPtr = switch (builtin.zig_backend) {
8 var actualClzsi2 = @ptrCast(fn (a: i32) callconv(.C) i32, nakedClzsi2);9 .stage1 => fnProto,
9 var x = @bitCast(i32, a);10 else => *const fnProto,
10 var result = actualClzsi2(x);11 };
12 const fn_ptr = switch (builtin.zig_backend) {
13 .stage1 => nakedClzsi2,
14 else => &nakedClzsi2,
15 };
16 const actualClzsi2 = @ptrCast(fnProtoPtr, fn_ptr);
17 const x = @bitCast(i32, a);
18 const result = actualClzsi2(x);
11 try testing.expectEqual(expected, result);19 try testing.expectEqual(expected, result);
12}20}
1321
lib/std/special/compiler_rt/truncXfYf2.zig+4-1
...@@ -4,6 +4,8 @@ const native_arch = builtin.cpu.arch;...@@ -4,6 +4,8 @@ const native_arch = builtin.cpu.arch;
44
5// AArch64 is the only ABI (at the moment) to support f16 arguments without the5// AArch64 is the only ABI (at the moment) to support f16 arguments without the
6// need for extending them to wider fp types.6// need for extending them to wider fp types.
7// TODO remove this; do this type selection in the language rather than
8// here in compiler-rt.
7pub const F16T = if (native_arch.isAARCH64()) f16 else u16;9pub const F16T = if (native_arch.isAARCH64()) f16 else u16;
810
9pub fn __truncsfhf2(a: f32) callconv(.C) F16T {11pub 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...@@ -140,7 +142,8 @@ inline fn truncXfYf2(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t
140 }142 }
141 }143 }
142144
143 const result: dst_rep_t align(@alignOf(dst_t)) = absResult | @truncate(dst_rep_t, sign >> @intCast(SrcShift, srcBits - dstBits));145 const result: dst_rep_t align(@alignOf(dst_t)) = absResult |
146 @truncate(dst_rep_t, sign >> @intCast(SrcShift, srcBits - dstBits));
144 return @bitCast(dst_t, result);147 return @bitCast(dst_t, result);
145}148}
146149