Skip to content

[multibyte] Add multibyte array store instructions.#8059

Open
brendandahl wants to merge 14 commits intoWebAssembly:mainfrom
brendandahl:multibyte-array-store
Open

[multibyte] Add multibyte array store instructions.#8059
brendandahl wants to merge 14 commits intoWebAssembly:mainfrom
brendandahl:multibyte-array-store

Conversation

@brendandahl
Copy link
Collaborator

@brendandahl brendandahl commented Nov 18, 2025

Prototype implementation of the new multibyte array proposal that reuses the existing memory instructions.
The syntax for the new instructions is as follows:
<i32|i64|f32|f64>.store (type $type_idx) <array ref> <index> <value>

Some spec related TODOs:

  • Decide on new instructions vs existing memory instructions with memarg flag.
  • If using existing instructions:
    • What does the wat syntax look like? e.g. i32.store type=array x y or i32.store array x y or ???
    • Do we support immediate offsets? - Do we support i32.store8? (effectively the same as array.set on i8)
  • Do we support atomic instructions?

Some implementation TODOs:

  • Add feature flag.
  • Add v128.store.
  • Go through the various visitArrayStore functions and implement them or make sure the copied versions makes sense.
  • Add fuzzing support.
  • Make it so there's only one WasmBinaryReader::getMemarg
  • Add JS API

src/wasm.h Outdated
Comment on lines +1846 to +1847
// TODO is this needed?
MemoryOrder order = MemoryOrder::Unordered;
Copy link
Member

Choose a reason for hiding this comment

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

Probably in the long run, but not urgently. I would leave it out for now.

case BinaryConsts::I32StoreMem8: {
auto [mem, align, offset] = getMemarg();
return builder.makeStore(1, offset, align, Type::i32, mem);
auto [mem, align, offset, backing] = getMemargWithBacking();
Copy link
Member

Choose a reason for hiding this comment

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

The binary format will need the type immediate as well, so this will have to look something like this:

Suggested change
auto [mem, align, offset, backing] = getMemargWithBacking();
auto [mem, align, offset, backing] = getMemargWithBacking();
if (backing == BackingType::Array) {
HeapType type = getIndexedHeapType();
...

At that point we might as well add a separate IRBuilder method for making array stores, which should help separate concerns more.

@brendandahl brendandahl force-pushed the multibyte-array-store branch 4 times, most recently from 46cdca3 to 60f68c8 Compare February 19, 2026 18:34
@brendandahl brendandahl force-pushed the multibyte-array-store branch 2 times, most recently from 0a6ba01 to 2f3a132 Compare February 28, 2026 01:13
Add support for multibyte array store instructions as proposed in the
WebAssembly multibyte proposal. These instructions allow storing values
of various byte widths directly into i8 arrays, avoiding the need for
manual bit manipulation and masking.

Link: https://github.com/WebAssembly/multibyte
@brendandahl brendandahl force-pushed the multibyte-array-store branch from 2f3a132 to 0847ada Compare March 2, 2026 17:46
@brendandahl brendandahl requested a review from tlively March 2, 2026 18:26
Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

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

Nice!

@brendandahl brendandahl requested a review from tlively March 4, 2026 00:06
@brendandahl brendandahl changed the title [WIP][multibyte] Add multibyte array store instructions. [multibyte] Add multibyte array store instructions. Mar 6, 2026
@brendandahl brendandahl requested a review from tlively March 6, 2026 22:38
@brendandahl brendandahl requested a review from kripken March 6, 2026 22:38
Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

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

LGTM % final comment.

}
note(&curr->ref, Type(*ht, Nullable));
note(&curr->index, Type::i32);
note(&curr->value, valueType ? *valueType : curr->value->type);
Copy link
Member

Choose a reason for hiding this comment

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

We should self().noteUnknown() if curr->value->type == Type::unreachable.

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.

3 participants