| ... | ... | @@ -4,9 +4,10 @@ |
| 4 | 4 | // The MIT license requires this copyright notice to be included in all copies |
| 5 | 5 | // and substantial portions of the software. |
| 6 | 6 | const builtin = @import("builtin"); |
| 7 | | const __extenddftf2 = @import("extendXfYf2.zig").__extenddftf2; |
| 8 | 7 | const __extendhfsf2 = @import("extendXfYf2.zig").__extendhfsf2; |
| 8 | const __extendhftf2 = @import("extendXfYf2.zig").__extendhftf2; |
| 9 | 9 | const __extendsftf2 = @import("extendXfYf2.zig").__extendsftf2; |
| 10 | const __extenddftf2 = @import("extendXfYf2.zig").__extenddftf2; |
| 10 | 11 | |
| 11 | 12 | fn test__extenddftf2(a: f64, expectedHi: u64, expectedLo: u64) void { |
| 12 | 13 | const x = __extenddftf2(a); |
| ... | ... | @@ -161,3 +162,49 @@ fn makeNaN32(rand: u32) f32 { |
| 161 | 162 | fn makeInf32() f32 { |
| 162 | 163 | return @bitCast(f32, @as(u32, 0x7f800000)); |
| 163 | 164 | } |
| 165 | |
| 166 | fn 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 | |
| 188 | test "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 | } |