diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ir/ExpressionAnalyzer.cpp | 2 | ||||
-rw-r--r-- | src/literal.h | 7 | ||||
-rw-r--r-- | src/passes/Precompute.cpp | 2 | ||||
-rw-r--r-- | src/tools/execution-results.h | 2 | ||||
-rw-r--r-- | src/tools/wasm-shell.cpp | 4 | ||||
-rw-r--r-- | src/wasm/literal.cpp | 16 |
6 files changed, 13 insertions, 20 deletions
diff --git a/src/ir/ExpressionAnalyzer.cpp b/src/ir/ExpressionAnalyzer.cpp index 64b1ce24b..d91bc370c 100644 --- a/src/ir/ExpressionAnalyzer.cpp +++ b/src/ir/ExpressionAnalyzer.cpp @@ -257,7 +257,7 @@ bool ExpressionAnalyzer::flexibleEqual(Expression* left, Expression* right, Expr break; } case Expression::Id::ConstId: { - if (!left->cast<Const>()->value.bitwiseEqual(right->cast<Const>()->value)) { + if (left->cast<Const>()->value != right->cast<Const>()->value) { return false; } break; diff --git a/src/literal.h b/src/literal.h index ae628149e..aa9fd9705 100644 --- a/src/literal.h +++ b/src/literal.h @@ -71,9 +71,11 @@ public: int64_t getInteger() const; double getFloat() const; int64_t getBits() const; + // Equality checks for the type and the bits, so a nan float would + // be compared bitwise (which means that a Literal containing a nan + // would be equal to itself, if the bits are equal). bool operator==(const Literal& other) const; bool operator!=(const Literal& other) const; - bool bitwiseEqual(const Literal& other) const; static uint32_t NaNPayload(float f); static uint64_t NaNPayload(double f); @@ -130,6 +132,9 @@ public: Literal rotL(const Literal& other) const; Literal rotR(const Literal& other) const; + // Note that these functions perform equality checks based + // on the type of the literal, so that (unlike the == operator) + // a float nan would not be identical to itself. Literal eq(const Literal& other) const; Literal ne(const Literal& other) const; Literal ltS(const Literal& other) const; diff --git a/src/passes/Precompute.cpp b/src/passes/Precompute.cpp index b902c4231..9735b91d7 100644 --- a/src/passes/Precompute.cpp +++ b/src/passes/Precompute.cpp @@ -316,7 +316,7 @@ private: value = curr; // this is the first first = false; } else { - if (!value.bitwiseEqual(curr)) { + if (value != curr) { // not the same, give up value = Literal(); break; diff --git a/src/tools/execution-results.h b/src/tools/execution-results.h index fe82c024a..1e8fba4ff 100644 --- a/src/tools/execution-results.h +++ b/src/tools/execution-results.h @@ -78,7 +78,7 @@ struct ExecutionResults { abort(); } std::cout << "[fuzz-exec] comparing " << name << '\n'; - if (!results[name].bitwiseEqual(other.results[name])) { + if (results[name] != other.results[name]) { std::cout << "not identical!\n"; abort(); } diff --git a/src/tools/wasm-shell.cpp b/src/tools/wasm-shell.cpp index 613fc8040..2a59be167 100644 --- a/src/tools/wasm-shell.cpp +++ b/src/tools/wasm-shell.cpp @@ -201,14 +201,14 @@ static void run_asserts(Name moduleName, size_t* i, bool* checked, Module* wasm, ->dynCast<Const>() ->value; std::cerr << "seen " << result << ", expected " << expected << '\n'; - if (!expected.bitwiseEqual(result)) { + if (expected != result) { std::cout << "unexpected, should be identical\n"; abort(); } } else { Literal expected; std::cerr << "seen " << result << ", expected " << expected << '\n'; - if (!expected.bitwiseEqual(result)) { + if (expected != result) { std::cout << "unexpected, should be identical\n"; abort(); } diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp index 032b3f7f8..b5c575b1c 100644 --- a/src/wasm/literal.cpp +++ b/src/wasm/literal.cpp @@ -81,26 +81,14 @@ int64_t Literal::getBits() const { bool Literal::operator==(const Literal& other) const { if (type != other.type) return false; - switch (type) { - case Type::none: return true; - case Type::i32: return i32 == other.i32; - case Type::f32: return getf32() == other.getf32(); - case Type::i64: return i64 == other.i64; - case Type::f64: return getf64() == other.getf64(); - default: abort(); - } + if (type == none) return true; + return getBits() == other.getBits(); } bool Literal::operator!=(const Literal& other) const { return !(*this == other); } -bool Literal::bitwiseEqual(const Literal& other) const { - if (type != other.type) return false; - if (type == none) return true; - return getBits() == other.getBits(); -} - uint32_t Literal::NaNPayload(float f) { assert(std::isnan(f) && "expected a NaN"); // SEEEEEEE EFFFFFFF FFFFFFFF FFFFFFFF |