Skip to content

Enable bulk-memory copy/fill opcodes in WAMR#16

Open
e-fu wants to merge 3 commits into
elixir-volt:masterfrom
ZenHive:bulk-memory-opt
Open

Enable bulk-memory copy/fill opcodes in WAMR#16
e-fu wants to merge 3 commits into
elixir-volt:masterfrom
ZenHive:bulk-memory-opt

Conversation

@e-fu

@e-fu e-fu commented Jun 18, 2026

Copy link
Copy Markdown

Problem

Go's GOOS=js GOARCH=wasm compiler — and TinyGo, Rust wasm-bindgen — emit bulk-memory opcodes unconditionally. WASM_ENABLE_BULK_MEMORY and WASM_ENABLE_REF_TYPES were already set via -D in native.ex, but the _OPT sub-feature gating memory.copy (fc 0a) / memory.fill (fc 0b) was not. As a result any such module fails to instantiate with unsupported opcode fc 0a.

Fix

Add -DWASM_ENABLE_BULK_MEMORY_OPT=1 beside the existing flags in lib/quickbeam/native.ex (the build's single source of truth; the vendored config.h #ifndef defaults are overridden by these -D defines).

Test

A regression test runs a hand-assembled module exercising all four bulk-memory opcodes (memory.fill/copy/init + data.drop) via both the native WASM API and the JS WebAssembly API, asserting run() == 43998 (load8_u(100)*256 + load8_u(200) = 0xAB*256 + 0xDE). Without the flag the module fails to compile with unsupported opcode fc 0a.

Verification

CI was run on a downstream fork (the canonical CI setup) before opening this PR — all four jobs green on the same commit:

  • test (27.0, 1.18) — NIF built from source on Linux + full suite incl. the bulk-memory regression test
  • UBSan + Zig Debug
  • AddressSanitizer
  • C static analysis

Run: https://github.com/ZenHive/quickbeam/actions/runs/27730829659

Go's GOOS=js GOARCH=wasm compiler (and TinyGo, Rust wasm-bindgen) emit
bulk-memory opcodes unconditionally. WASM_ENABLE_BULK_MEMORY and
WASM_ENABLE_REF_TYPES were already set via -D in native.ex, but the
_OPT sub-feature gating memory.copy (fc 0a) / memory.fill (fc 0b) was
not, so any such module failed to instantiate with 'unsupported opcode
fc 0a'. Add -DWASM_ENABLE_BULK_MEMORY_OPT=1 beside the existing flags
(the build's single source of truth; the vendored config.h #ifndef
defaults are overridden by these -D defines).

Regression test runs a module exercising all four bulk-memory opcodes
(memory.fill/copy/init + data.drop) via both the native WASM API and
the JS WebAssembly API, asserting run() == 43998.
Copilot AI review requested due to automatic review settings June 18, 2026 03:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enables WAMR’s bulk-memory “_OPT” feature gate so memory.copy / memory.fill opcodes (emitted unconditionally by common WASM toolchains like Go/TinyGo/wasm-bindgen) are accepted by QuickBEAM’s embedded WASM runtime, and adds regression coverage to prevent future breakage.

Changes:

  • Enable WASM_ENABLE_BULK_MEMORY_OPT=1 in the WAMR C compilation flags used by the native NIF build.
  • Add a regression WASM fixture plus tests that exercise all bulk-memory opcodes via both QuickBEAM.WASM and the JS WebAssembly API.
  • Document the change in CHANGELOG.md.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
test/wasm_test.exs Adds a bulk-memory opcode fixture and regression tests for both the native WASM API and JS WebAssembly.instantiate.
lib/quickbeam/native.ex Enables WASM_ENABLE_BULK_MEMORY_OPT in WAMR build flags so memory.copy/memory.fill are supported.
CHANGELOG.md Notes the newly enabled bulk-memory opcode support and the previously observed failure mode.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/wasm_test.exs Outdated
Comment on lines +500 to +504
@bulk_memory_wasm <<0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 0, 1, 127, 3, 2, 1, 0, 5, 3, 1, 0,
1, 7, 13, 2, 3, 109, 101, 109, 2, 0, 3, 114, 117, 110, 0, 0, 12, 1, 1, 10,
56, 1, 54, 0, 65, 0, 65, 171, 1, 65, 16, 252, 11, 0, 65, 228, 0, 65, 0, 65,
16, 252, 10, 0, 0, 65, 200, 1, 65, 0, 65, 4, 252, 8, 0, 0, 252, 9, 0, 65,
228, 0, 45, 0, 0, 65, 128, 2, 108, 65, 200, 1, 45, 0, 0, 106, 11, 11, 7, 1,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants