stack-switching icon indicating copy to clipboard operation
stack-switching copied to clipboard

Encoding of opcodes

Open fgmccabe opened this issue 9 months ago • 3 comments

The explainer introduces six instructions: cont.new, cont.bind, resume, resume_throw, suspend, switch.

While this is not a large number, it is more than 1. Furthermore, it is entirely possible that we will need to describe additional instructions.

At the moment, the opcodes 0xe0 through 0xe5 are also described.

The wasm opcode space is getting pretty crowded nowadays. (In fact, the above codes already conflict with some internal opcodes used within V8).

Also, since suspend/resume instructions are unlikely to be that frequent in the code, the code size argument does not seem pressing.

I would like to suggest using some space in one of the existing prefix groups: GC (0xfb), Numeric (0xfc), Simd (0xfd) or Atomic (0xfe).

The one with the most room is Numeric (last used sub-opcode 0x31) but maybe the one that makes most sense is GC (last used opcode is 0xb8)

Another suggestion made to me: have a specific 'experimental' prefix to be used by proposals until (just before) they reach phase 4.

fgmccabe avatar Feb 24 '25 19:02 fgmccabe

The GC prefix or a new prefix would make sense to me. Choosing an experimental prefix (0xff?) with a documented intention to change it before phase 4 also makes sense to me, and is something we have wished we had done for other proposals as well.

tlively avatar Feb 25 '25 00:02 tlively

TBH I prefer that they remain unprefixed and low, because these opcodes are fundamental additions to control flow constructs.

Or, to put it another way, I cannot imagine other instructions that would be better to put in the low holes that exist in the opcode space today, so I think these new stack-switching opcodes fit best these low holes.

titzer avatar Mar 19 '25 18:03 titzer

FWIW we now have standard precedent for prefixed control flow instructions: br_on_cast and br_on_cast_fail.

tlively avatar Mar 19 '25 18:03 tlively