Skip to content

Commit f7dabdc

Browse files
Fix for NaNs
1 parent 2602030 commit f7dabdc

File tree

2 files changed

+14
-23
lines changed

2 files changed

+14
-23
lines changed

scripts/test/shared.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,6 @@ def get_tests(test_dir, extensions=[], recursive=False):
418418
'conversions.wast', # Promoted NaN should be canonical
419419
'data.wast', # Fail to parse data segment offset abbreviation
420420
'elem.wast', # Requires modeling empty declarative segments
421-
'f32.wast', # Adding -0 and -nan should give a canonical NaN
422-
'f64.wast', # Adding -0 and -nan should give a canonical NaN
423-
'float_exprs.wast', # Adding 0 and NaN should give canonical NaN
424-
'float_misc.wast', # Rounding wrong on f64.sqrt
425421
'func.wast', # Duplicate parameter names not properly rejected
426422
'global.wast', # Fail to parse table
427423
'if.wast', # Requires more precise unreachable validation
@@ -455,15 +451,7 @@ def get_tests(test_dir, extensions=[], recursive=False):
455451
'imports3.wast', # Requires better checking of exports from the special "spectest" module
456452
'relaxed_dot_product.wast', # i16x8.relaxed_dot_i8x16_i7x16_s instruction not supported
457453
'relaxed_laneselect.wast', # i8x16.relaxed_laneselect instruction not supported
458-
'relaxed_min_max.wast', # Non-canonical NaN from f32x4.relaxed_min
459454
'simd_const.wast', # Hex float constant not recognized as out of range
460-
'simd_conversions.wast', # Promoted NaN should be canonical
461-
'simd_f32x4.wast', # Min of 0 and NaN should give a canonical NaN
462-
'simd_f32x4_arith.wast', # Adding inf and -inf should give a canonical NaN
463-
'simd_f32x4_rounding.wast', # Ceil of NaN should give a canonical NaN
464-
'simd_f64x2.wast', # Min of 0 and NaN should give a canonical NaN
465-
'simd_f64x2_arith.wast', # Adding inf and -inf should give a canonical NaN
466-
'simd_f64x2_rounding.wast', # Ceil of NaN should give a canonical NaN
467455
'token.wast', # Lexer should require spaces between strings and non-paren tokens
468456
]
469457

src/wasm/literal.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -543,16 +543,16 @@ bool Literal::isCanonicalNaN() {
543543
if (!isNaN()) {
544544
return false;
545545
}
546-
return (type == Type::f32 && NaNPayload(getf32()) == (1u << 23) - 1) ||
547-
(type == Type::f64 && NaNPayload(getf64()) == (1ull << 52) - 1);
546+
return (type == Type::f32 && NaNPayload(getf32()) == (1u << 22)) ||
547+
(type == Type::f64 && NaNPayload(getf64()) == (1ull << 51));
548548
}
549549

550550
bool Literal::isArithmeticNaN() {
551551
if (!isNaN()) {
552552
return false;
553553
}
554-
return (type == Type::f32 && NaNPayload(getf32()) > (1u << 23) - 1) ||
555-
(type == Type::f64 && NaNPayload(getf64()) > (1ull << 52) - 1);
554+
return (type == Type::f32 && NaNPayload(getf32()) >= (1u << 22)) ||
555+
(type == Type::f64 && NaNPayload(getf64()) >= (1ull << 51));
556556
}
557557

558558
uint32_t Literal::NaNPayload(float f) {
@@ -1104,9 +1104,9 @@ Literal Literal::abs() const {
11041104
Literal Literal::ceil() const {
11051105
switch (type.getBasic()) {
11061106
case Type::f32:
1107-
return Literal(std::ceil(getf32()));
1107+
return standardizeNaN(Literal(std::ceil(getf32())));
11081108
case Type::f64:
1109-
return Literal(std::ceil(getf64()));
1109+
return standardizeNaN(Literal(std::ceil(getf64())));
11101110
default:
11111111
WASM_UNREACHABLE("unexpected type");
11121112
}
@@ -1115,9 +1115,9 @@ Literal Literal::ceil() const {
11151115
Literal Literal::floor() const {
11161116
switch (type.getBasic()) {
11171117
case Type::f32:
1118-
return Literal(std::floor(getf32()));
1118+
return standardizeNaN(Literal(std::floor(getf32())));
11191119
case Type::f64:
1120-
return Literal(std::floor(getf64()));
1120+
return standardizeNaN(Literal(std::floor(getf64())));
11211121
default:
11221122
WASM_UNREACHABLE("unexpected type");
11231123
}
@@ -1126,9 +1126,9 @@ Literal Literal::floor() const {
11261126
Literal Literal::trunc() const {
11271127
switch (type.getBasic()) {
11281128
case Type::f32:
1129-
return Literal(std::trunc(getf32()));
1129+
return standardizeNaN(Literal(std::trunc(getf32())));
11301130
case Type::f64:
1131-
return Literal(std::trunc(getf64()));
1131+
return standardizeNaN(Literal(std::trunc(getf64())));
11321132
default:
11331133
WASM_UNREACHABLE("unexpected type");
11341134
}
@@ -1149,8 +1149,11 @@ Literal Literal::sqrt() const {
11491149
switch (type.getBasic()) {
11501150
case Type::f32:
11511151
return standardizeNaN(Literal(std::sqrt(getf32())));
1152-
case Type::f64:
1152+
case Type::f64: {
1153+
std::cout << getf64() << " " << std::sqrt(getf64()) << " "
1154+
<< std::isnan(std::sqrt(getf64())) << "\n";
11531155
return standardizeNaN(Literal(std::sqrt(getf64())));
1156+
}
11541157
default:
11551158
WASM_UNREACHABLE("unexpected type");
11561159
}

0 commit comments

Comments
 (0)