| author | |
| committer | |
| log | 18d6523888ef08bc66eb808075d13c5e00b8fcf4 |
| tree | 0cc67106566871a471eeb930619cbfaed84361f5 |
| parent | c5e847744c82953d44189a2c7094c8257fdf5b09 |
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 @@ |
| 1 | const builtin = @import("builtin"); | ||
| 1 | const clz = @import("count0bits.zig"); | 2 | const clz = @import("count0bits.zig"); |
| 2 | const testing = @import("std").testing; | 3 | const testing = @import("std").testing; |
| 3 | 4 | ||
| 4 | fn test__clzsi2(a: u32, expected: i32) !void { | 5 | fn test__clzsi2(a: u32, expected: i32) !void { |
| 5 | // XXX At high optimization levels this test may be horribly miscompiled if | 6 | 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 | } |
| 13 | 21 |
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; |
| 4 | 4 | ||
| 5 | // AArch64 is the only ABI (at the moment) to support f16 arguments without the | 5 | // 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. | ||
| 7 | pub const F16T = if (native_arch.isAARCH64()) f16 else u16; | 9 | pub const F16T = if (native_arch.isAARCH64()) f16 else u16; |
| 8 | 10 | ||
| 9 | pub fn __truncsfhf2(a: f32) callconv(.C) F16T { | 11 | 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 | ... | @@ -140,7 +142,8 @@ inline fn truncXfYf2(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t |
| 140 | } | 142 | } |
| 141 | } | 143 | } |
| 142 | 144 | ||
| 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 | } |
| 146 | 149 |