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 @@
1const builtin = @import("builtin");
12const clz = @import("count0bits.zig");
23const testing = @import("std").testing;
34
45fn test__clzsi2(a: u32, expected: i32) !void {
5 // XXX At high optimization levels this test may be horribly miscompiled if
6 // one of the naked implementations is selected.
7 var nakedClzsi2 = clz.__clzsi2;
8 var actualClzsi2 = @ptrCast(fn (a: i32) callconv(.C) i32, nakedClzsi2);
9 var x = @bitCast(i32, a);
10 var result = actualClzsi2(x);
6 const nakedClzsi2 = clz.__clzsi2;
7 const fnProto = fn (a: i32) callconv(.C) i32;
8 const fnProtoPtr = switch (builtin.zig_backend) {
9 .stage1 => fnProto,
10 else => *const fnProto,
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);
1119 try testing.expectEqual(expected, result);
1220}
1321
lib/std/special/compiler_rt/truncXfYf2.zig+4-1
......@@ -4,6 +4,8 @@ const native_arch = builtin.cpu.arch;
44
55// AArch64 is the only ABI (at the moment) to support f16 arguments without the
66// 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.
79pub const F16T = if (native_arch.isAARCH64()) f16 else u16;
810
911pub 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
140142 }
141143 }
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));
144147 return @bitCast(dst_t, result);
145148}
146149