| author | |
| committer | |
| log | 92fd2df054d1e1523489c6a959354f5e75f647a4 |
| tree | 0c43f6799cd4276ccfc65b87509b0918eec9e627 |
| parent | c00167e91a452bb3c051c66157686e11487df94b |
Add AEABI builtin __aeabi_d2f3 files changed, 45 insertions(+), 0 deletions(-)
std/special/compiler_rt.zig+4| ... | ... | @@ -86,6 +86,8 @@ comptime { |
| 86 | 86 | @export("__trunctfdf2", @import("compiler_rt/truncXfYf2.zig").__trunctfdf2, linkage); |
| 87 | 87 | @export("__trunctfsf2", @import("compiler_rt/truncXfYf2.zig").__trunctfsf2, linkage); |
| 88 | 88 | |
| 89 | @export("__truncdfsf2", @import("compiler_rt/truncXfYf2.zig").__truncdfsf2, linkage); | |
| 90 | ||
| 89 | 91 | @export("__fixunssfsi", @import("compiler_rt/fixunssfsi.zig").__fixunssfsi, linkage); |
| 90 | 92 | @export("__fixunssfdi", @import("compiler_rt/fixunssfdi.zig").__fixunssfdi, linkage); |
| 91 | 93 | @export("__fixunssfti", @import("compiler_rt/fixunssfti.zig").__fixunssfti, linkage); |
| ... | ... | @@ -176,6 +178,8 @@ comptime { |
| 176 | 178 | @export("__aeabi_f2h", @import("compiler_rt/truncXfYf2.zig").__truncsfhf2, linkage); |
| 177 | 179 | |
| 178 | 180 | @export("__aeabi_i2f", @import("compiler_rt/floatsiXf.zig").__floatsisf, linkage); |
| 181 | @export("__aeabi_d2f", @import("compiler_rt/truncXfYf2.zig").__truncdfsf2, linkage); | |
| 182 | ||
| 179 | 183 | @export("__aeabi_fadd", @import("compiler_rt/addXf3.zig").__addsf3, linkage); |
| 180 | 184 | @export("__aeabi_dadd", @import("compiler_rt/addXf3.zig").__adddf3, linkage); |
| 181 | 185 | @export("__aeabi_fsub", @import("compiler_rt/addXf3.zig").__subsf3, linkage); |
std/special/compiler_rt/truncXfYf2.zig+4| ... | ... | @@ -16,6 +16,10 @@ pub extern fn __trunctfdf2(a: f128) f64 { |
| 16 | 16 | return truncXfYf2(f64, f128, a); |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | pub extern fn __truncdfsf2(a: f64) f32 { | |
| 20 | return truncXfYf2(f32, f64, a); | |
| 21 | } | |
| 22 | ||
| 19 | 23 | inline fn truncXfYf2(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t { |
| 20 | 24 | const src_rep_t = @IntType(false, @typeInfo(src_t).Float.bits); |
| 21 | 25 | const dst_rep_t = @IntType(false, @typeInfo(dst_t).Float.bits); |
std/special/compiler_rt/truncXfYf2_test.zig+37| ... | ... | @@ -200,3 +200,40 @@ test "trunctfdf2" { |
| 200 | 200 | test__trunctfdf2(0x1.2f34dd5f437e849b4baab754cdefp+4534, 0x7ff0000000000000); |
| 201 | 201 | test__trunctfdf2(0x1.edcbff8ad76ab5bf46463233214fp-435, 0x24cedcbff8ad76ab); |
| 202 | 202 | } |
| 203 | ||
| 204 | const __truncdfsf2 = @import("truncXfYf2.zig").__truncdfsf2; | |
| 205 | ||
| 206 | fn test__truncdfsf2(a: f64, expected: u32) void { | |
| 207 | const x = __truncdfsf2(a); | |
| 208 | ||
| 209 | const rep = @bitCast(u32, x); | |
| 210 | if (rep == expected) { | |
| 211 | return; | |
| 212 | } | |
| 213 | // test other possible NaN representation(signal NaN) | |
| 214 | else if (expected == 0x7fc00000) { | |
| 215 | if ((rep & 0x7f800000) == 0x7f800000 and (rep & 0x7fffff) > 0) { | |
| 216 | return; | |
| 217 | } | |
| 218 | } | |
| 219 | ||
| 220 | @import("std").debug.warn("got 0x{x} wanted 0x{x}\n", rep, expected); | |
| 221 | ||
| 222 | @panic("__trunctfsf2 test failure"); | |
| 223 | } | |
| 224 | ||
| 225 | test "truncdfsf2" { | |
| 226 | // nan & qnan | |
| 227 | test__truncdfsf2(@bitCast(f64, u64(0x7ff8000000000000)), 0x7fc00000); | |
| 228 | test__truncdfsf2(@bitCast(f64, u64(0x7ff0000000000001)), 0x7fc00000); | |
| 229 | // inf | |
| 230 | test__truncdfsf2(@bitCast(f64, u64(0x7ff0000000000000)), 0x7f800000); | |
| 231 | test__truncdfsf2(@bitCast(f64, u64(0xfff0000000000000)), 0xff800000); | |
| 232 | ||
| 233 | test__truncdfsf2(0.0, 0x0); | |
| 234 | test__truncdfsf2(1.0, 0x3f800000); | |
| 235 | test__truncdfsf2(-1.0, 0xbf800000); | |
| 236 | ||
| 237 | // huge number becomes inf | |
| 238 | test__truncdfsf2(340282366920938463463374607431768211456.0, 0x7f800000); | |
| 239 | } |