summaryrefslogtreecommitdiff
path: root/src/binaryen-shell.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/binaryen-shell.cpp')
-rw-r--r--src/binaryen-shell.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/binaryen-shell.cpp b/src/binaryen-shell.cpp
index a96716a02..d8277ad80 100644
--- a/src/binaryen-shell.cpp
+++ b/src/binaryen-shell.cpp
@@ -74,8 +74,10 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface {
public:
Memory() {}
void resize(size_t newSize) {
- // Allocate at least this size to get proper alignment: the allocator will
- // usually start allocating page-sized chunks which are properly aligned.
+ // Ensure the smallest allocation is large enough that most allocators
+ // will provide page-aligned storage. This hopefully allows the
+ // interpreter's memory to be as aligned as the memory being simulated,
+ // ensuring that the performance doesn't needlessly degrade.
//
// The code is optimistic this will work until WG21's p0035r0 happens.
const size_t minSize = 1 << 12;
@@ -224,6 +226,19 @@ struct Invocation {
}
};
+static void verify_result(Literal a, Literal b) {
+ if (a == b) return;
+ // accept equal nans if equal in all bits
+ assert(a.type == b.type);
+ if (a.type == f32) {
+ assert(a.reinterpreti32() == b.reinterpreti32());
+ } else if (a.type == f64) {
+ assert(a.reinterpreti64() == b.reinterpreti64());
+ } else {
+ abort();
+ }
+}
+
static void run_asserts(size_t* i, bool* checked, AllocatingModule* wasm,
Element* root,
std::unique_ptr<SExpressionWasmBuilder>* builder,
@@ -300,11 +315,11 @@ static void run_asserts(size_t* i, bool* checked, AllocatingModule* wasm,
->dyn_cast<Const>()
->value;
std::cerr << "seen " << result << ", expected " << expected << '\n';
- assert(expected == result);
+ verify_result(expected, result);
} else {
Literal expected;
std::cerr << "seen " << result << ", expected " << expected << '\n';
- assert(expected == result);
+ verify_result(expected, result);
}
}
if (id == ASSERT_TRAP) assert(trapped);