mirror of
https://github.com/hanzoai/wasm2go.git
synced 2026-10-30 15:06:48 +00:00
The threads support and the memory64 support each worked alone but were kept apart by two gates: shared memory64 modules were rejected at translation, and every 0xFE atomic was rejected on a memory64 memory. A wasm64-wasip1-threads toolchain now exists, so compose them. - atomicEA64 mirrors simdEA64's overflow-guarded address math; every atomic op body moves into an ea-keyed core, the wasm32 helpers become one-line wrappers through atomicEA, and each gets an _m64 twin through atomicEA64 (loads/stores/RMW families, wait/notify). Contended fast paths and memory orders are moved, not rewritten. - The 0xFE lowering decodes the memarg offset as u64 under memory64 (the one place still reading u32), passes it as Const64, and selects the _m64 helper names; the inline atomic fast path becomes width-correct instead of truncating. - wasi_thread_spawn under memory64 passes the start_arg as i64 (it is a linear-memory pointer): threadSpawn splits into a shared launch core with per-width entries, and the module wires a threadStart64 field for the widened wasi_thread_start export. - memoryGrow64 gains the no-relocation branch for shared memories a grow must never move the backing array out from under peer agents. A shared memory64 requires a declared maximum: the reservation is the mapping ceiling, and the memory64 hard cap is not a ceiling. - WasiStubs gains the trivial Sched_yield64 LP64 twin (musl's spin paths import sched_yield; single-threaded modules never did). - New shared+i64 fixtures mirror the wasm32 threads fixtures and run under the race detector; an atomicEA64 unit test covers beyond-4GiB addresses, overflow and misalignment; a regression test pins that unshared memory64 modules may use atomics. Generated output for wasm32 modules is byte-identical. Verified end to end: a wasm64-wasip1-threads C program (pthread_create x4 over a shared counter) transpiles and runs correctly on goroutines, including under -race; llama.cpp built for wasm64-wasip1-threads decodes correctly with ggml n_threads parallelism. Co-authored-by: Claude Fable 5 <[email protected]>
15 lines
730 B
WebAssembly Text Format
15 lines
730 B
WebAssembly Text Format
;; cg_mem64_atomics_unshared.wat — threads-proposal atomics on a PLAIN
|
|
;; (unshared) memory64, which is legal wasm: the transpiler used to reject
|
|
;; every 0xFE opcode under memory64, so this locks the regression. A
|
|
;; zero-timeout wait on an unshared memory returns not-equal semantics per
|
|
;; the runtime's single-agent handling (never parks).
|
|
(module
|
|
(memory i64 1)
|
|
(func (export "bump") (result i32)
|
|
(i32.atomic.store (i64.const 16) (i32.const 40))
|
|
(drop (i32.atomic.rmw.add (i64.const 16) (i32.const 2)))
|
|
(i32.atomic.load (i64.const 16)))
|
|
(func (export "wait_unshared") (result i32)
|
|
(i32.atomic.store (i64.const 32) (i32.const 1))
|
|
(memory.atomic.wait32 (i64.const 32) (i32.const 1) (i64.const 0))))
|