Opcodes
Daniel Wirtz edited this page
·
7 revisions
Pages 5
All opcodes are encoded as a single byte. This byte may include both an opcode and a value, the so called "imm". If an imm is present, the top most bit (0x80) is 1.
Please note: Opcodes mentioned in this document are based on the polyfill prototype. This document does not reflect the final binary format, which hasn't been drafted yet.
Stmt
Opcode without Imm
| Name | Code | Behavior | Description |
|---|---|---|---|
| SetLoc | 0 | SetLocal | opcode + local variable index + Expr<local variable type> |
| SetGlo | 1 | SetGlobal | opcode + global variable index + Expr<global variable type> |
| I32Store8 | 2 | StoreI | opcode + Expr<I32> type-specific heap index + Expr<I32> value |
| I32StoreOff8 | 3 | StoreWithOffsetI | opcode + Expr<I32> type-specific heap index + Expr<I32> heap offset + Expr<I32> value |
| I32Store16 | 4 | StoreI | opcode + Expr<I32> type-specific heap index + Expr<I32> value |
| I32StoreOff16 | 5 | StoreWithOffsetI | opcode + Expr<I32> type-specific heap index + Expr<I32> heap offset + Expr<I32> value |
| I32Store32 | 6 | StoreI | opcode + Expr<I32> type-specific heap index + Expr<I32> value |
| I32StoreOff32 | 7 | StoreWithOffsetI | opcode + Expr<I32> type-specific heap index + Expr<I32> heap offset + Expr<I32> value |
| F32Store | 8 | StoreF32 | opcode + Expr<I32> F32 heap index + Expr<F32> value |
| F32StoreOff | 9 | StoreWithOffsetF32 | opcode + Expr<I32> F32 heap index + Expr<I32> heap offset + Expr<F32> value |
| F64Store | 10 | StoreF64 | opcode + Expr<I32> F64 heap index + Expr<F64> value |
| F64StoreOff | 11 | StoreWithOffsetF64 | opcode + Expr<I32> F64 heap index + Expr<I32> heap offset + Expr<F64> value |
| CallInt | 12 | CallInternal | opcode + varint function declaration index + Expr<argument type> for each argument |
| CallInd | 13 | CallIndirect | opcode + varint function pointer table index + Expr<I32> element index + Expr<argument type> for each argument |
| CallImp | 14 | CallImport | opcode + varint function import signature index + Expr<argument type> for each argument |
| Ret | 15 | Return | opcode [ + Expr<function return type> if function return type is not void ] |
| Block | 16 | Block | opcode + varint count + count * Stmt |
| IfThen | 17 | IfThen | opcode + Expr<I32> condition + Stmt then |
| IfElse | 18 | IfElse | opcode + Expr<I32> condition + Stmt then + Stmt else |
| While | 19 | While | opcode + Expr<I32> condition + Stmt body |
| Do | 20 | Do | opcode + Stmt body + Expr<I32> condition |
| Label | 21 | Label | opcode + Stmt body |
| Break | 22 | Break | opcode only |
| BreakLabel | 23 | BreakLabel | opcode + label index |
| Continue | 24 | Continue | opcode only |
| ContinueLabel | 25 | ContinueLabel | opcode + label index |
| Switch | 26 | Switch | opcode + varint cases + cases * SwitchCase |
Opcode with Imm
| Name | Code | Behavior | Description |
|---|---|---|---|
| SetLoc | 0 | SetLocal | opcode + local variable index + Expr<local variable type> |
| SetGlo | 1 | SetGlobal | opcode + global variable index + Expr<global variable type> |
Expr<I32>
Opcode without Imm
| Name | Code | Behavior | Description |
|---|---|---|---|
| LitPool | 0 | ConstantI32 | opcode + I32 constant index |
| LitImm | 1 | LiteralI32 | opcode + varint/imm value |
| GetLoc | 2 | GetLocalI32 | opcode + local I32 variable index |
| GetGlo | 3 | GetGlobalI32 | opcode + global I32 variable index |
| SetLoc | 4 | SetLocalI32 | opcode + local I32 variable index + Expr<I32> |
| SetGlo | 5 | SetGlobalI32 | opcode + global I32 variable index + Expr<I32> |
| SLoad8 | 6 | LoadI | opcode + Expr<I32> type-specific heap index |
| SLoadOff8 | 7 | LoadWithOffsetI | opcode + Expr<I32> type-specific heap index + Expr<I32> heap offset |
| ULoad8 | 8 | LoadI | opcode + Expr<I32> type-specific heap index |
| ULoadOff8 | 9 | LoadWithOffsetI | opcode + Expr<I32> type-specific heap index + Expr<I32> heap offset |
| SLoad16 | 10 | LoadI | opcode + Expr<I32> type-specific heap index |
| SLoadOff16 | 11 | LoadWithOffsetI | opcode + Expr<I32> type-specific heap index + Expr<I32> heap offset |
| ULoad16 | 12 | LoadI | opcode + Expr<I32> type-specific heap index |
| ULoadOff16 | 13 | LoadWithOffsetI | opcode + Expr<I32> type-specific heap index + Expr<I32> heap offset |
| Load32 | 14 | LoadI | opcode + Expr<I32> type-specific heap index |
| LoadOff32 | 15 | LoadWithOffsetI | opcode + Expr<I32> type-specific heap index + Expr<I32> heap offset |
| Store8 | 16 | StoreI | opcode + Expr<I32> type-specific heap index + Expr<I32> value |
| StoreOff8 | 17 | StoreWithOffsetI | opcode + Expr<I32> type-specific heap index + Expr<I32> heap offset + Expr<I32> value |
| Store16 | 18 | StoreI | opcode + Expr<I32> type-specific heap index + Expr<I32> value |
| StoreOff16 | 19 | StoreWithOffsetI | opcode + Expr<I32> type-specific heap index + Expr<I32> heap offset + Expr<I32> value |
| Store32 | 20 | StoreI | opcode + Expr<I32> type-specific heap index + Expr<I32> value |
| StoreOff32 | 21 | StoreWithOffsetI | opcode + Expr<I32> type-specific heap index + Expr<I32> heap offset + Expr<I32> value |
| CallInt | 22 | CallInternalI32 | opcode + varint function declaration index + Expr<argument type> for each argument |
| CallInd | 23 | CallIndirectI32 | opcode + varint function pointer table index + Expr<I32> element index + Expr<argument type> for each argument |
| CallImp | 24 | CallImportI32 | opcode + varint function import signature index + Expr<argument type> for each argument |
| Cond | 25 | ConditionalI32 | opcode + Expr<I32> condition + Expr<I32> then + Expr<I32> else |
| Comma | 26 | CommaI32 | opcode + byte return type + Expr<return type> + Expr<I32> |
| FromF32 | 27 | UnaryF32 | opcode + Expr<F32> |
| FromF64 | 28 | UnaryF64 | opcode + Expr<F64> |
| Neg | 29 | UnaryI32 | opcode + Expr<I32> |
| Add | 30 | BinaryI32 | opcode + Expr<I32> + Expr<I32> |
| Sub | 31 | BinaryI32 | opcode + Expr<I32> + Expr<I32> |
| Mul | 32 | BinaryI32 | opcode + Expr<I32> + Expr<I32> |
| SDiv | 33 | BinaryI32 | opcode + Expr<I32> + Expr<I32> |
| UDiv | 34 | BinaryI32 | opcode + Expr<I32> + Expr<I32> |
| SMod | 35 | BinaryI32 | opcode + Expr<I32> + Expr<I32> |
| UMod | 36 | BinaryI32 | opcode + Expr<I32> + Expr<I32> |
| BitNot | 37 | UnaryI32 | opcode + Expr<I32> |
| BitOr | 38 | BinaryI32 | opcode + Expr<I32> + Expr<I32> |
| BitAnd | 39 | BinaryI32 | opcode + Expr<I32> + Expr<I32> |
| BitXor | 40 | BinaryI32 | opcode + Expr<I32> + Expr<I32> |
| Lsh | 41 | BinaryI32 | opcode + Expr<I32> + Expr<I32> |
| ArithRsh | 42 | BinaryI32 | opcode + Expr<I32> + Expr<I32> |
| LogicRsh | 43 | BinaryI32 | opcode + Expr<I32> + Expr<I32> |
| Clz | 44 | UnaryI32 | opcode + Expr<I32> |
| LogicNot | 45 | UnaryI32 | opcode + Expr<I32> |
| EqI32 | 46 | BinaryI32 | opcode + Expr<I32> + Expr<I32> |
| EqF32 | 47 | BinaryF32 | opcode + Expr<F32> + Expr<F32> |
| EqF64 | 48 | BinaryF64 | opcode + Expr<F64> + Expr<F64> |
| NEqI32 | 49 | BinaryI32 | opcode + Expr<I32> + Expr<I32> |
| NEqF32 | 50 | BinaryF32 | opcode + Expr<F32> + Expr<F32> |
| NEqF64 | 51 | BinaryF64 | opcode + Expr<F64> + Expr<F64> |
| SLeThI32 | 52 | BinaryI32 | opcode + Expr<I32> + Expr<I32> |
| ULeThI32 | 53 | BinaryI32 | opcode + Expr<I32> + Expr<I32> |
| LeThF32 | 54 | BinaryF32 | opcode + Expr<F32> + Expr<F32> |
| LeThF64 | 55 | BinaryF64 | opcode + Expr<F64> + Expr<F64> |
| SLeEqI32 | 56 | BinaryI32 | opcode + Expr<I32> + Expr<I32> |
| ULeEqI32 | 57 | BinaryI32 | opcode + Expr<I32> + Expr<I32> |
| LeEqF32 | 58 | BinaryF32 | opcode + Expr<F32> + Expr<F32> |
| LeEqF64 | 59 | BinaryF64 | opcode + Expr<F64> + Expr<F64> |
| SGrThI32 | 60 | BinaryI32 | opcode + Expr<I32> + Expr<I32> |
| UGrThI32 | 61 | BinaryI32 | opcode + Expr<I32> + Expr<I32> |
| GrThF32 | 62 | BinaryF32 | opcode + Expr<F32> + Expr<F32> |
| GrThF64 | 63 | BinaryF64 | opcode + Expr<F64> + Expr<F64> |
| SGrEqI32 | 64 | BinaryI32 | opcode + Expr<I32> + Expr<I32> |
| UGrEqI32 | 65 | BinaryI32 | opcode + Expr<I32> + Expr<I32> |
| GrEqF32 | 66 | BinaryF32 | opcode + Expr<F32> + Expr<F32> |
| GrEqF64 | 67 | BinaryF64 | opcode + Expr<F64> + Expr<F64> |
| SMin | 68 | MultiaryI32 | opcode + varint count + count * Expr<I32> |
| UMin | 69 | MultiaryI32 | opcode + varint count + count * Expr<I32> |
| SMax | 70 | MultiaryI32 | opcode + varint count + count * Expr<I32> |
| UMax | 71 | MultiaryI32 | opcode + varint count + count * Expr<I32> |
| Abs | 72 | UnaryI32 | opcode + Expr<I32> |
Opcode with Imm
| Name | Code | Behavior | Description |
|---|---|---|---|
| LitPool | 0 | ConstantI32 | opcode + I32 constant index |
| LitImm | 1 | LiteralI32 | opcode + varint/imm value |
| GetLoc | 2 | GetLocalI32 | opcode + local I32 variable index |
Expr<F32>
Opcode without Imm
| Name | Code | Behavior | Description |
|---|---|---|---|
| LitPool | 0 | ConstantF32 | opcode + F32 constant index |
| LitImm | 1 | LiteralF32 | opcode + float value |
| GetLoc | 2 | GetLocalF32 | opcode + local F32 variable index |
| GetGlo | 3 | GetGlobalF32 | opcode + global F32 variable index |
| SetLoc | 4 | SetLocalF32 | opcode + local F32 variable index + Expr<F32> |
| SetGlo | 5 | SetGlobalF32 | opcode + global F32 variable index + Expr<F32> |
| Load | 6 | LoadF32 | opcode + Expr<I32> F32 heap index |
| LoadOff | 7 | LoadWithOffsetF32 | opcode + Expr<I32> F32 heap index + Expr<I32> heap offset |
| Store | 8 | StoreF32 | opcode + Expr<I32> F32 heap index + Expr<F32> value |
| StoreOff | 9 | StoreWithOffsetF32 | opcode + Expr<I32> F32 heap index + Expr<I32> heap offset + Expr<F32> value |
| CallInt | 10 | CallInternalF32 | opcode + varint function declaration index + Expr<argument type> for each argument |
| CallInd | 11 | CallIndirectF32 | opcode + varint function pointer table index + Expr<I32> element index + Expr<argument type> for each argument |
| Cond | 12 | ConditionalF32 | opcode + Expr<I32> condition + Expr<F32> then + Expr<F32> else |
| Comma | 13 | CommaF32 | opcode + byte return type + Expr<return type> + Expr<F32> |
| FromS32 | 14 | UnaryI32 | opcode + Expr<I32> |
| FromU32 | 15 | UnaryI32 | opcode + Expr<I32> |
| FromF64 | 16 | UnaryF64 | opcode + Expr<F64> |
| Neg | 17 | UnaryF32 | opcode + Expr<F32> |
| Add | 18 | BinaryF32 | opcode + Expr<F32> + Expr<F32> |
| Sub | 19 | BinaryF32 | opcode + Expr<F32> + Expr<F32> |
| Mul | 20 | BinaryF32 | opcode + Expr<F32> + Expr<F32> |
| Div | 21 | BinaryF32 | opcode + Expr<F32> + Expr<F32> |
| Abs | 22 | UnaryF32 | opcode + Expr<F32> |
| Ceil | 23 | UnaryF32 | opcode + Expr<F32> |
| Floor | 24 | UnaryF32 | opcode + Expr<F32> |
| Sqrt | 25 | UnaryF32 | opcode + Expr<F32> |
Opcode with Imm
| Name | Code | Behavior | Description |
|---|---|---|---|
| LitPool | 0 | ConstantF32 | opcode + F32 constant index |
| GetLoc | 1 | GetLocalF32 | opcode + local F32 variable index |
Expr<F64>
Opcode without Imm
| Name | Code | Behavior | Description |
|---|---|---|---|
| LitPool | 0 | ConstantF64 | opcode + F64 constant index |
| LitImm | 1 | LiteralF64 | opcode + double value |
| GetLoc | 2 | GetLocalF64 | opcode + local F64 variable index |
| GetGlo | 3 | GetGlobalF64 | opcode + global F64 variable index |
| SetLoc | 4 | SetLocalF64 | opcode + local F64 variable index + Expr<F64> |
| SetGlo | 5 | SetGlobalF64 | opcode + global F64 variable index + Expr<F64> |
| Load | 6 | LoadF64 | opcode + Expr<I32> F64 heap index |
| LoadOff | 7 | LoadWithOffsetF64 | opcode + Expr<I32> F64 heap index + Expr<I32> heap offset |
| Store | 8 | StoreF64 | opcode + Expr<I32> F64 heap index + Expr<F64> value |
| StoreOff | 9 | StoreWithOffsetF64 | opcode + Expr<I32> F64 heap index + Expr<I32> heap offset + Expr<F64> value |
| CallInt | 10 | CallInternalF64 | opcode + varint function declaration index + Expr<argument type> for each argument |
| CallInd | 11 | CallIndirectF64 | opcode + varint function pointer table index + Expr<I32> element index + Expr<argument type> for each argument |
| CallImp | 12 | CallImportF64 | opcode + varint function import signature index + Expr<argument type> for each argument |
| Cond | 13 | ConditionalF64 | opcode + Expr<I32> condition + Expr<F64> then + Expr<F64> else |
| Comma | 14 | CommaF64 | opcode + byte return type + Expr<return type> + Expr<F64> |
| FromS32 | 15 | UnaryI32 | opcode + Expr<I32> |
| FromU32 | 16 | UnaryI32 | opcode + Expr<I32> |
| FromF32 | 17 | UnaryF32 | opcode + Expr<F32> |
| Neg | 18 | UnaryF64 | opcode + Expr<F64> |
| Add | 19 | BinaryF64 | opcode + Expr<F64> + Expr<F64> |
| Sub | 20 | BinaryF64 | opcode + Expr<F64> + Expr<F64> |
| Mul | 21 | BinaryF64 | opcode + Expr<F64> + Expr<F64> |
| Div | 22 | BinaryF64 | opcode + Expr<F64> + Expr<F64> |
| Mod | 23 | BinaryF64 | opcode + Expr<F64> + Expr<F64> |
| Min | 24 | MultiaryF64 | opcode + varint count + count * Expr<F64> |
| Max | 25 | MultiaryF64 | opcode + varint count + count * Expr<F64> |
| Abs | 26 | UnaryF64 | opcode + Expr<F64> |
| Ceil | 27 | UnaryF64 | opcode + Expr<F64> |
| Floor | 28 | UnaryF64 | opcode + Expr<F64> |
| Sqrt | 29 | UnaryF64 | opcode + Expr<F64> |
| Cos | 30 | UnaryF64 | opcode + Expr<F64> |
| Sin | 31 | UnaryF64 | opcode + Expr<F64> |
| Tan | 32 | UnaryF64 | opcode + Expr<F64> |
| ACos | 33 | UnaryF64 | opcode + Expr<F64> |
| ASin | 34 | UnaryF64 | opcode + Expr<F64> |
| ATan | 35 | UnaryF64 | opcode + Expr<F64> |
| ATan2 | 36 | BinaryF64 | opcode + Expr<F64> + Expr<F64> |
| Exp | 37 | UnaryF64 | opcode + Expr<F64> |
| Ln | 38 | UnaryF64 | opcode + Expr<F64> |
| Pow | 39 | BinaryF64 | opcode + Expr<F64> + Expr<F64> |
Opcode with Imm
| Name | Code | Behavior | Description |
|---|---|---|---|
| LitPool | 0 | ConstantF64 | opcode + F64 constant index |
| GetLoc | 1 | GetLocalF64 | opcode + local F64 variable index |
Expr<Void>
Opcode without Imm
| Name | Code | Behavior | Description |
|---|---|---|---|
| CallInt | 0 | CallInternalVoid | opcode + varint function declaration index + Expr<argument type> for each argument |
| CallInd | 1 | CallIndirectVoid | opcode + varint function pointer table index + Expr<I32> element index + Expr<argument type> for each argument |
| CallImp | 2 | CallImportVoid | opcode + varint function import signature index + Expr<argument type> for each argument |
SwitchCase
Opcode without Imm
| Name | Code | Behavior | Description |
|---|---|---|---|
| Case0 | 0 | SwitchCase0 | opcode + signed varint label |
| Case1 | 1 | SwitchCase1 | opcode + signed varint label + Stmt |
| CaseN | 2 | SwitchCaseN | opcode + signed varint label + varint count + count * Stmt |
| Default0 | 3 | SwitchDefault0 | opcode only |
| Default1 | 4 | SwitchDefault1 | opcode + Stmt |
| DefaultN | 5 | SwitchDefaultN | opcode + varint count + count * Stmt |