authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-11-01 18:25:43+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-11-01 14:30:31-07:00
log2957433b25373dccc336492f6817a1cefadb945c
treebdef4c40bfc6b1e325e49cac310c8efee0119085
parentd530e7f9c7e19b2c9d9117c3120cd75855f4023b

stage1: Fix comptime comparison of NaNs


2 files changed, 15 insertions(+), 2 deletions(-)

src/stage1/ir.cpp+2-2
...@@ -10953,13 +10953,13 @@ static bool float_is_nan(ZigValue *op) {...@@ -10953,13 +10953,13 @@ static bool float_is_nan(ZigValue *op) {
10953 } else if (op->type->id == ZigTypeIdFloat) {10953 } else if (op->type->id == ZigTypeIdFloat) {
10954 switch (op->type->data.floating.bit_count) {10954 switch (op->type->data.floating.bit_count) {
10955 case 16:10955 case 16:
10956 return f16_isSignalingNaN(op->data.x_f16);10956 return zig_f16_isNaN(op->data.x_f16);
10957 case 32:10957 case 32:
10958 return op->data.x_f32 != op->data.x_f32;10958 return op->data.x_f32 != op->data.x_f32;
10959 case 64:10959 case 64:
10960 return op->data.x_f64 != op->data.x_f64;10960 return op->data.x_f64 != op->data.x_f64;
10961 case 128:10961 case 128:
10962 return f128M_isSignalingNaN(&op->data.x_f128);10962 return zig_f128_isNaN(&op->data.x_f128);
10963 default:10963 default:
10964 zig_unreachable();10964 zig_unreachable();
10965 }10965 }
src/stage1/softfloat.hpp+13
...@@ -29,4 +29,17 @@ static inline double zig_f16_to_double(float16_t x) {...@@ -29,4 +29,17 @@ static inline double zig_f16_to_double(float16_t x) {
29 return z;29 return z;
30}30}
3131
32static inline bool zig_f16_isNaN(float16_t a) {
33 union { uint16_t ui; float16_t f; } uA;
34 uA.f = a;
35 return 0x7C00 < (uA.ui & 0x7FFF);
36}
37
38static inline bool zig_f128_isNaN(float128_t *aPtr) {
39 uint64_t absA64 = aPtr->v[1] & UINT64_C(0x7FFFFFFFFFFFFFFF);
40 return
41 (UINT64_C(0x7FFF000000000000) < absA64)
42 || ((absA64 == UINT64_C(0x7FFF000000000000)) && aPtr->v[0]);
43}
44
32#endif45#endif