authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-04-15 18:20:50+02:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-04-15 18:21:58+02:00
logb29677dd12b5a19618295757a6044c0b0d741dbb
tree544d19e219a01588a03a9960baa65117184a096a
parent7a4dad7e87bd5561bbe62f5d38fda1b968f9d529

compiler-rt: Implement __extendhftf2


2 files changed, 52 insertions(+), 1 deletions(-)

lib/std/special/compiler_rt/extendXfYf2.zig+4
...@@ -23,6 +23,10 @@ pub fn __extendhfsf2(a: u16) callconv(.C) f32 {...@@ -23,6 +23,10 @@ pub fn __extendhfsf2(a: u16) callconv(.C) f32 {
23 return @call(.{ .modifier = .always_inline }, extendXfYf2, .{ f32, f16, a });23 return @call(.{ .modifier = .always_inline }, extendXfYf2, .{ f32, f16, a });
24}24}
2525
26pub fn __extendhftf2(a: u16) callconv(.C) f128 {
27 return @call(.{ .modifier = .always_inline }, extendXfYf2, .{ f128, f16, a });
28}
29
26pub fn __aeabi_h2f(arg: u16) callconv(.AAPCS) f32 {30pub fn __aeabi_h2f(arg: u16) callconv(.AAPCS) f32 {
27 @setRuntimeSafety(false);31 @setRuntimeSafety(false);
28 return @call(.{ .modifier = .always_inline }, __extendhfsf2, .{arg});32 return @call(.{ .modifier = .always_inline }, __extendhfsf2, .{arg});
lib/std/special/compiler_rt/extendXfYf2_test.zig+48-1
...@@ -4,9 +4,10 @@...@@ -4,9 +4,10 @@
4// The MIT license requires this copyright notice to be included in all copies4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.5// and substantial portions of the software.
6const builtin = @import("builtin");6const builtin = @import("builtin");
7const __extenddftf2 = @import("extendXfYf2.zig").__extenddftf2;
8const __extendhfsf2 = @import("extendXfYf2.zig").__extendhfsf2;7const __extendhfsf2 = @import("extendXfYf2.zig").__extendhfsf2;
8const __extendhftf2 = @import("extendXfYf2.zig").__extendhftf2;
9const __extendsftf2 = @import("extendXfYf2.zig").__extendsftf2;9const __extendsftf2 = @import("extendXfYf2.zig").__extendsftf2;
10const __extenddftf2 = @import("extendXfYf2.zig").__extenddftf2;
1011
11fn test__extenddftf2(a: f64, expectedHi: u64, expectedLo: u64) void {12fn test__extenddftf2(a: f64, expectedHi: u64, expectedLo: u64) void {
12 const x = __extenddftf2(a);13 const x = __extenddftf2(a);
...@@ -161,3 +162,49 @@ fn makeNaN32(rand: u32) f32 {...@@ -161,3 +162,49 @@ fn makeNaN32(rand: u32) f32 {
161fn makeInf32() f32 {162fn makeInf32() f32 {
162 return @bitCast(f32, @as(u32, 0x7f800000));163 return @bitCast(f32, @as(u32, 0x7f800000));
163}164}
165
166fn test__extendhftf2(a: f16, expectedHi: u64, expectedLo: u64) void {
167 const x = __extendhftf2(@bitCast(u16, a));
168
169 const rep = @bitCast(u128, x);
170 const hi = @intCast(u64, rep >> 64);
171 const lo = @truncate(u64, rep);
172
173 if (hi == expectedHi and lo == expectedLo)
174 return;
175
176 // test other possible NaN representation(signal NaN)
177 if (expectedHi == 0x7fff800000000000 and expectedLo == 0x0) {
178 if ((hi & 0x7fff000000000000) == 0x7fff000000000000 and
179 ((hi & 0xffffffffffff) > 0 or lo > 0))
180 {
181 return;
182 }
183 }
184
185 @panic("__extendhftf2 test failure");
186}
187
188test "extendhftf2" {
189 // qNaN
190 test__extendhftf2(@bitCast(f16, @as(u16, 0x7e00)), 0x7fff800000000000, 0x0);
191 // NaN
192 test__extendhftf2(@bitCast(f16, @as(u16, 0x7d00)), 0x7fff400000000000, 0x0);
193 // inf
194 test__extendhftf2(@bitCast(f16, @as(u16, 0x7c00)), 0x7fff000000000000, 0x0);
195 test__extendhftf2(-@bitCast(f16, @as(u16, 0x7c00)), 0xffff000000000000, 0x0);
196 // zero
197 test__extendhftf2(@bitCast(f16, @as(u16, 0x0)), 0x0, 0x0);
198 test__extendhftf2(@bitCast(f16, @as(u16, 0x8000)), 0x8000000000000000, 0x0);
199 // denormal
200 test__extendhftf2(@bitCast(f16, @as(u16, 0x0010)), 0x3feb000000000000, 0x0000000000000000);
201 test__extendhftf2(@bitCast(f16, @as(u16, 0x0001)), 0x3fe7000000000000, 0x0000000000000000);
202 test__extendhftf2(@bitCast(f16, @as(u16, 0x8001)), 0xbfe7000000000000, 0x0000000000000000);
203
204 // pi
205 test__extendhftf2(@bitCast(f16, @as(u16, 0x4248)), 0x4000920000000000, 0x0000000000000000);
206 test__extendhftf2(@bitCast(f16, @as(u16, 0xc248)), 0xc000920000000000, 0x0000000000000000);
207
208 test__extendhftf2(@bitCast(f16, @as(u16, 0x508c)), 0x4004230000000000, 0x0);
209 test__extendhftf2(@bitCast(f16, @as(u16, 0x1bb7)), 0x3ff6edc000000000, 0x0);
210}