WebAssembly/multi-memory

memarg encoding

AndrewScheidecker opened this issue · 2 comments

How should memarg encode a non-zero memory index?

Using some range from the alignment field seems like the simplest way to do it in a backward compatible way. Fortunately, the alignment field stores log2(alignment), and so needs very little range. Using 3 bits for alignment is probably safe, and 4 bits is definitely safe.

So I propose that we use the lower 4 bits of the current alignment field to encode the alignment, and the 5th bit as a flag to indicate that the other immediate fields will be followed by a varuint32 memory index field.

My plan was to be as conservative as is possible without wasting space, which means allocating bits in the memarg from the high end of a single byte LEB. That would be the 7th bit (bit 6).

I think it's unlikely we'll ever need the 5th and 6th alignment bits, but I suppose it makes sense to keep them until there's a specific use for them.