Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Contradiction in multi-memory binary format instruction rules #28

Closed

Description

@ashleynh

Hi,

I'm implementing multi-memories in Binaryen and noticed a contradiction while following the Multiple Memories for Wasm proposal.

Under Binary format, the proposal says "For loads and stores: Reinterpret the alignment value in the memarg as a bitfield; if bit 6 (the MSB of the first LEB byte) is set, then an i32 memory index follows after the offset immediate." The problem is this ordering requires parsing the offset before the memory index. While the memory index is always i32, with the introduction of 64-bit, the offset can now be i32 or i64. Before adding multi-memories support, the code checked the index type of the memory before parsing either an i32 or i64 offset.

As a result, the following steps are now performed to follow the proposal as currently written:

  1. Create an i64 for the offset
  2. Identify the memory based on the index following the offset
  3. Check whether the memory index type is i32
  4. If step 3 is true, check if the offset is a larger number than what fits into an i32
  5. If step 4 is true, throw an error
  6. If step 4 is false, down-cast the i64 offset to an i32 offset

It would be better if the i32 memory index immediately followed the alignment instead of the offset, because then the index type would be known and the code would parse the offset accordingly. I propose changing the sentence above in bold to "then an i32 memory index follows after the alignment".

@rossberg @titzer @kmiller68 @eqrion @jkummerow - seeking thoughts & sign off, thanks!

Activity

  1. rossberg commented on Jun 27, 2022

    @rossberg
    Member

    Ah, this is an interference with the Wasm64 extension that I hadn't considered.

    From first glance, it makes total sense to me to change the immediates around to make this easier. I'll try that out.

  2. rossberg commented on Jun 27, 2022

    @rossberg
    Member

    Okay, very easy change, please have a look at #29.

  3. ashleynh commented on Jun 27, 2022

    @ashleynh
    ContributorAuthor

    Awesome! Thanks for handling so quickly. LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions