Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/abi/js.h
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
4 changes: 2 additions & 2 deletions src/passes/I64ToI32Lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
Expand Down
5 changes: 3 additions & 2 deletions src/wasm2js.h
Original file line number Diff line number Diff line change
Expand Up @@ -2989,15 +2989,16 @@ 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
// Taken from convertI32PairToI53 in emscripten's library_int53.js
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;
Expand Down
4 changes: 2 additions & 2 deletions test/passes/remove-non-js-ops.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
(type $f64_=>_none (func (param f64)))
(type $i32_i32_i32_i32_=>_none (func (param i32 i32 i32 i32)))
(type $i32_=>_none (func (param i32)))
(type $i32_i32_i32_i32_=>_i32 (func (param i32 i32 i32 i32) (result i32)))
(type $i32_i32_i32_i32_i32_=>_i32 (func (param i32 i32 i32 i32 i32) (result i32)))
(type $i32_i32_i32_i32_i32_i32_=>_i32 (func (param i32 i32 i32 i32 i32 i32) (result i32)))
(type $none_=>_i32 (func (result i32)))
(type $none_=>_none (func))
Expand All @@ -28,7 +28,7 @@
(import "env" "wasm2js_memory_fill" (func $wasm2js_memory_fill (param i32 i32 i32)))
(import "env" "wasm2js_memory_copy" (func $wasm2js_memory_copy (param i32 i32 i32)))
(import "env" "wasm2js_data_drop" (func $wasm2js_data_drop (param i32)))
(import "env" "wasm2js_atomic_wait_i32" (func $wasm2js_atomic_wait_i32 (param i32 i32 i32 i32) (result i32)))
(import "env" "wasm2js_atomic_wait_i32" (func $wasm2js_atomic_wait_i32 (param i32 i32 i32 i32 i32) (result i32)))
(import "env" "wasm2js_atomic_rmw_i64" (func $wasm2js_atomic_rmw_i64 (param i32 i32 i32 i32 i32 i32) (result i32)))
(import "env" "wasm2js_get_stashed_bits" (func $wasm2js_get_stashed_bits (result i32)))
(import "env" "wasm2js_trap" (func $wasm2js_trap))
Expand Down
7 changes: 4 additions & 3 deletions test/wasm2js/atomics_32.2asm.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@
memorySegments[0] = base64DecodeToExistingUint8Array(new Uint8Array(6), 0, "aGVsbG8s");
memorySegments[1] = base64DecodeToExistingUint8Array(new Uint8Array(6), 0, "d29ybGQh");

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
// Taken from convertI32PairToI53 in emscripten's library_int53.js
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;
Expand Down Expand Up @@ -119,7 +120,7 @@ function asmFunc(imports) {
Atomics.load(HEAP32, 1028 >> 2) | 0;
Atomics.store(HEAP32, 100 >> 2, 200);
i64toi32_i32$0 = -1;
wasm2js_atomic_wait_i32(4 | 0, 8 | 0, -1 | 0, i64toi32_i32$0 | 0) | 0;
wasm2js_atomic_wait_i32(4 | 0, 8 | 0, 16 | 0, -1 | 0, i64toi32_i32$0 | 0) | 0;
wasm2js_memory_init(0, 512, 0, 4);
wasm2js_memory_init(1, 1024, 4, 2);
Atomics.notify(HEAP32, 4 >> 2, 2);
Expand Down
7 changes: 4 additions & 3 deletions test/wasm2js/atomics_32.2asm.js.opt
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@
memorySegments[0] = base64DecodeToExistingUint8Array(new Uint8Array(6), 0, "aGVsbG8s");
memorySegments[1] = base64DecodeToExistingUint8Array(new Uint8Array(6), 0, "d29ybGQh");

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
// Taken from convertI32PairToI53 in emscripten's library_int53.js
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;
Expand Down Expand Up @@ -117,7 +118,7 @@ function asmFunc(imports) {
Atomics.load(HEAPU16, 514);
Atomics.load(HEAP32, 257);
Atomics.store(HEAP32, 25, 200);
wasm2js_atomic_wait_i32(4, 8, -1, -1) | 0;
wasm2js_atomic_wait_i32(4, 8, 16, -1, -1) | 0;
wasm2js_memory_init(0, 512, 0, 4);
wasm2js_memory_init(1, 1024, 4, 2);
Atomics.notify(HEAP32, 1, 2);
Expand Down
2 changes: 1 addition & 1 deletion test/wasm2js/atomics_32.wast
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
(local.set $x (i32.atomic.load16_u (i32.const 1028)))
(local.set $x (i32.atomic.load (i32.const 1028)))
(i32.atomic.store (i32.const 100) (i32.const 200))
(local.set $x (memory.atomic.wait32 (i32.const 4) (i32.const 8) (i64.const -1)))
(local.set $x (memory.atomic.wait32 offset=4 (i32.const 8) (i32.const 16) (i64.const -1)))
(memory.init 0 (i32.const 512) (i32.const 0) (i32.const 4))
(memory.init 1 (i32.const 1024) (i32.const 4) (i32.const 2))
(local.set $x (memory.atomic.notify (i32.const 4) (i32.const 2)))
Expand Down