diff options
author | Thomas Lively <tlively@google.com> | 2023-02-14 16:36:36 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-14 14:36:36 -0800 |
commit | 8f98375c051f2b8e1be87e7eb97e88d73cfb2c26 (patch) | |
tree | 171ab05759465e63ebe7ce898585813801820cbd /src | |
parent | 3a315fb8248be7a2a7b7e27ebfde634d05668bf3 (diff) | |
download | binaryen-8f98375c051f2b8e1be87e7eb97e88d73cfb2c26.tar.gz binaryen-8f98375c051f2b8e1be87e7eb97e88d73cfb2c26.tar.bz2 binaryen-8f98375c051f2b8e1be87e7eb97e88d73cfb2c26.zip |
[wasm2js] Support nonzero offsets in memory.atomic.wait32 (#5489)
The assertion that the offset is zero does not necessarily hold for code that
uses this instruction via the clang builtin. Add support so that Emscripten
wasm2js tests pass in the presence of such code.
Diffstat (limited to 'src')
-rw-r--r-- | src/abi/js.h | 5 | ||||
-rw-r--r-- | src/passes/I64ToI32Lowering.cpp | 4 | ||||
-rw-r--r-- | src/wasm2js.h | 5 |
3 files changed, 8 insertions, 6 deletions
diff --git a/src/abi/js.h b/src/abi/js.h index 735f71af7..d22376c13 100644 --- a/src/abi/js.h +++ b/src/abi/js.h @@ -82,8 +82,9 @@ inline void ensureHelpers(Module* wasm, IString specific = IString()) { ensureImport(MEMORY_FILL, {Type::i32, Type::i32, Type::i32}, Type::none); ensureImport(MEMORY_COPY, {Type::i32, Type::i32, Type::i32}, Type::none); ensureImport(DATA_DROP, {Type::i32}, Type::none); - ensureImport( - ATOMIC_WAIT_I32, {Type::i32, Type::i32, Type::i32, Type::i32}, Type::i32); + ensureImport(ATOMIC_WAIT_I32, + {Type::i32, Type::i32, Type::i32, Type::i32, Type::i32}, + Type::i32); ensureImport( ATOMIC_RMW_I64, {Type::i32, Type::i32, Type::i32, Type::i32, Type::i32, Type::i32}, diff --git a/src/passes/I64ToI32Lowering.cpp b/src/passes/I64ToI32Lowering.cpp index aee65c22a..dfcc65a51 100644 --- a/src/passes/I64ToI32Lowering.cpp +++ b/src/passes/I64ToI32Lowering.cpp @@ -478,10 +478,10 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> { void visitAtomicWait(AtomicWait* curr) { // The last parameter is an i64, so we cannot leave it as it is - assert(curr->offset == 0); replaceCurrent(builder->makeCall( ABI::wasm2js::ATOMIC_WAIT_I32, - {curr->ptr, + {builder->makeConst(int32_t(curr->offset)), + curr->ptr, curr->expected, curr->timeout, builder->makeLocalGet(fetchOutParam(curr->timeout), Type::i32)}, diff --git a/src/wasm2js.h b/src/wasm2js.h index eddb26866..08969b8ba 100644 --- a/src/wasm2js.h +++ b/src/wasm2js.h @@ -2989,7 +2989,8 @@ void Wasm2JSGlue::emitSpecialSupport() { )"; } else if (import->base == ABI::wasm2js::ATOMIC_WAIT_I32) { out << R"( - function wasm2js_atomic_wait_i32(ptr, expected, timeoutLow, timeoutHigh) { + function wasm2js_atomic_wait_i32(offset, ptr, expected, timeoutLow, timeoutHigh) { + ptr = (ptr + offset) >> 2; var timeout = Infinity; if (timeoutHigh >= 0) { // Convert from nanoseconds to milliseconds @@ -2997,7 +2998,7 @@ void Wasm2JSGlue::emitSpecialSupport() { timeout = ((timeoutLow >>> 0) / 1e6) + timeoutHigh * (4294967296 / 1e6); } var view = new Int32Array(bufferView.buffer); // TODO cache - var result = Atomics.wait(view, ptr >> 2, expected, timeout); + var result = Atomics.wait(view, ptr, expected, timeout); if (result == 'ok') return 0; if (result == 'not-equal') return 1; if (result == 'timed-out') return 2; |