diff --git a/RATIONALE.md b/RATIONALE.md index 622b362f52..8d783cb448 100644 --- a/RATIONALE.md +++ b/RATIONALE.md @@ -471,17 +471,6 @@ case, a user can use multiple runtimes until "multi-store" is better understood. If later, we have demand for multiple stores, that can be accomplished by overload. e.g. `Runtime.InstantiateInStore` or `Runtime.Store(name) Store`. -## wazeroir -wazero's intermediate representation (IR) is called `wazeroir`. Lowering into an IR provides us a faster interpreter -and a closer to assembly representation for used by our compiler. - -### Intermediate Representation (IR) design -`wazeroir`'s initial design borrowed heavily from the defunct `microwasm` format (a.k.a. LightbeamIR). Notably, -`wazeroir` doesn't have block operations: this simplifies the implementation. - -Note: `microwasm` was never specified formally, and only exists in a historical codebase of wasmtime: -https://github.com/bytecodealliance/wasmtime/blob/v0.29.0/crates/lightbeam/src/microwasm.rs - ## Exit ### Why do we only return a `sys.ExitError` on a non-zero exit code? @@ -1545,15 +1534,13 @@ that trampoline function. Therefore, runtime-generated machine code is also corr Since [wazero v1.0.0-pre.9](https://github.com/tetratelabs/wazero/releases/tag/v1.0.0-pre.9), the runtime supports integration with Go contexts to interrupt execution after a timeout, or in response to explicit cancellation. This support is internally implemented as a special opcode `builtinFunctionCheckExitCode` that triggers the execution of -a Go function (`ModuleInstance.FailIfClosed`) that atomically checks a sentinel value at strategic points in the code -(e.g. [within loops][checkexitcode_loop]). +a Go function (`ModuleInstance.FailIfClosed`) that atomically checks a sentinel value at strategic points in the code. [It _is indeed_ possible to check the sentinel value directly, without leaving the native world][native_check], thus sparing some cycles; however, because native code never preempts (see section above), this may lead to a state where the other goroutines never get the chance to run, and thus never get the chance to set the sentinel value; effectively preventing cancellation from taking place. -[checkexitcode_loop]: https://github.com/tetratelabs/wazero/blob/86444c67a37dbf9e693ae5b365901f64968d9025/internal/wazeroir/compiler.go#L467-L476 [native_check]: https://github.com/tetratelabs/wazero/issues/1409 ## Golang patterns diff --git a/config.go b/config.go index 04bce10e3c..819a76df5e 100644 --- a/config.go +++ b/config.go @@ -218,7 +218,7 @@ const ( // Runtime.CompileModule is invoked. // // Warning: This panics at runtime if the runtime.GOOS or runtime.GOARCH does not -// support Compiler. Use NewRuntimeConfig to safely detect and fallback to +// support compiler. Use NewRuntimeConfig to safely detect and fallback to // NewRuntimeConfigInterpreter if needed. func NewRuntimeConfigCompiler() RuntimeConfig { ret := engineLessConfig.clone() diff --git a/internal/wazeroir/compiler.go b/internal/engine/interpreter/compiler.go similarity index 70% rename from internal/wazeroir/compiler.go rename to internal/engine/interpreter/compiler.go index 2699cb876c..56dfac6206 100644 --- a/internal/wazeroir/compiler.go +++ b/internal/engine/interpreter/compiler.go @@ -1,4 +1,4 @@ -package wazeroir +package interpreter import ( "bytes" @@ -44,20 +44,20 @@ func (c *controlFrame) ensureContinuation() { } } -func (c *controlFrame) asLabel() Label { +func (c *controlFrame) asLabel() label { switch c.kind { case controlFrameKindBlockWithContinuationLabel, controlFrameKindBlockWithoutContinuationLabel: - return NewLabel(LabelKindContinuation, c.frameID) + return newLabel(labelKindContinuation, c.frameID) case controlFrameKindLoop: - return NewLabel(LabelKindHeader, c.frameID) + return newLabel(labelKindHeader, c.frameID) case controlFrameKindFunction: - return NewLabel(LabelKindReturn, 0) + return newLabel(labelKindReturn, 0) case controlFrameKindIfWithElse, controlFrameKindIfWithoutElse: - return NewLabel(LabelKindContinuation, c.frameID) + return newLabel(labelKindContinuation, c.frameID) } - panic(fmt.Sprintf("unreachable: a bug in wazeroir implementation: %v", c.kind)) + panic(fmt.Sprintf("unreachable: a bug in interpreterir implementation: %v", c.kind)) } func (c *controlFrames) functionFrame() *controlFrame { @@ -102,7 +102,7 @@ func (c *controlFrames) push(frame controlFrame) { c.frames = append(c.frames, frame) } -func (c *Compiler) initializeStack() { +func (c *compiler) initializeStack() { // Reuse the existing slice. c.localIndexToStackHeightInUint64 = c.localIndexToStackHeightInUint64[:0] var current int @@ -134,29 +134,29 @@ func (c *Compiler) initializeStack() { // Push function arguments. for _, t := range c.sig.Params { - c.stackPush(wasmValueTypeToUnsignedType(t)) + c.stackPush(wasmValueTypeTounsignedType(t)) } if c.callFrameStackSizeInUint64 > 0 { // Reserve the stack slots for results. for i := 0; i < c.sig.ResultNumInUint64-c.sig.ParamNumInUint64; i++ { - c.stackPush(UnsignedTypeI64) + c.stackPush(unsignedTypeI64) } // Reserve the stack slots for call frame. for i := 0; i < c.callFrameStackSizeInUint64; i++ { - c.stackPush(UnsignedTypeI64) + c.stackPush(unsignedTypeI64) } } } -// Compiler is in charge of lowering raw Wasm function body to get CompilationResult. +// compiler is in charge of lowering raw Wasm function body to get compilationResult. // This is created per *wasm.Module and reused for all functions in it to reduce memory allocations. -type Compiler struct { +type compiler struct { module *wasm.Module enabledFeatures api.CoreFeatures callFrameStackSizeInUint64 int - stack []UnsignedType + stack []unsignedType currentFrameID uint32 controlFrames controlFrames unreachableState struct { @@ -164,7 +164,7 @@ type Compiler struct { depth int } pc, currentOpPC uint64 - result CompilationResult + result compilationResult // body holds the code for the function's body where Wasm instructions are stored. body []byte @@ -197,7 +197,7 @@ type Compiler struct { } //lint:ignore U1000 for debugging only. -func (c *Compiler) stackDump() string { +func (c *compiler) stackDump() string { strs := make([]string, 0, len(c.stack)) for _, s := range c.stack { strs = append(strs, s.String()) @@ -205,36 +205,36 @@ func (c *Compiler) stackDump() string { return "[" + strings.Join(strs, ", ") + "]" } -func (c *Compiler) markUnreachable() { +func (c *compiler) markUnreachable() { c.unreachableState.on = true } -func (c *Compiler) resetUnreachable() { +func (c *compiler) resetUnreachable() { c.unreachableState.on = false } -// MemoryType is the type of memory in a compiled module. -type MemoryType byte +// memoryType is the type of memory in a compiled module. +type memoryType byte const ( - // MemoryTypeNone indicates there is no memory. - MemoryTypeNone MemoryType = iota - // MemoryTypeStandard indicates there is a non-shared memory. - MemoryTypeStandard - // MemoryTypeShared indicates there is a shared memory. - MemoryTypeShared + // memoryTypeNone indicates there is no memory. + memoryTypeNone memoryType = iota + // memoryTypeStandard indicates there is a non-shared memory. + memoryTypeStandard + // memoryTypeShared indicates there is a shared memory. + memoryTypeShared ) -type CompilationResult struct { - // Operations holds wazeroir operations compiled from Wasm instructions in a Wasm function. - Operations []UnionOperation +type compilationResult struct { + // Operations holds interpreterir operations compiled from Wasm instructions in a Wasm function. + Operations []unionOperation // IROperationSourceOffsetsInWasmBinary is index-correlated with Operation and maps each operation to the corresponding source instruction's // offset in the original WebAssembly binary. // Non nil only when the given Wasm module has the DWARF section. IROperationSourceOffsetsInWasmBinary []uint64 - // LabelCallers maps Label to the number of callers to that label. + // LabelCallers maps label to the number of callers to that label. // Here "callers" means that the call-sites which jumps to the label with br, br_if or br_table // instructions. // @@ -246,7 +246,7 @@ type CompilationResult struct { // ) // // This example the label corresponding to `(block i32.const 1111)` is never be reached at runtime because `br 0` exits the function before we reach there - LabelCallers map[Label]uint32 + LabelCallers map[label]uint32 // UsesMemory is true if this function might use memory. UsesMemory bool @@ -259,7 +259,7 @@ type CompilationResult struct { // Types holds all the types in the module from which this function is compiled. Types []wasm.FunctionType // Memory indicates the type of memory of the module. - Memory MemoryType + Memory memoryType // HasTable is true if the module from which this function is compiled has table declaration. HasTable bool // HasDataInstances is true if the module has data instances which might be used by memory.init or data.drop instructions. @@ -268,9 +268,9 @@ type CompilationResult struct { HasElementInstances bool } -// NewCompiler returns the new *Compiler for the given parameters. -// Use Compiler.Next function to get compilation result per function. -func NewCompiler(enabledFeatures api.CoreFeatures, callFrameStackSizeInUint64 int, module *wasm.Module, ensureTermination bool) (*Compiler, error) { +// newCompiler returns the new *compiler for the given parameters. +// Use compiler.Next function to get compilation result per function. +func newCompiler(enabledFeatures api.CoreFeatures, callFrameStackSizeInUint64 int, module *wasm.Module, ensureTermination bool) (*compiler, error) { functions, globals, mem, tables, err := module.AllDeclarations() if err != nil { return nil, err @@ -279,24 +279,24 @@ func NewCompiler(enabledFeatures api.CoreFeatures, callFrameStackSizeInUint64 in hasTable, hasDataInstances, hasElementInstances := len(tables) > 0, len(module.DataSection) > 0, len(module.ElementSection) > 0 - var mt MemoryType + var mt memoryType switch { case mem == nil: - mt = MemoryTypeNone + mt = memoryTypeNone case mem.IsShared: - mt = MemoryTypeShared + mt = memoryTypeShared default: - mt = MemoryTypeStandard + mt = memoryTypeStandard } types := module.TypeSection - c := &Compiler{ + c := &compiler{ module: module, enabledFeatures: enabledFeatures, controlFrames: controlFrames{}, callFrameStackSizeInUint64: callFrameStackSizeInUint64, - result: CompilationResult{ + result: compilationResult{ Globals: globals, Functions: functions, Types: types, @@ -304,7 +304,7 @@ func NewCompiler(enabledFeatures api.CoreFeatures, callFrameStackSizeInUint64 in HasTable: hasTable, HasDataInstances: hasDataInstances, HasElementInstances: hasElementInstances, - LabelCallers: map[Label]uint32{}, + LabelCallers: map[label]uint32{}, }, globals: globals, funcs: functions, @@ -321,8 +321,8 @@ func NewCompiler(enabledFeatures api.CoreFeatures, callFrameStackSizeInUint64 in return c, nil } -// Next returns the next CompilationResult for this Compiler. -func (c *Compiler) Next() (*CompilationResult, error) { +// Next returns the next compilationResult for this compiler. +func (c *compiler) Next() (*compilationResult, error) { funcIndex := c.next code := &c.module.CodeSection[funcIndex] sig := &c.types[c.module.FunctionSection[funcIndex]] @@ -333,8 +333,8 @@ func (c *Compiler) Next() (*CompilationResult, error) { c.result.UsesMemory = false // Clears the existing entries in LabelCallers. for frameID := uint32(0); frameID <= c.currentFrameID; frameID++ { - for k := LabelKind(0); k < LabelKindNum; k++ { - delete(c.result.LabelCallers, NewLabel(k, frameID)) + for k := labelKind(0); k < labelKindNum; k++ { + delete(c.result.LabelCallers, newLabel(k, frameID)) } } // Reset the previous states. @@ -350,10 +350,10 @@ func (c *Compiler) Next() (*CompilationResult, error) { return &c.result, nil } -// Compile lowers given function instance into wazeroir operations +// Compile lowers given function instance into interpreterir operations // so that the resulting operations can be consumed by the interpreter -// or the Compiler compilation engine. -func (c *Compiler) compile(sig *wasm.FunctionType, body []byte, localTypes []wasm.ValueType, bodyOffsetInCodeSection uint64) error { +// or the compiler compilation engine. +func (c *compiler) compile(sig *wasm.FunctionType, body []byte, localTypes []wasm.ValueType, bodyOffsetInCodeSection uint64) error { // Set function specific fields. c.body = body c.localTypes = localTypes @@ -390,9 +390,9 @@ func (c *Compiler) compile(sig *wasm.FunctionType, body []byte, localTypes []was return nil } -// Translate the current Wasm instruction to wazeroir's operations, +// Translate the current Wasm instruction to interpreterir's operations, // and emit the results into c.results. -func (c *Compiler) handleInstruction() error { +func (c *compiler) handleInstruction() error { op := c.body[c.pc] c.currentOpPC = c.pc if false { @@ -411,7 +411,7 @@ func (c *Compiler) handleInstruction() error { ) } - var peekValueType UnsignedType + var peekValueType unsignedType if len(c.stack) > 0 { peekValueType = c.stackPeek() } @@ -424,11 +424,11 @@ func (c *Compiler) handleInstruction() error { return fmt.Errorf("apply stack failed for %s: %w", wasm.InstructionName(op), err) } // Now we handle each instruction, and - // emit the corresponding wazeroir operations to the results. + // emit the corresponding interpreterir operations to the results. operatorSwitch: switch op { case wasm.OpcodeUnreachable: - c.emit(NewOperationUnreachable()) + c.emit(newOperationUnreachable()) c.markUnreachable() case wasm.OpcodeNop: // Nop is noop! @@ -481,12 +481,12 @@ operatorSwitch: c.controlFrames.push(frame) // Prep labels for inside and the continuation of this loop. - loopLabel := NewLabel(LabelKindHeader, frame.frameID) + loopLabel := newLabel(labelKindHeader, frame.frameID) c.result.LabelCallers[loopLabel]++ // Emit the branch operation to enter inside the loop. - c.emit(NewOperationBr(loopLabel)) - c.emit(NewOperationLabel(loopLabel)) + c.emit(newOperationBr(loopLabel)) + c.emit(newOperationLabel(loopLabel)) // Insert the exit code check on the loop header, which is the only necessary point in the function body // to prevent infinite loop. @@ -496,7 +496,7 @@ operatorSwitch: // exist. However, in reality, that shouldn't be an issue since such "noop" loop header will highly likely be // optimized out by almost all guest language compilers which have the control flow optimization passes. if c.ensureTermination { - c.emit(NewOperationBuiltinFunctionCheckExitCode()) + c.emit(newOperationBuiltinFunctionCheckExitCode()) } case wasm.OpcodeIf: c.br.Reset(c.body[c.pc+1:]) @@ -525,14 +525,14 @@ operatorSwitch: c.controlFrames.push(frame) // Prep labels for if and else of this if. - thenLabel := NewLabel(LabelKindHeader, frame.frameID) - elseLabel := NewLabel(LabelKindElse, frame.frameID) + thenLabel := newLabel(labelKindHeader, frame.frameID) + elseLabel := newLabel(labelKindElse, frame.frameID) c.result.LabelCallers[thenLabel]++ c.result.LabelCallers[elseLabel]++ // Emit the branch operation to enter the then block. - c.emit(NewOperationBrIf(thenLabel, elseLabel, NopInclusiveRange)) - c.emit(NewOperationLabel(thenLabel)) + c.emit(newOperationBrIf(thenLabel, elseLabel, nopinclusiveRange)) + c.emit(newOperationLabel(thenLabel)) case wasm.OpcodeElse: frame := c.controlFrames.top() if c.unreachableState.on && c.unreachableState.depth > 0 { @@ -548,15 +548,15 @@ operatorSwitch: // Re-push the parameters to the if block so that else block can use them. for _, t := range frame.blockType.Params { - c.stackPush(wasmValueTypeToUnsignedType(t)) + c.stackPush(wasmValueTypeTounsignedType(t)) } // We are no longer unreachable in else frame, // so emit the correct label, and reset the unreachable state. - elseLabel := NewLabel(LabelKindElse, frame.frameID) + elseLabel := newLabel(labelKindElse, frame.frameID) c.resetUnreachable() c.emit( - NewOperationLabel(elseLabel), + newOperationLabel(elseLabel), ) break operatorSwitch } @@ -568,27 +568,27 @@ operatorSwitch: // We need to reset the stack so that // the values pushed inside the then block // do not affect the else block. - dropOp := NewOperationDrop(c.getFrameDropRange(frame, false)) + dropOp := newOperationDrop(c.getFrameDropRange(frame, false)) // Reset the stack manipulated by the then block, and re-push the block param types to the stack. c.stack = c.stack[:frame.originalStackLenWithoutParam] for _, t := range frame.blockType.Params { - c.stackPush(wasmValueTypeToUnsignedType(t)) + c.stackPush(wasmValueTypeTounsignedType(t)) } // Prep labels for else and the continuation of this if block. - elseLabel := NewLabel(LabelKindElse, frame.frameID) - continuationLabel := NewLabel(LabelKindContinuation, frame.frameID) + elseLabel := newLabel(labelKindElse, frame.frameID) + continuationLabel := newLabel(labelKindContinuation, frame.frameID) c.result.LabelCallers[continuationLabel]++ // Emit the instructions for exiting the if loop, // and then the initiation of else block. c.emit(dropOp) // Jump to the continuation of this block. - c.emit(NewOperationBr(continuationLabel)) + c.emit(newOperationBr(continuationLabel)) // Initiate the else block. - c.emit(NewOperationLabel(elseLabel)) + c.emit(newOperationLabel(elseLabel)) case wasm.OpcodeEnd: if c.unreachableState.on && c.unreachableState.depth > 0 { c.unreachableState.depth-- @@ -603,20 +603,20 @@ operatorSwitch: c.stack = c.stack[:frame.originalStackLenWithoutParam] for _, t := range frame.blockType.Results { - c.stackPush(wasmValueTypeToUnsignedType(t)) + c.stackPush(wasmValueTypeTounsignedType(t)) } - continuationLabel := NewLabel(LabelKindContinuation, frame.frameID) + continuationLabel := newLabel(labelKindContinuation, frame.frameID) if frame.kind == controlFrameKindIfWithoutElse { // Emit the else label. - elseLabel := NewLabel(LabelKindElse, frame.frameID) + elseLabel := newLabel(labelKindElse, frame.frameID) c.result.LabelCallers[continuationLabel]++ - c.emit(NewOperationLabel(elseLabel)) - c.emit(NewOperationBr(continuationLabel)) - c.emit(NewOperationLabel(continuationLabel)) + c.emit(newOperationLabel(elseLabel)) + c.emit(newOperationBr(continuationLabel)) + c.emit(newOperationLabel(continuationLabel)) } else { c.emit( - NewOperationLabel(continuationLabel), + newOperationLabel(continuationLabel), ) } @@ -627,12 +627,12 @@ operatorSwitch: // We need to reset the stack so that // the values pushed inside the block. - dropOp := NewOperationDrop(c.getFrameDropRange(frame, true)) + dropOp := newOperationDrop(c.getFrameDropRange(frame, true)) c.stack = c.stack[:frame.originalStackLenWithoutParam] // Push the result types onto the stack. for _, t := range frame.blockType.Results { - c.stackPush(wasmValueTypeToUnsignedType(t)) + c.stackPush(wasmValueTypeTounsignedType(t)) } // Emit the instructions according to the Kind of the current control frame. @@ -644,26 +644,26 @@ operatorSwitch: } // Return from function. c.emit(dropOp) - c.emit(NewOperationBr(NewLabel(LabelKindReturn, 0))) + c.emit(newOperationBr(newLabel(labelKindReturn, 0))) case controlFrameKindIfWithoutElse: // This case we have to emit "empty" else label. - elseLabel := NewLabel(LabelKindElse, frame.frameID) - continuationLabel := NewLabel(LabelKindContinuation, frame.frameID) + elseLabel := newLabel(labelKindElse, frame.frameID) + continuationLabel := newLabel(labelKindContinuation, frame.frameID) c.result.LabelCallers[continuationLabel] += 2 c.emit(dropOp) - c.emit(NewOperationBr(continuationLabel)) + c.emit(newOperationBr(continuationLabel)) // Emit the else which soon branches into the continuation. - c.emit(NewOperationLabel(elseLabel)) - c.emit(NewOperationBr(continuationLabel)) + c.emit(newOperationLabel(elseLabel)) + c.emit(newOperationBr(continuationLabel)) // Initiate the continuation. - c.emit(NewOperationLabel(continuationLabel)) + c.emit(newOperationLabel(continuationLabel)) case controlFrameKindBlockWithContinuationLabel, controlFrameKindIfWithElse: - continuationLabel := NewLabel(LabelKindContinuation, frame.frameID) + continuationLabel := newLabel(labelKindContinuation, frame.frameID) c.result.LabelCallers[continuationLabel]++ c.emit(dropOp) - c.emit(NewOperationBr(continuationLabel)) - c.emit(NewOperationLabel(continuationLabel)) + c.emit(newOperationBr(continuationLabel)) + c.emit(newOperationLabel(continuationLabel)) case controlFrameKindLoop, controlFrameKindBlockWithoutContinuationLabel: c.emit( dropOp, @@ -687,11 +687,11 @@ operatorSwitch: targetFrame := c.controlFrames.get(int(targetIndex)) targetFrame.ensureContinuation() - dropOp := NewOperationDrop(c.getFrameDropRange(targetFrame, false)) + dropOp := newOperationDrop(c.getFrameDropRange(targetFrame, false)) targetID := targetFrame.asLabel() c.result.LabelCallers[targetID]++ c.emit(dropOp) - c.emit(NewOperationBr(targetID)) + c.emit(newOperationBr(targetID)) // Br operation is stack-polymorphic, and mark the state as unreachable. // That means subsequent instructions in the current control frame are "unreachable" // and can be safely removed. @@ -714,11 +714,11 @@ operatorSwitch: target := targetFrame.asLabel() c.result.LabelCallers[target]++ - continuationLabel := NewLabel(LabelKindHeader, c.nextFrameID()) + continuationLabel := newLabel(labelKindHeader, c.nextFrameID()) c.result.LabelCallers[continuationLabel]++ - c.emit(NewOperationBrIf(target, continuationLabel, drop)) + c.emit(newOperationBrIf(target, continuationLabel, drop)) // Start emitting else block operations. - c.emit(NewOperationLabel(continuationLabel)) + c.emit(newOperationLabel(continuationLabel)) case wasm.OpcodeBrTable: c.br.Reset(c.body[c.pc+1:]) r := c.br @@ -744,7 +744,7 @@ operatorSwitch: // Read the branch targets. s := numTargets * 2 - targetLabels := make([]uint64, 2+s) // (label, InclusiveRange) * (default+numTargets) + targetLabels := make([]uint64, 2+s) // (label, inclusiveRange) * (default+numTargets) for i := uint32(0); i < s; i += 2 { l, n, err := leb128.DecodeUint32(r) if err != nil { @@ -773,7 +773,7 @@ operatorSwitch: c.result.LabelCallers[defaultLabel]++ targetLabels[s] = uint64(defaultLabel) targetLabels[s+1] = defaultTargetDrop.AsU64() - c.emit(NewOperationBrTable(targetLabels)) + c.emit(newOperationBrTable(targetLabels)) // br_table operation is stack-polymorphic, and mark the state as unreachable. // That means subsequent instructions in the current control frame are "unreachable" @@ -781,11 +781,11 @@ operatorSwitch: c.markUnreachable() case wasm.OpcodeReturn: functionFrame := c.controlFrames.functionFrame() - dropOp := NewOperationDrop(c.getFrameDropRange(functionFrame, false)) + dropOp := newOperationDrop(c.getFrameDropRange(functionFrame, false)) // Cleanup the stack and then jmp to function frame's continuation (meaning return). c.emit(dropOp) - c.emit(NewOperationBr(functionFrame.asLabel())) + c.emit(newOperationBr(functionFrame.asLabel())) // Return operation is stack-polymorphic, and mark the state as unreachable. // That means subsequent instructions in the current control frame are "unreachable" @@ -793,7 +793,7 @@ operatorSwitch: c.markUnreachable() case wasm.OpcodeCall: c.emit( - NewOperationCall(index), + newOperationCall(index), ) case wasm.OpcodeCallIndirect: typeIndex := index @@ -803,24 +803,24 @@ operatorSwitch: } c.pc += n c.emit( - NewOperationCallIndirect(typeIndex, tableIndex), + newOperationCallIndirect(typeIndex, tableIndex), ) case wasm.OpcodeDrop: - r := InclusiveRange{Start: 0, End: 0} - if peekValueType == UnsignedTypeV128 { - // InclusiveRange is the range in uint64 representation, so dropping a vector value on top + r := inclusiveRange{Start: 0, End: 0} + if peekValueType == unsignedTypeV128 { + // inclusiveRange is the range in uint64 representation, so dropping a vector value on top // should be translated as drop [0..1] inclusively. r.End++ } - c.emit(NewOperationDrop(r)) + c.emit(newOperationDrop(r)) case wasm.OpcodeSelect: // If it is on the unreachable state, ignore the instruction. if c.unreachableState.on { break operatorSwitch } - isTargetVector := c.stackPeek() == UnsignedTypeV128 + isTargetVector := c.stackPeek() == unsignedTypeV128 c.emit( - NewOperationSelect(isTargetVector), + newOperationSelect(isTargetVector), ) case wasm.OpcodeTypedSelect: // Skips two bytes: vector size fixed to 1, and the value type for select. @@ -830,9 +830,9 @@ operatorSwitch: break operatorSwitch } // Typed select is semantically equivalent to select at runtime. - isTargetVector := c.stackPeek() == UnsignedTypeV128 + isTargetVector := c.stackPeek() == unsignedTypeV128 c.emit( - NewOperationSelect(isTargetVector), + newOperationSelect(isTargetVector), ) case wasm.OpcodeLocalGet: depth := c.localDepth(index) @@ -840,13 +840,13 @@ operatorSwitch: c.emit( // -1 because we already manipulated the stack before // called localDepth ^^. - NewOperationPick(depth-1, isVector), + newOperationPick(depth-1, isVector), ) } else { c.emit( // -2 because we already manipulated the stack before // called localDepth ^^. - NewOperationPick(depth-2, isVector), + newOperationPick(depth-2, isVector), ) } case wasm.OpcodeLocalSet: @@ -857,125 +857,125 @@ operatorSwitch: c.emit( // +2 because we already popped the operands for this operation from the c.stack before // called localDepth ^^, - NewOperationSet(depth+2, isVector), + newOperationSet(depth+2, isVector), ) } else { c.emit( // +1 because we already popped the operands for this operation from the c.stack before // called localDepth ^^, - NewOperationSet(depth+1, isVector), + newOperationSet(depth+1, isVector), ) } case wasm.OpcodeLocalTee: depth := c.localDepth(index) isVector := c.localType(index) == wasm.ValueTypeV128 if isVector { - c.emit(NewOperationPick(1, isVector)) - c.emit(NewOperationSet(depth+2, isVector)) + c.emit(newOperationPick(1, isVector)) + c.emit(newOperationSet(depth+2, isVector)) } else { c.emit( - NewOperationPick(0, isVector)) - c.emit(NewOperationSet(depth+1, isVector)) + newOperationPick(0, isVector)) + c.emit(newOperationSet(depth+1, isVector)) } case wasm.OpcodeGlobalGet: c.emit( - NewOperationGlobalGet(index), + newOperationGlobalGet(index), ) case wasm.OpcodeGlobalSet: c.emit( - NewOperationGlobalSet(index), + newOperationGlobalSet(index), ) case wasm.OpcodeI32Load: imm, err := c.readMemoryArg(wasm.OpcodeI32LoadName) if err != nil { return err } - c.emit(NewOperationLoad(UnsignedTypeI32, imm)) + c.emit(newOperationLoad(unsignedTypeI32, imm)) case wasm.OpcodeI64Load: imm, err := c.readMemoryArg(wasm.OpcodeI64LoadName) if err != nil { return err } - c.emit(NewOperationLoad(UnsignedTypeI64, imm)) + c.emit(newOperationLoad(unsignedTypeI64, imm)) case wasm.OpcodeF32Load: imm, err := c.readMemoryArg(wasm.OpcodeF32LoadName) if err != nil { return err } - c.emit(NewOperationLoad(UnsignedTypeF32, imm)) + c.emit(newOperationLoad(unsignedTypeF32, imm)) case wasm.OpcodeF64Load: imm, err := c.readMemoryArg(wasm.OpcodeF64LoadName) if err != nil { return err } - c.emit(NewOperationLoad(UnsignedTypeF64, imm)) + c.emit(newOperationLoad(unsignedTypeF64, imm)) case wasm.OpcodeI32Load8S: imm, err := c.readMemoryArg(wasm.OpcodeI32Load8SName) if err != nil { return err } - c.emit(NewOperationLoad8(SignedInt32, imm)) + c.emit(newOperationLoad8(signedInt32, imm)) case wasm.OpcodeI32Load8U: imm, err := c.readMemoryArg(wasm.OpcodeI32Load8UName) if err != nil { return err } - c.emit(NewOperationLoad8(SignedUint32, imm)) + c.emit(newOperationLoad8(signedUint32, imm)) case wasm.OpcodeI32Load16S: imm, err := c.readMemoryArg(wasm.OpcodeI32Load16SName) if err != nil { return err } - c.emit(NewOperationLoad16(SignedInt32, imm)) + c.emit(newOperationLoad16(signedInt32, imm)) case wasm.OpcodeI32Load16U: imm, err := c.readMemoryArg(wasm.OpcodeI32Load16UName) if err != nil { return err } - c.emit(NewOperationLoad16(SignedUint32, imm)) + c.emit(newOperationLoad16(signedUint32, imm)) case wasm.OpcodeI64Load8S: imm, err := c.readMemoryArg(wasm.OpcodeI64Load8SName) if err != nil { return err } - c.emit(NewOperationLoad8(SignedInt64, imm)) + c.emit(newOperationLoad8(signedInt64, imm)) case wasm.OpcodeI64Load8U: imm, err := c.readMemoryArg(wasm.OpcodeI64Load8UName) if err != nil { return err } - c.emit(NewOperationLoad8(SignedUint64, imm)) + c.emit(newOperationLoad8(signedUint64, imm)) case wasm.OpcodeI64Load16S: imm, err := c.readMemoryArg(wasm.OpcodeI64Load16SName) if err != nil { return err } - c.emit(NewOperationLoad16(SignedInt64, imm)) + c.emit(newOperationLoad16(signedInt64, imm)) case wasm.OpcodeI64Load16U: imm, err := c.readMemoryArg(wasm.OpcodeI64Load16UName) if err != nil { return err } - c.emit(NewOperationLoad16(SignedUint64, imm)) + c.emit(newOperationLoad16(signedUint64, imm)) case wasm.OpcodeI64Load32S: imm, err := c.readMemoryArg(wasm.OpcodeI64Load32SName) if err != nil { return err } - c.emit(NewOperationLoad32(true, imm)) + c.emit(newOperationLoad32(true, imm)) case wasm.OpcodeI64Load32U: imm, err := c.readMemoryArg(wasm.OpcodeI64Load32UName) if err != nil { return err } - c.emit(NewOperationLoad32(false, imm)) + c.emit(newOperationLoad32(false, imm)) case wasm.OpcodeI32Store: imm, err := c.readMemoryArg(wasm.OpcodeI32StoreName) if err != nil { return err } c.emit( - NewOperationStore(UnsignedTypeI32, imm), + newOperationStore(unsignedTypeI32, imm), ) case wasm.OpcodeI64Store: imm, err := c.readMemoryArg(wasm.OpcodeI64StoreName) @@ -983,7 +983,7 @@ operatorSwitch: return err } c.emit( - NewOperationStore(UnsignedTypeI64, imm), + newOperationStore(unsignedTypeI64, imm), ) case wasm.OpcodeF32Store: imm, err := c.readMemoryArg(wasm.OpcodeF32StoreName) @@ -991,7 +991,7 @@ operatorSwitch: return err } c.emit( - NewOperationStore(UnsignedTypeF32, imm), + newOperationStore(unsignedTypeF32, imm), ) case wasm.OpcodeF64Store: imm, err := c.readMemoryArg(wasm.OpcodeF64StoreName) @@ -999,7 +999,7 @@ operatorSwitch: return err } c.emit( - NewOperationStore(UnsignedTypeF64, imm), + newOperationStore(unsignedTypeF64, imm), ) case wasm.OpcodeI32Store8: imm, err := c.readMemoryArg(wasm.OpcodeI32Store8Name) @@ -1007,7 +1007,7 @@ operatorSwitch: return err } c.emit( - NewOperationStore8(imm), + newOperationStore8(imm), ) case wasm.OpcodeI32Store16: imm, err := c.readMemoryArg(wasm.OpcodeI32Store16Name) @@ -1015,7 +1015,7 @@ operatorSwitch: return err } c.emit( - NewOperationStore16(imm), + newOperationStore16(imm), ) case wasm.OpcodeI64Store8: imm, err := c.readMemoryArg(wasm.OpcodeI64Store8Name) @@ -1023,7 +1023,7 @@ operatorSwitch: return err } c.emit( - NewOperationStore8(imm), + newOperationStore8(imm), ) case wasm.OpcodeI64Store16: imm, err := c.readMemoryArg(wasm.OpcodeI64Store16Name) @@ -1031,7 +1031,7 @@ operatorSwitch: return err } c.emit( - NewOperationStore16(imm), + newOperationStore16(imm), ) case wasm.OpcodeI64Store32: imm, err := c.readMemoryArg(wasm.OpcodeI64Store32Name) @@ -1039,19 +1039,19 @@ operatorSwitch: return err } c.emit( - NewOperationStore32(imm), + newOperationStore32(imm), ) case wasm.OpcodeMemorySize: c.result.UsesMemory = true c.pc++ // Skip the reserved one byte. c.emit( - NewOperationMemorySize(), + newOperationMemorySize(), ) case wasm.OpcodeMemoryGrow: c.result.UsesMemory = true c.pc++ // Skip the reserved one byte. c.emit( - NewOperationMemoryGrow(), + newOperationMemoryGrow(), ) case wasm.OpcodeI32Const: val, num, err := leb128.LoadInt32(c.body[c.pc+1:]) @@ -1060,7 +1060,7 @@ operatorSwitch: } c.pc += num c.emit( - NewOperationConstI32(uint32(val)), + newOperationConstI32(uint32(val)), ) case wasm.OpcodeI64Const: val, num, err := leb128.LoadInt64(c.body[c.pc+1:]) @@ -1069,531 +1069,531 @@ operatorSwitch: } c.pc += num c.emit( - NewOperationConstI64(uint64(val)), + newOperationConstI64(uint64(val)), ) case wasm.OpcodeF32Const: v := math.Float32frombits(binary.LittleEndian.Uint32(c.body[c.pc+1:])) c.pc += 4 c.emit( - NewOperationConstF32(v), + newOperationConstF32(v), ) case wasm.OpcodeF64Const: v := math.Float64frombits(binary.LittleEndian.Uint64(c.body[c.pc+1:])) c.pc += 8 c.emit( - NewOperationConstF64(v), + newOperationConstF64(v), ) case wasm.OpcodeI32Eqz: c.emit( - NewOperationEqz(UnsignedInt32), + newOperationEqz(unsignedInt32), ) case wasm.OpcodeI32Eq: c.emit( - NewOperationEq(UnsignedTypeI32), + newOperationEq(unsignedTypeI32), ) case wasm.OpcodeI32Ne: c.emit( - NewOperationNe(UnsignedTypeI32), + newOperationNe(unsignedTypeI32), ) case wasm.OpcodeI32LtS: c.emit( - NewOperationLt(SignedTypeInt32), + newOperationLt(signedTypeInt32), ) case wasm.OpcodeI32LtU: c.emit( - NewOperationLt(SignedTypeUint32), + newOperationLt(signedTypeUint32), ) case wasm.OpcodeI32GtS: c.emit( - NewOperationGt(SignedTypeInt32), + newOperationGt(signedTypeInt32), ) case wasm.OpcodeI32GtU: c.emit( - NewOperationGt(SignedTypeUint32), + newOperationGt(signedTypeUint32), ) case wasm.OpcodeI32LeS: c.emit( - NewOperationLe(SignedTypeInt32), + newOperationLe(signedTypeInt32), ) case wasm.OpcodeI32LeU: c.emit( - NewOperationLe(SignedTypeUint32), + newOperationLe(signedTypeUint32), ) case wasm.OpcodeI32GeS: c.emit( - NewOperationGe(SignedTypeInt32), + newOperationGe(signedTypeInt32), ) case wasm.OpcodeI32GeU: c.emit( - NewOperationGe(SignedTypeUint32), + newOperationGe(signedTypeUint32), ) case wasm.OpcodeI64Eqz: c.emit( - NewOperationEqz(UnsignedInt64), + newOperationEqz(unsignedInt64), ) case wasm.OpcodeI64Eq: c.emit( - NewOperationEq(UnsignedTypeI64), + newOperationEq(unsignedTypeI64), ) case wasm.OpcodeI64Ne: c.emit( - NewOperationNe(UnsignedTypeI64), + newOperationNe(unsignedTypeI64), ) case wasm.OpcodeI64LtS: c.emit( - NewOperationLt(SignedTypeInt64), + newOperationLt(signedTypeInt64), ) case wasm.OpcodeI64LtU: c.emit( - NewOperationLt(SignedTypeUint64), + newOperationLt(signedTypeUint64), ) case wasm.OpcodeI64GtS: c.emit( - NewOperationGt(SignedTypeInt64), + newOperationGt(signedTypeInt64), ) case wasm.OpcodeI64GtU: c.emit( - NewOperationGt(SignedTypeUint64), + newOperationGt(signedTypeUint64), ) case wasm.OpcodeI64LeS: c.emit( - NewOperationLe(SignedTypeInt64), + newOperationLe(signedTypeInt64), ) case wasm.OpcodeI64LeU: c.emit( - NewOperationLe(SignedTypeUint64), + newOperationLe(signedTypeUint64), ) case wasm.OpcodeI64GeS: c.emit( - NewOperationGe(SignedTypeInt64), + newOperationGe(signedTypeInt64), ) case wasm.OpcodeI64GeU: c.emit( - NewOperationGe(SignedTypeUint64), + newOperationGe(signedTypeUint64), ) case wasm.OpcodeF32Eq: c.emit( - NewOperationEq(UnsignedTypeF32), + newOperationEq(unsignedTypeF32), ) case wasm.OpcodeF32Ne: c.emit( - NewOperationNe(UnsignedTypeF32), + newOperationNe(unsignedTypeF32), ) case wasm.OpcodeF32Lt: c.emit( - NewOperationLt(SignedTypeFloat32), + newOperationLt(signedTypeFloat32), ) case wasm.OpcodeF32Gt: c.emit( - NewOperationGt(SignedTypeFloat32), + newOperationGt(signedTypeFloat32), ) case wasm.OpcodeF32Le: c.emit( - NewOperationLe(SignedTypeFloat32), + newOperationLe(signedTypeFloat32), ) case wasm.OpcodeF32Ge: c.emit( - NewOperationGe(SignedTypeFloat32), + newOperationGe(signedTypeFloat32), ) case wasm.OpcodeF64Eq: c.emit( - NewOperationEq(UnsignedTypeF64), + newOperationEq(unsignedTypeF64), ) case wasm.OpcodeF64Ne: c.emit( - NewOperationNe(UnsignedTypeF64), + newOperationNe(unsignedTypeF64), ) case wasm.OpcodeF64Lt: c.emit( - NewOperationLt(SignedTypeFloat64), + newOperationLt(signedTypeFloat64), ) case wasm.OpcodeF64Gt: c.emit( - NewOperationGt(SignedTypeFloat64), + newOperationGt(signedTypeFloat64), ) case wasm.OpcodeF64Le: c.emit( - NewOperationLe(SignedTypeFloat64), + newOperationLe(signedTypeFloat64), ) case wasm.OpcodeF64Ge: c.emit( - NewOperationGe(SignedTypeFloat64), + newOperationGe(signedTypeFloat64), ) case wasm.OpcodeI32Clz: c.emit( - NewOperationClz(UnsignedInt32), + newOperationClz(unsignedInt32), ) case wasm.OpcodeI32Ctz: c.emit( - NewOperationCtz(UnsignedInt32), + newOperationCtz(unsignedInt32), ) case wasm.OpcodeI32Popcnt: c.emit( - NewOperationPopcnt(UnsignedInt32), + newOperationPopcnt(unsignedInt32), ) case wasm.OpcodeI32Add: c.emit( - NewOperationAdd(UnsignedTypeI32), + newOperationAdd(unsignedTypeI32), ) case wasm.OpcodeI32Sub: c.emit( - NewOperationSub(UnsignedTypeI32), + newOperationSub(unsignedTypeI32), ) case wasm.OpcodeI32Mul: c.emit( - NewOperationMul(UnsignedTypeI32), + newOperationMul(unsignedTypeI32), ) case wasm.OpcodeI32DivS: c.emit( - NewOperationDiv(SignedTypeInt32), + newOperationDiv(signedTypeInt32), ) case wasm.OpcodeI32DivU: c.emit( - NewOperationDiv(SignedTypeUint32), + newOperationDiv(signedTypeUint32), ) case wasm.OpcodeI32RemS: c.emit( - NewOperationRem(SignedInt32), + newOperationRem(signedInt32), ) case wasm.OpcodeI32RemU: c.emit( - NewOperationRem(SignedUint32), + newOperationRem(signedUint32), ) case wasm.OpcodeI32And: c.emit( - NewOperationAnd(UnsignedInt32), + newOperationAnd(unsignedInt32), ) case wasm.OpcodeI32Or: c.emit( - NewOperationOr(UnsignedInt32), + newOperationOr(unsignedInt32), ) case wasm.OpcodeI32Xor: c.emit( - NewOperationXor(UnsignedInt64), + newOperationXor(unsignedInt64), ) case wasm.OpcodeI32Shl: c.emit( - NewOperationShl(UnsignedInt32), + newOperationShl(unsignedInt32), ) case wasm.OpcodeI32ShrS: c.emit( - NewOperationShr(SignedInt32), + newOperationShr(signedInt32), ) case wasm.OpcodeI32ShrU: c.emit( - NewOperationShr(SignedUint32), + newOperationShr(signedUint32), ) case wasm.OpcodeI32Rotl: c.emit( - NewOperationRotl(UnsignedInt32), + newOperationRotl(unsignedInt32), ) case wasm.OpcodeI32Rotr: c.emit( - NewOperationRotr(UnsignedInt32), + newOperationRotr(unsignedInt32), ) case wasm.OpcodeI64Clz: c.emit( - NewOperationClz(UnsignedInt64), + newOperationClz(unsignedInt64), ) case wasm.OpcodeI64Ctz: c.emit( - NewOperationCtz(UnsignedInt64), + newOperationCtz(unsignedInt64), ) case wasm.OpcodeI64Popcnt: c.emit( - NewOperationPopcnt(UnsignedInt64), + newOperationPopcnt(unsignedInt64), ) case wasm.OpcodeI64Add: c.emit( - NewOperationAdd(UnsignedTypeI64), + newOperationAdd(unsignedTypeI64), ) case wasm.OpcodeI64Sub: c.emit( - NewOperationSub(UnsignedTypeI64), + newOperationSub(unsignedTypeI64), ) case wasm.OpcodeI64Mul: c.emit( - NewOperationMul(UnsignedTypeI64), + newOperationMul(unsignedTypeI64), ) case wasm.OpcodeI64DivS: c.emit( - NewOperationDiv(SignedTypeInt64), + newOperationDiv(signedTypeInt64), ) case wasm.OpcodeI64DivU: c.emit( - NewOperationDiv(SignedTypeUint64), + newOperationDiv(signedTypeUint64), ) case wasm.OpcodeI64RemS: c.emit( - NewOperationRem(SignedInt64), + newOperationRem(signedInt64), ) case wasm.OpcodeI64RemU: c.emit( - NewOperationRem(SignedUint64), + newOperationRem(signedUint64), ) case wasm.OpcodeI64And: c.emit( - NewOperationAnd(UnsignedInt64), + newOperationAnd(unsignedInt64), ) case wasm.OpcodeI64Or: c.emit( - NewOperationOr(UnsignedInt64), + newOperationOr(unsignedInt64), ) case wasm.OpcodeI64Xor: c.emit( - NewOperationXor(UnsignedInt64), + newOperationXor(unsignedInt64), ) case wasm.OpcodeI64Shl: c.emit( - NewOperationShl(UnsignedInt64), + newOperationShl(unsignedInt64), ) case wasm.OpcodeI64ShrS: c.emit( - NewOperationShr(SignedInt64), + newOperationShr(signedInt64), ) case wasm.OpcodeI64ShrU: c.emit( - NewOperationShr(SignedUint64), + newOperationShr(signedUint64), ) case wasm.OpcodeI64Rotl: c.emit( - NewOperationRotl(UnsignedInt64), + newOperationRotl(unsignedInt64), ) case wasm.OpcodeI64Rotr: c.emit( - NewOperationRotr(UnsignedInt64), + newOperationRotr(unsignedInt64), ) case wasm.OpcodeF32Abs: c.emit( - NewOperationAbs(Float32), + newOperationAbs(f32), ) case wasm.OpcodeF32Neg: c.emit( - NewOperationNeg(Float32), + newOperationNeg(f32), ) case wasm.OpcodeF32Ceil: c.emit( - NewOperationCeil(Float32), + newOperationCeil(f32), ) case wasm.OpcodeF32Floor: c.emit( - NewOperationFloor(Float32), + newOperationFloor(f32), ) case wasm.OpcodeF32Trunc: c.emit( - NewOperationTrunc(Float32), + newOperationTrunc(f32), ) case wasm.OpcodeF32Nearest: c.emit( - NewOperationNearest(Float32), + newOperationNearest(f32), ) case wasm.OpcodeF32Sqrt: c.emit( - NewOperationSqrt(Float32), + newOperationSqrt(f32), ) case wasm.OpcodeF32Add: c.emit( - NewOperationAdd(UnsignedTypeF32), + newOperationAdd(unsignedTypeF32), ) case wasm.OpcodeF32Sub: c.emit( - NewOperationSub(UnsignedTypeF32), + newOperationSub(unsignedTypeF32), ) case wasm.OpcodeF32Mul: c.emit( - NewOperationMul(UnsignedTypeF32), + newOperationMul(unsignedTypeF32), ) case wasm.OpcodeF32Div: c.emit( - NewOperationDiv(SignedTypeFloat32), + newOperationDiv(signedTypeFloat32), ) case wasm.OpcodeF32Min: c.emit( - NewOperationMin(Float32), + newOperationMin(f32), ) case wasm.OpcodeF32Max: c.emit( - NewOperationMax(Float32), + newOperationMax(f32), ) case wasm.OpcodeF32Copysign: c.emit( - NewOperationCopysign(Float32), + newOperationCopysign(f32), ) case wasm.OpcodeF64Abs: c.emit( - NewOperationAbs(Float64), + newOperationAbs(f64), ) case wasm.OpcodeF64Neg: c.emit( - NewOperationNeg(Float64), + newOperationNeg(f64), ) case wasm.OpcodeF64Ceil: c.emit( - NewOperationCeil(Float64), + newOperationCeil(f64), ) case wasm.OpcodeF64Floor: c.emit( - NewOperationFloor(Float64), + newOperationFloor(f64), ) case wasm.OpcodeF64Trunc: c.emit( - NewOperationTrunc(Float64), + newOperationTrunc(f64), ) case wasm.OpcodeF64Nearest: c.emit( - NewOperationNearest(Float64), + newOperationNearest(f64), ) case wasm.OpcodeF64Sqrt: c.emit( - NewOperationSqrt(Float64), + newOperationSqrt(f64), ) case wasm.OpcodeF64Add: c.emit( - NewOperationAdd(UnsignedTypeF64), + newOperationAdd(unsignedTypeF64), ) case wasm.OpcodeF64Sub: c.emit( - NewOperationSub(UnsignedTypeF64), + newOperationSub(unsignedTypeF64), ) case wasm.OpcodeF64Mul: c.emit( - NewOperationMul(UnsignedTypeF64), + newOperationMul(unsignedTypeF64), ) case wasm.OpcodeF64Div: c.emit( - NewOperationDiv(SignedTypeFloat64), + newOperationDiv(signedTypeFloat64), ) case wasm.OpcodeF64Min: c.emit( - NewOperationMin(Float64), + newOperationMin(f64), ) case wasm.OpcodeF64Max: c.emit( - NewOperationMax(Float64), + newOperationMax(f64), ) case wasm.OpcodeF64Copysign: c.emit( - NewOperationCopysign(Float64), + newOperationCopysign(f64), ) case wasm.OpcodeI32WrapI64: c.emit( - NewOperationI32WrapFromI64(), + newOperationI32WrapFromI64(), ) case wasm.OpcodeI32TruncF32S: c.emit( - NewOperationITruncFromF(Float32, SignedInt32, false), + newOperationITruncFromF(f32, signedInt32, false), ) case wasm.OpcodeI32TruncF32U: c.emit( - NewOperationITruncFromF(Float32, SignedUint32, false), + newOperationITruncFromF(f32, signedUint32, false), ) case wasm.OpcodeI32TruncF64S: c.emit( - NewOperationITruncFromF(Float64, SignedInt32, false), + newOperationITruncFromF(f64, signedInt32, false), ) case wasm.OpcodeI32TruncF64U: c.emit( - NewOperationITruncFromF(Float64, SignedUint32, false), + newOperationITruncFromF(f64, signedUint32, false), ) case wasm.OpcodeI64ExtendI32S: c.emit( - NewOperationExtend(true), + newOperationExtend(true), ) case wasm.OpcodeI64ExtendI32U: c.emit( - NewOperationExtend(false), + newOperationExtend(false), ) case wasm.OpcodeI64TruncF32S: c.emit( - NewOperationITruncFromF(Float32, SignedInt64, false), + newOperationITruncFromF(f32, signedInt64, false), ) case wasm.OpcodeI64TruncF32U: c.emit( - NewOperationITruncFromF(Float32, SignedUint64, false), + newOperationITruncFromF(f32, signedUint64, false), ) case wasm.OpcodeI64TruncF64S: c.emit( - NewOperationITruncFromF(Float64, SignedInt64, false), + newOperationITruncFromF(f64, signedInt64, false), ) case wasm.OpcodeI64TruncF64U: c.emit( - NewOperationITruncFromF(Float64, SignedUint64, false), + newOperationITruncFromF(f64, signedUint64, false), ) case wasm.OpcodeF32ConvertI32S: c.emit( - NewOperationFConvertFromI(SignedInt32, Float32), + newOperationFConvertFromI(signedInt32, f32), ) case wasm.OpcodeF32ConvertI32U: c.emit( - NewOperationFConvertFromI(SignedUint32, Float32), + newOperationFConvertFromI(signedUint32, f32), ) case wasm.OpcodeF32ConvertI64S: c.emit( - NewOperationFConvertFromI(SignedInt64, Float32), + newOperationFConvertFromI(signedInt64, f32), ) case wasm.OpcodeF32ConvertI64U: c.emit( - NewOperationFConvertFromI(SignedUint64, Float32), + newOperationFConvertFromI(signedUint64, f32), ) case wasm.OpcodeF32DemoteF64: c.emit( - NewOperationF32DemoteFromF64(), + newOperationF32DemoteFromF64(), ) case wasm.OpcodeF64ConvertI32S: c.emit( - NewOperationFConvertFromI(SignedInt32, Float64), + newOperationFConvertFromI(signedInt32, f64), ) case wasm.OpcodeF64ConvertI32U: c.emit( - NewOperationFConvertFromI(SignedUint32, Float64), + newOperationFConvertFromI(signedUint32, f64), ) case wasm.OpcodeF64ConvertI64S: c.emit( - NewOperationFConvertFromI(SignedInt64, Float64), + newOperationFConvertFromI(signedInt64, f64), ) case wasm.OpcodeF64ConvertI64U: c.emit( - NewOperationFConvertFromI(SignedUint64, Float64), + newOperationFConvertFromI(signedUint64, f64), ) case wasm.OpcodeF64PromoteF32: c.emit( - NewOperationF64PromoteFromF32(), + newOperationF64PromoteFromF32(), ) case wasm.OpcodeI32ReinterpretF32: c.emit( - NewOperationI32ReinterpretFromF32(), + newOperationI32ReinterpretFromF32(), ) case wasm.OpcodeI64ReinterpretF64: c.emit( - NewOperationI64ReinterpretFromF64(), + newOperationI64ReinterpretFromF64(), ) case wasm.OpcodeF32ReinterpretI32: c.emit( - NewOperationF32ReinterpretFromI32(), + newOperationF32ReinterpretFromI32(), ) case wasm.OpcodeF64ReinterpretI64: c.emit( - NewOperationF64ReinterpretFromI64(), + newOperationF64ReinterpretFromI64(), ) case wasm.OpcodeI32Extend8S: c.emit( - NewOperationSignExtend32From8(), + newOperationSignExtend32From8(), ) case wasm.OpcodeI32Extend16S: c.emit( - NewOperationSignExtend32From16(), + newOperationSignExtend32From16(), ) case wasm.OpcodeI64Extend8S: c.emit( - NewOperationSignExtend64From8(), + newOperationSignExtend64From8(), ) case wasm.OpcodeI64Extend16S: c.emit( - NewOperationSignExtend64From16(), + newOperationSignExtend64From16(), ) case wasm.OpcodeI64Extend32S: c.emit( - NewOperationSignExtend64From32(), + newOperationSignExtend64From32(), ) case wasm.OpcodeRefFunc: c.pc++ @@ -1603,17 +1603,17 @@ operatorSwitch: } c.pc += num - 1 c.emit( - NewOperationRefFunc(index), + newOperationRefFunc(index), ) case wasm.OpcodeRefNull: c.pc++ // Skip the type of reftype as every ref value is opaque pointer. c.emit( - NewOperationConstI64(0), + newOperationConstI64(0), ) case wasm.OpcodeRefIsNull: // Simply compare the opaque pointer (i64) with zero. c.emit( - NewOperationEqz(UnsignedInt64), + newOperationEqz(unsignedInt64), ) case wasm.OpcodeTableGet: c.pc++ @@ -1623,7 +1623,7 @@ operatorSwitch: } c.pc += num - 1 c.emit( - NewOperationTableGet(tableIndex), + newOperationTableGet(tableIndex), ) case wasm.OpcodeTableSet: c.pc++ @@ -1633,7 +1633,7 @@ operatorSwitch: } c.pc += num - 1 c.emit( - NewOperationTableSet(tableIndex), + newOperationTableSet(tableIndex), ) case wasm.OpcodeMiscPrefix: c.pc++ @@ -1646,35 +1646,35 @@ operatorSwitch: switch byte(miscOp) { case wasm.OpcodeMiscI32TruncSatF32S: c.emit( - NewOperationITruncFromF(Float32, SignedInt32, true), + newOperationITruncFromF(f32, signedInt32, true), ) case wasm.OpcodeMiscI32TruncSatF32U: c.emit( - NewOperationITruncFromF(Float32, SignedUint32, true), + newOperationITruncFromF(f32, signedUint32, true), ) case wasm.OpcodeMiscI32TruncSatF64S: c.emit( - NewOperationITruncFromF(Float64, SignedInt32, true), + newOperationITruncFromF(f64, signedInt32, true), ) case wasm.OpcodeMiscI32TruncSatF64U: c.emit( - NewOperationITruncFromF(Float64, SignedUint32, true), + newOperationITruncFromF(f64, signedUint32, true), ) case wasm.OpcodeMiscI64TruncSatF32S: c.emit( - NewOperationITruncFromF(Float32, SignedInt64, true), + newOperationITruncFromF(f32, signedInt64, true), ) case wasm.OpcodeMiscI64TruncSatF32U: c.emit( - NewOperationITruncFromF(Float32, SignedUint64, true), + newOperationITruncFromF(f32, signedUint64, true), ) case wasm.OpcodeMiscI64TruncSatF64S: c.emit( - NewOperationITruncFromF(Float64, SignedInt64, true), + newOperationITruncFromF(f64, signedInt64, true), ) case wasm.OpcodeMiscI64TruncSatF64U: c.emit( - NewOperationITruncFromF(Float64, SignedUint64, true), + newOperationITruncFromF(f64, signedUint64, true), ) case wasm.OpcodeMiscMemoryInit: c.result.UsesMemory = true @@ -1684,7 +1684,7 @@ operatorSwitch: } c.pc += num + 1 // +1 to skip the memory index which is fixed to zero. c.emit( - NewOperationMemoryInit(dataIndex), + newOperationMemoryInit(dataIndex), ) case wasm.OpcodeMiscDataDrop: dataIndex, num, err := leb128.LoadUint32(c.body[c.pc+1:]) @@ -1693,19 +1693,19 @@ operatorSwitch: } c.pc += num c.emit( - NewOperationDataDrop(dataIndex), + newOperationDataDrop(dataIndex), ) case wasm.OpcodeMiscMemoryCopy: c.result.UsesMemory = true c.pc += 2 // +2 to skip two memory indexes which are fixed to zero. c.emit( - NewOperationMemoryCopy(), + newOperationMemoryCopy(), ) case wasm.OpcodeMiscMemoryFill: c.result.UsesMemory = true c.pc += 1 // +1 to skip the memory index which is fixed to zero. c.emit( - NewOperationMemoryFill(), + newOperationMemoryFill(), ) case wasm.OpcodeMiscTableInit: elemIndex, num, err := leb128.LoadUint32(c.body[c.pc+1:]) @@ -1720,7 +1720,7 @@ operatorSwitch: } c.pc += num c.emit( - NewOperationTableInit(elemIndex, tableIndex), + newOperationTableInit(elemIndex, tableIndex), ) case wasm.OpcodeMiscElemDrop: elemIndex, num, err := leb128.LoadUint32(c.body[c.pc+1:]) @@ -1729,7 +1729,7 @@ operatorSwitch: } c.pc += num c.emit( - NewOperationElemDrop(elemIndex), + newOperationElemDrop(elemIndex), ) case wasm.OpcodeMiscTableCopy: // Read the source table inde.g. @@ -1745,7 +1745,7 @@ operatorSwitch: } c.pc += num c.emit( - NewOperationTableCopy(src, dst), + newOperationTableCopy(src, dst), ) case wasm.OpcodeMiscTableGrow: // Read the source table inde.g. @@ -1755,7 +1755,7 @@ operatorSwitch: } c.pc += num c.emit( - NewOperationTableGrow(tableIndex), + newOperationTableGrow(tableIndex), ) case wasm.OpcodeMiscTableSize: // Read the source table inde.g. @@ -1765,7 +1765,7 @@ operatorSwitch: } c.pc += num c.emit( - NewOperationTableSize(tableIndex), + newOperationTableSize(tableIndex), ) case wasm.OpcodeMiscTableFill: // Read the source table index. @@ -1775,10 +1775,10 @@ operatorSwitch: } c.pc += num c.emit( - NewOperationTableFill(tableIndex), + newOperationTableFill(tableIndex), ) default: - return fmt.Errorf("unsupported misc instruction in wazeroir: 0x%x", op) + return fmt.Errorf("unsupported misc instruction in interpreterir: 0x%x", op) } case wasm.OpcodeVecPrefix: c.pc++ @@ -1789,7 +1789,7 @@ operatorSwitch: c.pc += 8 hi := binary.LittleEndian.Uint64(c.body[c.pc : c.pc+8]) c.emit( - NewOperationV128Const(lo, hi), + newOperationV128Const(lo, hi), ) c.pc += 7 case wasm.OpcodeVecV128Load: @@ -1798,7 +1798,7 @@ operatorSwitch: return err } c.emit( - NewOperationV128Load(V128LoadType128, arg), + newOperationV128Load(v128LoadType128, arg), ) case wasm.OpcodeVecV128Load8x8s: arg, err := c.readMemoryArg(wasm.OpcodeVecV128Load8x8SName) @@ -1806,7 +1806,7 @@ operatorSwitch: return err } c.emit( - NewOperationV128Load(V128LoadType8x8s, arg), + newOperationV128Load(v128LoadType8x8s, arg), ) case wasm.OpcodeVecV128Load8x8u: arg, err := c.readMemoryArg(wasm.OpcodeVecV128Load8x8UName) @@ -1814,7 +1814,7 @@ operatorSwitch: return err } c.emit( - NewOperationV128Load(V128LoadType8x8u, arg), + newOperationV128Load(v128LoadType8x8u, arg), ) case wasm.OpcodeVecV128Load16x4s: arg, err := c.readMemoryArg(wasm.OpcodeVecV128Load16x4SName) @@ -1822,7 +1822,7 @@ operatorSwitch: return err } c.emit( - NewOperationV128Load(V128LoadType16x4s, arg), + newOperationV128Load(v128LoadType16x4s, arg), ) case wasm.OpcodeVecV128Load16x4u: arg, err := c.readMemoryArg(wasm.OpcodeVecV128Load16x4UName) @@ -1830,7 +1830,7 @@ operatorSwitch: return err } c.emit( - NewOperationV128Load(V128LoadType16x4u, arg), + newOperationV128Load(v128LoadType16x4u, arg), ) case wasm.OpcodeVecV128Load32x2s: arg, err := c.readMemoryArg(wasm.OpcodeVecV128Load32x2SName) @@ -1838,7 +1838,7 @@ operatorSwitch: return err } c.emit( - NewOperationV128Load(V128LoadType32x2s, arg), + newOperationV128Load(v128LoadType32x2s, arg), ) case wasm.OpcodeVecV128Load32x2u: arg, err := c.readMemoryArg(wasm.OpcodeVecV128Load32x2UName) @@ -1846,7 +1846,7 @@ operatorSwitch: return err } c.emit( - NewOperationV128Load(V128LoadType32x2u, arg), + newOperationV128Load(v128LoadType32x2u, arg), ) case wasm.OpcodeVecV128Load8Splat: arg, err := c.readMemoryArg(wasm.OpcodeVecV128Load8SplatName) @@ -1854,7 +1854,7 @@ operatorSwitch: return err } c.emit( - NewOperationV128Load(V128LoadType8Splat, arg), + newOperationV128Load(v128LoadType8Splat, arg), ) case wasm.OpcodeVecV128Load16Splat: arg, err := c.readMemoryArg(wasm.OpcodeVecV128Load16SplatName) @@ -1862,7 +1862,7 @@ operatorSwitch: return err } c.emit( - NewOperationV128Load(V128LoadType16Splat, arg), + newOperationV128Load(v128LoadType16Splat, arg), ) case wasm.OpcodeVecV128Load32Splat: arg, err := c.readMemoryArg(wasm.OpcodeVecV128Load32SplatName) @@ -1870,7 +1870,7 @@ operatorSwitch: return err } c.emit( - NewOperationV128Load(V128LoadType32Splat, arg), + newOperationV128Load(v128LoadType32Splat, arg), ) case wasm.OpcodeVecV128Load64Splat: arg, err := c.readMemoryArg(wasm.OpcodeVecV128Load64SplatName) @@ -1878,7 +1878,7 @@ operatorSwitch: return err } c.emit( - NewOperationV128Load(V128LoadType64Splat, arg), + newOperationV128Load(v128LoadType64Splat, arg), ) case wasm.OpcodeVecV128Load32zero: arg, err := c.readMemoryArg(wasm.OpcodeVecV128Load32zeroName) @@ -1886,7 +1886,7 @@ operatorSwitch: return err } c.emit( - NewOperationV128Load(V128LoadType32zero, arg), + newOperationV128Load(v128LoadType32zero, arg), ) case wasm.OpcodeVecV128Load64zero: arg, err := c.readMemoryArg(wasm.OpcodeVecV128Load64zeroName) @@ -1894,7 +1894,7 @@ operatorSwitch: return err } c.emit( - NewOperationV128Load(V128LoadType64zero, arg), + newOperationV128Load(v128LoadType64zero, arg), ) case wasm.OpcodeVecV128Load8Lane: arg, err := c.readMemoryArg(wasm.OpcodeVecV128Load8LaneName) @@ -1904,7 +1904,7 @@ operatorSwitch: c.pc++ laneIndex := c.body[c.pc] c.emit( - NewOperationV128LoadLane(laneIndex, 8, arg), + newOperationV128LoadLane(laneIndex, 8, arg), ) case wasm.OpcodeVecV128Load16Lane: arg, err := c.readMemoryArg(wasm.OpcodeVecV128Load16LaneName) @@ -1914,7 +1914,7 @@ operatorSwitch: c.pc++ laneIndex := c.body[c.pc] c.emit( - NewOperationV128LoadLane(laneIndex, 16, arg), + newOperationV128LoadLane(laneIndex, 16, arg), ) case wasm.OpcodeVecV128Load32Lane: arg, err := c.readMemoryArg(wasm.OpcodeVecV128Load32LaneName) @@ -1924,7 +1924,7 @@ operatorSwitch: c.pc++ laneIndex := c.body[c.pc] c.emit( - NewOperationV128LoadLane(laneIndex, 32, arg), + newOperationV128LoadLane(laneIndex, 32, arg), ) case wasm.OpcodeVecV128Load64Lane: arg, err := c.readMemoryArg(wasm.OpcodeVecV128Load64LaneName) @@ -1934,7 +1934,7 @@ operatorSwitch: c.pc++ laneIndex := c.body[c.pc] c.emit( - NewOperationV128LoadLane(laneIndex, 64, arg), + newOperationV128LoadLane(laneIndex, 64, arg), ) case wasm.OpcodeVecV128Store: arg, err := c.readMemoryArg(wasm.OpcodeVecV128StoreName) @@ -1942,7 +1942,7 @@ operatorSwitch: return err } c.emit( - NewOperationV128Store(arg), + newOperationV128Store(arg), ) case wasm.OpcodeVecV128Store8Lane: arg, err := c.readMemoryArg(wasm.OpcodeVecV128Store8LaneName) @@ -1952,7 +1952,7 @@ operatorSwitch: c.pc++ laneIndex := c.body[c.pc] c.emit( - NewOperationV128StoreLane(laneIndex, 8, arg), + newOperationV128StoreLane(laneIndex, 8, arg), ) case wasm.OpcodeVecV128Store16Lane: arg, err := c.readMemoryArg(wasm.OpcodeVecV128Store16LaneName) @@ -1962,7 +1962,7 @@ operatorSwitch: c.pc++ laneIndex := c.body[c.pc] c.emit( - NewOperationV128StoreLane(laneIndex, 16, arg), + newOperationV128StoreLane(laneIndex, 16, arg), ) case wasm.OpcodeVecV128Store32Lane: arg, err := c.readMemoryArg(wasm.OpcodeVecV128Store32LaneName) @@ -1972,7 +1972,7 @@ operatorSwitch: c.pc++ laneIndex := c.body[c.pc] c.emit( - NewOperationV128StoreLane(laneIndex, 32, arg), + newOperationV128StoreLane(laneIndex, 32, arg), ) case wasm.OpcodeVecV128Store64Lane: arg, err := c.readMemoryArg(wasm.OpcodeVecV128Store64LaneName) @@ -1982,119 +1982,119 @@ operatorSwitch: c.pc++ laneIndex := c.body[c.pc] c.emit( - NewOperationV128StoreLane(laneIndex, 64, arg), + newOperationV128StoreLane(laneIndex, 64, arg), ) case wasm.OpcodeVecI8x16ExtractLaneS: c.pc++ laneIndex := c.body[c.pc] c.emit( - NewOperationV128ExtractLane(laneIndex, true, ShapeI8x16), + newOperationV128ExtractLane(laneIndex, true, shapeI8x16), ) case wasm.OpcodeVecI8x16ExtractLaneU: c.pc++ laneIndex := c.body[c.pc] c.emit( - NewOperationV128ExtractLane(laneIndex, false, ShapeI8x16), + newOperationV128ExtractLane(laneIndex, false, shapeI8x16), ) case wasm.OpcodeVecI16x8ExtractLaneS: c.pc++ laneIndex := c.body[c.pc] c.emit( - NewOperationV128ExtractLane(laneIndex, true, ShapeI16x8), + newOperationV128ExtractLane(laneIndex, true, shapeI16x8), ) case wasm.OpcodeVecI16x8ExtractLaneU: c.pc++ laneIndex := c.body[c.pc] c.emit( - NewOperationV128ExtractLane(laneIndex, false, ShapeI16x8), + newOperationV128ExtractLane(laneIndex, false, shapeI16x8), ) case wasm.OpcodeVecI32x4ExtractLane: c.pc++ laneIndex := c.body[c.pc] c.emit( - NewOperationV128ExtractLane(laneIndex, false, ShapeI32x4), + newOperationV128ExtractLane(laneIndex, false, shapeI32x4), ) case wasm.OpcodeVecI64x2ExtractLane: c.pc++ laneIndex := c.body[c.pc] c.emit( - NewOperationV128ExtractLane(laneIndex, false, ShapeI64x2), + newOperationV128ExtractLane(laneIndex, false, shapeI64x2), ) case wasm.OpcodeVecF32x4ExtractLane: c.pc++ laneIndex := c.body[c.pc] c.emit( - NewOperationV128ExtractLane(laneIndex, false, ShapeF32x4), + newOperationV128ExtractLane(laneIndex, false, shapeF32x4), ) case wasm.OpcodeVecF64x2ExtractLane: c.pc++ laneIndex := c.body[c.pc] c.emit( - NewOperationV128ExtractLane(laneIndex, false, ShapeF64x2), + newOperationV128ExtractLane(laneIndex, false, shapeF64x2), ) case wasm.OpcodeVecI8x16ReplaceLane: c.pc++ laneIndex := c.body[c.pc] c.emit( - NewOperationV128ReplaceLane(laneIndex, ShapeI8x16), + newOperationV128ReplaceLane(laneIndex, shapeI8x16), ) case wasm.OpcodeVecI16x8ReplaceLane: c.pc++ laneIndex := c.body[c.pc] c.emit( - NewOperationV128ReplaceLane(laneIndex, ShapeI16x8), + newOperationV128ReplaceLane(laneIndex, shapeI16x8), ) case wasm.OpcodeVecI32x4ReplaceLane: c.pc++ laneIndex := c.body[c.pc] c.emit( - NewOperationV128ReplaceLane(laneIndex, ShapeI32x4), + newOperationV128ReplaceLane(laneIndex, shapeI32x4), ) case wasm.OpcodeVecI64x2ReplaceLane: c.pc++ laneIndex := c.body[c.pc] c.emit( - NewOperationV128ReplaceLane(laneIndex, ShapeI64x2), + newOperationV128ReplaceLane(laneIndex, shapeI64x2), ) case wasm.OpcodeVecF32x4ReplaceLane: c.pc++ laneIndex := c.body[c.pc] c.emit( - NewOperationV128ReplaceLane(laneIndex, ShapeF32x4), + newOperationV128ReplaceLane(laneIndex, shapeF32x4), ) case wasm.OpcodeVecF64x2ReplaceLane: c.pc++ laneIndex := c.body[c.pc] c.emit( - NewOperationV128ReplaceLane(laneIndex, ShapeF64x2), + newOperationV128ReplaceLane(laneIndex, shapeF64x2), ) case wasm.OpcodeVecI8x16Splat: c.emit( - NewOperationV128Splat(ShapeI8x16), + newOperationV128Splat(shapeI8x16), ) case wasm.OpcodeVecI16x8Splat: c.emit( - NewOperationV128Splat(ShapeI16x8), + newOperationV128Splat(shapeI16x8), ) case wasm.OpcodeVecI32x4Splat: c.emit( - NewOperationV128Splat(ShapeI32x4), + newOperationV128Splat(shapeI32x4), ) case wasm.OpcodeVecI64x2Splat: c.emit( - NewOperationV128Splat(ShapeI64x2), + newOperationV128Splat(shapeI64x2), ) case wasm.OpcodeVecF32x4Splat: c.emit( - NewOperationV128Splat(ShapeF32x4), + newOperationV128Splat(shapeF32x4), ) case wasm.OpcodeVecF64x2Splat: c.emit( - NewOperationV128Splat(ShapeF64x2), + newOperationV128Splat(shapeF64x2), ) case wasm.OpcodeVecI8x16Swizzle: c.emit( - NewOperationV128Swizzle(), + newOperationV128Swizzle(), ) case wasm.OpcodeVecV128i8x16Shuffle: c.pc++ @@ -2102,775 +2102,775 @@ operatorSwitch: for i := uint64(0); i < 16; i++ { lanes[i] = uint64(c.body[c.pc+i]) } - op := NewOperationV128Shuffle(lanes) + op := newOperationV128Shuffle(lanes) c.emit(op) c.pc += 15 case wasm.OpcodeVecV128AnyTrue: c.emit( - NewOperationV128AnyTrue(), + newOperationV128AnyTrue(), ) case wasm.OpcodeVecI8x16AllTrue: c.emit( - NewOperationV128AllTrue(ShapeI8x16), + newOperationV128AllTrue(shapeI8x16), ) case wasm.OpcodeVecI16x8AllTrue: c.emit( - NewOperationV128AllTrue(ShapeI16x8), + newOperationV128AllTrue(shapeI16x8), ) case wasm.OpcodeVecI32x4AllTrue: c.emit( - NewOperationV128AllTrue(ShapeI32x4), + newOperationV128AllTrue(shapeI32x4), ) case wasm.OpcodeVecI64x2AllTrue: c.emit( - NewOperationV128AllTrue(ShapeI64x2), + newOperationV128AllTrue(shapeI64x2), ) case wasm.OpcodeVecI8x16BitMask: c.emit( - NewOperationV128BitMask(ShapeI8x16), + newOperationV128BitMask(shapeI8x16), ) case wasm.OpcodeVecI16x8BitMask: c.emit( - NewOperationV128BitMask(ShapeI16x8), + newOperationV128BitMask(shapeI16x8), ) case wasm.OpcodeVecI32x4BitMask: c.emit( - NewOperationV128BitMask(ShapeI32x4), + newOperationV128BitMask(shapeI32x4), ) case wasm.OpcodeVecI64x2BitMask: c.emit( - NewOperationV128BitMask(ShapeI64x2), + newOperationV128BitMask(shapeI64x2), ) case wasm.OpcodeVecV128And: c.emit( - NewOperationV128And(), + newOperationV128And(), ) case wasm.OpcodeVecV128Not: c.emit( - NewOperationV128Not(), + newOperationV128Not(), ) case wasm.OpcodeVecV128Or: c.emit( - NewOperationV128Or(), + newOperationV128Or(), ) case wasm.OpcodeVecV128Xor: c.emit( - NewOperationV128Xor(), + newOperationV128Xor(), ) case wasm.OpcodeVecV128Bitselect: c.emit( - NewOperationV128Bitselect(), + newOperationV128Bitselect(), ) case wasm.OpcodeVecV128AndNot: c.emit( - NewOperationV128AndNot(), + newOperationV128AndNot(), ) case wasm.OpcodeVecI8x16Shl: c.emit( - NewOperationV128Shl(ShapeI8x16), + newOperationV128Shl(shapeI8x16), ) case wasm.OpcodeVecI8x16ShrS: c.emit( - NewOperationV128Shr(ShapeI8x16, true), + newOperationV128Shr(shapeI8x16, true), ) case wasm.OpcodeVecI8x16ShrU: c.emit( - NewOperationV128Shr(ShapeI8x16, false), + newOperationV128Shr(shapeI8x16, false), ) case wasm.OpcodeVecI16x8Shl: c.emit( - NewOperationV128Shl(ShapeI16x8), + newOperationV128Shl(shapeI16x8), ) case wasm.OpcodeVecI16x8ShrS: c.emit( - NewOperationV128Shr(ShapeI16x8, true), + newOperationV128Shr(shapeI16x8, true), ) case wasm.OpcodeVecI16x8ShrU: c.emit( - NewOperationV128Shr(ShapeI16x8, false), + newOperationV128Shr(shapeI16x8, false), ) case wasm.OpcodeVecI32x4Shl: c.emit( - NewOperationV128Shl(ShapeI32x4), + newOperationV128Shl(shapeI32x4), ) case wasm.OpcodeVecI32x4ShrS: c.emit( - NewOperationV128Shr(ShapeI32x4, true), + newOperationV128Shr(shapeI32x4, true), ) case wasm.OpcodeVecI32x4ShrU: c.emit( - NewOperationV128Shr(ShapeI32x4, false), + newOperationV128Shr(shapeI32x4, false), ) case wasm.OpcodeVecI64x2Shl: c.emit( - NewOperationV128Shl(ShapeI64x2), + newOperationV128Shl(shapeI64x2), ) case wasm.OpcodeVecI64x2ShrS: c.emit( - NewOperationV128Shr(ShapeI64x2, true), + newOperationV128Shr(shapeI64x2, true), ) case wasm.OpcodeVecI64x2ShrU: c.emit( - NewOperationV128Shr(ShapeI64x2, false), + newOperationV128Shr(shapeI64x2, false), ) case wasm.OpcodeVecI8x16Eq: c.emit( - NewOperationV128Cmp(V128CmpTypeI8x16Eq), + newOperationV128Cmp(v128CmpTypeI8x16Eq), ) case wasm.OpcodeVecI8x16Ne: c.emit( - NewOperationV128Cmp(V128CmpTypeI8x16Ne), + newOperationV128Cmp(v128CmpTypeI8x16Ne), ) case wasm.OpcodeVecI8x16LtS: c.emit( - NewOperationV128Cmp(V128CmpTypeI8x16LtS), + newOperationV128Cmp(v128CmpTypeI8x16LtS), ) case wasm.OpcodeVecI8x16LtU: c.emit( - NewOperationV128Cmp(V128CmpTypeI8x16LtU), + newOperationV128Cmp(v128CmpTypeI8x16LtU), ) case wasm.OpcodeVecI8x16GtS: c.emit( - NewOperationV128Cmp(V128CmpTypeI8x16GtS), + newOperationV128Cmp(v128CmpTypeI8x16GtS), ) case wasm.OpcodeVecI8x16GtU: c.emit( - NewOperationV128Cmp(V128CmpTypeI8x16GtU), + newOperationV128Cmp(v128CmpTypeI8x16GtU), ) case wasm.OpcodeVecI8x16LeS: c.emit( - NewOperationV128Cmp(V128CmpTypeI8x16LeS), + newOperationV128Cmp(v128CmpTypeI8x16LeS), ) case wasm.OpcodeVecI8x16LeU: c.emit( - NewOperationV128Cmp(V128CmpTypeI8x16LeU), + newOperationV128Cmp(v128CmpTypeI8x16LeU), ) case wasm.OpcodeVecI8x16GeS: c.emit( - NewOperationV128Cmp(V128CmpTypeI8x16GeS), + newOperationV128Cmp(v128CmpTypeI8x16GeS), ) case wasm.OpcodeVecI8x16GeU: c.emit( - NewOperationV128Cmp(V128CmpTypeI8x16GeU), + newOperationV128Cmp(v128CmpTypeI8x16GeU), ) case wasm.OpcodeVecI16x8Eq: c.emit( - NewOperationV128Cmp(V128CmpTypeI16x8Eq), + newOperationV128Cmp(v128CmpTypeI16x8Eq), ) case wasm.OpcodeVecI16x8Ne: c.emit( - NewOperationV128Cmp(V128CmpTypeI16x8Ne), + newOperationV128Cmp(v128CmpTypeI16x8Ne), ) case wasm.OpcodeVecI16x8LtS: c.emit( - NewOperationV128Cmp(V128CmpTypeI16x8LtS), + newOperationV128Cmp(v128CmpTypeI16x8LtS), ) case wasm.OpcodeVecI16x8LtU: c.emit( - NewOperationV128Cmp(V128CmpTypeI16x8LtU), + newOperationV128Cmp(v128CmpTypeI16x8LtU), ) case wasm.OpcodeVecI16x8GtS: c.emit( - NewOperationV128Cmp(V128CmpTypeI16x8GtS), + newOperationV128Cmp(v128CmpTypeI16x8GtS), ) case wasm.OpcodeVecI16x8GtU: c.emit( - NewOperationV128Cmp(V128CmpTypeI16x8GtU), + newOperationV128Cmp(v128CmpTypeI16x8GtU), ) case wasm.OpcodeVecI16x8LeS: c.emit( - NewOperationV128Cmp(V128CmpTypeI16x8LeS), + newOperationV128Cmp(v128CmpTypeI16x8LeS), ) case wasm.OpcodeVecI16x8LeU: c.emit( - NewOperationV128Cmp(V128CmpTypeI16x8LeU), + newOperationV128Cmp(v128CmpTypeI16x8LeU), ) case wasm.OpcodeVecI16x8GeS: c.emit( - NewOperationV128Cmp(V128CmpTypeI16x8GeS), + newOperationV128Cmp(v128CmpTypeI16x8GeS), ) case wasm.OpcodeVecI16x8GeU: c.emit( - NewOperationV128Cmp(V128CmpTypeI16x8GeU), + newOperationV128Cmp(v128CmpTypeI16x8GeU), ) case wasm.OpcodeVecI32x4Eq: c.emit( - NewOperationV128Cmp(V128CmpTypeI32x4Eq), + newOperationV128Cmp(v128CmpTypeI32x4Eq), ) case wasm.OpcodeVecI32x4Ne: c.emit( - NewOperationV128Cmp(V128CmpTypeI32x4Ne), + newOperationV128Cmp(v128CmpTypeI32x4Ne), ) case wasm.OpcodeVecI32x4LtS: c.emit( - NewOperationV128Cmp(V128CmpTypeI32x4LtS), + newOperationV128Cmp(v128CmpTypeI32x4LtS), ) case wasm.OpcodeVecI32x4LtU: c.emit( - NewOperationV128Cmp(V128CmpTypeI32x4LtU), + newOperationV128Cmp(v128CmpTypeI32x4LtU), ) case wasm.OpcodeVecI32x4GtS: c.emit( - NewOperationV128Cmp(V128CmpTypeI32x4GtS), + newOperationV128Cmp(v128CmpTypeI32x4GtS), ) case wasm.OpcodeVecI32x4GtU: c.emit( - NewOperationV128Cmp(V128CmpTypeI32x4GtU), + newOperationV128Cmp(v128CmpTypeI32x4GtU), ) case wasm.OpcodeVecI32x4LeS: c.emit( - NewOperationV128Cmp(V128CmpTypeI32x4LeS), + newOperationV128Cmp(v128CmpTypeI32x4LeS), ) case wasm.OpcodeVecI32x4LeU: c.emit( - NewOperationV128Cmp(V128CmpTypeI32x4LeU), + newOperationV128Cmp(v128CmpTypeI32x4LeU), ) case wasm.OpcodeVecI32x4GeS: c.emit( - NewOperationV128Cmp(V128CmpTypeI32x4GeS), + newOperationV128Cmp(v128CmpTypeI32x4GeS), ) case wasm.OpcodeVecI32x4GeU: c.emit( - NewOperationV128Cmp(V128CmpTypeI32x4GeU), + newOperationV128Cmp(v128CmpTypeI32x4GeU), ) case wasm.OpcodeVecI64x2Eq: c.emit( - NewOperationV128Cmp(V128CmpTypeI64x2Eq), + newOperationV128Cmp(v128CmpTypeI64x2Eq), ) case wasm.OpcodeVecI64x2Ne: c.emit( - NewOperationV128Cmp(V128CmpTypeI64x2Ne), + newOperationV128Cmp(v128CmpTypeI64x2Ne), ) case wasm.OpcodeVecI64x2LtS: c.emit( - NewOperationV128Cmp(V128CmpTypeI64x2LtS), + newOperationV128Cmp(v128CmpTypeI64x2LtS), ) case wasm.OpcodeVecI64x2GtS: c.emit( - NewOperationV128Cmp(V128CmpTypeI64x2GtS), + newOperationV128Cmp(v128CmpTypeI64x2GtS), ) case wasm.OpcodeVecI64x2LeS: c.emit( - NewOperationV128Cmp(V128CmpTypeI64x2LeS), + newOperationV128Cmp(v128CmpTypeI64x2LeS), ) case wasm.OpcodeVecI64x2GeS: c.emit( - NewOperationV128Cmp(V128CmpTypeI64x2GeS), + newOperationV128Cmp(v128CmpTypeI64x2GeS), ) case wasm.OpcodeVecF32x4Eq: c.emit( - NewOperationV128Cmp(V128CmpTypeF32x4Eq), + newOperationV128Cmp(v128CmpTypeF32x4Eq), ) case wasm.OpcodeVecF32x4Ne: c.emit( - NewOperationV128Cmp(V128CmpTypeF32x4Ne), + newOperationV128Cmp(v128CmpTypeF32x4Ne), ) case wasm.OpcodeVecF32x4Lt: c.emit( - NewOperationV128Cmp(V128CmpTypeF32x4Lt), + newOperationV128Cmp(v128CmpTypeF32x4Lt), ) case wasm.OpcodeVecF32x4Gt: c.emit( - NewOperationV128Cmp(V128CmpTypeF32x4Gt), + newOperationV128Cmp(v128CmpTypeF32x4Gt), ) case wasm.OpcodeVecF32x4Le: c.emit( - NewOperationV128Cmp(V128CmpTypeF32x4Le), + newOperationV128Cmp(v128CmpTypeF32x4Le), ) case wasm.OpcodeVecF32x4Ge: c.emit( - NewOperationV128Cmp(V128CmpTypeF32x4Ge), + newOperationV128Cmp(v128CmpTypeF32x4Ge), ) case wasm.OpcodeVecF64x2Eq: c.emit( - NewOperationV128Cmp(V128CmpTypeF64x2Eq), + newOperationV128Cmp(v128CmpTypeF64x2Eq), ) case wasm.OpcodeVecF64x2Ne: c.emit( - NewOperationV128Cmp(V128CmpTypeF64x2Ne), + newOperationV128Cmp(v128CmpTypeF64x2Ne), ) case wasm.OpcodeVecF64x2Lt: c.emit( - NewOperationV128Cmp(V128CmpTypeF64x2Lt), + newOperationV128Cmp(v128CmpTypeF64x2Lt), ) case wasm.OpcodeVecF64x2Gt: c.emit( - NewOperationV128Cmp(V128CmpTypeF64x2Gt), + newOperationV128Cmp(v128CmpTypeF64x2Gt), ) case wasm.OpcodeVecF64x2Le: c.emit( - NewOperationV128Cmp(V128CmpTypeF64x2Le), + newOperationV128Cmp(v128CmpTypeF64x2Le), ) case wasm.OpcodeVecF64x2Ge: c.emit( - NewOperationV128Cmp(V128CmpTypeF64x2Ge), + newOperationV128Cmp(v128CmpTypeF64x2Ge), ) case wasm.OpcodeVecI8x16Neg: c.emit( - NewOperationV128Neg(ShapeI8x16), + newOperationV128Neg(shapeI8x16), ) case wasm.OpcodeVecI16x8Neg: c.emit( - NewOperationV128Neg(ShapeI16x8), + newOperationV128Neg(shapeI16x8), ) case wasm.OpcodeVecI32x4Neg: c.emit( - NewOperationV128Neg(ShapeI32x4), + newOperationV128Neg(shapeI32x4), ) case wasm.OpcodeVecI64x2Neg: c.emit( - NewOperationV128Neg(ShapeI64x2), + newOperationV128Neg(shapeI64x2), ) case wasm.OpcodeVecF32x4Neg: c.emit( - NewOperationV128Neg(ShapeF32x4), + newOperationV128Neg(shapeF32x4), ) case wasm.OpcodeVecF64x2Neg: c.emit( - NewOperationV128Neg(ShapeF64x2), + newOperationV128Neg(shapeF64x2), ) case wasm.OpcodeVecI8x16Add: c.emit( - NewOperationV128Add(ShapeI8x16), + newOperationV128Add(shapeI8x16), ) case wasm.OpcodeVecI16x8Add: c.emit( - NewOperationV128Add(ShapeI16x8), + newOperationV128Add(shapeI16x8), ) case wasm.OpcodeVecI32x4Add: c.emit( - NewOperationV128Add(ShapeI32x4), + newOperationV128Add(shapeI32x4), ) case wasm.OpcodeVecI64x2Add: c.emit( - NewOperationV128Add(ShapeI64x2), + newOperationV128Add(shapeI64x2), ) case wasm.OpcodeVecF32x4Add: c.emit( - NewOperationV128Add(ShapeF32x4), + newOperationV128Add(shapeF32x4), ) case wasm.OpcodeVecF64x2Add: c.emit( - NewOperationV128Add(ShapeF64x2), + newOperationV128Add(shapeF64x2), ) case wasm.OpcodeVecI8x16Sub: c.emit( - NewOperationV128Sub(ShapeI8x16), + newOperationV128Sub(shapeI8x16), ) case wasm.OpcodeVecI16x8Sub: c.emit( - NewOperationV128Sub(ShapeI16x8), + newOperationV128Sub(shapeI16x8), ) case wasm.OpcodeVecI32x4Sub: c.emit( - NewOperationV128Sub(ShapeI32x4), + newOperationV128Sub(shapeI32x4), ) case wasm.OpcodeVecI64x2Sub: c.emit( - NewOperationV128Sub(ShapeI64x2), + newOperationV128Sub(shapeI64x2), ) case wasm.OpcodeVecF32x4Sub: c.emit( - NewOperationV128Sub(ShapeF32x4), + newOperationV128Sub(shapeF32x4), ) case wasm.OpcodeVecF64x2Sub: c.emit( - NewOperationV128Sub(ShapeF64x2), + newOperationV128Sub(shapeF64x2), ) case wasm.OpcodeVecI8x16AddSatS: c.emit( - NewOperationV128AddSat(ShapeI8x16, true), + newOperationV128AddSat(shapeI8x16, true), ) case wasm.OpcodeVecI8x16AddSatU: c.emit( - NewOperationV128AddSat(ShapeI8x16, false), + newOperationV128AddSat(shapeI8x16, false), ) case wasm.OpcodeVecI16x8AddSatS: c.emit( - NewOperationV128AddSat(ShapeI16x8, true), + newOperationV128AddSat(shapeI16x8, true), ) case wasm.OpcodeVecI16x8AddSatU: c.emit( - NewOperationV128AddSat(ShapeI16x8, false), + newOperationV128AddSat(shapeI16x8, false), ) case wasm.OpcodeVecI8x16SubSatS: c.emit( - NewOperationV128SubSat(ShapeI8x16, true), + newOperationV128SubSat(shapeI8x16, true), ) case wasm.OpcodeVecI8x16SubSatU: c.emit( - NewOperationV128SubSat(ShapeI8x16, false), + newOperationV128SubSat(shapeI8x16, false), ) case wasm.OpcodeVecI16x8SubSatS: c.emit( - NewOperationV128SubSat(ShapeI16x8, true), + newOperationV128SubSat(shapeI16x8, true), ) case wasm.OpcodeVecI16x8SubSatU: c.emit( - NewOperationV128SubSat(ShapeI16x8, false), + newOperationV128SubSat(shapeI16x8, false), ) case wasm.OpcodeVecI16x8Mul: c.emit( - NewOperationV128Mul(ShapeI16x8), + newOperationV128Mul(shapeI16x8), ) case wasm.OpcodeVecI32x4Mul: c.emit( - NewOperationV128Mul(ShapeI32x4), + newOperationV128Mul(shapeI32x4), ) case wasm.OpcodeVecI64x2Mul: c.emit( - NewOperationV128Mul(ShapeI64x2), + newOperationV128Mul(shapeI64x2), ) case wasm.OpcodeVecF32x4Mul: c.emit( - NewOperationV128Mul(ShapeF32x4), + newOperationV128Mul(shapeF32x4), ) case wasm.OpcodeVecF64x2Mul: c.emit( - NewOperationV128Mul(ShapeF64x2), + newOperationV128Mul(shapeF64x2), ) case wasm.OpcodeVecF32x4Sqrt: c.emit( - NewOperationV128Sqrt(ShapeF32x4), + newOperationV128Sqrt(shapeF32x4), ) case wasm.OpcodeVecF64x2Sqrt: c.emit( - NewOperationV128Sqrt(ShapeF64x2), + newOperationV128Sqrt(shapeF64x2), ) case wasm.OpcodeVecF32x4Div: c.emit( - NewOperationV128Div(ShapeF32x4), + newOperationV128Div(shapeF32x4), ) case wasm.OpcodeVecF64x2Div: c.emit( - NewOperationV128Div(ShapeF64x2), + newOperationV128Div(shapeF64x2), ) case wasm.OpcodeVecI8x16Abs: c.emit( - NewOperationV128Abs(ShapeI8x16), + newOperationV128Abs(shapeI8x16), ) case wasm.OpcodeVecI8x16Popcnt: c.emit( - NewOperationV128Popcnt(ShapeI8x16), + newOperationV128Popcnt(shapeI8x16), ) case wasm.OpcodeVecI16x8Abs: c.emit( - NewOperationV128Abs(ShapeI16x8), + newOperationV128Abs(shapeI16x8), ) case wasm.OpcodeVecI32x4Abs: c.emit( - NewOperationV128Abs(ShapeI32x4), + newOperationV128Abs(shapeI32x4), ) case wasm.OpcodeVecI64x2Abs: c.emit( - NewOperationV128Abs(ShapeI64x2), + newOperationV128Abs(shapeI64x2), ) case wasm.OpcodeVecF32x4Abs: c.emit( - NewOperationV128Abs(ShapeF32x4), + newOperationV128Abs(shapeF32x4), ) case wasm.OpcodeVecF64x2Abs: c.emit( - NewOperationV128Abs(ShapeF64x2), + newOperationV128Abs(shapeF64x2), ) case wasm.OpcodeVecI8x16MinS: c.emit( - NewOperationV128Min(ShapeI8x16, true), + newOperationV128Min(shapeI8x16, true), ) case wasm.OpcodeVecI8x16MinU: c.emit( - NewOperationV128Min(ShapeI8x16, false), + newOperationV128Min(shapeI8x16, false), ) case wasm.OpcodeVecI8x16MaxS: c.emit( - NewOperationV128Max(ShapeI8x16, true), + newOperationV128Max(shapeI8x16, true), ) case wasm.OpcodeVecI8x16MaxU: c.emit( - NewOperationV128Max(ShapeI8x16, false), + newOperationV128Max(shapeI8x16, false), ) case wasm.OpcodeVecI8x16AvgrU: c.emit( - NewOperationV128AvgrU(ShapeI8x16), + newOperationV128AvgrU(shapeI8x16), ) case wasm.OpcodeVecI16x8MinS: c.emit( - NewOperationV128Min(ShapeI16x8, true), + newOperationV128Min(shapeI16x8, true), ) case wasm.OpcodeVecI16x8MinU: c.emit( - NewOperationV128Min(ShapeI16x8, false), + newOperationV128Min(shapeI16x8, false), ) case wasm.OpcodeVecI16x8MaxS: c.emit( - NewOperationV128Max(ShapeI16x8, true), + newOperationV128Max(shapeI16x8, true), ) case wasm.OpcodeVecI16x8MaxU: c.emit( - NewOperationV128Max(ShapeI16x8, false), + newOperationV128Max(shapeI16x8, false), ) case wasm.OpcodeVecI16x8AvgrU: c.emit( - NewOperationV128AvgrU(ShapeI16x8), + newOperationV128AvgrU(shapeI16x8), ) case wasm.OpcodeVecI32x4MinS: c.emit( - NewOperationV128Min(ShapeI32x4, true), + newOperationV128Min(shapeI32x4, true), ) case wasm.OpcodeVecI32x4MinU: c.emit( - NewOperationV128Min(ShapeI32x4, false), + newOperationV128Min(shapeI32x4, false), ) case wasm.OpcodeVecI32x4MaxS: c.emit( - NewOperationV128Max(ShapeI32x4, true), + newOperationV128Max(shapeI32x4, true), ) case wasm.OpcodeVecI32x4MaxU: c.emit( - NewOperationV128Max(ShapeI32x4, false), + newOperationV128Max(shapeI32x4, false), ) case wasm.OpcodeVecF32x4Min: c.emit( - NewOperationV128Min(ShapeF32x4, false), + newOperationV128Min(shapeF32x4, false), ) case wasm.OpcodeVecF32x4Max: c.emit( - NewOperationV128Max(ShapeF32x4, false), + newOperationV128Max(shapeF32x4, false), ) case wasm.OpcodeVecF64x2Min: c.emit( - NewOperationV128Min(ShapeF64x2, false), + newOperationV128Min(shapeF64x2, false), ) case wasm.OpcodeVecF64x2Max: c.emit( - NewOperationV128Max(ShapeF64x2, false), + newOperationV128Max(shapeF64x2, false), ) case wasm.OpcodeVecF32x4Pmin: c.emit( - NewOperationV128Pmin(ShapeF32x4), + newOperationV128Pmin(shapeF32x4), ) case wasm.OpcodeVecF32x4Pmax: c.emit( - NewOperationV128Pmax(ShapeF32x4), + newOperationV128Pmax(shapeF32x4), ) case wasm.OpcodeVecF64x2Pmin: c.emit( - NewOperationV128Pmin(ShapeF64x2), + newOperationV128Pmin(shapeF64x2), ) case wasm.OpcodeVecF64x2Pmax: c.emit( - NewOperationV128Pmax(ShapeF64x2), + newOperationV128Pmax(shapeF64x2), ) case wasm.OpcodeVecF32x4Ceil: c.emit( - NewOperationV128Ceil(ShapeF32x4), + newOperationV128Ceil(shapeF32x4), ) case wasm.OpcodeVecF32x4Floor: c.emit( - NewOperationV128Floor(ShapeF32x4), + newOperationV128Floor(shapeF32x4), ) case wasm.OpcodeVecF32x4Trunc: c.emit( - NewOperationV128Trunc(ShapeF32x4), + newOperationV128Trunc(shapeF32x4), ) case wasm.OpcodeVecF32x4Nearest: c.emit( - NewOperationV128Nearest(ShapeF32x4), + newOperationV128Nearest(shapeF32x4), ) case wasm.OpcodeVecF64x2Ceil: c.emit( - NewOperationV128Ceil(ShapeF64x2), + newOperationV128Ceil(shapeF64x2), ) case wasm.OpcodeVecF64x2Floor: c.emit( - NewOperationV128Floor(ShapeF64x2), + newOperationV128Floor(shapeF64x2), ) case wasm.OpcodeVecF64x2Trunc: c.emit( - NewOperationV128Trunc(ShapeF64x2), + newOperationV128Trunc(shapeF64x2), ) case wasm.OpcodeVecF64x2Nearest: c.emit( - NewOperationV128Nearest(ShapeF64x2), + newOperationV128Nearest(shapeF64x2), ) case wasm.OpcodeVecI16x8ExtendLowI8x16S: c.emit( - NewOperationV128Extend(ShapeI8x16, true, true), + newOperationV128Extend(shapeI8x16, true, true), ) case wasm.OpcodeVecI16x8ExtendHighI8x16S: c.emit( - NewOperationV128Extend(ShapeI8x16, true, false), + newOperationV128Extend(shapeI8x16, true, false), ) case wasm.OpcodeVecI16x8ExtendLowI8x16U: c.emit( - NewOperationV128Extend(ShapeI8x16, false, true), + newOperationV128Extend(shapeI8x16, false, true), ) case wasm.OpcodeVecI16x8ExtendHighI8x16U: c.emit( - NewOperationV128Extend(ShapeI8x16, false, false), + newOperationV128Extend(shapeI8x16, false, false), ) case wasm.OpcodeVecI32x4ExtendLowI16x8S: c.emit( - NewOperationV128Extend(ShapeI16x8, true, true), + newOperationV128Extend(shapeI16x8, true, true), ) case wasm.OpcodeVecI32x4ExtendHighI16x8S: c.emit( - NewOperationV128Extend(ShapeI16x8, true, false), + newOperationV128Extend(shapeI16x8, true, false), ) case wasm.OpcodeVecI32x4ExtendLowI16x8U: c.emit( - NewOperationV128Extend(ShapeI16x8, false, true), + newOperationV128Extend(shapeI16x8, false, true), ) case wasm.OpcodeVecI32x4ExtendHighI16x8U: c.emit( - NewOperationV128Extend(ShapeI16x8, false, false), + newOperationV128Extend(shapeI16x8, false, false), ) case wasm.OpcodeVecI64x2ExtendLowI32x4S: c.emit( - NewOperationV128Extend(ShapeI32x4, true, true), + newOperationV128Extend(shapeI32x4, true, true), ) case wasm.OpcodeVecI64x2ExtendHighI32x4S: c.emit( - NewOperationV128Extend(ShapeI32x4, true, false), + newOperationV128Extend(shapeI32x4, true, false), ) case wasm.OpcodeVecI64x2ExtendLowI32x4U: c.emit( - NewOperationV128Extend(ShapeI32x4, false, true), + newOperationV128Extend(shapeI32x4, false, true), ) case wasm.OpcodeVecI64x2ExtendHighI32x4U: c.emit( - NewOperationV128Extend(ShapeI32x4, false, false), + newOperationV128Extend(shapeI32x4, false, false), ) case wasm.OpcodeVecI16x8Q15mulrSatS: c.emit( - NewOperationV128Q15mulrSatS(), + newOperationV128Q15mulrSatS(), ) case wasm.OpcodeVecI16x8ExtMulLowI8x16S: c.emit( - NewOperationV128ExtMul(ShapeI8x16, true, true), + newOperationV128ExtMul(shapeI8x16, true, true), ) case wasm.OpcodeVecI16x8ExtMulHighI8x16S: c.emit( - NewOperationV128ExtMul(ShapeI8x16, true, false), + newOperationV128ExtMul(shapeI8x16, true, false), ) case wasm.OpcodeVecI16x8ExtMulLowI8x16U: c.emit( - NewOperationV128ExtMul(ShapeI8x16, false, true), + newOperationV128ExtMul(shapeI8x16, false, true), ) case wasm.OpcodeVecI16x8ExtMulHighI8x16U: c.emit( - NewOperationV128ExtMul(ShapeI8x16, false, false), + newOperationV128ExtMul(shapeI8x16, false, false), ) case wasm.OpcodeVecI32x4ExtMulLowI16x8S: c.emit( - NewOperationV128ExtMul(ShapeI16x8, true, true), + newOperationV128ExtMul(shapeI16x8, true, true), ) case wasm.OpcodeVecI32x4ExtMulHighI16x8S: c.emit( - NewOperationV128ExtMul(ShapeI16x8, true, false), + newOperationV128ExtMul(shapeI16x8, true, false), ) case wasm.OpcodeVecI32x4ExtMulLowI16x8U: c.emit( - NewOperationV128ExtMul(ShapeI16x8, false, true), + newOperationV128ExtMul(shapeI16x8, false, true), ) case wasm.OpcodeVecI32x4ExtMulHighI16x8U: c.emit( - NewOperationV128ExtMul(ShapeI16x8, false, false), + newOperationV128ExtMul(shapeI16x8, false, false), ) case wasm.OpcodeVecI64x2ExtMulLowI32x4S: c.emit( - NewOperationV128ExtMul(ShapeI32x4, true, true), + newOperationV128ExtMul(shapeI32x4, true, true), ) case wasm.OpcodeVecI64x2ExtMulHighI32x4S: c.emit( - NewOperationV128ExtMul(ShapeI32x4, true, false), + newOperationV128ExtMul(shapeI32x4, true, false), ) case wasm.OpcodeVecI64x2ExtMulLowI32x4U: c.emit( - NewOperationV128ExtMul(ShapeI32x4, false, true), + newOperationV128ExtMul(shapeI32x4, false, true), ) case wasm.OpcodeVecI64x2ExtMulHighI32x4U: c.emit( - NewOperationV128ExtMul(ShapeI32x4, false, false), + newOperationV128ExtMul(shapeI32x4, false, false), ) case wasm.OpcodeVecI16x8ExtaddPairwiseI8x16S: c.emit( - NewOperationV128ExtAddPairwise(ShapeI8x16, true), + newOperationV128ExtAddPairwise(shapeI8x16, true), ) case wasm.OpcodeVecI16x8ExtaddPairwiseI8x16U: c.emit( - NewOperationV128ExtAddPairwise(ShapeI8x16, false), + newOperationV128ExtAddPairwise(shapeI8x16, false), ) case wasm.OpcodeVecI32x4ExtaddPairwiseI16x8S: c.emit( - NewOperationV128ExtAddPairwise(ShapeI16x8, true), + newOperationV128ExtAddPairwise(shapeI16x8, true), ) case wasm.OpcodeVecI32x4ExtaddPairwiseI16x8U: c.emit( - NewOperationV128ExtAddPairwise(ShapeI16x8, false), + newOperationV128ExtAddPairwise(shapeI16x8, false), ) case wasm.OpcodeVecF64x2PromoteLowF32x4Zero: c.emit( - NewOperationV128FloatPromote(), + newOperationV128FloatPromote(), ) case wasm.OpcodeVecF32x4DemoteF64x2Zero: c.emit( - NewOperationV128FloatDemote(), + newOperationV128FloatDemote(), ) case wasm.OpcodeVecF32x4ConvertI32x4S: c.emit( - NewOperationV128FConvertFromI(ShapeF32x4, true), + newOperationV128FConvertFromI(shapeF32x4, true), ) case wasm.OpcodeVecF32x4ConvertI32x4U: c.emit( - NewOperationV128FConvertFromI(ShapeF32x4, false), + newOperationV128FConvertFromI(shapeF32x4, false), ) case wasm.OpcodeVecF64x2ConvertLowI32x4S: c.emit( - NewOperationV128FConvertFromI(ShapeF64x2, true), + newOperationV128FConvertFromI(shapeF64x2, true), ) case wasm.OpcodeVecF64x2ConvertLowI32x4U: c.emit( - NewOperationV128FConvertFromI(ShapeF64x2, false), + newOperationV128FConvertFromI(shapeF64x2, false), ) case wasm.OpcodeVecI32x4DotI16x8S: c.emit( - NewOperationV128Dot(), + newOperationV128Dot(), ) case wasm.OpcodeVecI8x16NarrowI16x8S: c.emit( - NewOperationV128Narrow(ShapeI16x8, true), + newOperationV128Narrow(shapeI16x8, true), ) case wasm.OpcodeVecI8x16NarrowI16x8U: c.emit( - NewOperationV128Narrow(ShapeI16x8, false), + newOperationV128Narrow(shapeI16x8, false), ) case wasm.OpcodeVecI16x8NarrowI32x4S: c.emit( - NewOperationV128Narrow(ShapeI32x4, true), + newOperationV128Narrow(shapeI32x4, true), ) case wasm.OpcodeVecI16x8NarrowI32x4U: c.emit( - NewOperationV128Narrow(ShapeI32x4, false), + newOperationV128Narrow(shapeI32x4, false), ) case wasm.OpcodeVecI32x4TruncSatF32x4S: c.emit( - NewOperationV128ITruncSatFromF(ShapeF32x4, true), + newOperationV128ITruncSatFromF(shapeF32x4, true), ) case wasm.OpcodeVecI32x4TruncSatF32x4U: c.emit( - NewOperationV128ITruncSatFromF(ShapeF32x4, false), + newOperationV128ITruncSatFromF(shapeF32x4, false), ) case wasm.OpcodeVecI32x4TruncSatF64x2SZero: c.emit( - NewOperationV128ITruncSatFromF(ShapeF64x2, true), + newOperationV128ITruncSatFromF(shapeF64x2, true), ) case wasm.OpcodeVecI32x4TruncSatF64x2UZero: c.emit( - NewOperationV128ITruncSatFromF(ShapeF64x2, false), + newOperationV128ITruncSatFromF(shapeF64x2, false), ) default: - return fmt.Errorf("unsupported vector instruction in wazeroir: %s", wasm.VectorInstructionName(vecOp)) + return fmt.Errorf("unsupported vector instruction in interpreterir: %s", wasm.VectorInstructionName(vecOp)) } case wasm.OpcodeAtomicPrefix: c.pc++ @@ -2882,7 +2882,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicMemoryWait(UnsignedTypeI32, imm), + newOperationAtomicMemoryWait(unsignedTypeI32, imm), ) case wasm.OpcodeAtomicMemoryWait64: imm, err := c.readMemoryArg(wasm.OpcodeAtomicMemoryWait64Name) @@ -2890,7 +2890,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicMemoryWait(UnsignedTypeI64, imm), + newOperationAtomicMemoryWait(unsignedTypeI64, imm), ) case wasm.OpcodeAtomicMemoryNotify: imm, err := c.readMemoryArg(wasm.OpcodeAtomicMemoryNotifyName) @@ -2898,14 +2898,14 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicMemoryNotify(imm), + newOperationAtomicMemoryNotify(imm), ) case wasm.OpcodeAtomicFence: // Skip immediate value c.pc++ _ = c.body[c.pc] c.emit( - NewOperationAtomicFence(), + newOperationAtomicFence(), ) case wasm.OpcodeAtomicI32Load: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI32LoadName) @@ -2913,7 +2913,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicLoad(UnsignedTypeI32, imm), + newOperationAtomicLoad(unsignedTypeI32, imm), ) case wasm.OpcodeAtomicI64Load: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64LoadName) @@ -2921,7 +2921,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicLoad(UnsignedTypeI64, imm), + newOperationAtomicLoad(unsignedTypeI64, imm), ) case wasm.OpcodeAtomicI32Load8U: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI32Load8UName) @@ -2929,7 +2929,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicLoad8(UnsignedTypeI32, imm), + newOperationAtomicLoad8(unsignedTypeI32, imm), ) case wasm.OpcodeAtomicI32Load16U: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI32Load16UName) @@ -2937,7 +2937,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicLoad16(UnsignedTypeI32, imm), + newOperationAtomicLoad16(unsignedTypeI32, imm), ) case wasm.OpcodeAtomicI64Load8U: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64Load8UName) @@ -2945,7 +2945,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicLoad8(UnsignedTypeI64, imm), + newOperationAtomicLoad8(unsignedTypeI64, imm), ) case wasm.OpcodeAtomicI64Load16U: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64Load16UName) @@ -2953,7 +2953,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicLoad16(UnsignedTypeI64, imm), + newOperationAtomicLoad16(unsignedTypeI64, imm), ) case wasm.OpcodeAtomicI64Load32U: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64Load32UName) @@ -2961,7 +2961,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicLoad(UnsignedTypeI32, imm), + newOperationAtomicLoad(unsignedTypeI32, imm), ) case wasm.OpcodeAtomicI32Store: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI32StoreName) @@ -2969,7 +2969,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicStore(UnsignedTypeI32, imm), + newOperationAtomicStore(unsignedTypeI32, imm), ) case wasm.OpcodeAtomicI32Store8: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI32Store8Name) @@ -2977,7 +2977,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicStore8(UnsignedTypeI32, imm), + newOperationAtomicStore8(unsignedTypeI32, imm), ) case wasm.OpcodeAtomicI32Store16: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI32Store16Name) @@ -2985,7 +2985,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicStore16(UnsignedTypeI32, imm), + newOperationAtomicStore16(unsignedTypeI32, imm), ) case wasm.OpcodeAtomicI64Store: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64StoreName) @@ -2993,7 +2993,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicStore(UnsignedTypeI64, imm), + newOperationAtomicStore(unsignedTypeI64, imm), ) case wasm.OpcodeAtomicI64Store8: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64Store8Name) @@ -3001,7 +3001,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicStore8(UnsignedTypeI64, imm), + newOperationAtomicStore8(unsignedTypeI64, imm), ) case wasm.OpcodeAtomicI64Store16: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64Store16Name) @@ -3009,7 +3009,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicStore16(UnsignedTypeI64, imm), + newOperationAtomicStore16(unsignedTypeI64, imm), ) case wasm.OpcodeAtomicI64Store32: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64Store32Name) @@ -3017,7 +3017,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicStore(UnsignedTypeI32, imm), + newOperationAtomicStore(unsignedTypeI32, imm), ) case wasm.OpcodeAtomicI32RmwAdd: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI32RmwAddName) @@ -3025,7 +3025,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW(UnsignedTypeI32, imm, AtomicArithmeticOpAdd), + newOperationAtomicRMW(unsignedTypeI32, imm, atomicArithmeticOpAdd), ) case wasm.OpcodeAtomicI64RmwAdd: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64RmwAddName) @@ -3033,7 +3033,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW(UnsignedTypeI64, imm, AtomicArithmeticOpAdd), + newOperationAtomicRMW(unsignedTypeI64, imm, atomicArithmeticOpAdd), ) case wasm.OpcodeAtomicI32Rmw8AddU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI32Rmw8AddUName) @@ -3041,7 +3041,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW8(UnsignedTypeI32, imm, AtomicArithmeticOpAdd), + newOperationAtomicRMW8(unsignedTypeI32, imm, atomicArithmeticOpAdd), ) case wasm.OpcodeAtomicI64Rmw8AddU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64Rmw8AddUName) @@ -3049,7 +3049,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW8(UnsignedTypeI64, imm, AtomicArithmeticOpAdd), + newOperationAtomicRMW8(unsignedTypeI64, imm, atomicArithmeticOpAdd), ) case wasm.OpcodeAtomicI32Rmw16AddU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI32Rmw16AddUName) @@ -3057,7 +3057,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW16(UnsignedTypeI32, imm, AtomicArithmeticOpAdd), + newOperationAtomicRMW16(unsignedTypeI32, imm, atomicArithmeticOpAdd), ) case wasm.OpcodeAtomicI64Rmw16AddU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64Rmw16AddUName) @@ -3065,7 +3065,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW16(UnsignedTypeI64, imm, AtomicArithmeticOpAdd), + newOperationAtomicRMW16(unsignedTypeI64, imm, atomicArithmeticOpAdd), ) case wasm.OpcodeAtomicI64Rmw32AddU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64Rmw32AddUName) @@ -3073,7 +3073,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW(UnsignedTypeI32, imm, AtomicArithmeticOpAdd), + newOperationAtomicRMW(unsignedTypeI32, imm, atomicArithmeticOpAdd), ) case wasm.OpcodeAtomicI32RmwSub: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI32RmwSubName) @@ -3081,7 +3081,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW(UnsignedTypeI32, imm, AtomicArithmeticOpSub), + newOperationAtomicRMW(unsignedTypeI32, imm, atomicArithmeticOpSub), ) case wasm.OpcodeAtomicI64RmwSub: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64RmwSubName) @@ -3089,7 +3089,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW(UnsignedTypeI64, imm, AtomicArithmeticOpSub), + newOperationAtomicRMW(unsignedTypeI64, imm, atomicArithmeticOpSub), ) case wasm.OpcodeAtomicI32Rmw8SubU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI32Rmw8SubUName) @@ -3097,7 +3097,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW8(UnsignedTypeI32, imm, AtomicArithmeticOpSub), + newOperationAtomicRMW8(unsignedTypeI32, imm, atomicArithmeticOpSub), ) case wasm.OpcodeAtomicI64Rmw8SubU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64Rmw8SubUName) @@ -3105,7 +3105,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW8(UnsignedTypeI64, imm, AtomicArithmeticOpSub), + newOperationAtomicRMW8(unsignedTypeI64, imm, atomicArithmeticOpSub), ) case wasm.OpcodeAtomicI32Rmw16SubU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI32Rmw16SubUName) @@ -3113,7 +3113,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW16(UnsignedTypeI32, imm, AtomicArithmeticOpSub), + newOperationAtomicRMW16(unsignedTypeI32, imm, atomicArithmeticOpSub), ) case wasm.OpcodeAtomicI64Rmw16SubU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64Rmw16SubUName) @@ -3121,7 +3121,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW16(UnsignedTypeI64, imm, AtomicArithmeticOpSub), + newOperationAtomicRMW16(unsignedTypeI64, imm, atomicArithmeticOpSub), ) case wasm.OpcodeAtomicI64Rmw32SubU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64Rmw32SubUName) @@ -3129,7 +3129,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW(UnsignedTypeI32, imm, AtomicArithmeticOpSub), + newOperationAtomicRMW(unsignedTypeI32, imm, atomicArithmeticOpSub), ) case wasm.OpcodeAtomicI32RmwAnd: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI32RmwAndName) @@ -3137,7 +3137,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW(UnsignedTypeI32, imm, AtomicArithmeticOpAnd), + newOperationAtomicRMW(unsignedTypeI32, imm, atomicArithmeticOpAnd), ) case wasm.OpcodeAtomicI64RmwAnd: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64RmwAndName) @@ -3145,7 +3145,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW(UnsignedTypeI64, imm, AtomicArithmeticOpAnd), + newOperationAtomicRMW(unsignedTypeI64, imm, atomicArithmeticOpAnd), ) case wasm.OpcodeAtomicI32Rmw8AndU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI32Rmw8AndUName) @@ -3153,7 +3153,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW8(UnsignedTypeI32, imm, AtomicArithmeticOpAnd), + newOperationAtomicRMW8(unsignedTypeI32, imm, atomicArithmeticOpAnd), ) case wasm.OpcodeAtomicI64Rmw8AndU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64Rmw8AndUName) @@ -3161,7 +3161,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW8(UnsignedTypeI64, imm, AtomicArithmeticOpAnd), + newOperationAtomicRMW8(unsignedTypeI64, imm, atomicArithmeticOpAnd), ) case wasm.OpcodeAtomicI32Rmw16AndU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI32Rmw16AndUName) @@ -3169,7 +3169,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW16(UnsignedTypeI32, imm, AtomicArithmeticOpAnd), + newOperationAtomicRMW16(unsignedTypeI32, imm, atomicArithmeticOpAnd), ) case wasm.OpcodeAtomicI64Rmw16AndU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64Rmw16AndUName) @@ -3177,7 +3177,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW16(UnsignedTypeI64, imm, AtomicArithmeticOpAnd), + newOperationAtomicRMW16(unsignedTypeI64, imm, atomicArithmeticOpAnd), ) case wasm.OpcodeAtomicI64Rmw32AndU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64Rmw32AndUName) @@ -3185,7 +3185,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW(UnsignedTypeI32, imm, AtomicArithmeticOpAnd), + newOperationAtomicRMW(unsignedTypeI32, imm, atomicArithmeticOpAnd), ) case wasm.OpcodeAtomicI32RmwOr: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI32RmwOrName) @@ -3193,7 +3193,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW(UnsignedTypeI32, imm, AtomicArithmeticOpOr), + newOperationAtomicRMW(unsignedTypeI32, imm, atomicArithmeticOpOr), ) case wasm.OpcodeAtomicI64RmwOr: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64RmwOrName) @@ -3201,7 +3201,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW(UnsignedTypeI64, imm, AtomicArithmeticOpOr), + newOperationAtomicRMW(unsignedTypeI64, imm, atomicArithmeticOpOr), ) case wasm.OpcodeAtomicI32Rmw8OrU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI32Rmw8OrUName) @@ -3209,7 +3209,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW8(UnsignedTypeI32, imm, AtomicArithmeticOpOr), + newOperationAtomicRMW8(unsignedTypeI32, imm, atomicArithmeticOpOr), ) case wasm.OpcodeAtomicI64Rmw8OrU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64Rmw8OrUName) @@ -3217,7 +3217,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW8(UnsignedTypeI64, imm, AtomicArithmeticOpOr), + newOperationAtomicRMW8(unsignedTypeI64, imm, atomicArithmeticOpOr), ) case wasm.OpcodeAtomicI32Rmw16OrU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI32Rmw16OrUName) @@ -3225,7 +3225,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW16(UnsignedTypeI32, imm, AtomicArithmeticOpOr), + newOperationAtomicRMW16(unsignedTypeI32, imm, atomicArithmeticOpOr), ) case wasm.OpcodeAtomicI64Rmw16OrU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64Rmw16OrUName) @@ -3233,7 +3233,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW16(UnsignedTypeI64, imm, AtomicArithmeticOpOr), + newOperationAtomicRMW16(unsignedTypeI64, imm, atomicArithmeticOpOr), ) case wasm.OpcodeAtomicI64Rmw32OrU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64Rmw32OrUName) @@ -3241,7 +3241,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW(UnsignedTypeI32, imm, AtomicArithmeticOpOr), + newOperationAtomicRMW(unsignedTypeI32, imm, atomicArithmeticOpOr), ) case wasm.OpcodeAtomicI32RmwXor: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI32RmwXorName) @@ -3249,7 +3249,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW(UnsignedTypeI32, imm, AtomicArithmeticOpXor), + newOperationAtomicRMW(unsignedTypeI32, imm, atomicArithmeticOpXor), ) case wasm.OpcodeAtomicI64RmwXor: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64RmwXorName) @@ -3257,7 +3257,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW(UnsignedTypeI64, imm, AtomicArithmeticOpXor), + newOperationAtomicRMW(unsignedTypeI64, imm, atomicArithmeticOpXor), ) case wasm.OpcodeAtomicI32Rmw8XorU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI32Rmw8XorUName) @@ -3265,7 +3265,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW8(UnsignedTypeI32, imm, AtomicArithmeticOpXor), + newOperationAtomicRMW8(unsignedTypeI32, imm, atomicArithmeticOpXor), ) case wasm.OpcodeAtomicI64Rmw8XorU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64Rmw8XorUName) @@ -3273,7 +3273,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW8(UnsignedTypeI64, imm, AtomicArithmeticOpXor), + newOperationAtomicRMW8(unsignedTypeI64, imm, atomicArithmeticOpXor), ) case wasm.OpcodeAtomicI32Rmw16XorU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI32Rmw16XorUName) @@ -3281,7 +3281,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW16(UnsignedTypeI32, imm, AtomicArithmeticOpXor), + newOperationAtomicRMW16(unsignedTypeI32, imm, atomicArithmeticOpXor), ) case wasm.OpcodeAtomicI64Rmw16XorU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64Rmw16XorUName) @@ -3289,7 +3289,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW16(UnsignedTypeI64, imm, AtomicArithmeticOpXor), + newOperationAtomicRMW16(unsignedTypeI64, imm, atomicArithmeticOpXor), ) case wasm.OpcodeAtomicI64Rmw32XorU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64Rmw32XorUName) @@ -3297,7 +3297,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW(UnsignedTypeI32, imm, AtomicArithmeticOpXor), + newOperationAtomicRMW(unsignedTypeI32, imm, atomicArithmeticOpXor), ) case wasm.OpcodeAtomicI32RmwXchg: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI32RmwXchgName) @@ -3305,7 +3305,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW(UnsignedTypeI32, imm, AtomicArithmeticOpNop), + newOperationAtomicRMW(unsignedTypeI32, imm, atomicArithmeticOpNop), ) case wasm.OpcodeAtomicI64RmwXchg: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64RmwXchgName) @@ -3313,7 +3313,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW(UnsignedTypeI64, imm, AtomicArithmeticOpNop), + newOperationAtomicRMW(unsignedTypeI64, imm, atomicArithmeticOpNop), ) case wasm.OpcodeAtomicI32Rmw8XchgU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI32Rmw8XchgUName) @@ -3321,7 +3321,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW8(UnsignedTypeI32, imm, AtomicArithmeticOpNop), + newOperationAtomicRMW8(unsignedTypeI32, imm, atomicArithmeticOpNop), ) case wasm.OpcodeAtomicI64Rmw8XchgU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64Rmw8XchgUName) @@ -3329,7 +3329,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW8(UnsignedTypeI64, imm, AtomicArithmeticOpNop), + newOperationAtomicRMW8(unsignedTypeI64, imm, atomicArithmeticOpNop), ) case wasm.OpcodeAtomicI32Rmw16XchgU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI32Rmw16XchgUName) @@ -3337,7 +3337,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW16(UnsignedTypeI32, imm, AtomicArithmeticOpNop), + newOperationAtomicRMW16(unsignedTypeI32, imm, atomicArithmeticOpNop), ) case wasm.OpcodeAtomicI64Rmw16XchgU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64Rmw16XchgUName) @@ -3345,7 +3345,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW16(UnsignedTypeI64, imm, AtomicArithmeticOpNop), + newOperationAtomicRMW16(unsignedTypeI64, imm, atomicArithmeticOpNop), ) case wasm.OpcodeAtomicI64Rmw32XchgU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64Rmw32XchgUName) @@ -3353,7 +3353,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW(UnsignedTypeI32, imm, AtomicArithmeticOpNop), + newOperationAtomicRMW(unsignedTypeI32, imm, atomicArithmeticOpNop), ) case wasm.OpcodeAtomicI32RmwCmpxchg: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI32RmwCmpxchgName) @@ -3361,7 +3361,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMWCmpxchg(UnsignedTypeI32, imm), + newOperationAtomicRMWCmpxchg(unsignedTypeI32, imm), ) case wasm.OpcodeAtomicI64RmwCmpxchg: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64RmwCmpxchgName) @@ -3369,7 +3369,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMWCmpxchg(UnsignedTypeI64, imm), + newOperationAtomicRMWCmpxchg(unsignedTypeI64, imm), ) case wasm.OpcodeAtomicI32Rmw8CmpxchgU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI32Rmw8CmpxchgUName) @@ -3377,7 +3377,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW8Cmpxchg(UnsignedTypeI32, imm), + newOperationAtomicRMW8Cmpxchg(unsignedTypeI32, imm), ) case wasm.OpcodeAtomicI64Rmw8CmpxchgU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64Rmw8CmpxchgUName) @@ -3385,7 +3385,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW8Cmpxchg(UnsignedTypeI64, imm), + newOperationAtomicRMW8Cmpxchg(unsignedTypeI64, imm), ) case wasm.OpcodeAtomicI32Rmw16CmpxchgU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI32Rmw16CmpxchgUName) @@ -3393,7 +3393,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW16Cmpxchg(UnsignedTypeI32, imm), + newOperationAtomicRMW16Cmpxchg(unsignedTypeI32, imm), ) case wasm.OpcodeAtomicI64Rmw16CmpxchgU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64Rmw16CmpxchgUName) @@ -3401,7 +3401,7 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMW16Cmpxchg(UnsignedTypeI64, imm), + newOperationAtomicRMW16Cmpxchg(unsignedTypeI64, imm), ) case wasm.OpcodeAtomicI64Rmw32CmpxchgU: imm, err := c.readMemoryArg(wasm.OpcodeAtomicI64Rmw32CmpxchgUName) @@ -3409,13 +3409,13 @@ operatorSwitch: return err } c.emit( - NewOperationAtomicRMWCmpxchg(UnsignedTypeI32, imm), + newOperationAtomicRMWCmpxchg(unsignedTypeI32, imm), ) default: - return fmt.Errorf("unsupported atomic instruction in wazeroir: %s", wasm.AtomicInstructionName(atomicOp)) + return fmt.Errorf("unsupported atomic instruction in interpreterir: %s", wasm.AtomicInstructionName(atomicOp)) } default: - return fmt.Errorf("unsupported instruction in wazeroir: 0x%x", op) + return fmt.Errorf("unsupported instruction in interpreterir: 0x%x", op) } // Move the program counter to point to the next instruction. @@ -3423,13 +3423,13 @@ operatorSwitch: return nil } -func (c *Compiler) nextFrameID() (id uint32) { +func (c *compiler) nextFrameID() (id uint32) { id = c.currentFrameID + 1 c.currentFrameID++ return } -func (c *Compiler) applyToStack(opcode wasm.Opcode) (index uint32, err error) { +func (c *compiler) applyToStack(opcode wasm.Opcode) (index uint32, err error) { switch opcode { case // These are the opcodes that is coupled with "index" immediate @@ -3470,14 +3470,14 @@ func (c *Compiler) applyToStack(opcode wasm.Opcode) (index uint32, err error) { // the unknown type is unique in the signature, // and is determined by the actual type on the stack. // The determined type is stored in this typeParam. - var typeParam UnsignedType + var typeParam unsignedType var typeParamFound bool for i := range s.in { want := s.in[len(s.in)-1-i] actual := c.stackPop() - if want == UnsignedTypeUnknown && typeParamFound { + if want == unsignedTypeUnknown && typeParamFound { want = typeParam - } else if want == UnsignedTypeUnknown { + } else if want == unsignedTypeUnknown { want = actual typeParam = want typeParamFound = true @@ -3488,9 +3488,9 @@ func (c *Compiler) applyToStack(opcode wasm.Opcode) (index uint32, err error) { } for _, target := range s.out { - if target == UnsignedTypeUnknown && !typeParamFound { + if target == unsignedTypeUnknown && !typeParamFound { return 0, fmt.Errorf("cannot determine type of unknown result") - } else if target == UnsignedTypeUnknown { + } else if target == unsignedTypeUnknown { c.stackPush(typeParam) } else { c.stackPush(target) @@ -3500,12 +3500,12 @@ func (c *Compiler) applyToStack(opcode wasm.Opcode) (index uint32, err error) { return index, nil } -func (c *Compiler) stackPeek() (ret UnsignedType) { +func (c *compiler) stackPeek() (ret unsignedType) { ret = c.stack[len(c.stack)-1] return } -func (c *Compiler) stackPop() (ret UnsignedType) { +func (c *compiler) stackPop() (ret unsignedType) { // No need to check stack bound // as we can assume that all the operations // are valid thanks to validateFunction @@ -3515,15 +3515,15 @@ func (c *Compiler) stackPop() (ret UnsignedType) { return } -func (c *Compiler) stackPush(ts UnsignedType) { +func (c *compiler) stackPush(ts unsignedType) { c.stack = append(c.stack, ts) } // emit adds the operations into the result. -func (c *Compiler) emit(op UnionOperation) { +func (c *compiler) emit(op unionOperation) { if !c.unreachableState.on { switch op.Kind { - case OperationKindDrop: + case operationKindDrop: // If the drop range is nil, // we could remove such operations. // That happens when drop operation is unnecessary. @@ -3541,34 +3541,34 @@ func (c *Compiler) emit(op UnionOperation) { } // Emit const expression with default values of the given type. -func (c *Compiler) emitDefaultValue(t wasm.ValueType) { +func (c *compiler) emitDefaultValue(t wasm.ValueType) { switch t { case wasm.ValueTypeI32: - c.stackPush(UnsignedTypeI32) - c.emit(NewOperationConstI32(0)) + c.stackPush(unsignedTypeI32) + c.emit(newOperationConstI32(0)) case wasm.ValueTypeI64, wasm.ValueTypeExternref, wasm.ValueTypeFuncref: - c.stackPush(UnsignedTypeI64) - c.emit(NewOperationConstI64(0)) + c.stackPush(unsignedTypeI64) + c.emit(newOperationConstI64(0)) case wasm.ValueTypeF32: - c.stackPush(UnsignedTypeF32) - c.emit(NewOperationConstF32(0)) + c.stackPush(unsignedTypeF32) + c.emit(newOperationConstF32(0)) case wasm.ValueTypeF64: - c.stackPush(UnsignedTypeF64) - c.emit(NewOperationConstF64(0)) + c.stackPush(unsignedTypeF64) + c.emit(newOperationConstF64(0)) case wasm.ValueTypeV128: - c.stackPush(UnsignedTypeV128) - c.emit(NewOperationV128Const(0, 0)) + c.stackPush(unsignedTypeV128) + c.emit(newOperationV128Const(0, 0)) } } // Returns the "depth" (starting from top of the stack) // of the n-th local. -func (c *Compiler) localDepth(index wasm.Index) int { +func (c *compiler) localDepth(index wasm.Index) int { height := c.localIndexToStackHeightInUint64[index] return c.stackLenInUint64(len(c.stack)) - 1 - int(height) } -func (c *Compiler) localType(index wasm.Index) (t wasm.ValueType) { +func (c *compiler) localType(index wasm.Index) (t wasm.ValueType) { if params := uint32(len(c.sig.Params)); index < params { t = c.sig.Params[index] } else { @@ -3582,7 +3582,7 @@ func (c *Compiler) localType(index wasm.Index) (t wasm.ValueType) { // // * frame is the control frame which the call-site is trying to branch into or exit. // * isEnd true if the call-site is handling wasm.OpcodeEnd. -func (c *Compiler) getFrameDropRange(frame *controlFrame, isEnd bool) InclusiveRange { +func (c *compiler) getFrameDropRange(frame *controlFrame, isEnd bool) inclusiveRange { var start int if !isEnd && frame.kind == controlFrameKindLoop { // If this is not End and the call-site is trying to branch into the Loop control frame, @@ -3601,15 +3601,15 @@ func (c *Compiler) getFrameDropRange(frame *controlFrame, isEnd bool) InclusiveR end = c.stackLenInUint64(len(c.stack)) - 1 - c.stackLenInUint64(frame.originalStackLenWithoutParam) } if start <= end { - return InclusiveRange{Start: int32(start), End: int32(end)} + return inclusiveRange{Start: int32(start), End: int32(end)} } else { - return NopInclusiveRange + return nopinclusiveRange } } -func (c *Compiler) stackLenInUint64(ceil int) (ret int) { +func (c *compiler) stackLenInUint64(ceil int) (ret int) { for i := 0; i < ceil; i++ { - if c.stack[i] == UnsignedTypeV128 { + if c.stack[i] == unsignedTypeV128 { ret += 2 } else { ret++ @@ -3618,17 +3618,17 @@ func (c *Compiler) stackLenInUint64(ceil int) (ret int) { return } -func (c *Compiler) readMemoryArg(tag string) (MemoryArg, error) { +func (c *compiler) readMemoryArg(tag string) (memoryArg, error) { c.result.UsesMemory = true alignment, num, err := leb128.LoadUint32(c.body[c.pc+1:]) if err != nil { - return MemoryArg{}, fmt.Errorf("reading alignment for %s: %w", tag, err) + return memoryArg{}, fmt.Errorf("reading alignment for %s: %w", tag, err) } c.pc += num offset, num, err := leb128.LoadUint32(c.body[c.pc+1:]) if err != nil { - return MemoryArg{}, fmt.Errorf("reading offset for %s: %w", tag, err) + return memoryArg{}, fmt.Errorf("reading offset for %s: %w", tag, err) } c.pc += num - return MemoryArg{Offset: offset, Alignment: alignment}, nil + return memoryArg{Offset: offset, Alignment: alignment}, nil } diff --git a/internal/wazeroir/compiler_test.go b/internal/engine/interpreter/compiler_test.go similarity index 69% rename from internal/wazeroir/compiler_test.go rename to internal/engine/interpreter/compiler_test.go index 90a3742dfd..a0c72881c7 100644 --- a/internal/wazeroir/compiler_test.go +++ b/internal/engine/interpreter/compiler_test.go @@ -1,4 +1,4 @@ -package wazeroir +package interpreter import ( "fmt" @@ -12,9 +12,9 @@ import ( ) var ( - f32, f64, i32 = wasm.ValueTypeF32, wasm.ValueTypeF64, wasm.ValueTypeI32 - f32_i32 = wasm.FunctionType{ - Params: []wasm.ValueType{f32}, Results: []wasm.ValueType{i32}, + wf32, wf64, i32 = wasm.ValueTypeF32, wasm.ValueTypeF64, wasm.ValueTypeI32 + f32_i32 = wasm.FunctionType{ + Params: []wasm.ValueType{wf32}, Results: []wasm.ValueType{i32}, ParamNumInUint64: 1, ResultNumInUint64: 1, } @@ -29,14 +29,14 @@ var ( ResultNumInUint64: 1, } v_v = wasm.FunctionType{} - v_f64f64 = wasm.FunctionType{Results: []wasm.ValueType{f64, f64}, ResultNumInUint64: 2} + v_f64f64 = wasm.FunctionType{Results: []wasm.ValueType{wf64, wf64}, ResultNumInUint64: 2} ) func TestCompile(t *testing.T) { tests := []struct { name string module *wasm.Module - expected *CompilationResult + expected *compilationResult enabledFeatures api.CoreFeatures }{ { @@ -46,11 +46,11 @@ func TestCompile(t *testing.T) { FunctionSection: []wasm.Index{0}, CodeSection: []wasm.Code{{Body: []byte{wasm.OpcodeEnd}}}, }, - expected: &CompilationResult{ - Operations: []UnionOperation{ // begin with params: [] - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + expected: &compilationResult{ + Operations: []unionOperation{ // begin with params: [] + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, - LabelCallers: map[Label]uint32{}, + LabelCallers: map[label]uint32{}, Functions: []uint32{0}, Types: []wasm.FunctionType{v_v}, }, @@ -62,11 +62,11 @@ func TestCompile(t *testing.T) { FunctionSection: []wasm.Index{0}, CodeSection: []wasm.Code{{Body: []byte{wasm.OpcodeEnd}}}, }, - expected: &CompilationResult{ - Operations: []UnionOperation{ // begin with params: [] - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + expected: &compilationResult{ + Operations: []unionOperation{ // begin with params: [] + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, - LabelCallers: map[Label]uint32{}, + LabelCallers: map[label]uint32{}, Functions: []uint32{0}, Types: []wasm.FunctionType{v_v}, }, @@ -78,13 +78,13 @@ func TestCompile(t *testing.T) { FunctionSection: []wasm.Index{0}, CodeSection: []wasm.Code{{Body: []byte{wasm.OpcodeLocalGet, 0, wasm.OpcodeEnd}}}, }, - expected: &CompilationResult{ - Operations: []UnionOperation{ // begin with params: [$x] - NewOperationPick(0, false), // [$x, $x] - NewOperationDrop(InclusiveRange{Start: 1, End: 1}), // [$x] - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + expected: &compilationResult{ + Operations: []unionOperation{ // begin with params: [$x] + newOperationPick(0, false), // [$x, $x] + newOperationDrop(inclusiveRange{Start: 1, End: 1}), // [$x] + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, - LabelCallers: map[Label]uint32{}, + LabelCallers: map[label]uint32{}, Types: []wasm.FunctionType{ { Params: []wasm.ValueType{i32}, Results: []wasm.ValueType{i32}, @@ -107,14 +107,14 @@ func TestCompile(t *testing.T) { wasm.OpcodeEnd, }}}, }, - expected: &CompilationResult{ - Operations: []UnionOperation{ // begin with params: [] - NewOperationConstI32(8), // [8] - NewOperationLoad(UnsignedTypeI32, MemoryArg{Alignment: 2, Offset: 0}), // [x] - NewOperationDrop(InclusiveRange{}), // [] - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + expected: &compilationResult{ + Operations: []unionOperation{ // begin with params: [] + newOperationConstI32(8), // [8] + newOperationLoad(unsignedTypeI32, memoryArg{Alignment: 2, Offset: 0}), // [x] + newOperationDrop(inclusiveRange{}), // [] + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, - LabelCallers: map[Label]uint32{}, + LabelCallers: map[label]uint32{}, Types: []wasm.FunctionType{v_v}, Functions: []uint32{0}, UsesMemory: true, @@ -132,14 +132,14 @@ func TestCompile(t *testing.T) { wasm.OpcodeEnd, }}}, }, - expected: &CompilationResult{ - Operations: []UnionOperation{ // begin with params: [] - NewOperationConstI32(8), // [8] - NewOperationLoad(UnsignedTypeI32, MemoryArg{Alignment: 2, Offset: 0}), // [x] - NewOperationDrop(InclusiveRange{}), // [] - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + expected: &compilationResult{ + Operations: []unionOperation{ // begin with params: [] + newOperationConstI32(8), // [8] + newOperationLoad(unsignedTypeI32, memoryArg{Alignment: 2, Offset: 0}), // [x] + newOperationDrop(inclusiveRange{}), // [] + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, - LabelCallers: map[Label]uint32{}, + LabelCallers: map[label]uint32{}, Types: []wasm.FunctionType{v_v}, Functions: []uint32{0}, UsesMemory: true, @@ -154,14 +154,14 @@ func TestCompile(t *testing.T) { wasm.OpcodeLocalGet, 0, wasm.OpcodeMemoryGrow, 0, wasm.OpcodeEnd, }}}, }, - expected: &CompilationResult{ - Operations: []UnionOperation{ // begin with params: [$delta] - NewOperationPick(0, false), // [$delta, $delta] - NewOperationMemoryGrow(), // [$delta, $old_size] - NewOperationDrop(InclusiveRange{Start: 1, End: 1}), // [$old_size] - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + expected: &compilationResult{ + Operations: []unionOperation{ // begin with params: [$delta] + newOperationPick(0, false), // [$delta, $delta] + newOperationMemoryGrow(), // [$delta, $old_size] + newOperationDrop(inclusiveRange{Start: 1, End: 1}), // [$old_size] + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, - LabelCallers: map[Label]uint32{}, + LabelCallers: map[label]uint32{}, Types: []wasm.FunctionType{{ Params: []wasm.ValueType{i32}, Results: []wasm.ValueType{i32}, ParamNumInUint64: 1, @@ -184,7 +184,7 @@ func TestCompile(t *testing.T) { for _, tp := range tc.module.TypeSection { tp.CacheNumInUint64() } - c, err := NewCompiler(enabledFeatures, 0, tc.module, false) + c, err := newCompiler(enabledFeatures, 0, tc.module, false) require.NoError(t, err) fn, err := c.Next() @@ -198,7 +198,7 @@ func TestCompile_Block(t *testing.T) { tests := []struct { name string module *wasm.Module - expected *CompilationResult + expected *compilationResult enabledFeatures api.CoreFeatures }{ { @@ -217,16 +217,16 @@ func TestCompile_Block(t *testing.T) { }, // Above set manually until the text compiler supports this: // (func (export "type-i32-i32") (block (drop (i32.add (br 0))))) - expected: &CompilationResult{ - Operations: []UnionOperation{ // begin with params: [] - NewOperationBr(NewLabel(LabelKindContinuation, 2)), // arbitrary FrameID - NewOperationLabel(NewLabel(LabelKindContinuation, 2)), // arbitrary FrameID - NewOperationBr(NewLabel(LabelKindReturn, 0)), + expected: &compilationResult{ + Operations: []unionOperation{ // begin with params: [] + newOperationBr(newLabel(labelKindContinuation, 2)), // arbitrary FrameID + newOperationLabel(newLabel(labelKindContinuation, 2)), // arbitrary FrameID + newOperationBr(newLabel(labelKindReturn, 0)), }, // Note: i32.add comes after br 0 so is unreachable. Compilation succeeds when it feels like it // shouldn't because the br instruction is stack-polymorphic. In other words, (br 0) substitutes for the // two i32 parameters to add. - LabelCallers: map[Label]uint32{NewLabel(LabelKindContinuation, 2): 1}, + LabelCallers: map[label]uint32{newLabel(labelKindContinuation, 2): 1}, Functions: []uint32{0}, Types: []wasm.FunctionType{v_v}, }, @@ -292,24 +292,24 @@ func TestCompile_BulkMemoryOperations(t *testing.T) { }}}, } - expected := &CompilationResult{ - Operations: []UnionOperation{ // begin with params: [] - NewOperationConstI32(16), // [16] - NewOperationConstI32(0), // [16, 0] - NewOperationConstI32(7), // [16, 0, 7] - NewOperationMemoryInit(1), // [] - NewOperationDataDrop(1), // [] - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + expected := &compilationResult{ + Operations: []unionOperation{ // begin with params: [] + newOperationConstI32(16), // [16] + newOperationConstI32(0), // [16, 0] + newOperationConstI32(7), // [16, 0, 7] + newOperationMemoryInit(1), // [] + newOperationDataDrop(1), // [] + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, - Memory: MemoryTypeStandard, + Memory: memoryTypeStandard, UsesMemory: true, HasDataInstances: true, - LabelCallers: map[Label]uint32{}, + LabelCallers: map[label]uint32{}, Functions: []wasm.Index{0}, Types: []wasm.FunctionType{v_v}, } - c, err := NewCompiler(api.CoreFeatureBulkMemoryOperations, 0, module, false) + c, err := newCompiler(api.CoreFeatureBulkMemoryOperations, 0, module, false) require.NoError(t, err) actual, err := c.Next() @@ -333,7 +333,7 @@ func TestCompile_MultiValue(t *testing.T) { tests := []struct { name string module *wasm.Module - expected *CompilationResult + expected *compilationResult enabledFeatures api.CoreFeatures }{ { @@ -346,14 +346,14 @@ func TestCompile_MultiValue(t *testing.T) { wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 0, wasm.OpcodeEnd, }}}, }, - expected: &CompilationResult{ - Operations: []UnionOperation{ // begin with params: [$x, $y] - NewOperationPick(0, false), // [$x, $y, $y] - NewOperationPick(2, false), // [$x, $y, $y, $x] - NewOperationDrop(InclusiveRange{Start: 2, End: 3}), // [$y, $x] - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + expected: &compilationResult{ + Operations: []unionOperation{ // begin with params: [$x, $y] + newOperationPick(0, false), // [$x, $y, $y] + newOperationPick(2, false), // [$x, $y, $y, $x] + newOperationDrop(inclusiveRange{Start: 2, End: 3}), // [$y, $x] + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, - LabelCallers: map[Label]uint32{}, + LabelCallers: map[label]uint32{}, Functions: []wasm.Index{0}, Types: []wasm.FunctionType{i32i32_i32i32}, }, @@ -380,17 +380,17 @@ func TestCompile_MultiValue(t *testing.T) { // (f64.add (br 0 (f64.const 4) (f64.const 5))) (f64.const 6) // ) // ) - expected: &CompilationResult{ - Operations: []UnionOperation{ // begin with params: [] - NewOperationConstF64(4), // [4] - NewOperationConstF64(5), // [4, 5] - NewOperationBr(NewLabel(LabelKindContinuation, 2)), // arbitrary FrameID - NewOperationLabel(NewLabel(LabelKindContinuation, 2)), // arbitrary FrameID - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + expected: &compilationResult{ + Operations: []unionOperation{ // begin with params: [] + newOperationConstF64(4), // [4] + newOperationConstF64(5), // [4, 5] + newOperationBr(newLabel(labelKindContinuation, 2)), // arbitrary FrameID + newOperationLabel(newLabel(labelKindContinuation, 2)), // arbitrary FrameID + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, // Note: f64.add comes after br 0 so is unreachable. This is why neither the add, nor its other operand // are in the above compilation result. - LabelCallers: map[Label]uint32{NewLabel(LabelKindContinuation, 2): 1}, // arbitrary label + LabelCallers: map[label]uint32{newLabel(labelKindContinuation, 2): 1}, // arbitrary label Functions: []wasm.Index{0}, Types: []wasm.FunctionType{v_f64f64}, }, @@ -405,13 +405,13 @@ func TestCompile_MultiValue(t *testing.T) { wasm.OpcodeI32Const, 0xb2, 0x2, wasm.OpcodeI64Const, 0xe4, 0x2, wasm.OpcodeEnd, }}}, }, - expected: &CompilationResult{ - Operations: []UnionOperation{ // begin with params: [] - NewOperationConstI32(306), // [306] - NewOperationConstI64(356), // [306, 356] - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + expected: &compilationResult{ + Operations: []unionOperation{ // begin with params: [] + newOperationConstI32(306), // [306] + newOperationConstI64(356), // [306, 356] + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, - LabelCallers: map[Label]uint32{}, + LabelCallers: map[label]uint32{}, Functions: []wasm.Index{0}, Types: []wasm.FunctionType{_i32i64}, }, @@ -438,31 +438,31 @@ func TestCompile_MultiValue(t *testing.T) { // (else (i32.const -2) (i32.add)) // ) // ) - expected: &CompilationResult{ - Operations: []UnionOperation{ // begin with params: [$0] - NewOperationConstI32(1), // [$0, 1] - NewOperationPick(1, false), // [$0, 1, $0] - NewOperationBrIf( // [$0, 1] - NewLabel(LabelKindHeader, 2), - NewLabel(LabelKindElse, 2), - NopInclusiveRange, + expected: &compilationResult{ + Operations: []unionOperation{ // begin with params: [$0] + newOperationConstI32(1), // [$0, 1] + newOperationPick(1, false), // [$0, 1, $0] + newOperationBrIf( // [$0, 1] + newLabel(labelKindHeader, 2), + newLabel(labelKindElse, 2), + nopinclusiveRange, ), - NewOperationLabel(NewLabel(LabelKindHeader, 2)), - NewOperationConstI32(2), // [$0, 1, 2] - NewOperationAdd(UnsignedTypeI32), // [$0, 3] - NewOperationBr(NewLabel(LabelKindContinuation, 2)), - NewOperationLabel(NewLabel(LabelKindElse, 2)), - NewOperationConstI32(uint32(api.EncodeI32(-2))), // [$0, 1, -2] - NewOperationAdd(UnsignedTypeI32), // [$0, -1] - NewOperationBr(NewLabel(LabelKindContinuation, 2)), - NewOperationLabel(NewLabel(LabelKindContinuation, 2)), - NewOperationDrop(InclusiveRange{Start: 1, End: 1}), // .L2 = [3], .L2_else = [-1] - NewOperationBr(NewLabel(LabelKindReturn, 0)), + newOperationLabel(newLabel(labelKindHeader, 2)), + newOperationConstI32(2), // [$0, 1, 2] + newOperationAdd(unsignedTypeI32), // [$0, 3] + newOperationBr(newLabel(labelKindContinuation, 2)), + newOperationLabel(newLabel(labelKindElse, 2)), + newOperationConstI32(uint32(api.EncodeI32(-2))), // [$0, 1, -2] + newOperationAdd(unsignedTypeI32), // [$0, -1] + newOperationBr(newLabel(labelKindContinuation, 2)), + newOperationLabel(newLabel(labelKindContinuation, 2)), + newOperationDrop(inclusiveRange{Start: 1, End: 1}), // .L2 = [3], .L2_else = [-1] + newOperationBr(newLabel(labelKindReturn, 0)), }, - LabelCallers: map[Label]uint32{ - NewLabel(LabelKindHeader, 2): 1, - NewLabel(LabelKindContinuation, 2): 2, - NewLabel(LabelKindElse, 2): 1, + LabelCallers: map[label]uint32{ + newLabel(labelKindHeader, 2): 1, + newLabel(labelKindContinuation, 2): 2, + newLabel(labelKindElse, 2): 1, }, Functions: []wasm.Index{0}, Types: []wasm.FunctionType{i32_i32}, @@ -495,30 +495,30 @@ func TestCompile_MultiValue(t *testing.T) { // (else (i32.sub)) // ) // ) - expected: &CompilationResult{ - Operations: []UnionOperation{ // begin with params: [$0] - NewOperationConstI32(1), // [$0, 1] - NewOperationConstI32(2), // [$0, 1, 2] - NewOperationPick(2, false), // [$0, 1, 2, $0] - NewOperationBrIf( // [$0, 1, 2] - NewLabel(LabelKindHeader, 2), - NewLabel(LabelKindElse, 2), - NopInclusiveRange, + expected: &compilationResult{ + Operations: []unionOperation{ // begin with params: [$0] + newOperationConstI32(1), // [$0, 1] + newOperationConstI32(2), // [$0, 1, 2] + newOperationPick(2, false), // [$0, 1, 2, $0] + newOperationBrIf( // [$0, 1, 2] + newLabel(labelKindHeader, 2), + newLabel(labelKindElse, 2), + nopinclusiveRange, ), - NewOperationLabel(NewLabel(LabelKindHeader, 2)), - NewOperationAdd(UnsignedTypeI32), // [$0, 3] - NewOperationBr(NewLabel(LabelKindContinuation, 2)), - NewOperationLabel(NewLabel(LabelKindElse, 2)), - NewOperationSub(UnsignedTypeI32), // [$0, -1] - NewOperationBr(NewLabel(LabelKindContinuation, 2)), - NewOperationLabel(NewLabel(LabelKindContinuation, 2)), - NewOperationDrop(InclusiveRange{Start: 1, End: 1}), // .L2 = [3], .L2_else = [-1] - NewOperationBr(NewLabel(LabelKindReturn, 0)), + newOperationLabel(newLabel(labelKindHeader, 2)), + newOperationAdd(unsignedTypeI32), // [$0, 3] + newOperationBr(newLabel(labelKindContinuation, 2)), + newOperationLabel(newLabel(labelKindElse, 2)), + newOperationSub(unsignedTypeI32), // [$0, -1] + newOperationBr(newLabel(labelKindContinuation, 2)), + newOperationLabel(newLabel(labelKindContinuation, 2)), + newOperationDrop(inclusiveRange{Start: 1, End: 1}), // .L2 = [3], .L2_else = [-1] + newOperationBr(newLabel(labelKindReturn, 0)), }, - LabelCallers: map[Label]uint32{ - NewLabel(LabelKindHeader, 2): 1, - NewLabel(LabelKindContinuation, 2): 2, - NewLabel(LabelKindElse, 2): 1, + LabelCallers: map[label]uint32{ + newLabel(labelKindHeader, 2): 1, + newLabel(labelKindContinuation, 2): 2, + newLabel(labelKindElse, 2): 1, }, Functions: []wasm.Index{0}, Types: []wasm.FunctionType{i32_i32, i32i32_i32}, @@ -551,30 +551,30 @@ func TestCompile_MultiValue(t *testing.T) { // (else (i32.sub) (br 0)) // ) // ) - expected: &CompilationResult{ - Operations: []UnionOperation{ // begin with params: [$0] - NewOperationConstI32(1), // [$0, 1] - NewOperationConstI32(2), // [$0, 1, 2] - NewOperationPick(2, false), // [$0, 1, 2, $0] - NewOperationBrIf( // [$0, 1, 2] - NewLabel(LabelKindHeader, 2), - NewLabel(LabelKindElse, 2), - NopInclusiveRange, + expected: &compilationResult{ + Operations: []unionOperation{ // begin with params: [$0] + newOperationConstI32(1), // [$0, 1] + newOperationConstI32(2), // [$0, 1, 2] + newOperationPick(2, false), // [$0, 1, 2, $0] + newOperationBrIf( // [$0, 1, 2] + newLabel(labelKindHeader, 2), + newLabel(labelKindElse, 2), + nopinclusiveRange, ), - NewOperationLabel(NewLabel(LabelKindHeader, 2)), - NewOperationAdd(UnsignedTypeI32), // [$0, 3] - NewOperationBr(NewLabel(LabelKindContinuation, 2)), - NewOperationLabel(NewLabel(LabelKindElse, 2)), - NewOperationSub(UnsignedTypeI32), // [$0, -1] - NewOperationBr(NewLabel(LabelKindContinuation, 2)), - NewOperationLabel(NewLabel(LabelKindContinuation, 2)), - NewOperationDrop(InclusiveRange{Start: 1, End: 1}), // .L2 = [3], .L2_else = [-1] - NewOperationBr(NewLabel(LabelKindReturn, 0)), + newOperationLabel(newLabel(labelKindHeader, 2)), + newOperationAdd(unsignedTypeI32), // [$0, 3] + newOperationBr(newLabel(labelKindContinuation, 2)), + newOperationLabel(newLabel(labelKindElse, 2)), + newOperationSub(unsignedTypeI32), // [$0, -1] + newOperationBr(newLabel(labelKindContinuation, 2)), + newOperationLabel(newLabel(labelKindContinuation, 2)), + newOperationDrop(inclusiveRange{Start: 1, End: 1}), // .L2 = [3], .L2_else = [-1] + newOperationBr(newLabel(labelKindReturn, 0)), }, - LabelCallers: map[Label]uint32{ - NewLabel(LabelKindHeader, 2): 1, - NewLabel(LabelKindContinuation, 2): 2, - NewLabel(LabelKindElse, 2): 1, + LabelCallers: map[label]uint32{ + newLabel(labelKindHeader, 2): 1, + newLabel(labelKindContinuation, 2): 2, + newLabel(labelKindElse, 2): 1, }, Functions: []wasm.Index{0}, Types: []wasm.FunctionType{i32_i32, i32i32_i32}, @@ -593,7 +593,7 @@ func TestCompile_MultiValue(t *testing.T) { for _, tp := range tc.module.TypeSection { tp.CacheNumInUint64() } - c, err := NewCompiler(enabledFeatures, 0, tc.module, false) + c, err := newCompiler(enabledFeatures, 0, tc.module, false) require.NoError(t, err) actual, err := c.Next() @@ -614,22 +614,22 @@ func TestCompile_NonTrappingFloatToIntConversion(t *testing.T) { }}}, } - expected := &CompilationResult{ - Operations: []UnionOperation{ // begin with params: [$0] - NewOperationPick(0, false), // [$0, $0] - NewOperationITruncFromF( // [$0, i32.trunc_sat_f32_s($0)] - Float32, - SignedInt32, + expected := &compilationResult{ + Operations: []unionOperation{ // begin with params: [$0] + newOperationPick(0, false), // [$0, $0] + newOperationITruncFromF( // [$0, i32.trunc_sat_f32_s($0)] + f32, + signedInt32, true, ), - NewOperationDrop(InclusiveRange{Start: 1, End: 1}), // [i32.trunc_sat_f32_s($0)] - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + newOperationDrop(inclusiveRange{Start: 1, End: 1}), // [i32.trunc_sat_f32_s($0)] + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, - LabelCallers: map[Label]uint32{}, + LabelCallers: map[label]uint32{}, Functions: []wasm.Index{0}, Types: []wasm.FunctionType{f32_i32}, } - c, err := NewCompiler(api.CoreFeatureNonTrappingFloatToIntConversion, 0, module, false) + c, err := newCompiler(api.CoreFeatureNonTrappingFloatToIntConversion, 0, module, false) require.NoError(t, err) actual, err := c.Next() @@ -647,18 +647,18 @@ func TestCompile_SignExtensionOps(t *testing.T) { }}}, } - expected := &CompilationResult{ - Operations: []UnionOperation{ // begin with params: [$0] - NewOperationPick(0, false), // [$0, $0] - NewOperationSignExtend32From8(), // [$0, i32.extend8_s($0)] - NewOperationDrop(InclusiveRange{Start: 1, End: 1}), // [i32.extend8_s($0)] - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + expected := &compilationResult{ + Operations: []unionOperation{ // begin with params: [$0] + newOperationPick(0, false), // [$0, $0] + newOperationSignExtend32From8(), // [$0, i32.extend8_s($0)] + newOperationDrop(inclusiveRange{Start: 1, End: 1}), // [i32.extend8_s($0)] + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, - LabelCallers: map[Label]uint32{}, + LabelCallers: map[label]uint32{}, Functions: []wasm.Index{0}, Types: []wasm.FunctionType{i32_i32}, } - c, err := NewCompiler(api.CoreFeatureSignExtensionOps, 0, module, false) + c, err := newCompiler(api.CoreFeatureSignExtensionOps, 0, module, false) require.NoError(t, err) actual, err := c.Next() @@ -666,11 +666,11 @@ func TestCompile_SignExtensionOps(t *testing.T) { require.Equal(t, expected, actual) } -func requireCompilationResult(t *testing.T, enabledFeatures api.CoreFeatures, expected *CompilationResult, module *wasm.Module) { +func requireCompilationResult(t *testing.T, enabledFeatures api.CoreFeatures, expected *compilationResult, module *wasm.Module) { if enabledFeatures == 0 { enabledFeatures = api.CoreFeaturesV2 } - c, err := NewCompiler(enabledFeatures, 0, module, false) + c, err := newCompiler(enabledFeatures, 0, module, false) require.NoError(t, err) actual, err := c.Next() @@ -701,19 +701,19 @@ func TestCompile_CallIndirectNonZeroTableIndex(t *testing.T) { }, } - expected := &CompilationResult{ - Operations: []UnionOperation{ // begin with params: [] - NewOperationConstI32(0), - NewOperationCallIndirect(2, 5), - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + expected := &compilationResult{ + Operations: []unionOperation{ // begin with params: [] + newOperationConstI32(0), + newOperationCallIndirect(2, 5), + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, HasTable: true, - LabelCallers: map[Label]uint32{}, + LabelCallers: map[label]uint32{}, Functions: []wasm.Index{0}, Types: []wasm.FunctionType{v_v, v_v, v_v}, } - c, err := NewCompiler(api.CoreFeatureBulkMemoryOperations, 0, module, false) + c, err := newCompiler(api.CoreFeatureBulkMemoryOperations, 0, module, false) require.NoError(t, err) actual, err := c.Next() @@ -725,7 +725,7 @@ func TestCompile_Refs(t *testing.T) { tests := []struct { name string body []byte - expected []UnionOperation + expected []unionOperation }{ { name: "ref.func", @@ -734,10 +734,10 @@ func TestCompile_Refs(t *testing.T) { wasm.OpcodeDrop, wasm.OpcodeEnd, }, - expected: []UnionOperation{ - NewOperationRefFunc(100), - NewOperationDrop(InclusiveRange{Start: 0, End: 0}), - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + expected: []unionOperation{ + newOperationRefFunc(100), + newOperationDrop(inclusiveRange{Start: 0, End: 0}), + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, }, { @@ -747,10 +747,10 @@ func TestCompile_Refs(t *testing.T) { wasm.OpcodeDrop, wasm.OpcodeEnd, }, - expected: []UnionOperation{ - NewOperationConstI64(0), - NewOperationDrop(InclusiveRange{Start: 0, End: 0}), - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + expected: []unionOperation{ + newOperationConstI64(0), + newOperationDrop(inclusiveRange{Start: 0, End: 0}), + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, }, { @@ -760,10 +760,10 @@ func TestCompile_Refs(t *testing.T) { wasm.OpcodeDrop, wasm.OpcodeEnd, }, - expected: []UnionOperation{ - NewOperationConstI64(0), - NewOperationDrop(InclusiveRange{Start: 0, End: 0}), - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + expected: []unionOperation{ + newOperationConstI64(0), + newOperationDrop(inclusiveRange{Start: 0, End: 0}), + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, }, { @@ -774,11 +774,11 @@ func TestCompile_Refs(t *testing.T) { wasm.OpcodeDrop, wasm.OpcodeEnd, }, - expected: []UnionOperation{ - NewOperationRefFunc(100), - NewOperationEqz(UnsignedInt64), - NewOperationDrop(InclusiveRange{Start: 0, End: 0}), - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + expected: []unionOperation{ + newOperationRefFunc(100), + newOperationEqz(unsignedInt64), + newOperationDrop(inclusiveRange{Start: 0, End: 0}), + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, }, { @@ -789,11 +789,11 @@ func TestCompile_Refs(t *testing.T) { wasm.OpcodeDrop, wasm.OpcodeEnd, }, - expected: []UnionOperation{ - NewOperationConstI64(0), - NewOperationEqz(UnsignedInt64), - NewOperationDrop(InclusiveRange{Start: 0, End: 0}), - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + expected: []unionOperation{ + newOperationConstI64(0), + newOperationEqz(unsignedInt64), + newOperationDrop(inclusiveRange{Start: 0, End: 0}), + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, }, } @@ -806,7 +806,7 @@ func TestCompile_Refs(t *testing.T) { FunctionSection: []wasm.Index{0}, CodeSection: []wasm.Code{{Body: tc.body}}, } - c, err := NewCompiler(api.CoreFeaturesV2, 0, module, false) + c, err := newCompiler(api.CoreFeaturesV2, 0, module, false) require.NoError(t, err) actual, err := c.Next() @@ -820,7 +820,7 @@ func TestCompile_TableGetOrSet(t *testing.T) { tests := []struct { name string body []byte - expected []UnionOperation + expected []unionOperation }{ { name: "table.get", @@ -830,11 +830,11 @@ func TestCompile_TableGetOrSet(t *testing.T) { wasm.OpcodeDrop, wasm.OpcodeEnd, }, - expected: []UnionOperation{ - NewOperationConstI32(10), - NewOperationTableGet(0), - NewOperationDrop(InclusiveRange{Start: 0, End: 0}), - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + expected: []unionOperation{ + newOperationConstI32(10), + newOperationTableGet(0), + newOperationDrop(inclusiveRange{Start: 0, End: 0}), + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, }, { @@ -845,11 +845,11 @@ func TestCompile_TableGetOrSet(t *testing.T) { wasm.OpcodeTableSet, 0, wasm.OpcodeEnd, }, - expected: []UnionOperation{ - NewOperationConstI32(10), - NewOperationConstI64(0), - NewOperationTableSet(0), - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + expected: []unionOperation{ + newOperationConstI32(10), + newOperationConstI64(0), + newOperationTableSet(0), + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, }, { @@ -860,11 +860,11 @@ func TestCompile_TableGetOrSet(t *testing.T) { wasm.OpcodeTableSet, 0, wasm.OpcodeEnd, }, - expected: []UnionOperation{ - NewOperationConstI32(10), - NewOperationRefFunc(1), - NewOperationTableSet(0), - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + expected: []unionOperation{ + newOperationConstI32(10), + newOperationRefFunc(1), + newOperationTableSet(0), + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, }, } @@ -878,7 +878,7 @@ func TestCompile_TableGetOrSet(t *testing.T) { CodeSection: []wasm.Code{{Body: tc.body}}, TableSection: []wasm.Table{{}}, } - c, err := NewCompiler(api.CoreFeaturesV2, 0, module, false) + c, err := newCompiler(api.CoreFeaturesV2, 0, module, false) require.NoError(t, err) actual, err := c.Next() @@ -892,7 +892,7 @@ func TestCompile_TableGrowFillSize(t *testing.T) { tests := []struct { name string body []byte - expected []UnionOperation + expected []unionOperation }{ { name: "table.grow", @@ -902,12 +902,12 @@ func TestCompile_TableGrowFillSize(t *testing.T) { wasm.OpcodeMiscPrefix, wasm.OpcodeMiscTableGrow, 1, wasm.OpcodeEnd, }, - expected: []UnionOperation{ - NewOperationConstI64(0), // Null ref. - NewOperationConstI32(1), - NewOperationTableGrow(1), - NewOperationDrop(InclusiveRange{Start: 0, End: 0}), - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + expected: []unionOperation{ + newOperationConstI64(0), // Null ref. + newOperationConstI32(1), + newOperationTableGrow(1), + newOperationDrop(inclusiveRange{Start: 0, End: 0}), + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, }, { @@ -919,12 +919,12 @@ func TestCompile_TableGrowFillSize(t *testing.T) { wasm.OpcodeMiscPrefix, wasm.OpcodeMiscTableFill, 1, wasm.OpcodeEnd, }, - expected: []UnionOperation{ - NewOperationConstI32(10), - NewOperationConstI64(0), // Null ref. - NewOperationConstI32(1), - NewOperationTableFill(1), - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + expected: []unionOperation{ + newOperationConstI32(10), + newOperationConstI64(0), // Null ref. + newOperationConstI32(1), + newOperationTableFill(1), + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, }, { @@ -933,10 +933,10 @@ func TestCompile_TableGrowFillSize(t *testing.T) { wasm.OpcodeMiscPrefix, wasm.OpcodeMiscTableSize, 1, wasm.OpcodeEnd, }, - expected: []UnionOperation{ - NewOperationTableSize(1), - NewOperationDrop(InclusiveRange{Start: 0, End: 0}), - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + expected: []unionOperation{ + newOperationTableSize(1), + newOperationDrop(inclusiveRange{Start: 0, End: 0}), + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, }, } @@ -950,7 +950,7 @@ func TestCompile_TableGrowFillSize(t *testing.T) { CodeSection: []wasm.Code{{Body: tc.body}}, TableSection: []wasm.Table{{}}, } - c, err := NewCompiler(api.CoreFeaturesV2, 0, module, false) + c, err := newCompiler(api.CoreFeaturesV2, 0, module, false) require.NoError(t, err) actual, err := c.Next() @@ -965,7 +965,7 @@ func TestCompile_Locals(t *testing.T) { tests := []struct { name string mod *wasm.Module - expected []UnionOperation + expected []unionOperation }{ { name: "local.get - func param - v128", @@ -977,10 +977,10 @@ func TestCompile_Locals(t *testing.T) { wasm.OpcodeEnd, }}}, }, - expected: []UnionOperation{ - NewOperationPick(1, true), // [param[0].low, param[0].high] -> [param[0].low, param[0].high, param[0].low, param[0].high] - NewOperationDrop(InclusiveRange{Start: 0, End: 3}), - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + expected: []unionOperation{ + newOperationPick(1, true), // [param[0].low, param[0].high] -> [param[0].low, param[0].high, param[0].low, param[0].high] + newOperationDrop(inclusiveRange{Start: 0, End: 3}), + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, }, { @@ -993,10 +993,10 @@ func TestCompile_Locals(t *testing.T) { wasm.OpcodeEnd, }}}, }, - expected: []UnionOperation{ - NewOperationPick(0, false), // [param[0]] -> [param[0], param[0]] - NewOperationDrop(InclusiveRange{Start: 0, End: 1}), - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + expected: []unionOperation{ + newOperationPick(0, false), // [param[0]] -> [param[0], param[0]] + newOperationDrop(inclusiveRange{Start: 0, End: 1}), + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, }, { @@ -1012,11 +1012,11 @@ func TestCompile_Locals(t *testing.T) { LocalTypes: []wasm.ValueType{wasm.ValueTypeV128}, }}, }, - expected: []UnionOperation{ - NewOperationV128Const(0, 0), - NewOperationPick(1, true), // [p[0].low, p[0].high] -> [p[0].low, p[0].high, p[0].low, p[0].high] - NewOperationDrop(InclusiveRange{Start: 0, End: 3}), - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + expected: []unionOperation{ + newOperationV128Const(0, 0), + newOperationPick(1, true), // [p[0].low, p[0].high] -> [p[0].low, p[0].high, p[0].low, p[0].high] + newOperationDrop(inclusiveRange{Start: 0, End: 3}), + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, }, { @@ -1032,13 +1032,13 @@ func TestCompile_Locals(t *testing.T) { wasm.OpcodeEnd, }}}, }, - expected: []UnionOperation{ + expected: []unionOperation{ // [p[0].lo, p[1].hi] -> [p[0].lo, p[1].hi, 0x01, 0x02] - NewOperationV128Const(0x01, 0x02), + newOperationV128Const(0x01, 0x02), // [p[0].lo, p[1].hi, 0x01, 0x02] -> [0x01, 0x02] - NewOperationSet(3, true), - NewOperationDrop(InclusiveRange{Start: 0, End: 1}), - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + newOperationSet(3, true), + newOperationDrop(inclusiveRange{Start: 0, End: 1}), + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, }, { @@ -1052,11 +1052,11 @@ func TestCompile_Locals(t *testing.T) { wasm.OpcodeEnd, }}}, }, - expected: []UnionOperation{ - NewOperationConstI32(0x1), - NewOperationSet(1, false), - NewOperationDrop(InclusiveRange{Start: 0, End: 0}), - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + expected: []unionOperation{ + newOperationConstI32(0x1), + newOperationSet(1, false), + newOperationDrop(inclusiveRange{Start: 0, End: 0}), + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, }, { @@ -1075,14 +1075,14 @@ func TestCompile_Locals(t *testing.T) { LocalTypes: []wasm.ValueType{wasm.ValueTypeV128}, }}, }, - expected: []UnionOperation{ - NewOperationV128Const(0, 0), + expected: []unionOperation{ + newOperationV128Const(0, 0), // [p[0].lo, p[1].hi] -> [p[0].lo, p[1].hi, 0x01, 0x02] - NewOperationV128Const(0x01, 0x02), + newOperationV128Const(0x01, 0x02), // [p[0].lo, p[1].hi, 0x01, 0x02] -> [0x01, 0x02] - NewOperationSet(3, true), - NewOperationDrop(InclusiveRange{Start: 0, End: 1}), - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + newOperationSet(3, true), + newOperationDrop(inclusiveRange{Start: 0, End: 1}), + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, }, { @@ -1098,15 +1098,15 @@ func TestCompile_Locals(t *testing.T) { wasm.OpcodeEnd, }}}, }, - expected: []UnionOperation{ + expected: []unionOperation{ // [p[0].lo, p[1].hi] -> [p[0].lo, p[1].hi, 0x01, 0x02] - NewOperationV128Const(0x01, 0x02), + newOperationV128Const(0x01, 0x02), // [p[0].lo, p[1].hi, 0x01, 0x02] -> [p[0].lo, p[1].hi, 0x01, 0x02, 0x01, 0x02] - NewOperationPick(1, true), + newOperationPick(1, true), // [p[0].lo, p[1].hi, 0x01, 0x02, 0x01, 0x02] -> [0x01, 0x02, 0x01, 0x02] - NewOperationSet(5, true), - NewOperationDrop(InclusiveRange{Start: 0, End: 3}), - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + newOperationSet(5, true), + newOperationDrop(inclusiveRange{Start: 0, End: 3}), + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, }, { @@ -1120,12 +1120,12 @@ func TestCompile_Locals(t *testing.T) { wasm.OpcodeEnd, }}}, }, - expected: []UnionOperation{ - NewOperationConstF32(math.Float32frombits(1)), - NewOperationPick(0, false), - NewOperationSet(2, false), - NewOperationDrop(InclusiveRange{Start: 0, End: 1}), - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + expected: []unionOperation{ + newOperationConstF32(math.Float32frombits(1)), + newOperationPick(0, false), + newOperationSet(2, false), + newOperationDrop(inclusiveRange{Start: 0, End: 1}), + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, }, { @@ -1144,16 +1144,16 @@ func TestCompile_Locals(t *testing.T) { LocalTypes: []wasm.ValueType{wasm.ValueTypeV128}, }}, }, - expected: []UnionOperation{ - NewOperationV128Const(0, 0), + expected: []unionOperation{ + newOperationV128Const(0, 0), // [p[0].lo, p[1].hi] -> [p[0].lo, p[1].hi, 0x01, 0x02] - NewOperationV128Const(0x01, 0x02), + newOperationV128Const(0x01, 0x02), // [p[0].lo, p[1].hi, 0x01, 0x02] -> [p[0].lo, p[1].hi, 0x01, 0x02, 0x01, 0x02] - NewOperationPick(1, true), + newOperationPick(1, true), // [p[0].lo, p[1].hi, 0x01, 0x02, 0x01, 0x2] -> [0x01, 0x02, 0x01, 0x02] - NewOperationSet(5, true), - NewOperationDrop(InclusiveRange{Start: 0, End: 3}), - NewOperationBr(NewLabel(LabelKindReturn, 0)), // return! + newOperationSet(5, true), + newOperationDrop(inclusiveRange{Start: 0, End: 3}), + newOperationBr(newLabel(labelKindReturn, 0)), // return! }, }, } @@ -1161,12 +1161,12 @@ func TestCompile_Locals(t *testing.T) { for _, tt := range tests { tc := tt t.Run(tc.name, func(t *testing.T) { - c, err := NewCompiler(api.CoreFeaturesV2, 0, tc.mod, false) + c, err := newCompiler(api.CoreFeaturesV2, 0, tc.mod, false) require.NoError(t, err) actual, err := c.Next() require.NoError(t, err) - msg := fmt.Sprintf("\nhave:\n\t%s\nwant:\n\t%s", Format(actual.Operations), Format(tc.expected)) + msg := fmt.Sprintf("\nhave:\n\t%s\nwant:\n\t%s", format(actual.Operations), format(tc.expected)) require.Equal(t, tc.expected, actual.Operations, msg) }) } @@ -1273,176 +1273,176 @@ func TestCompile_Vec(t *testing.T) { tests := []struct { name string body []byte - expected UnionOperation + expected unionOperation needDropBeforeReturn bool }{ { name: "i8x16 add", needDropBeforeReturn: true, body: vv2v(wasm.OpcodeVecI8x16Add), - expected: NewOperationV128Add(ShapeI8x16), + expected: newOperationV128Add(shapeI8x16), }, { name: "i8x16 add", needDropBeforeReturn: true, body: vv2v(wasm.OpcodeVecI16x8Add), - expected: NewOperationV128Add(ShapeI16x8), + expected: newOperationV128Add(shapeI16x8), }, { name: "i32x2 add", needDropBeforeReturn: true, body: vv2v(wasm.OpcodeVecI64x2Add), - expected: NewOperationV128Add(ShapeI64x2), + expected: newOperationV128Add(shapeI64x2), }, { name: "i64x2 add", needDropBeforeReturn: true, body: vv2v(wasm.OpcodeVecI64x2Add), - expected: NewOperationV128Add(ShapeI64x2), + expected: newOperationV128Add(shapeI64x2), }, { name: "i8x16 sub", needDropBeforeReturn: true, body: vv2v(wasm.OpcodeVecI8x16Sub), - expected: NewOperationV128Sub(ShapeI8x16), + expected: newOperationV128Sub(shapeI8x16), }, { name: "i16x8 sub", needDropBeforeReturn: true, body: vv2v(wasm.OpcodeVecI16x8Sub), - expected: NewOperationV128Sub(ShapeI16x8), + expected: newOperationV128Sub(shapeI16x8), }, { name: "i32x2 sub", needDropBeforeReturn: true, body: vv2v(wasm.OpcodeVecI64x2Sub), - expected: NewOperationV128Sub(ShapeI64x2), + expected: newOperationV128Sub(shapeI64x2), }, { name: "i64x2 sub", needDropBeforeReturn: true, body: vv2v(wasm.OpcodeVecI64x2Sub), - expected: NewOperationV128Sub(ShapeI64x2), + expected: newOperationV128Sub(shapeI64x2), }, { name: wasm.OpcodeVecV128LoadName, body: load(wasm.OpcodeVecV128Load, 0, 0), needDropBeforeReturn: true, - expected: NewOperationV128Load(V128LoadType128, MemoryArg{Alignment: 0, Offset: 0}), + expected: newOperationV128Load(v128LoadType128, memoryArg{Alignment: 0, Offset: 0}), }, { name: wasm.OpcodeVecV128LoadName + "/align=4", body: load(wasm.OpcodeVecV128Load, 0, 4), needDropBeforeReturn: true, - expected: NewOperationV128Load(V128LoadType128, MemoryArg{Alignment: 4, Offset: 0}), + expected: newOperationV128Load(v128LoadType128, memoryArg{Alignment: 4, Offset: 0}), }, { name: wasm.OpcodeVecV128Load8x8SName, body: load(wasm.OpcodeVecV128Load8x8s, 1, 0), needDropBeforeReturn: true, - expected: NewOperationV128Load(V128LoadType8x8s, MemoryArg{Alignment: 0, Offset: 1}), + expected: newOperationV128Load(v128LoadType8x8s, memoryArg{Alignment: 0, Offset: 1}), }, { name: wasm.OpcodeVecV128Load8x8SName + "/align=1", body: load(wasm.OpcodeVecV128Load8x8s, 0, 1), needDropBeforeReturn: true, - expected: NewOperationV128Load(V128LoadType8x8s, MemoryArg{Alignment: 1, Offset: 0}), + expected: newOperationV128Load(v128LoadType8x8s, memoryArg{Alignment: 1, Offset: 0}), }, { name: wasm.OpcodeVecV128Load8x8UName, body: load(wasm.OpcodeVecV128Load8x8u, 0, 0), needDropBeforeReturn: true, - expected: NewOperationV128Load(V128LoadType8x8u, MemoryArg{Alignment: 0, Offset: 0}), + expected: newOperationV128Load(v128LoadType8x8u, memoryArg{Alignment: 0, Offset: 0}), }, { name: wasm.OpcodeVecV128Load8x8UName + "/align=1", body: load(wasm.OpcodeVecV128Load8x8u, 0, 1), needDropBeforeReturn: true, - expected: NewOperationV128Load(V128LoadType8x8u, MemoryArg{Alignment: 1, Offset: 0}), + expected: newOperationV128Load(v128LoadType8x8u, memoryArg{Alignment: 1, Offset: 0}), }, { name: wasm.OpcodeVecV128Load16x4SName, body: load(wasm.OpcodeVecV128Load16x4s, 1, 0), needDropBeforeReturn: true, - expected: NewOperationV128Load(V128LoadType16x4s, MemoryArg{Alignment: 0, Offset: 1}), + expected: newOperationV128Load(v128LoadType16x4s, memoryArg{Alignment: 0, Offset: 1}), }, { name: wasm.OpcodeVecV128Load16x4SName + "/align=2", body: load(wasm.OpcodeVecV128Load16x4s, 0, 2), needDropBeforeReturn: true, - expected: NewOperationV128Load(V128LoadType16x4s, MemoryArg{Alignment: 2, Offset: 0}), + expected: newOperationV128Load(v128LoadType16x4s, memoryArg{Alignment: 2, Offset: 0}), }, { name: wasm.OpcodeVecV128Load16x4UName, body: load(wasm.OpcodeVecV128Load16x4u, 0, 0), needDropBeforeReturn: true, - expected: NewOperationV128Load(V128LoadType16x4u, MemoryArg{Alignment: 0, Offset: 0}), + expected: newOperationV128Load(v128LoadType16x4u, memoryArg{Alignment: 0, Offset: 0}), }, { name: wasm.OpcodeVecV128Load16x4UName + "/align=2", body: load(wasm.OpcodeVecV128Load16x4u, 0, 2), needDropBeforeReturn: true, - expected: NewOperationV128Load(V128LoadType16x4u, MemoryArg{Alignment: 2, Offset: 0}), + expected: newOperationV128Load(v128LoadType16x4u, memoryArg{Alignment: 2, Offset: 0}), }, { name: wasm.OpcodeVecV128Load32x2SName, body: load(wasm.OpcodeVecV128Load32x2s, 1, 0), needDropBeforeReturn: true, - expected: NewOperationV128Load(V128LoadType32x2s, MemoryArg{Alignment: 0, Offset: 1}), + expected: newOperationV128Load(v128LoadType32x2s, memoryArg{Alignment: 0, Offset: 1}), }, { name: wasm.OpcodeVecV128Load32x2SName + "/align=3", body: load(wasm.OpcodeVecV128Load32x2s, 0, 3), needDropBeforeReturn: true, - expected: NewOperationV128Load(V128LoadType32x2s, MemoryArg{Alignment: 3, Offset: 0}), + expected: newOperationV128Load(v128LoadType32x2s, memoryArg{Alignment: 3, Offset: 0}), }, { name: wasm.OpcodeVecV128Load32x2UName, body: load(wasm.OpcodeVecV128Load32x2u, 0, 0), needDropBeforeReturn: true, - expected: NewOperationV128Load(V128LoadType32x2u, MemoryArg{Alignment: 0, Offset: 0}), + expected: newOperationV128Load(v128LoadType32x2u, memoryArg{Alignment: 0, Offset: 0}), }, { name: wasm.OpcodeVecV128Load32x2UName + "/align=3", body: load(wasm.OpcodeVecV128Load32x2u, 0, 3), needDropBeforeReturn: true, - expected: NewOperationV128Load(V128LoadType32x2u, MemoryArg{Alignment: 3, Offset: 0}), + expected: newOperationV128Load(v128LoadType32x2u, memoryArg{Alignment: 3, Offset: 0}), }, { name: wasm.OpcodeVecV128Load8SplatName, body: load(wasm.OpcodeVecV128Load8Splat, 2, 0), needDropBeforeReturn: true, - expected: NewOperationV128Load(V128LoadType8Splat, MemoryArg{Alignment: 0, Offset: 2}), + expected: newOperationV128Load(v128LoadType8Splat, memoryArg{Alignment: 0, Offset: 2}), }, { name: wasm.OpcodeVecV128Load16SplatName, body: load(wasm.OpcodeVecV128Load16Splat, 0, 1), needDropBeforeReturn: true, - expected: NewOperationV128Load(V128LoadType16Splat, MemoryArg{Alignment: 1, Offset: 0}), + expected: newOperationV128Load(v128LoadType16Splat, memoryArg{Alignment: 1, Offset: 0}), }, { name: wasm.OpcodeVecV128Load32SplatName, body: load(wasm.OpcodeVecV128Load32Splat, 3, 2), needDropBeforeReturn: true, - expected: NewOperationV128Load(V128LoadType32Splat, MemoryArg{Alignment: 2, Offset: 3}), + expected: newOperationV128Load(v128LoadType32Splat, memoryArg{Alignment: 2, Offset: 3}), }, { name: wasm.OpcodeVecV128Load64SplatName, body: load(wasm.OpcodeVecV128Load64Splat, 0, 3), needDropBeforeReturn: true, - expected: NewOperationV128Load(V128LoadType64Splat, MemoryArg{Alignment: 3, Offset: 0}), + expected: newOperationV128Load(v128LoadType64Splat, memoryArg{Alignment: 3, Offset: 0}), }, { name: wasm.OpcodeVecV128Load32zeroName, body: load(wasm.OpcodeVecV128Load32zero, 0, 2), needDropBeforeReturn: true, - expected: NewOperationV128Load(V128LoadType32zero, MemoryArg{Alignment: 2, Offset: 0}), + expected: newOperationV128Load(v128LoadType32zero, memoryArg{Alignment: 2, Offset: 0}), }, { name: wasm.OpcodeVecV128Load64zeroName, body: load(wasm.OpcodeVecV128Load64zero, 5, 3), needDropBeforeReturn: true, - expected: NewOperationV128Load(V128LoadType64zero, MemoryArg{Alignment: 3, Offset: 5}), + expected: newOperationV128Load(v128LoadType64zero, memoryArg{Alignment: 3, Offset: 5}), }, { name: wasm.OpcodeVecV128Load8LaneName, needDropBeforeReturn: true, body: loadLane(wasm.OpcodeVecV128Load8Lane, 5, 0, 10), - expected: NewOperationV128LoadLane(10, 8, MemoryArg{Alignment: 0, Offset: 5}), + expected: newOperationV128LoadLane(10, 8, memoryArg{Alignment: 0, Offset: 5}), }, { name: wasm.OpcodeVecV128Load16LaneName, needDropBeforeReturn: true, body: loadLane(wasm.OpcodeVecV128Load16Lane, 100, 1, 7), - expected: NewOperationV128LoadLane(7, 16, MemoryArg{Alignment: 1, Offset: 100}), + expected: newOperationV128LoadLane(7, 16, memoryArg{Alignment: 1, Offset: 100}), }, { name: wasm.OpcodeVecV128Load32LaneName, needDropBeforeReturn: true, body: loadLane(wasm.OpcodeVecV128Load32Lane, 0, 2, 3), - expected: NewOperationV128LoadLane(3, 32, MemoryArg{Alignment: 2, Offset: 0}), + expected: newOperationV128LoadLane(3, 32, memoryArg{Alignment: 2, Offset: 0}), }, { name: wasm.OpcodeVecV128Load64LaneName, needDropBeforeReturn: true, body: loadLane(wasm.OpcodeVecV128Load64Lane, 0, 3, 1), - expected: NewOperationV128LoadLane(1, 64, MemoryArg{Alignment: 3, Offset: 0}), + expected: newOperationV128LoadLane(1, 64, memoryArg{Alignment: 3, Offset: 0}), }, { name: wasm.OpcodeVecV128StoreName, body: []byte{ @@ -1458,250 +1458,250 @@ func TestCompile_Vec(t *testing.T) { 10, // offset wasm.OpcodeEnd, }, - expected: NewOperationV128Store(MemoryArg{Alignment: 4, Offset: 10}), + expected: newOperationV128Store(memoryArg{Alignment: 4, Offset: 10}), }, { name: wasm.OpcodeVecV128Store8LaneName, body: storeLane(wasm.OpcodeVecV128Store8Lane, 0, 0, 0), - expected: NewOperationV128StoreLane(0, 8, MemoryArg{Alignment: 0, Offset: 0}), + expected: newOperationV128StoreLane(0, 8, memoryArg{Alignment: 0, Offset: 0}), }, { name: wasm.OpcodeVecV128Store8LaneName + "/lane=15", body: storeLane(wasm.OpcodeVecV128Store8Lane, 100, 0, 15), - expected: NewOperationV128StoreLane(15, 8, MemoryArg{Alignment: 0, Offset: 100}), + expected: newOperationV128StoreLane(15, 8, memoryArg{Alignment: 0, Offset: 100}), }, { name: wasm.OpcodeVecV128Store16LaneName, body: storeLane(wasm.OpcodeVecV128Store16Lane, 0, 0, 0), - expected: NewOperationV128StoreLane(0, 16, MemoryArg{Alignment: 0, Offset: 0}), + expected: newOperationV128StoreLane(0, 16, memoryArg{Alignment: 0, Offset: 0}), }, { name: wasm.OpcodeVecV128Store16LaneName + "/lane=7/align=1", body: storeLane(wasm.OpcodeVecV128Store16Lane, 100, 1, 7), - expected: NewOperationV128StoreLane(7, 16, MemoryArg{Alignment: 1, Offset: 100}), + expected: newOperationV128StoreLane(7, 16, memoryArg{Alignment: 1, Offset: 100}), }, { name: wasm.OpcodeVecV128Store32LaneName, body: storeLane(wasm.OpcodeVecV128Store32Lane, 0, 0, 0), - expected: NewOperationV128StoreLane(0, 32, MemoryArg{Alignment: 0, Offset: 0}), + expected: newOperationV128StoreLane(0, 32, memoryArg{Alignment: 0, Offset: 0}), }, { name: wasm.OpcodeVecV128Store32LaneName + "/lane=3/align=2", body: storeLane(wasm.OpcodeVecV128Store32Lane, 100, 2, 3), - expected: NewOperationV128StoreLane(3, 32, MemoryArg{Alignment: 2, Offset: 100}), + expected: newOperationV128StoreLane(3, 32, memoryArg{Alignment: 2, Offset: 100}), }, { name: wasm.OpcodeVecV128Store64LaneName, body: storeLane(wasm.OpcodeVecV128Store64Lane, 0, 0, 0), - expected: NewOperationV128StoreLane(0, 64, MemoryArg{Alignment: 0, Offset: 0}), + expected: newOperationV128StoreLane(0, 64, memoryArg{Alignment: 0, Offset: 0}), }, { name: wasm.OpcodeVecV128Store64LaneName + "/lane=1/align=3", body: storeLane(wasm.OpcodeVecV128Store64Lane, 50, 3, 1), - expected: NewOperationV128StoreLane(1, 64, MemoryArg{Alignment: 3, Offset: 50}), + expected: newOperationV128StoreLane(1, 64, memoryArg{Alignment: 3, Offset: 50}), }, { name: wasm.OpcodeVecI8x16ExtractLaneSName, body: extractLane(wasm.OpcodeVecI8x16ExtractLaneS, 0), - expected: NewOperationV128ExtractLane(0, true, ShapeI8x16), + expected: newOperationV128ExtractLane(0, true, shapeI8x16), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecI8x16ExtractLaneSName + "/lane=15", body: extractLane(wasm.OpcodeVecI8x16ExtractLaneS, 15), - expected: NewOperationV128ExtractLane(15, true, ShapeI8x16), + expected: newOperationV128ExtractLane(15, true, shapeI8x16), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecI8x16ExtractLaneUName, body: extractLane(wasm.OpcodeVecI8x16ExtractLaneU, 0), - expected: NewOperationV128ExtractLane(0, false, ShapeI8x16), + expected: newOperationV128ExtractLane(0, false, shapeI8x16), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecI8x16ExtractLaneUName + "/lane=15", body: extractLane(wasm.OpcodeVecI8x16ExtractLaneU, 15), - expected: NewOperationV128ExtractLane(15, false, ShapeI8x16), + expected: newOperationV128ExtractLane(15, false, shapeI8x16), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecI16x8ExtractLaneSName, body: extractLane(wasm.OpcodeVecI16x8ExtractLaneS, 0), - expected: NewOperationV128ExtractLane(0, true, ShapeI16x8), + expected: newOperationV128ExtractLane(0, true, shapeI16x8), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecI16x8ExtractLaneSName + "/lane=7", body: extractLane(wasm.OpcodeVecI16x8ExtractLaneS, 7), - expected: NewOperationV128ExtractLane(7, true, ShapeI16x8), + expected: newOperationV128ExtractLane(7, true, shapeI16x8), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecI16x8ExtractLaneUName, body: extractLane(wasm.OpcodeVecI16x8ExtractLaneU, 0), - expected: NewOperationV128ExtractLane(0, false, ShapeI16x8), + expected: newOperationV128ExtractLane(0, false, shapeI16x8), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecI16x8ExtractLaneUName + "/lane=7", body: extractLane(wasm.OpcodeVecI16x8ExtractLaneU, 7), - expected: NewOperationV128ExtractLane(7, false, ShapeI16x8), + expected: newOperationV128ExtractLane(7, false, shapeI16x8), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecI32x4ExtractLaneName, body: extractLane(wasm.OpcodeVecI32x4ExtractLane, 0), - expected: NewOperationV128ExtractLane(0, false, ShapeI32x4), + expected: newOperationV128ExtractLane(0, false, shapeI32x4), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecI32x4ExtractLaneName + "/lane=3", body: extractLane(wasm.OpcodeVecI32x4ExtractLane, 3), - expected: NewOperationV128ExtractLane(3, false, ShapeI32x4), + expected: newOperationV128ExtractLane(3, false, shapeI32x4), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecI64x2ExtractLaneName, body: extractLane(wasm.OpcodeVecI64x2ExtractLane, 0), - expected: NewOperationV128ExtractLane(0, false, ShapeI64x2), + expected: newOperationV128ExtractLane(0, false, shapeI64x2), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecI64x2ExtractLaneName + "/lane=1", body: extractLane(wasm.OpcodeVecI64x2ExtractLane, 1), - expected: NewOperationV128ExtractLane(1, false, ShapeI64x2), + expected: newOperationV128ExtractLane(1, false, shapeI64x2), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecF32x4ExtractLaneName, body: extractLane(wasm.OpcodeVecF32x4ExtractLane, 0), - expected: NewOperationV128ExtractLane(0, false, ShapeF32x4), + expected: newOperationV128ExtractLane(0, false, shapeF32x4), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecF32x4ExtractLaneName + "/lane=3", body: extractLane(wasm.OpcodeVecF32x4ExtractLane, 3), - expected: NewOperationV128ExtractLane(3, false, ShapeF32x4), + expected: newOperationV128ExtractLane(3, false, shapeF32x4), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecF64x2ExtractLaneName, body: extractLane(wasm.OpcodeVecF64x2ExtractLane, 0), - expected: NewOperationV128ExtractLane(0, false, ShapeF64x2), + expected: newOperationV128ExtractLane(0, false, shapeF64x2), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecF64x2ExtractLaneName + "/lane=1", body: extractLane(wasm.OpcodeVecF64x2ExtractLane, 1), - expected: NewOperationV128ExtractLane(1, false, ShapeF64x2), + expected: newOperationV128ExtractLane(1, false, shapeF64x2), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecI8x16ReplaceLaneName, body: replaceLane(wasm.OpcodeVecI8x16ReplaceLane, 0), - expected: NewOperationV128ReplaceLane(0, ShapeI8x16), + expected: newOperationV128ReplaceLane(0, shapeI8x16), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecI8x16ReplaceLaneName + "/lane=15", body: replaceLane(wasm.OpcodeVecI8x16ReplaceLane, 15), - expected: NewOperationV128ReplaceLane(15, ShapeI8x16), + expected: newOperationV128ReplaceLane(15, shapeI8x16), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecI16x8ReplaceLaneName, body: replaceLane(wasm.OpcodeVecI16x8ReplaceLane, 0), - expected: NewOperationV128ReplaceLane(0, ShapeI16x8), + expected: newOperationV128ReplaceLane(0, shapeI16x8), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecI16x8ReplaceLaneName + "/lane=7", body: replaceLane(wasm.OpcodeVecI16x8ReplaceLane, 7), - expected: NewOperationV128ReplaceLane(7, ShapeI16x8), + expected: newOperationV128ReplaceLane(7, shapeI16x8), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecI32x4ReplaceLaneName, body: replaceLane(wasm.OpcodeVecI32x4ReplaceLane, 0), - expected: NewOperationV128ReplaceLane(0, ShapeI32x4), + expected: newOperationV128ReplaceLane(0, shapeI32x4), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecI32x4ReplaceLaneName + "/lane=3", body: replaceLane(wasm.OpcodeVecI32x4ReplaceLane, 3), - expected: NewOperationV128ReplaceLane(3, ShapeI32x4), + expected: newOperationV128ReplaceLane(3, shapeI32x4), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecI64x2ReplaceLaneName, body: replaceLane(wasm.OpcodeVecI64x2ReplaceLane, 0), - expected: NewOperationV128ReplaceLane(0, ShapeI64x2), + expected: newOperationV128ReplaceLane(0, shapeI64x2), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecI64x2ReplaceLaneName + "/lane=1", body: replaceLane(wasm.OpcodeVecI64x2ReplaceLane, 1), - expected: NewOperationV128ReplaceLane(1, ShapeI64x2), + expected: newOperationV128ReplaceLane(1, shapeI64x2), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecF32x4ReplaceLaneName, body: replaceLane(wasm.OpcodeVecF32x4ReplaceLane, 0), - expected: NewOperationV128ReplaceLane(0, ShapeF32x4), + expected: newOperationV128ReplaceLane(0, shapeF32x4), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecF32x4ReplaceLaneName + "/lane=3", body: replaceLane(wasm.OpcodeVecF32x4ReplaceLane, 3), - expected: NewOperationV128ReplaceLane(3, ShapeF32x4), + expected: newOperationV128ReplaceLane(3, shapeF32x4), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecF64x2ReplaceLaneName, body: replaceLane(wasm.OpcodeVecF64x2ReplaceLane, 0), - expected: NewOperationV128ReplaceLane(0, ShapeF64x2), + expected: newOperationV128ReplaceLane(0, shapeF64x2), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecF64x2ReplaceLaneName + "/lane=1", body: replaceLane(wasm.OpcodeVecF64x2ReplaceLane, 1), - expected: NewOperationV128ReplaceLane(1, ShapeF64x2), + expected: newOperationV128ReplaceLane(1, shapeF64x2), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecI8x16SplatName, body: splat(wasm.OpcodeVecI8x16Splat), - expected: NewOperationV128Splat(ShapeI8x16), + expected: newOperationV128Splat(shapeI8x16), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecI16x8SplatName, body: splat(wasm.OpcodeVecI16x8Splat), - expected: NewOperationV128Splat(ShapeI16x8), + expected: newOperationV128Splat(shapeI16x8), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecI32x4SplatName, body: splat(wasm.OpcodeVecI32x4Splat), - expected: NewOperationV128Splat(ShapeI32x4), + expected: newOperationV128Splat(shapeI32x4), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecI64x2SplatName, body: splat(wasm.OpcodeVecI64x2Splat), - expected: NewOperationV128Splat(ShapeI64x2), + expected: newOperationV128Splat(shapeI64x2), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecF32x4SplatName, body: splat(wasm.OpcodeVecF32x4Splat), - expected: NewOperationV128Splat(ShapeF32x4), + expected: newOperationV128Splat(shapeF32x4), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecF64x2SplatName, body: splat(wasm.OpcodeVecF64x2Splat), - expected: NewOperationV128Splat(ShapeF64x2), + expected: newOperationV128Splat(shapeF64x2), needDropBeforeReturn: true, }, { name: wasm.OpcodeVecI8x16SwizzleName, body: vv2v(wasm.OpcodeVecI8x16Swizzle), - expected: NewOperationV128Swizzle(), + expected: newOperationV128Swizzle(), needDropBeforeReturn: true, }, { @@ -1716,7 +1716,7 @@ func TestCompile_Vec(t *testing.T) { wasm.OpcodeDrop, wasm.OpcodeEnd, }, - expected: NewOperationV128Shuffle([]uint64{ + expected: newOperationV128Shuffle([]uint64{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, }), needDropBeforeReturn: true, @@ -1724,914 +1724,914 @@ func TestCompile_Vec(t *testing.T) { { name: wasm.OpcodeVecV128NotName, body: v2v(wasm.OpcodeVecV128Not), needDropBeforeReturn: true, - expected: NewOperationV128Not(), + expected: newOperationV128Not(), }, { name: wasm.OpcodeVecV128AndName, body: vv2v(wasm.OpcodeVecV128And), needDropBeforeReturn: true, - expected: NewOperationV128And(), + expected: newOperationV128And(), }, { name: wasm.OpcodeVecV128AndNotName, body: vv2v(wasm.OpcodeVecV128AndNot), needDropBeforeReturn: true, - expected: NewOperationV128AndNot(), + expected: newOperationV128AndNot(), }, { name: wasm.OpcodeVecV128OrName, body: vv2v(wasm.OpcodeVecV128Or), needDropBeforeReturn: true, - expected: NewOperationV128Or(), + expected: newOperationV128Or(), }, { name: wasm.OpcodeVecV128XorName, body: vv2v(wasm.OpcodeVecV128Xor), needDropBeforeReturn: true, - expected: NewOperationV128Xor(), + expected: newOperationV128Xor(), }, { name: wasm.OpcodeVecV128BitselectName, body: vvv2v(wasm.OpcodeVecV128Bitselect), needDropBeforeReturn: true, - expected: NewOperationV128Bitselect(), + expected: newOperationV128Bitselect(), }, { name: wasm.OpcodeVecI8x16ShlName, body: vi2v(wasm.OpcodeVecI8x16Shl), needDropBeforeReturn: true, - expected: NewOperationV128Shl(ShapeI8x16), + expected: newOperationV128Shl(shapeI8x16), }, { name: wasm.OpcodeVecI8x16ShrSName, body: vi2v(wasm.OpcodeVecI8x16ShrS), needDropBeforeReturn: true, - expected: NewOperationV128Shr(ShapeI8x16, true), + expected: newOperationV128Shr(shapeI8x16, true), }, { name: wasm.OpcodeVecI8x16ShrUName, body: vi2v(wasm.OpcodeVecI8x16ShrU), needDropBeforeReturn: true, - expected: NewOperationV128Shr(ShapeI8x16, false), + expected: newOperationV128Shr(shapeI8x16, false), }, { name: wasm.OpcodeVecI16x8ShlName, body: vi2v(wasm.OpcodeVecI16x8Shl), needDropBeforeReturn: true, - expected: NewOperationV128Shl(ShapeI16x8), + expected: newOperationV128Shl(shapeI16x8), }, { name: wasm.OpcodeVecI16x8ShrSName, body: vi2v(wasm.OpcodeVecI16x8ShrS), needDropBeforeReturn: true, - expected: NewOperationV128Shr(ShapeI16x8, true), + expected: newOperationV128Shr(shapeI16x8, true), }, { name: wasm.OpcodeVecI16x8ShrUName, body: vi2v(wasm.OpcodeVecI16x8ShrU), needDropBeforeReturn: true, - expected: NewOperationV128Shr(ShapeI16x8, false), + expected: newOperationV128Shr(shapeI16x8, false), }, { name: wasm.OpcodeVecI32x4ShlName, body: vi2v(wasm.OpcodeVecI32x4Shl), needDropBeforeReturn: true, - expected: NewOperationV128Shl(ShapeI32x4), + expected: newOperationV128Shl(shapeI32x4), }, { name: wasm.OpcodeVecI32x4ShrSName, body: vi2v(wasm.OpcodeVecI32x4ShrS), needDropBeforeReturn: true, - expected: NewOperationV128Shr(ShapeI32x4, true), + expected: newOperationV128Shr(shapeI32x4, true), }, { name: wasm.OpcodeVecI32x4ShrUName, body: vi2v(wasm.OpcodeVecI32x4ShrU), needDropBeforeReturn: true, - expected: NewOperationV128Shr(ShapeI32x4, false), + expected: newOperationV128Shr(shapeI32x4, false), }, { name: wasm.OpcodeVecI64x2ShlName, body: vi2v(wasm.OpcodeVecI64x2Shl), needDropBeforeReturn: true, - expected: NewOperationV128Shl(ShapeI64x2), + expected: newOperationV128Shl(shapeI64x2), }, { name: wasm.OpcodeVecI64x2ShrSName, body: vi2v(wasm.OpcodeVecI64x2ShrS), needDropBeforeReturn: true, - expected: NewOperationV128Shr(ShapeI64x2, true), + expected: newOperationV128Shr(shapeI64x2, true), }, { name: wasm.OpcodeVecI64x2ShrUName, body: vi2v(wasm.OpcodeVecI64x2ShrU), needDropBeforeReturn: true, - expected: NewOperationV128Shr(ShapeI64x2, false), + expected: newOperationV128Shr(shapeI64x2, false), }, { name: wasm.OpcodeVecI8x16EqName, body: vv2v(wasm.OpcodeVecI8x16Eq), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI8x16Eq), + expected: newOperationV128Cmp(v128CmpTypeI8x16Eq), }, { name: wasm.OpcodeVecI8x16NeName, body: vv2v(wasm.OpcodeVecI8x16Ne), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI8x16Ne), + expected: newOperationV128Cmp(v128CmpTypeI8x16Ne), }, { name: wasm.OpcodeVecI8x16LtSName, body: vv2v(wasm.OpcodeVecI8x16LtS), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI8x16LtS), + expected: newOperationV128Cmp(v128CmpTypeI8x16LtS), }, { name: wasm.OpcodeVecI8x16LtUName, body: vv2v(wasm.OpcodeVecI8x16LtU), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI8x16LtU), + expected: newOperationV128Cmp(v128CmpTypeI8x16LtU), }, { name: wasm.OpcodeVecI8x16GtSName, body: vv2v(wasm.OpcodeVecI8x16GtS), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI8x16GtS), + expected: newOperationV128Cmp(v128CmpTypeI8x16GtS), }, { name: wasm.OpcodeVecI8x16GtUName, body: vv2v(wasm.OpcodeVecI8x16GtU), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI8x16GtU), + expected: newOperationV128Cmp(v128CmpTypeI8x16GtU), }, { name: wasm.OpcodeVecI8x16LeSName, body: vv2v(wasm.OpcodeVecI8x16LeS), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI8x16LeS), + expected: newOperationV128Cmp(v128CmpTypeI8x16LeS), }, { name: wasm.OpcodeVecI8x16LeUName, body: vv2v(wasm.OpcodeVecI8x16LeU), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI8x16LeU), + expected: newOperationV128Cmp(v128CmpTypeI8x16LeU), }, { name: wasm.OpcodeVecI8x16GeSName, body: vv2v(wasm.OpcodeVecI8x16GeS), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI8x16GeS), + expected: newOperationV128Cmp(v128CmpTypeI8x16GeS), }, { name: wasm.OpcodeVecI8x16GeUName, body: vv2v(wasm.OpcodeVecI8x16GeU), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI8x16GeU), + expected: newOperationV128Cmp(v128CmpTypeI8x16GeU), }, { name: wasm.OpcodeVecI16x8EqName, body: vv2v(wasm.OpcodeVecI16x8Eq), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI16x8Eq), + expected: newOperationV128Cmp(v128CmpTypeI16x8Eq), }, { name: wasm.OpcodeVecI16x8NeName, body: vv2v(wasm.OpcodeVecI16x8Ne), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI16x8Ne), + expected: newOperationV128Cmp(v128CmpTypeI16x8Ne), }, { name: wasm.OpcodeVecI16x8LtSName, body: vv2v(wasm.OpcodeVecI16x8LtS), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI16x8LtS), + expected: newOperationV128Cmp(v128CmpTypeI16x8LtS), }, { name: wasm.OpcodeVecI16x8LtUName, body: vv2v(wasm.OpcodeVecI16x8LtU), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI16x8LtU), + expected: newOperationV128Cmp(v128CmpTypeI16x8LtU), }, { name: wasm.OpcodeVecI16x8GtSName, body: vv2v(wasm.OpcodeVecI16x8GtS), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI16x8GtS), + expected: newOperationV128Cmp(v128CmpTypeI16x8GtS), }, { name: wasm.OpcodeVecI16x8GtUName, body: vv2v(wasm.OpcodeVecI16x8GtU), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI16x8GtU), + expected: newOperationV128Cmp(v128CmpTypeI16x8GtU), }, { name: wasm.OpcodeVecI16x8LeSName, body: vv2v(wasm.OpcodeVecI16x8LeS), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI16x8LeS), + expected: newOperationV128Cmp(v128CmpTypeI16x8LeS), }, { name: wasm.OpcodeVecI16x8LeUName, body: vv2v(wasm.OpcodeVecI16x8LeU), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI16x8LeU), + expected: newOperationV128Cmp(v128CmpTypeI16x8LeU), }, { name: wasm.OpcodeVecI16x8GeSName, body: vv2v(wasm.OpcodeVecI16x8GeS), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI16x8GeS), + expected: newOperationV128Cmp(v128CmpTypeI16x8GeS), }, { name: wasm.OpcodeVecI16x8GeUName, body: vv2v(wasm.OpcodeVecI16x8GeU), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI16x8GeU), + expected: newOperationV128Cmp(v128CmpTypeI16x8GeU), }, { name: wasm.OpcodeVecI32x4EqName, body: vv2v(wasm.OpcodeVecI32x4Eq), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI32x4Eq), + expected: newOperationV128Cmp(v128CmpTypeI32x4Eq), }, { name: wasm.OpcodeVecI32x4NeName, body: vv2v(wasm.OpcodeVecI32x4Ne), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI32x4Ne), + expected: newOperationV128Cmp(v128CmpTypeI32x4Ne), }, { name: wasm.OpcodeVecI32x4LtSName, body: vv2v(wasm.OpcodeVecI32x4LtS), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI32x4LtS), + expected: newOperationV128Cmp(v128CmpTypeI32x4LtS), }, { name: wasm.OpcodeVecI32x4LtUName, body: vv2v(wasm.OpcodeVecI32x4LtU), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI32x4LtU), + expected: newOperationV128Cmp(v128CmpTypeI32x4LtU), }, { name: wasm.OpcodeVecI32x4GtSName, body: vv2v(wasm.OpcodeVecI32x4GtS), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI32x4GtS), + expected: newOperationV128Cmp(v128CmpTypeI32x4GtS), }, { name: wasm.OpcodeVecI32x4GtUName, body: vv2v(wasm.OpcodeVecI32x4GtU), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI32x4GtU), + expected: newOperationV128Cmp(v128CmpTypeI32x4GtU), }, { name: wasm.OpcodeVecI32x4LeSName, body: vv2v(wasm.OpcodeVecI32x4LeS), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI32x4LeS), + expected: newOperationV128Cmp(v128CmpTypeI32x4LeS), }, { name: wasm.OpcodeVecI32x4LeUName, body: vv2v(wasm.OpcodeVecI32x4LeU), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI32x4LeU), + expected: newOperationV128Cmp(v128CmpTypeI32x4LeU), }, { name: wasm.OpcodeVecI32x4GeSName, body: vv2v(wasm.OpcodeVecI32x4GeS), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI32x4GeS), + expected: newOperationV128Cmp(v128CmpTypeI32x4GeS), }, { name: wasm.OpcodeVecI32x4GeUName, body: vv2v(wasm.OpcodeVecI32x4GeU), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI32x4GeU), + expected: newOperationV128Cmp(v128CmpTypeI32x4GeU), }, { name: wasm.OpcodeVecI64x2EqName, body: vv2v(wasm.OpcodeVecI64x2Eq), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI64x2Eq), + expected: newOperationV128Cmp(v128CmpTypeI64x2Eq), }, { name: wasm.OpcodeVecI64x2NeName, body: vv2v(wasm.OpcodeVecI64x2Ne), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI64x2Ne), + expected: newOperationV128Cmp(v128CmpTypeI64x2Ne), }, { name: wasm.OpcodeVecI64x2LtSName, body: vv2v(wasm.OpcodeVecI64x2LtS), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI64x2LtS), + expected: newOperationV128Cmp(v128CmpTypeI64x2LtS), }, { name: wasm.OpcodeVecI64x2GtSName, body: vv2v(wasm.OpcodeVecI64x2GtS), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI64x2GtS), + expected: newOperationV128Cmp(v128CmpTypeI64x2GtS), }, { name: wasm.OpcodeVecI64x2LeSName, body: vv2v(wasm.OpcodeVecI64x2LeS), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI64x2LeS), + expected: newOperationV128Cmp(v128CmpTypeI64x2LeS), }, { name: wasm.OpcodeVecI64x2GeSName, body: vv2v(wasm.OpcodeVecI64x2GeS), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeI64x2GeS), + expected: newOperationV128Cmp(v128CmpTypeI64x2GeS), }, { name: wasm.OpcodeVecF32x4EqName, body: vv2v(wasm.OpcodeVecF32x4Eq), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeF32x4Eq), + expected: newOperationV128Cmp(v128CmpTypeF32x4Eq), }, { name: wasm.OpcodeVecF32x4NeName, body: vv2v(wasm.OpcodeVecF32x4Ne), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeF32x4Ne), + expected: newOperationV128Cmp(v128CmpTypeF32x4Ne), }, { name: wasm.OpcodeVecF32x4LtName, body: vv2v(wasm.OpcodeVecF32x4Lt), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeF32x4Lt), + expected: newOperationV128Cmp(v128CmpTypeF32x4Lt), }, { name: wasm.OpcodeVecF32x4GtName, body: vv2v(wasm.OpcodeVecF32x4Gt), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeF32x4Gt), + expected: newOperationV128Cmp(v128CmpTypeF32x4Gt), }, { name: wasm.OpcodeVecF32x4LeName, body: vv2v(wasm.OpcodeVecF32x4Le), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeF32x4Le), + expected: newOperationV128Cmp(v128CmpTypeF32x4Le), }, { name: wasm.OpcodeVecF32x4GeName, body: vv2v(wasm.OpcodeVecF32x4Ge), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeF32x4Ge), + expected: newOperationV128Cmp(v128CmpTypeF32x4Ge), }, { name: wasm.OpcodeVecF64x2EqName, body: vv2v(wasm.OpcodeVecF64x2Eq), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeF64x2Eq), + expected: newOperationV128Cmp(v128CmpTypeF64x2Eq), }, { name: wasm.OpcodeVecF64x2NeName, body: vv2v(wasm.OpcodeVecF64x2Ne), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeF64x2Ne), + expected: newOperationV128Cmp(v128CmpTypeF64x2Ne), }, { name: wasm.OpcodeVecF64x2LtName, body: vv2v(wasm.OpcodeVecF64x2Lt), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeF64x2Lt), + expected: newOperationV128Cmp(v128CmpTypeF64x2Lt), }, { name: wasm.OpcodeVecF64x2GtName, body: vv2v(wasm.OpcodeVecF64x2Gt), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeF64x2Gt), + expected: newOperationV128Cmp(v128CmpTypeF64x2Gt), }, { name: wasm.OpcodeVecF64x2LeName, body: vv2v(wasm.OpcodeVecF64x2Le), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeF64x2Le), + expected: newOperationV128Cmp(v128CmpTypeF64x2Le), }, { name: wasm.OpcodeVecF64x2GeName, body: vv2v(wasm.OpcodeVecF64x2Ge), needDropBeforeReturn: true, - expected: NewOperationV128Cmp(V128CmpTypeF64x2Ge), + expected: newOperationV128Cmp(v128CmpTypeF64x2Ge), }, { name: wasm.OpcodeVecI8x16AllTrueName, body: v2v(wasm.OpcodeVecI8x16AllTrue), needDropBeforeReturn: true, - expected: NewOperationV128AllTrue(ShapeI8x16), + expected: newOperationV128AllTrue(shapeI8x16), }, { name: wasm.OpcodeVecI16x8AllTrueName, body: v2v(wasm.OpcodeVecI16x8AllTrue), needDropBeforeReturn: true, - expected: NewOperationV128AllTrue(ShapeI16x8), + expected: newOperationV128AllTrue(shapeI16x8), }, { name: wasm.OpcodeVecI32x4AllTrueName, body: v2v(wasm.OpcodeVecI32x4AllTrue), needDropBeforeReturn: true, - expected: NewOperationV128AllTrue(ShapeI32x4), + expected: newOperationV128AllTrue(shapeI32x4), }, { name: wasm.OpcodeVecI64x2AllTrueName, body: v2v(wasm.OpcodeVecI64x2AllTrue), needDropBeforeReturn: true, - expected: NewOperationV128AllTrue(ShapeI64x2), + expected: newOperationV128AllTrue(shapeI64x2), }, { name: wasm.OpcodeVecI8x16BitMaskName, body: v2v(wasm.OpcodeVecI8x16BitMask), - needDropBeforeReturn: true, expected: NewOperationV128BitMask(ShapeI8x16), + needDropBeforeReturn: true, expected: newOperationV128BitMask(shapeI8x16), }, { name: wasm.OpcodeVecI16x8BitMaskName, body: v2v(wasm.OpcodeVecI16x8BitMask), - needDropBeforeReturn: true, expected: NewOperationV128BitMask(ShapeI16x8), + needDropBeforeReturn: true, expected: newOperationV128BitMask(shapeI16x8), }, { name: wasm.OpcodeVecI32x4BitMaskName, body: v2v(wasm.OpcodeVecI32x4BitMask), - needDropBeforeReturn: true, expected: NewOperationV128BitMask(ShapeI32x4), + needDropBeforeReturn: true, expected: newOperationV128BitMask(shapeI32x4), }, { name: wasm.OpcodeVecI64x2BitMaskName, body: v2v(wasm.OpcodeVecI64x2BitMask), - needDropBeforeReturn: true, expected: NewOperationV128BitMask(ShapeI64x2), + needDropBeforeReturn: true, expected: newOperationV128BitMask(shapeI64x2), }, { name: wasm.OpcodeVecV128AnyTrueName, body: v2v(wasm.OpcodeVecV128AnyTrue), needDropBeforeReturn: true, - expected: NewOperationV128AnyTrue(), + expected: newOperationV128AnyTrue(), }, { name: wasm.OpcodeVecI8x16AddName, body: vv2v(wasm.OpcodeVecI8x16Add), needDropBeforeReturn: true, - expected: NewOperationV128Add(ShapeI8x16), + expected: newOperationV128Add(shapeI8x16), }, { name: wasm.OpcodeVecI8x16AddSatSName, body: vv2v(wasm.OpcodeVecI8x16AddSatS), needDropBeforeReturn: true, - expected: NewOperationV128AddSat(ShapeI8x16, true), + expected: newOperationV128AddSat(shapeI8x16, true), }, { name: wasm.OpcodeVecI8x16AddSatUName, body: vv2v(wasm.OpcodeVecI8x16AddSatU), needDropBeforeReturn: true, - expected: NewOperationV128AddSat(ShapeI8x16, false), + expected: newOperationV128AddSat(shapeI8x16, false), }, { name: wasm.OpcodeVecI8x16SubName, body: vv2v(wasm.OpcodeVecI8x16Sub), needDropBeforeReturn: true, - expected: NewOperationV128Sub(ShapeI8x16), + expected: newOperationV128Sub(shapeI8x16), }, { name: wasm.OpcodeVecI8x16SubSatSName, body: vv2v(wasm.OpcodeVecI8x16SubSatS), needDropBeforeReturn: true, - expected: NewOperationV128SubSat(ShapeI8x16, true), + expected: newOperationV128SubSat(shapeI8x16, true), }, { name: wasm.OpcodeVecI8x16SubSatUName, body: vv2v(wasm.OpcodeVecI8x16SubSatU), needDropBeforeReturn: true, - expected: NewOperationV128SubSat(ShapeI8x16, false), + expected: newOperationV128SubSat(shapeI8x16, false), }, { name: wasm.OpcodeVecI16x8AddName, body: vv2v(wasm.OpcodeVecI16x8Add), needDropBeforeReturn: true, - expected: NewOperationV128Add(ShapeI16x8), + expected: newOperationV128Add(shapeI16x8), }, { name: wasm.OpcodeVecI16x8AddSatSName, body: vv2v(wasm.OpcodeVecI16x8AddSatS), needDropBeforeReturn: true, - expected: NewOperationV128AddSat(ShapeI16x8, true), + expected: newOperationV128AddSat(shapeI16x8, true), }, { name: wasm.OpcodeVecI16x8AddSatUName, body: vv2v(wasm.OpcodeVecI16x8AddSatU), needDropBeforeReturn: true, - expected: NewOperationV128AddSat(ShapeI16x8, false), + expected: newOperationV128AddSat(shapeI16x8, false), }, { name: wasm.OpcodeVecI16x8SubName, body: vv2v(wasm.OpcodeVecI16x8Sub), needDropBeforeReturn: true, - expected: NewOperationV128Sub(ShapeI16x8), + expected: newOperationV128Sub(shapeI16x8), }, { name: wasm.OpcodeVecI16x8SubSatSName, body: vv2v(wasm.OpcodeVecI16x8SubSatS), needDropBeforeReturn: true, - expected: NewOperationV128SubSat(ShapeI16x8, true), + expected: newOperationV128SubSat(shapeI16x8, true), }, { name: wasm.OpcodeVecI16x8SubSatUName, body: vv2v(wasm.OpcodeVecI16x8SubSatU), needDropBeforeReturn: true, - expected: NewOperationV128SubSat(ShapeI16x8, false), + expected: newOperationV128SubSat(shapeI16x8, false), }, { name: wasm.OpcodeVecI16x8MulName, body: vv2v(wasm.OpcodeVecI16x8Mul), needDropBeforeReturn: true, - expected: NewOperationV128Mul(ShapeI16x8), + expected: newOperationV128Mul(shapeI16x8), }, { name: wasm.OpcodeVecI32x4AddName, body: vv2v(wasm.OpcodeVecI32x4Add), needDropBeforeReturn: true, - expected: NewOperationV128Add(ShapeI32x4), + expected: newOperationV128Add(shapeI32x4), }, { name: wasm.OpcodeVecI32x4SubName, body: vv2v(wasm.OpcodeVecI32x4Sub), needDropBeforeReturn: true, - expected: NewOperationV128Sub(ShapeI32x4), + expected: newOperationV128Sub(shapeI32x4), }, { name: wasm.OpcodeVecI32x4MulName, body: vv2v(wasm.OpcodeVecI32x4Mul), needDropBeforeReturn: true, - expected: NewOperationV128Mul(ShapeI32x4), + expected: newOperationV128Mul(shapeI32x4), }, { name: wasm.OpcodeVecI64x2AddName, body: vv2v(wasm.OpcodeVecI64x2Add), needDropBeforeReturn: true, - expected: NewOperationV128Add(ShapeI64x2), + expected: newOperationV128Add(shapeI64x2), }, { name: wasm.OpcodeVecI64x2SubName, body: vv2v(wasm.OpcodeVecI64x2Sub), needDropBeforeReturn: true, - expected: NewOperationV128Sub(ShapeI64x2), + expected: newOperationV128Sub(shapeI64x2), }, { name: wasm.OpcodeVecI64x2MulName, body: vv2v(wasm.OpcodeVecI64x2Mul), needDropBeforeReturn: true, - expected: NewOperationV128Mul(ShapeI64x2), + expected: newOperationV128Mul(shapeI64x2), }, { name: wasm.OpcodeVecF32x4AddName, body: vv2v(wasm.OpcodeVecF32x4Add), needDropBeforeReturn: true, - expected: NewOperationV128Add(ShapeF32x4), + expected: newOperationV128Add(shapeF32x4), }, { name: wasm.OpcodeVecF32x4SubName, body: vv2v(wasm.OpcodeVecF32x4Sub), needDropBeforeReturn: true, - expected: NewOperationV128Sub(ShapeF32x4), + expected: newOperationV128Sub(shapeF32x4), }, { name: wasm.OpcodeVecF32x4MulName, body: vv2v(wasm.OpcodeVecF32x4Mul), needDropBeforeReturn: true, - expected: NewOperationV128Mul(ShapeF32x4), + expected: newOperationV128Mul(shapeF32x4), }, { name: wasm.OpcodeVecF32x4DivName, body: vv2v(wasm.OpcodeVecF32x4Div), needDropBeforeReturn: true, - expected: NewOperationV128Div(ShapeF32x4), + expected: newOperationV128Div(shapeF32x4), }, { name: wasm.OpcodeVecF64x2AddName, body: vv2v(wasm.OpcodeVecF64x2Add), needDropBeforeReturn: true, - expected: NewOperationV128Add(ShapeF64x2), + expected: newOperationV128Add(shapeF64x2), }, { name: wasm.OpcodeVecF64x2SubName, body: vv2v(wasm.OpcodeVecF64x2Sub), needDropBeforeReturn: true, - expected: NewOperationV128Sub(ShapeF64x2), + expected: newOperationV128Sub(shapeF64x2), }, { name: wasm.OpcodeVecF64x2MulName, body: vv2v(wasm.OpcodeVecF64x2Mul), needDropBeforeReturn: true, - expected: NewOperationV128Mul(ShapeF64x2), + expected: newOperationV128Mul(shapeF64x2), }, { name: wasm.OpcodeVecF64x2DivName, body: vv2v(wasm.OpcodeVecF64x2Div), needDropBeforeReturn: true, - expected: NewOperationV128Div(ShapeF64x2), + expected: newOperationV128Div(shapeF64x2), }, { name: wasm.OpcodeVecI8x16MinSName, body: vv2v(wasm.OpcodeVecI8x16MinS), needDropBeforeReturn: true, - expected: NewOperationV128Min(ShapeI8x16, true), + expected: newOperationV128Min(shapeI8x16, true), }, { name: wasm.OpcodeVecI8x16MinUName, body: vv2v(wasm.OpcodeVecI8x16MinU), needDropBeforeReturn: true, - expected: NewOperationV128Min(ShapeI8x16, false), + expected: newOperationV128Min(shapeI8x16, false), }, { name: wasm.OpcodeVecI8x16MaxSName, body: vv2v(wasm.OpcodeVecI8x16MaxS), needDropBeforeReturn: true, - expected: NewOperationV128Max(ShapeI8x16, true), + expected: newOperationV128Max(shapeI8x16, true), }, { name: wasm.OpcodeVecI8x16MaxUName, body: vv2v(wasm.OpcodeVecI8x16MaxU), needDropBeforeReturn: true, - expected: NewOperationV128Max(ShapeI8x16, false), + expected: newOperationV128Max(shapeI8x16, false), }, { name: wasm.OpcodeVecI8x16AvgrUName, body: vv2v(wasm.OpcodeVecI8x16AvgrU), needDropBeforeReturn: true, - expected: NewOperationV128AvgrU(ShapeI8x16), + expected: newOperationV128AvgrU(shapeI8x16), }, { name: wasm.OpcodeVecI16x8MinSName, body: vv2v(wasm.OpcodeVecI16x8MinS), needDropBeforeReturn: true, - expected: NewOperationV128Min(ShapeI16x8, true), + expected: newOperationV128Min(shapeI16x8, true), }, { name: wasm.OpcodeVecI16x8MinUName, body: vv2v(wasm.OpcodeVecI16x8MinU), needDropBeforeReturn: true, - expected: NewOperationV128Min(ShapeI16x8, false), + expected: newOperationV128Min(shapeI16x8, false), }, { name: wasm.OpcodeVecI16x8MaxSName, body: vv2v(wasm.OpcodeVecI16x8MaxS), needDropBeforeReturn: true, - expected: NewOperationV128Max(ShapeI16x8, true), + expected: newOperationV128Max(shapeI16x8, true), }, { name: wasm.OpcodeVecI16x8MaxUName, body: vv2v(wasm.OpcodeVecI16x8MaxU), needDropBeforeReturn: true, - expected: NewOperationV128Max(ShapeI16x8, false), + expected: newOperationV128Max(shapeI16x8, false), }, { name: wasm.OpcodeVecI16x8AvgrUName, body: vv2v(wasm.OpcodeVecI16x8AvgrU), needDropBeforeReturn: true, - expected: NewOperationV128AvgrU(ShapeI16x8), + expected: newOperationV128AvgrU(shapeI16x8), }, { name: wasm.OpcodeVecI32x4MinSName, body: vv2v(wasm.OpcodeVecI32x4MinS), needDropBeforeReturn: true, - expected: NewOperationV128Min(ShapeI32x4, true), + expected: newOperationV128Min(shapeI32x4, true), }, { name: wasm.OpcodeVecI32x4MinUName, body: vv2v(wasm.OpcodeVecI32x4MinU), needDropBeforeReturn: true, - expected: NewOperationV128Min(ShapeI32x4, false), + expected: newOperationV128Min(shapeI32x4, false), }, { name: wasm.OpcodeVecI32x4MaxSName, body: vv2v(wasm.OpcodeVecI32x4MaxS), needDropBeforeReturn: true, - expected: NewOperationV128Max(ShapeI32x4, true), + expected: newOperationV128Max(shapeI32x4, true), }, { name: wasm.OpcodeVecI32x4MaxUName, body: vv2v(wasm.OpcodeVecI32x4MaxU), needDropBeforeReturn: true, - expected: NewOperationV128Max(ShapeI32x4, false), + expected: newOperationV128Max(shapeI32x4, false), }, { name: wasm.OpcodeVecF32x4MinName, body: vv2v(wasm.OpcodeVecF32x4Min), needDropBeforeReturn: true, - expected: NewOperationV128Min(ShapeF32x4, false), + expected: newOperationV128Min(shapeF32x4, false), }, { name: wasm.OpcodeVecF32x4MaxName, body: vv2v(wasm.OpcodeVecF32x4Max), needDropBeforeReturn: true, - expected: NewOperationV128Max(ShapeF32x4, false), + expected: newOperationV128Max(shapeF32x4, false), }, { name: wasm.OpcodeVecF64x2MinName, body: vv2v(wasm.OpcodeVecF64x2Min), needDropBeforeReturn: true, - expected: NewOperationV128Min(ShapeF64x2, false), + expected: newOperationV128Min(shapeF64x2, false), }, { name: wasm.OpcodeVecF64x2MaxName, body: vv2v(wasm.OpcodeVecF64x2Max), needDropBeforeReturn: true, - expected: NewOperationV128Max(ShapeF64x2, false), + expected: newOperationV128Max(shapeF64x2, false), }, { name: wasm.OpcodeVecI8x16AbsName, body: v2v(wasm.OpcodeVecI8x16Abs), needDropBeforeReturn: true, - expected: NewOperationV128Abs(ShapeI8x16), + expected: newOperationV128Abs(shapeI8x16), }, { name: wasm.OpcodeVecI8x16PopcntName, body: v2v(wasm.OpcodeVecI8x16Popcnt), needDropBeforeReturn: true, - expected: NewOperationV128Popcnt(ShapeI8x16), + expected: newOperationV128Popcnt(shapeI8x16), }, { name: wasm.OpcodeVecI16x8AbsName, body: v2v(wasm.OpcodeVecI16x8Abs), needDropBeforeReturn: true, - expected: NewOperationV128Abs(ShapeI16x8), + expected: newOperationV128Abs(shapeI16x8), }, { name: wasm.OpcodeVecI32x4AbsName, body: v2v(wasm.OpcodeVecI32x4Abs), needDropBeforeReturn: true, - expected: NewOperationV128Abs(ShapeI32x4), + expected: newOperationV128Abs(shapeI32x4), }, { name: wasm.OpcodeVecI64x2AbsName, body: v2v(wasm.OpcodeVecI64x2Abs), needDropBeforeReturn: true, - expected: NewOperationV128Abs(ShapeI64x2), + expected: newOperationV128Abs(shapeI64x2), }, { name: wasm.OpcodeVecF32x4AbsName, body: v2v(wasm.OpcodeVecF32x4Abs), needDropBeforeReturn: true, - expected: NewOperationV128Abs(ShapeF32x4), + expected: newOperationV128Abs(shapeF32x4), }, { name: wasm.OpcodeVecF64x2AbsName, body: v2v(wasm.OpcodeVecF64x2Abs), needDropBeforeReturn: true, - expected: NewOperationV128Abs(ShapeF64x2), + expected: newOperationV128Abs(shapeF64x2), }, { name: wasm.OpcodeVecF32x4CeilName, body: v2v(wasm.OpcodeVecF32x4Ceil), needDropBeforeReturn: true, - expected: NewOperationV128Ceil(ShapeF32x4), + expected: newOperationV128Ceil(shapeF32x4), }, { name: wasm.OpcodeVecF32x4FloorName, body: v2v(wasm.OpcodeVecF32x4Floor), needDropBeforeReturn: true, - expected: NewOperationV128Floor(ShapeF32x4), + expected: newOperationV128Floor(shapeF32x4), }, { name: wasm.OpcodeVecF32x4TruncName, body: v2v(wasm.OpcodeVecF32x4Trunc), needDropBeforeReturn: true, - expected: NewOperationV128Trunc(ShapeF32x4), + expected: newOperationV128Trunc(shapeF32x4), }, { name: wasm.OpcodeVecF32x4NearestName, body: v2v(wasm.OpcodeVecF32x4Nearest), needDropBeforeReturn: true, - expected: NewOperationV128Nearest(ShapeF32x4), + expected: newOperationV128Nearest(shapeF32x4), }, { name: wasm.OpcodeVecF64x2CeilName, body: v2v(wasm.OpcodeVecF64x2Ceil), needDropBeforeReturn: true, - expected: NewOperationV128Ceil(ShapeF64x2), + expected: newOperationV128Ceil(shapeF64x2), }, { name: wasm.OpcodeVecF64x2FloorName, body: v2v(wasm.OpcodeVecF64x2Floor), needDropBeforeReturn: true, - expected: NewOperationV128Floor(ShapeF64x2), + expected: newOperationV128Floor(shapeF64x2), }, { name: wasm.OpcodeVecF64x2TruncName, body: v2v(wasm.OpcodeVecF64x2Trunc), needDropBeforeReturn: true, - expected: NewOperationV128Trunc(ShapeF64x2), + expected: newOperationV128Trunc(shapeF64x2), }, { name: wasm.OpcodeVecF64x2NearestName, body: v2v(wasm.OpcodeVecF64x2Nearest), needDropBeforeReturn: true, - expected: NewOperationV128Nearest(ShapeF64x2), + expected: newOperationV128Nearest(shapeF64x2), }, { name: wasm.OpcodeVecF32x4PminName, body: vv2v(wasm.OpcodeVecF32x4Pmin), needDropBeforeReturn: true, - expected: NewOperationV128Pmin(ShapeF32x4), + expected: newOperationV128Pmin(shapeF32x4), }, { name: wasm.OpcodeVecF32x4PmaxName, body: vv2v(wasm.OpcodeVecF32x4Pmax), needDropBeforeReturn: true, - expected: NewOperationV128Pmax(ShapeF32x4), + expected: newOperationV128Pmax(shapeF32x4), }, { name: wasm.OpcodeVecF64x2PminName, body: vv2v(wasm.OpcodeVecF64x2Pmin), needDropBeforeReturn: true, - expected: NewOperationV128Pmin(ShapeF64x2), + expected: newOperationV128Pmin(shapeF64x2), }, { name: wasm.OpcodeVecF64x2PmaxName, body: vv2v(wasm.OpcodeVecF64x2Pmax), needDropBeforeReturn: true, - expected: NewOperationV128Pmax(ShapeF64x2), + expected: newOperationV128Pmax(shapeF64x2), }, { name: wasm.OpcodeVecI16x8Q15mulrSatSName, body: vv2v(wasm.OpcodeVecI16x8Q15mulrSatS), needDropBeforeReturn: true, - expected: NewOperationV128Q15mulrSatS(), + expected: newOperationV128Q15mulrSatS(), }, { name: wasm.OpcodeVecI16x8ExtMulLowI8x16SName, body: vv2v(wasm.OpcodeVecI16x8ExtMulLowI8x16S), needDropBeforeReturn: true, - expected: NewOperationV128ExtMul(ShapeI8x16, true, true), + expected: newOperationV128ExtMul(shapeI8x16, true, true), }, { name: wasm.OpcodeVecI16x8ExtMulHighI8x16SName, body: vv2v(wasm.OpcodeVecI16x8ExtMulHighI8x16S), needDropBeforeReturn: true, - expected: NewOperationV128ExtMul(ShapeI8x16, true, false), + expected: newOperationV128ExtMul(shapeI8x16, true, false), }, { name: wasm.OpcodeVecI16x8ExtMulLowI8x16UName, body: vv2v(wasm.OpcodeVecI16x8ExtMulLowI8x16U), needDropBeforeReturn: true, - expected: NewOperationV128ExtMul(ShapeI8x16, false, true), + expected: newOperationV128ExtMul(shapeI8x16, false, true), }, { name: wasm.OpcodeVecI16x8ExtMulHighI8x16UName, body: vv2v(wasm.OpcodeVecI16x8ExtMulHighI8x16U), needDropBeforeReturn: true, - expected: NewOperationV128ExtMul(ShapeI8x16, false, false), + expected: newOperationV128ExtMul(shapeI8x16, false, false), }, { name: wasm.OpcodeVecI32x4ExtMulLowI16x8SName, body: vv2v(wasm.OpcodeVecI32x4ExtMulLowI16x8S), needDropBeforeReturn: true, - expected: NewOperationV128ExtMul(ShapeI16x8, true, true), + expected: newOperationV128ExtMul(shapeI16x8, true, true), }, { name: wasm.OpcodeVecI32x4ExtMulHighI16x8SName, body: vv2v(wasm.OpcodeVecI32x4ExtMulHighI16x8S), needDropBeforeReturn: true, - expected: NewOperationV128ExtMul(ShapeI16x8, true, false), + expected: newOperationV128ExtMul(shapeI16x8, true, false), }, { name: wasm.OpcodeVecI32x4ExtMulLowI16x8UName, body: vv2v(wasm.OpcodeVecI32x4ExtMulLowI16x8U), needDropBeforeReturn: true, - expected: NewOperationV128ExtMul(ShapeI16x8, false, true), + expected: newOperationV128ExtMul(shapeI16x8, false, true), }, { name: wasm.OpcodeVecI32x4ExtMulHighI16x8UName, body: vv2v(wasm.OpcodeVecI32x4ExtMulHighI16x8U), needDropBeforeReturn: true, - expected: NewOperationV128ExtMul(ShapeI16x8, false, false), + expected: newOperationV128ExtMul(shapeI16x8, false, false), }, { name: wasm.OpcodeVecI64x2ExtMulLowI32x4SName, body: vv2v(wasm.OpcodeVecI64x2ExtMulLowI32x4S), needDropBeforeReturn: true, - expected: NewOperationV128ExtMul(ShapeI32x4, true, true), + expected: newOperationV128ExtMul(shapeI32x4, true, true), }, { name: wasm.OpcodeVecI64x2ExtMulHighI32x4SName, body: vv2v(wasm.OpcodeVecI64x2ExtMulHighI32x4S), needDropBeforeReturn: true, - expected: NewOperationV128ExtMul(ShapeI32x4, true, false), + expected: newOperationV128ExtMul(shapeI32x4, true, false), }, { name: wasm.OpcodeVecI64x2ExtMulLowI32x4UName, body: vv2v(wasm.OpcodeVecI64x2ExtMulLowI32x4U), needDropBeforeReturn: true, - expected: NewOperationV128ExtMul(ShapeI32x4, false, true), + expected: newOperationV128ExtMul(shapeI32x4, false, true), }, { name: wasm.OpcodeVecI64x2ExtMulHighI32x4UName, body: vv2v(wasm.OpcodeVecI64x2ExtMulHighI32x4U), needDropBeforeReturn: true, - expected: NewOperationV128ExtMul(ShapeI32x4, false, false), + expected: newOperationV128ExtMul(shapeI32x4, false, false), }, { name: wasm.OpcodeVecI16x8ExtendLowI8x16SName, body: v2v(wasm.OpcodeVecI16x8ExtendLowI8x16S), needDropBeforeReturn: true, - expected: NewOperationV128Extend(ShapeI8x16, true, true), + expected: newOperationV128Extend(shapeI8x16, true, true), }, { name: wasm.OpcodeVecI16x8ExtendHighI8x16SName, body: v2v(wasm.OpcodeVecI16x8ExtendHighI8x16S), needDropBeforeReturn: true, - expected: NewOperationV128Extend(ShapeI8x16, true, false), + expected: newOperationV128Extend(shapeI8x16, true, false), }, { name: wasm.OpcodeVecI16x8ExtendLowI8x16UName, body: v2v(wasm.OpcodeVecI16x8ExtendLowI8x16U), needDropBeforeReturn: true, - expected: NewOperationV128Extend(ShapeI8x16, false, true), + expected: newOperationV128Extend(shapeI8x16, false, true), }, { name: wasm.OpcodeVecI16x8ExtendHighI8x16UName, body: v2v(wasm.OpcodeVecI16x8ExtendHighI8x16U), needDropBeforeReturn: true, - expected: NewOperationV128Extend(ShapeI8x16, false, false), + expected: newOperationV128Extend(shapeI8x16, false, false), }, { name: wasm.OpcodeVecI32x4ExtendLowI16x8SName, body: v2v(wasm.OpcodeVecI32x4ExtendLowI16x8S), needDropBeforeReturn: true, - expected: NewOperationV128Extend(ShapeI16x8, true, true), + expected: newOperationV128Extend(shapeI16x8, true, true), }, { name: wasm.OpcodeVecI32x4ExtendHighI16x8SName, body: v2v(wasm.OpcodeVecI32x4ExtendHighI16x8S), needDropBeforeReturn: true, - expected: NewOperationV128Extend(ShapeI16x8, true, false), + expected: newOperationV128Extend(shapeI16x8, true, false), }, { name: wasm.OpcodeVecI32x4ExtendLowI16x8UName, body: v2v(wasm.OpcodeVecI32x4ExtendLowI16x8U), needDropBeforeReturn: true, - expected: NewOperationV128Extend(ShapeI16x8, false, true), + expected: newOperationV128Extend(shapeI16x8, false, true), }, { name: wasm.OpcodeVecI32x4ExtendHighI16x8UName, body: v2v(wasm.OpcodeVecI32x4ExtendHighI16x8U), needDropBeforeReturn: true, - expected: NewOperationV128Extend(ShapeI16x8, false, false), + expected: newOperationV128Extend(shapeI16x8, false, false), }, { name: wasm.OpcodeVecI64x2ExtendLowI32x4SName, body: v2v(wasm.OpcodeVecI64x2ExtendLowI32x4S), needDropBeforeReturn: true, - expected: NewOperationV128Extend(ShapeI32x4, true, true), + expected: newOperationV128Extend(shapeI32x4, true, true), }, { name: wasm.OpcodeVecI64x2ExtendHighI32x4SName, body: v2v(wasm.OpcodeVecI64x2ExtendHighI32x4S), needDropBeforeReturn: true, - expected: NewOperationV128Extend(ShapeI32x4, true, false), + expected: newOperationV128Extend(shapeI32x4, true, false), }, { name: wasm.OpcodeVecI64x2ExtendLowI32x4UName, body: v2v(wasm.OpcodeVecI64x2ExtendLowI32x4U), needDropBeforeReturn: true, - expected: NewOperationV128Extend(ShapeI32x4, false, true), + expected: newOperationV128Extend(shapeI32x4, false, true), }, { name: wasm.OpcodeVecI64x2ExtendHighI32x4UName, body: v2v(wasm.OpcodeVecI64x2ExtendHighI32x4U), needDropBeforeReturn: true, - expected: NewOperationV128Extend(ShapeI32x4, false, false), + expected: newOperationV128Extend(shapeI32x4, false, false), }, { name: wasm.OpcodeVecI16x8ExtaddPairwiseI8x16SName, body: v2v(wasm.OpcodeVecI16x8ExtaddPairwiseI8x16S), needDropBeforeReturn: true, - expected: NewOperationV128ExtAddPairwise(ShapeI8x16, true), + expected: newOperationV128ExtAddPairwise(shapeI8x16, true), }, { name: wasm.OpcodeVecI16x8ExtaddPairwiseI8x16UName, body: v2v(wasm.OpcodeVecI16x8ExtaddPairwiseI8x16U), needDropBeforeReturn: true, - expected: NewOperationV128ExtAddPairwise(ShapeI8x16, false), + expected: newOperationV128ExtAddPairwise(shapeI8x16, false), }, { name: wasm.OpcodeVecI32x4ExtaddPairwiseI16x8SName, body: v2v(wasm.OpcodeVecI32x4ExtaddPairwiseI16x8S), needDropBeforeReturn: true, - expected: NewOperationV128ExtAddPairwise(ShapeI16x8, true), + expected: newOperationV128ExtAddPairwise(shapeI16x8, true), }, { name: wasm.OpcodeVecI32x4ExtaddPairwiseI16x8UName, body: v2v(wasm.OpcodeVecI32x4ExtaddPairwiseI16x8U), needDropBeforeReturn: true, - expected: NewOperationV128ExtAddPairwise(ShapeI16x8, false), + expected: newOperationV128ExtAddPairwise(shapeI16x8, false), }, { name: wasm.OpcodeVecF64x2PromoteLowF32x4ZeroName, body: v2v(wasm.OpcodeVecF64x2PromoteLowF32x4Zero), needDropBeforeReturn: true, - expected: NewOperationV128FloatPromote(), + expected: newOperationV128FloatPromote(), }, { name: wasm.OpcodeVecF32x4DemoteF64x2ZeroName, body: v2v(wasm.OpcodeVecF32x4DemoteF64x2Zero), needDropBeforeReturn: true, - expected: NewOperationV128FloatDemote(), + expected: newOperationV128FloatDemote(), }, { name: wasm.OpcodeVecF32x4ConvertI32x4SName, body: v2v(wasm.OpcodeVecF32x4ConvertI32x4S), needDropBeforeReturn: true, - expected: NewOperationV128FConvertFromI(ShapeF32x4, true), + expected: newOperationV128FConvertFromI(shapeF32x4, true), }, { name: wasm.OpcodeVecF32x4ConvertI32x4UName, body: v2v(wasm.OpcodeVecF32x4ConvertI32x4U), needDropBeforeReturn: true, - expected: NewOperationV128FConvertFromI(ShapeF32x4, false), + expected: newOperationV128FConvertFromI(shapeF32x4, false), }, { name: wasm.OpcodeVecF64x2ConvertLowI32x4SName, body: v2v(wasm.OpcodeVecF64x2ConvertLowI32x4S), needDropBeforeReturn: true, - expected: NewOperationV128FConvertFromI(ShapeF64x2, true), + expected: newOperationV128FConvertFromI(shapeF64x2, true), }, { name: wasm.OpcodeVecF64x2ConvertLowI32x4UName, body: v2v(wasm.OpcodeVecF64x2ConvertLowI32x4U), needDropBeforeReturn: true, - expected: NewOperationV128FConvertFromI(ShapeF64x2, false), + expected: newOperationV128FConvertFromI(shapeF64x2, false), }, { name: wasm.OpcodeVecI32x4DotI16x8SName, body: vv2v(wasm.OpcodeVecI32x4DotI16x8S), needDropBeforeReturn: true, - expected: NewOperationV128Dot(), + expected: newOperationV128Dot(), }, { name: wasm.OpcodeVecI8x16NarrowI16x8SName, body: vv2v(wasm.OpcodeVecI8x16NarrowI16x8S), needDropBeforeReturn: true, - expected: NewOperationV128Narrow(ShapeI16x8, true), + expected: newOperationV128Narrow(shapeI16x8, true), }, { name: wasm.OpcodeVecI8x16NarrowI16x8UName, body: vv2v(wasm.OpcodeVecI8x16NarrowI16x8U), needDropBeforeReturn: true, - expected: NewOperationV128Narrow(ShapeI16x8, false), + expected: newOperationV128Narrow(shapeI16x8, false), }, { name: wasm.OpcodeVecI16x8NarrowI32x4SName, body: vv2v(wasm.OpcodeVecI16x8NarrowI32x4S), needDropBeforeReturn: true, - expected: NewOperationV128Narrow(ShapeI32x4, true), + expected: newOperationV128Narrow(shapeI32x4, true), }, { name: wasm.OpcodeVecI16x8NarrowI32x4UName, body: vv2v(wasm.OpcodeVecI16x8NarrowI32x4U), needDropBeforeReturn: true, - expected: NewOperationV128Narrow(ShapeI32x4, false), + expected: newOperationV128Narrow(shapeI32x4, false), }, { name: wasm.OpcodeVecI32x4TruncSatF32x4SName, body: v2v(wasm.OpcodeVecI32x4TruncSatF32x4S), needDropBeforeReturn: true, - expected: NewOperationV128ITruncSatFromF(ShapeF32x4, true), + expected: newOperationV128ITruncSatFromF(shapeF32x4, true), }, { name: wasm.OpcodeVecI32x4TruncSatF32x4UName, body: v2v(wasm.OpcodeVecI32x4TruncSatF32x4U), needDropBeforeReturn: true, - expected: NewOperationV128ITruncSatFromF(ShapeF32x4, false), + expected: newOperationV128ITruncSatFromF(shapeF32x4, false), }, { name: wasm.OpcodeVecI32x4TruncSatF64x2SZeroName, body: v2v(wasm.OpcodeVecI32x4TruncSatF64x2SZero), needDropBeforeReturn: true, - expected: NewOperationV128ITruncSatFromF(ShapeF64x2, true), + expected: newOperationV128ITruncSatFromF(shapeF64x2, true), }, { name: wasm.OpcodeVecI32x4TruncSatF64x2UZeroName, body: v2v(wasm.OpcodeVecI32x4TruncSatF64x2UZero), needDropBeforeReturn: true, - expected: NewOperationV128ITruncSatFromF(ShapeF64x2, false), + expected: newOperationV128ITruncSatFromF(shapeF64x2, false), }, } @@ -2644,13 +2644,13 @@ func TestCompile_Vec(t *testing.T) { MemorySection: &wasm.Memory{}, CodeSection: []wasm.Code{{Body: tc.body}}, } - c, err := NewCompiler(api.CoreFeaturesV2, 0, module, false) + c, err := newCompiler(api.CoreFeaturesV2, 0, module, false) require.NoError(t, err) res, err := c.Next() require.NoError(t, err) - var actual UnionOperation + var actual unionOperation if tc.needDropBeforeReturn { // If the drop operation is inserted, the target op exits at -3 // as the operations looks like: [... target, drop, br(to return)]. @@ -2671,7 +2671,7 @@ func TestCompile_unreachable_Br_BrIf_BrTable(t *testing.T) { tests := []struct { name string mod *wasm.Module - expected []UnionOperation + expected []unionOperation }{ { name: "br", @@ -2686,7 +2686,7 @@ func TestCompile_unreachable_Br_BrIf_BrTable(t *testing.T) { wasm.OpcodeEnd, // End the function. }}}, }, - expected: []UnionOperation{NewOperationBr(NewLabel(LabelKindReturn, 0))}, + expected: []unionOperation{newOperationBr(newLabel(labelKindReturn, 0))}, }, { name: "br_if", @@ -2702,7 +2702,7 @@ func TestCompile_unreachable_Br_BrIf_BrTable(t *testing.T) { wasm.OpcodeEnd, // End the function. }}}, }, - expected: []UnionOperation{NewOperationBr(NewLabel(LabelKindReturn, 0))}, + expected: []unionOperation{newOperationBr(newLabel(labelKindReturn, 0))}, }, { name: "br_table", @@ -2717,14 +2717,14 @@ func TestCompile_unreachable_Br_BrIf_BrTable(t *testing.T) { wasm.OpcodeEnd, // End the function. }}}, }, - expected: []UnionOperation{NewOperationBr(NewLabel(LabelKindReturn, 0))}, + expected: []unionOperation{newOperationBr(newLabel(labelKindReturn, 0))}, }, } for _, tt := range tests { tc := tt t.Run(tc.name, func(t *testing.T) { - c, err := NewCompiler(api.CoreFeaturesV2, 0, tc.mod, false) + c, err := newCompiler(api.CoreFeaturesV2, 0, tc.mod, false) require.NoError(t, err) actual, err := c.Next() @@ -2740,7 +2740,7 @@ func TestCompile_drop_vectors(t *testing.T) { tests := []struct { name string mod *wasm.Module - expected []UnionOperation + expected []unionOperation }{ { name: "basic", @@ -2754,12 +2754,12 @@ func TestCompile_drop_vectors(t *testing.T) { wasm.OpcodeEnd, }}}, }, - expected: []UnionOperation{ - NewOperationV128Const(0x1, 0x2), - // InclusiveRange is the range in uint64 representation, so dropping a vector value on top + expected: []unionOperation{ + newOperationV128Const(0x1, 0x2), + // inclusiveRange is the range in uint64 representation, so dropping a vector value on top // should be translated as drop [0..1] inclusively. - NewOperationDrop(InclusiveRange{Start: 0, End: 1}), - NewOperationBr(NewLabel(LabelKindReturn, 0)), + newOperationDrop(inclusiveRange{Start: 0, End: 1}), + newOperationBr(newLabel(labelKindReturn, 0)), }, }, } @@ -2767,7 +2767,7 @@ func TestCompile_drop_vectors(t *testing.T) { for _, tt := range tests { tc := tt t.Run(tc.name, func(t *testing.T) { - c, err := NewCompiler(api.CoreFeaturesV2, 0, tc.mod, false) + c, err := newCompiler(api.CoreFeaturesV2, 0, tc.mod, false) require.NoError(t, err) actual, err := c.Next() @@ -2781,7 +2781,7 @@ func TestCompile_select_vectors(t *testing.T) { tests := []struct { name string mod *wasm.Module - expected []UnionOperation + expected []unionOperation }{ { name: "non typed", @@ -2800,13 +2800,13 @@ func TestCompile_select_vectors(t *testing.T) { }}}, FunctionDefinitionSection: []wasm.FunctionDefinition{{}}, }, - expected: []UnionOperation{ - NewOperationV128Const(0x1, 0x2), - NewOperationV128Const(0x3, 0x4), - NewOperationConstI32(0), - NewOperationSelect(true), - NewOperationDrop(InclusiveRange{Start: 0, End: 1}), - NewOperationBr(NewLabel(LabelKindReturn, 0)), + expected: []unionOperation{ + newOperationV128Const(0x1, 0x2), + newOperationV128Const(0x3, 0x4), + newOperationConstI32(0), + newOperationSelect(true), + newOperationDrop(inclusiveRange{Start: 0, End: 1}), + newOperationBr(newLabel(labelKindReturn, 0)), }, }, { @@ -2826,13 +2826,13 @@ func TestCompile_select_vectors(t *testing.T) { }}}, FunctionDefinitionSection: []wasm.FunctionDefinition{{}}, }, - expected: []UnionOperation{ - NewOperationV128Const(0x1, 0x2), - NewOperationV128Const(0x3, 0x4), - NewOperationConstI32(0), - NewOperationSelect(true), - NewOperationDrop(InclusiveRange{Start: 0, End: 1}), - NewOperationBr(NewLabel(LabelKindReturn, 0)), + expected: []unionOperation{ + newOperationV128Const(0x1, 0x2), + newOperationV128Const(0x3, 0x4), + newOperationConstI32(0), + newOperationSelect(true), + newOperationDrop(inclusiveRange{Start: 0, End: 1}), + newOperationBr(newLabel(labelKindReturn, 0)), }, }, } @@ -2840,7 +2840,7 @@ func TestCompile_select_vectors(t *testing.T) { for _, tt := range tests { tc := tt t.Run(tc.name, func(t *testing.T) { - c, err := NewCompiler(api.CoreFeaturesV2, 0, tc.mod, false) + c, err := newCompiler(api.CoreFeaturesV2, 0, tc.mod, false) require.NoError(t, err) actual, err := c.Next() @@ -2862,7 +2862,7 @@ func TestCompiler_initializeStack(t *testing.T) { { name: "no function local, args>results", sig: &wasm.FunctionType{ - Params: []wasm.ValueType{i32, f32}, + Params: []wasm.ValueType{i32, wf32}, Results: []wasm.ValueType{i32}, ParamNumInUint64: 2, ResultNumInUint64: 1, @@ -2882,7 +2882,7 @@ func TestCompiler_initializeStack(t *testing.T) { { name: "no function local, args>results, with vector", sig: &wasm.FunctionType{ - Params: []wasm.ValueType{i32, v128, f32}, + Params: []wasm.ValueType{i32, v128, wf32}, Results: []wasm.ValueType{i32}, ParamNumInUint64: 4, ResultNumInUint64: 1, @@ -2904,7 +2904,7 @@ func TestCompiler_initializeStack(t *testing.T) { name: "no function local, argsresults", sig: &wasm.FunctionType{ - Params: []wasm.ValueType{i32, f32}, + Params: []wasm.ValueType{i32, wf32}, Results: []wasm.ValueType{i32}, ParamNumInUint64: 2, ResultNumInUint64: 1, }, - functionLocalTypes: []wasm.ValueType{f64}, + functionLocalTypes: []wasm.ValueType{wf64}, callFrameStackSizeInUint64: 4, // [i32, f32, callframe.0, callframe.1, callframe.2, callframe.3, f64] expLocalIndexToStackHeightInUint64: []int{ @@ -2945,7 +2945,7 @@ func TestCompiler_initializeStack(t *testing.T) { { name: "function locals, args>results, with vector", sig: &wasm.FunctionType{ - Params: []wasm.ValueType{i32, v128, f32}, + Params: []wasm.ValueType{i32, v128, wf32}, Results: []wasm.ValueType{i32}, ParamNumInUint64: 4, ResultNumInUint64: 1, @@ -2970,7 +2970,7 @@ func TestCompiler_initializeStack(t *testing.T) { ParamNumInUint64: 1, ResultNumInUint64: 4, }, - functionLocalTypes: []wasm.ValueType{f64}, + functionLocalTypes: []wasm.ValueType{wf64}, callFrameStackSizeInUint64: 4, // [i32, _, _, _, callframe.0, callframe.1, callframe.2, callframe.3, f64] expLocalIndexToStackHeightInUint64: []int{0, 8}, @@ -2978,12 +2978,12 @@ func TestCompiler_initializeStack(t *testing.T) { { name: "function locals, args 0 { @@ -433,14 +432,14 @@ func (e *engine) lowerIR(ir *wazeroir.CompilationResult, ret *compiledFunction) copy(ret.offsetsInWasmBinary, offsets) } - labelAddressResolutions := [wazeroir.LabelKindNum][]uint64{} + labelAddressResolutions := [labelKindNum][]uint64{} // First, we iterate all labels, and resolve the address. for i := range ret.body { op := &ret.body[i] switch op.Kind { - case wazeroir.OperationKindLabel: - label := wazeroir.Label(op.U1) + case operationKindLabel: + label := label(op.U1) address := uint64(i) kind, fid := label.Kind(), label.FrameID() @@ -460,22 +459,22 @@ func (e *engine) lowerIR(ir *wazeroir.CompilationResult, ret *compiledFunction) for i := range ret.body { op := &ret.body[i] switch op.Kind { - case wazeroir.OperationKindBr: - e.setLabelAddress(&op.U1, wazeroir.Label(op.U1), labelAddressResolutions) - case wazeroir.OperationKindBrIf: - e.setLabelAddress(&op.U1, wazeroir.Label(op.U1), labelAddressResolutions) - e.setLabelAddress(&op.U2, wazeroir.Label(op.U2), labelAddressResolutions) - case wazeroir.OperationKindBrTable: + case operationKindBr: + e.setLabelAddress(&op.U1, label(op.U1), labelAddressResolutions) + case operationKindBrIf: + e.setLabelAddress(&op.U1, label(op.U1), labelAddressResolutions) + e.setLabelAddress(&op.U2, label(op.U2), labelAddressResolutions) + case operationKindBrTable: for j := 0; j < len(op.Us); j += 2 { target := op.Us[j] - e.setLabelAddress(&op.Us[j], wazeroir.Label(target), labelAddressResolutions) + e.setLabelAddress(&op.Us[j], label(target), labelAddressResolutions) } } } return nil } -func (e *engine) setLabelAddress(op *uint64, label wazeroir.Label, labelAddressResolutions [wazeroir.LabelKindNum][]uint64) { +func (e *engine) setLabelAddress(op *uint64, label label, labelAddressResolutions [labelKindNum][]uint64) { if label.IsReturnTarget() { // Jmp to the end of the possible binary. *op = math.MaxUint64 @@ -712,23 +711,23 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance // on, for example, how many args are used, // how the stack is modified, etc. switch op.Kind { - case wazeroir.OperationKindBuiltinFunctionCheckExitCode: + case operationKindBuiltinFunctionCheckExitCode: if err := m.FailIfClosed(); err != nil { panic(err) } frame.pc++ - case wazeroir.OperationKindUnreachable: + case operationKindUnreachable: panic(wasmruntime.ErrRuntimeUnreachable) - case wazeroir.OperationKindBr: + case operationKindBr: frame.pc = op.U1 - case wazeroir.OperationKindBrIf: + case operationKindBrIf: if ce.popValue() > 0 { ce.drop(op.U3) frame.pc = op.U1 } else { frame.pc = op.U2 } - case wazeroir.OperationKindBrTable: + case operationKindBrTable: v := ce.popValue() defaultAt := uint64(len(op.Us))/2 - 1 if v > defaultAt { @@ -737,7 +736,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance v *= 2 ce.drop(op.Us[v+1]) frame.pc = op.Us[v] - case wazeroir.OperationKindCall: + case operationKindCall: func() { if ctx.Value(expctxkeys.EnableSnapshotterKey{}) != nil { defer func() { @@ -756,7 +755,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.callFunction(ctx, f.moduleInstance, &functions[op.U1]) }() frame.pc++ - case wazeroir.OperationKindCallIndirect: + case operationKindCallIndirect: offset := ce.popValue() table := tables[op.U2] if offset >= uint64(len(table.References)) { @@ -774,10 +773,10 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.callFunction(ctx, f.moduleInstance, tf) frame.pc++ - case wazeroir.OperationKindDrop: + case operationKindDrop: ce.drop(op.U1) frame.pc++ - case wazeroir.OperationKindSelect: + case operationKindSelect: c := ce.popValue() if op.B3 { // Target is vector. x2Hi, x2Lo := ce.popValue(), ce.popValue() @@ -794,14 +793,14 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance } } frame.pc++ - case wazeroir.OperationKindPick: + case operationKindPick: index := len(ce.stack) - 1 - int(op.U1) ce.pushValue(ce.stack[index]) if op.B3 { // V128 value target. ce.pushValue(ce.stack[index+1]) } frame.pc++ - case wazeroir.OperationKindSet: + case operationKindSet: if op.B3 { // V128 value target. lowIndex := len(ce.stack) - 1 - int(op.U1) highIndex := lowIndex + 1 @@ -812,30 +811,30 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.stack[index] = ce.popValue() } frame.pc++ - case wazeroir.OperationKindGlobalGet: + case operationKindGlobalGet: g := globals[op.U1] ce.pushValue(g.Val) if g.Type.ValType == wasm.ValueTypeV128 { ce.pushValue(g.ValHi) } frame.pc++ - case wazeroir.OperationKindGlobalSet: + case operationKindGlobalSet: g := globals[op.U1] if g.Type.ValType == wasm.ValueTypeV128 { g.ValHi = ce.popValue() } g.Val = ce.popValue() frame.pc++ - case wazeroir.OperationKindLoad: + case operationKindLoad: offset := ce.popMemoryOffset(op) - switch wazeroir.UnsignedType(op.B1) { - case wazeroir.UnsignedTypeI32, wazeroir.UnsignedTypeF32: + switch unsignedType(op.B1) { + case unsignedTypeI32, unsignedTypeF32: if val, ok := memoryInst.ReadUint32Le(offset); !ok { panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) } else { ce.pushValue(uint64(val)) } - case wazeroir.UnsignedTypeI64, wazeroir.UnsignedTypeF64: + case unsignedTypeI64, unsignedTypeF64: if val, ok := memoryInst.ReadUint64Le(offset); !ok { panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) } else { @@ -843,38 +842,38 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance } } frame.pc++ - case wazeroir.OperationKindLoad8: + case operationKindLoad8: val, ok := memoryInst.ReadByte(ce.popMemoryOffset(op)) if !ok { panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) } - switch wazeroir.SignedInt(op.B1) { - case wazeroir.SignedInt32: + switch signedInt(op.B1) { + case signedInt32: ce.pushValue(uint64(uint32(int8(val)))) - case wazeroir.SignedInt64: + case signedInt64: ce.pushValue(uint64(int8(val))) - case wazeroir.SignedUint32, wazeroir.SignedUint64: + case signedUint32, signedUint64: ce.pushValue(uint64(val)) } frame.pc++ - case wazeroir.OperationKindLoad16: + case operationKindLoad16: val, ok := memoryInst.ReadUint16Le(ce.popMemoryOffset(op)) if !ok { panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) } - switch wazeroir.SignedInt(op.B1) { - case wazeroir.SignedInt32: + switch signedInt(op.B1) { + case signedInt32: ce.pushValue(uint64(uint32(int16(val)))) - case wazeroir.SignedInt64: + case signedInt64: ce.pushValue(uint64(int16(val))) - case wazeroir.SignedUint32, wazeroir.SignedUint64: + case signedUint32, signedUint64: ce.pushValue(uint64(val)) } frame.pc++ - case wazeroir.OperationKindLoad32: + case operationKindLoad32: val, ok := memoryInst.ReadUint32Le(ce.popMemoryOffset(op)) if !ok { panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) @@ -886,45 +885,45 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(uint64(val)) } frame.pc++ - case wazeroir.OperationKindStore: + case operationKindStore: val := ce.popValue() offset := ce.popMemoryOffset(op) - switch wazeroir.UnsignedType(op.B1) { - case wazeroir.UnsignedTypeI32, wazeroir.UnsignedTypeF32: + switch unsignedType(op.B1) { + case unsignedTypeI32, unsignedTypeF32: if !memoryInst.WriteUint32Le(offset, uint32(val)) { panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) } - case wazeroir.UnsignedTypeI64, wazeroir.UnsignedTypeF64: + case unsignedTypeI64, unsignedTypeF64: if !memoryInst.WriteUint64Le(offset, val) { panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) } } frame.pc++ - case wazeroir.OperationKindStore8: + case operationKindStore8: val := byte(ce.popValue()) offset := ce.popMemoryOffset(op) if !memoryInst.WriteByte(offset, val) { panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) } frame.pc++ - case wazeroir.OperationKindStore16: + case operationKindStore16: val := uint16(ce.popValue()) offset := ce.popMemoryOffset(op) if !memoryInst.WriteUint16Le(offset, val) { panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) } frame.pc++ - case wazeroir.OperationKindStore32: + case operationKindStore32: val := uint32(ce.popValue()) offset := ce.popMemoryOffset(op) if !memoryInst.WriteUint32Le(offset, val) { panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) } frame.pc++ - case wazeroir.OperationKindMemorySize: + case operationKindMemorySize: ce.pushValue(uint64(memoryInst.Pages())) frame.pc++ - case wazeroir.OperationKindMemoryGrow: + case operationKindMemoryGrow: n := ce.popValue() if res, ok := memoryInst.Grow(uint32(n)); !ok { ce.pushValue(uint64(0xffffffff)) // = -1 in signed 32-bit integer. @@ -932,23 +931,23 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(uint64(res)) } frame.pc++ - case wazeroir.OperationKindConstI32, wazeroir.OperationKindConstI64, - wazeroir.OperationKindConstF32, wazeroir.OperationKindConstF64: + case operationKindConstI32, operationKindConstI64, + operationKindConstF32, operationKindConstF64: ce.pushValue(op.U1) frame.pc++ - case wazeroir.OperationKindEq: + case operationKindEq: var b bool - switch wazeroir.UnsignedType(op.B1) { - case wazeroir.UnsignedTypeI32: + switch unsignedType(op.B1) { + case unsignedTypeI32: v2, v1 := ce.popValue(), ce.popValue() b = uint32(v1) == uint32(v2) - case wazeroir.UnsignedTypeI64: + case unsignedTypeI64: v2, v1 := ce.popValue(), ce.popValue() b = v1 == v2 - case wazeroir.UnsignedTypeF32: + case unsignedTypeF32: v2, v1 := ce.popValue(), ce.popValue() b = math.Float32frombits(uint32(v2)) == math.Float32frombits(uint32(v1)) - case wazeroir.UnsignedTypeF64: + case unsignedTypeF64: v2, v1 := ce.popValue(), ce.popValue() b = math.Float64frombits(v2) == math.Float64frombits(v1) } @@ -958,16 +957,16 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(0) } frame.pc++ - case wazeroir.OperationKindNe: + case operationKindNe: var b bool - switch wazeroir.UnsignedType(op.B1) { - case wazeroir.UnsignedTypeI32, wazeroir.UnsignedTypeI64: + switch unsignedType(op.B1) { + case unsignedTypeI32, unsignedTypeI64: v2, v1 := ce.popValue(), ce.popValue() b = v1 != v2 - case wazeroir.UnsignedTypeF32: + case unsignedTypeF32: v2, v1 := ce.popValue(), ce.popValue() b = math.Float32frombits(uint32(v2)) != math.Float32frombits(uint32(v1)) - case wazeroir.UnsignedTypeF64: + case unsignedTypeF64: v2, v1 := ce.popValue(), ce.popValue() b = math.Float64frombits(v2) != math.Float64frombits(v1) } @@ -977,27 +976,27 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(0) } frame.pc++ - case wazeroir.OperationKindEqz: + case operationKindEqz: if ce.popValue() == 0 { ce.pushValue(1) } else { ce.pushValue(0) } frame.pc++ - case wazeroir.OperationKindLt: + case operationKindLt: v2 := ce.popValue() v1 := ce.popValue() var b bool - switch wazeroir.SignedType(op.B1) { - case wazeroir.SignedTypeInt32: + switch signedType(op.B1) { + case signedTypeInt32: b = int32(v1) < int32(v2) - case wazeroir.SignedTypeInt64: + case signedTypeInt64: b = int64(v1) < int64(v2) - case wazeroir.SignedTypeUint32, wazeroir.SignedTypeUint64: + case signedTypeUint32, signedTypeUint64: b = v1 < v2 - case wazeroir.SignedTypeFloat32: + case signedTypeFloat32: b = math.Float32frombits(uint32(v1)) < math.Float32frombits(uint32(v2)) - case wazeroir.SignedTypeFloat64: + case signedTypeFloat64: b = math.Float64frombits(v1) < math.Float64frombits(v2) } if b { @@ -1006,20 +1005,20 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(0) } frame.pc++ - case wazeroir.OperationKindGt: + case operationKindGt: v2 := ce.popValue() v1 := ce.popValue() var b bool - switch wazeroir.SignedType(op.B1) { - case wazeroir.SignedTypeInt32: + switch signedType(op.B1) { + case signedTypeInt32: b = int32(v1) > int32(v2) - case wazeroir.SignedTypeInt64: + case signedTypeInt64: b = int64(v1) > int64(v2) - case wazeroir.SignedTypeUint32, wazeroir.SignedTypeUint64: + case signedTypeUint32, signedTypeUint64: b = v1 > v2 - case wazeroir.SignedTypeFloat32: + case signedTypeFloat32: b = math.Float32frombits(uint32(v1)) > math.Float32frombits(uint32(v2)) - case wazeroir.SignedTypeFloat64: + case signedTypeFloat64: b = math.Float64frombits(v1) > math.Float64frombits(v2) } if b { @@ -1028,20 +1027,20 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(0) } frame.pc++ - case wazeroir.OperationKindLe: + case operationKindLe: v2 := ce.popValue() v1 := ce.popValue() var b bool - switch wazeroir.SignedType(op.B1) { - case wazeroir.SignedTypeInt32: + switch signedType(op.B1) { + case signedTypeInt32: b = int32(v1) <= int32(v2) - case wazeroir.SignedTypeInt64: + case signedTypeInt64: b = int64(v1) <= int64(v2) - case wazeroir.SignedTypeUint32, wazeroir.SignedTypeUint64: + case signedTypeUint32, signedTypeUint64: b = v1 <= v2 - case wazeroir.SignedTypeFloat32: + case signedTypeFloat32: b = math.Float32frombits(uint32(v1)) <= math.Float32frombits(uint32(v2)) - case wazeroir.SignedTypeFloat64: + case signedTypeFloat64: b = math.Float64frombits(v1) <= math.Float64frombits(v2) } if b { @@ -1050,20 +1049,20 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(0) } frame.pc++ - case wazeroir.OperationKindGe: + case operationKindGe: v2 := ce.popValue() v1 := ce.popValue() var b bool - switch wazeroir.SignedType(op.B1) { - case wazeroir.SignedTypeInt32: + switch signedType(op.B1) { + case signedTypeInt32: b = int32(v1) >= int32(v2) - case wazeroir.SignedTypeInt64: + case signedTypeInt64: b = int64(v1) >= int64(v2) - case wazeroir.SignedTypeUint32, wazeroir.SignedTypeUint64: + case signedTypeUint32, signedTypeUint64: b = v1 >= v2 - case wazeroir.SignedTypeFloat32: + case signedTypeFloat32: b = math.Float32frombits(uint32(v1)) >= math.Float32frombits(uint32(v2)) - case wazeroir.SignedTypeFloat64: + case signedTypeFloat64: b = math.Float64frombits(v1) >= math.Float64frombits(v2) } if b { @@ -1072,88 +1071,88 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(0) } frame.pc++ - case wazeroir.OperationKindAdd: + case operationKindAdd: v2 := ce.popValue() v1 := ce.popValue() - switch wazeroir.UnsignedType(op.B1) { - case wazeroir.UnsignedTypeI32: + switch unsignedType(op.B1) { + case unsignedTypeI32: v := uint32(v1) + uint32(v2) ce.pushValue(uint64(v)) - case wazeroir.UnsignedTypeI64: + case unsignedTypeI64: ce.pushValue(v1 + v2) - case wazeroir.UnsignedTypeF32: + case unsignedTypeF32: ce.pushValue(addFloat32bits(uint32(v1), uint32(v2))) - case wazeroir.UnsignedTypeF64: + case unsignedTypeF64: v := math.Float64frombits(v1) + math.Float64frombits(v2) ce.pushValue(math.Float64bits(v)) } frame.pc++ - case wazeroir.OperationKindSub: + case operationKindSub: v2 := ce.popValue() v1 := ce.popValue() - switch wazeroir.UnsignedType(op.B1) { - case wazeroir.UnsignedTypeI32: + switch unsignedType(op.B1) { + case unsignedTypeI32: ce.pushValue(uint64(uint32(v1) - uint32(v2))) - case wazeroir.UnsignedTypeI64: + case unsignedTypeI64: ce.pushValue(v1 - v2) - case wazeroir.UnsignedTypeF32: + case unsignedTypeF32: ce.pushValue(subFloat32bits(uint32(v1), uint32(v2))) - case wazeroir.UnsignedTypeF64: + case unsignedTypeF64: v := math.Float64frombits(v1) - math.Float64frombits(v2) ce.pushValue(math.Float64bits(v)) } frame.pc++ - case wazeroir.OperationKindMul: + case operationKindMul: v2 := ce.popValue() v1 := ce.popValue() - switch wazeroir.UnsignedType(op.B1) { - case wazeroir.UnsignedTypeI32: + switch unsignedType(op.B1) { + case unsignedTypeI32: ce.pushValue(uint64(uint32(v1) * uint32(v2))) - case wazeroir.UnsignedTypeI64: + case unsignedTypeI64: ce.pushValue(v1 * v2) - case wazeroir.UnsignedTypeF32: + case unsignedTypeF32: ce.pushValue(mulFloat32bits(uint32(v1), uint32(v2))) - case wazeroir.UnsignedTypeF64: + case unsignedTypeF64: v := math.Float64frombits(v2) * math.Float64frombits(v1) ce.pushValue(math.Float64bits(v)) } frame.pc++ - case wazeroir.OperationKindClz: + case operationKindClz: v := ce.popValue() if op.B1 == 0 { - // UnsignedInt32 + // unsignedInt32 ce.pushValue(uint64(bits.LeadingZeros32(uint32(v)))) } else { - // UnsignedInt64 + // unsignedInt64 ce.pushValue(uint64(bits.LeadingZeros64(v))) } frame.pc++ - case wazeroir.OperationKindCtz: + case operationKindCtz: v := ce.popValue() if op.B1 == 0 { - // UnsignedInt32 + // unsignedInt32 ce.pushValue(uint64(bits.TrailingZeros32(uint32(v)))) } else { - // UnsignedInt64 + // unsignedInt64 ce.pushValue(uint64(bits.TrailingZeros64(v))) } frame.pc++ - case wazeroir.OperationKindPopcnt: + case operationKindPopcnt: v := ce.popValue() if op.B1 == 0 { - // UnsignedInt32 + // unsignedInt32 ce.pushValue(uint64(bits.OnesCount32(uint32(v)))) } else { - // UnsignedInt64 + // unsignedInt64 ce.pushValue(uint64(bits.OnesCount64(v))) } frame.pc++ - case wazeroir.OperationKindDiv: + case operationKindDiv: // If an integer, check we won't divide by zero. - t := wazeroir.SignedType(op.B1) + t := signedType(op.B1) v2, v1 := ce.popValue(), ce.popValue() switch t { - case wazeroir.SignedTypeFloat32, wazeroir.SignedTypeFloat64: // not integers + case signedTypeFloat32, signedTypeFloat64: // not integers default: if v2 == 0 { panic(wasmruntime.ErrRuntimeIntegerDivideByZero) @@ -1161,258 +1160,258 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance } switch t { - case wazeroir.SignedTypeInt32: + case signedTypeInt32: d := int32(v2) n := int32(v1) if n == math.MinInt32 && d == -1 { panic(wasmruntime.ErrRuntimeIntegerOverflow) } ce.pushValue(uint64(uint32(n / d))) - case wazeroir.SignedTypeInt64: + case signedTypeInt64: d := int64(v2) n := int64(v1) if n == math.MinInt64 && d == -1 { panic(wasmruntime.ErrRuntimeIntegerOverflow) } ce.pushValue(uint64(n / d)) - case wazeroir.SignedTypeUint32: + case signedTypeUint32: d := uint32(v2) n := uint32(v1) ce.pushValue(uint64(n / d)) - case wazeroir.SignedTypeUint64: + case signedTypeUint64: d := v2 n := v1 ce.pushValue(n / d) - case wazeroir.SignedTypeFloat32: + case signedTypeFloat32: ce.pushValue(divFloat32bits(uint32(v1), uint32(v2))) - case wazeroir.SignedTypeFloat64: + case signedTypeFloat64: ce.pushValue(math.Float64bits(math.Float64frombits(v1) / math.Float64frombits(v2))) } frame.pc++ - case wazeroir.OperationKindRem: + case operationKindRem: v2, v1 := ce.popValue(), ce.popValue() if v2 == 0 { panic(wasmruntime.ErrRuntimeIntegerDivideByZero) } - switch wazeroir.SignedInt(op.B1) { - case wazeroir.SignedInt32: + switch signedInt(op.B1) { + case signedInt32: d := int32(v2) n := int32(v1) ce.pushValue(uint64(uint32(n % d))) - case wazeroir.SignedInt64: + case signedInt64: d := int64(v2) n := int64(v1) ce.pushValue(uint64(n % d)) - case wazeroir.SignedUint32: + case signedUint32: d := uint32(v2) n := uint32(v1) ce.pushValue(uint64(n % d)) - case wazeroir.SignedUint64: + case signedUint64: d := v2 n := v1 ce.pushValue(n % d) } frame.pc++ - case wazeroir.OperationKindAnd: + case operationKindAnd: v2 := ce.popValue() v1 := ce.popValue() if op.B1 == 0 { - // UnsignedInt32 + // unsignedInt32 ce.pushValue(uint64(uint32(v2) & uint32(v1))) } else { - // UnsignedInt64 + // unsignedInt64 ce.pushValue(uint64(v2 & v1)) } frame.pc++ - case wazeroir.OperationKindOr: + case operationKindOr: v2 := ce.popValue() v1 := ce.popValue() if op.B1 == 0 { - // UnsignedInt32 + // unsignedInt32 ce.pushValue(uint64(uint32(v2) | uint32(v1))) } else { - // UnsignedInt64 + // unsignedInt64 ce.pushValue(uint64(v2 | v1)) } frame.pc++ - case wazeroir.OperationKindXor: + case operationKindXor: v2 := ce.popValue() v1 := ce.popValue() if op.B1 == 0 { - // UnsignedInt32 + // unsignedInt32 ce.pushValue(uint64(uint32(v2) ^ uint32(v1))) } else { - // UnsignedInt64 + // unsignedInt64 ce.pushValue(uint64(v2 ^ v1)) } frame.pc++ - case wazeroir.OperationKindShl: + case operationKindShl: v2 := ce.popValue() v1 := ce.popValue() if op.B1 == 0 { - // UnsignedInt32 + // unsignedInt32 ce.pushValue(uint64(uint32(v1) << (uint32(v2) % 32))) } else { - // UnsignedInt64 + // unsignedInt64 ce.pushValue(v1 << (v2 % 64)) } frame.pc++ - case wazeroir.OperationKindShr: + case operationKindShr: v2 := ce.popValue() v1 := ce.popValue() - switch wazeroir.SignedInt(op.B1) { - case wazeroir.SignedInt32: + switch signedInt(op.B1) { + case signedInt32: ce.pushValue(uint64(uint32(int32(v1) >> (uint32(v2) % 32)))) - case wazeroir.SignedInt64: + case signedInt64: ce.pushValue(uint64(int64(v1) >> (v2 % 64))) - case wazeroir.SignedUint32: + case signedUint32: ce.pushValue(uint64(uint32(v1) >> (uint32(v2) % 32))) - case wazeroir.SignedUint64: + case signedUint64: ce.pushValue(v1 >> (v2 % 64)) } frame.pc++ - case wazeroir.OperationKindRotl: + case operationKindRotl: v2 := ce.popValue() v1 := ce.popValue() if op.B1 == 0 { - // UnsignedInt32 + // unsignedInt32 ce.pushValue(uint64(bits.RotateLeft32(uint32(v1), int(v2)))) } else { - // UnsignedInt64 + // unsignedInt64 ce.pushValue(uint64(bits.RotateLeft64(v1, int(v2)))) } frame.pc++ - case wazeroir.OperationKindRotr: + case operationKindRotr: v2 := ce.popValue() v1 := ce.popValue() if op.B1 == 0 { - // UnsignedInt32 + // unsignedInt32 ce.pushValue(uint64(bits.RotateLeft32(uint32(v1), -int(v2)))) } else { - // UnsignedInt64 + // unsignedInt64 ce.pushValue(uint64(bits.RotateLeft64(v1, -int(v2)))) } frame.pc++ - case wazeroir.OperationKindAbs: + case operationKindAbs: if op.B1 == 0 { - // Float32 + // float32 const mask uint32 = 1 << 31 ce.pushValue(uint64(uint32(ce.popValue()) &^ mask)) } else { - // Float64 + // float64 const mask uint64 = 1 << 63 ce.pushValue(ce.popValue() &^ mask) } frame.pc++ - case wazeroir.OperationKindNeg: + case operationKindNeg: if op.B1 == 0 { - // Float32 + // float32 v := -math.Float32frombits(uint32(ce.popValue())) ce.pushValue(uint64(math.Float32bits(v))) } else { - // Float64 + // float64 v := -math.Float64frombits(ce.popValue()) ce.pushValue(math.Float64bits(v)) } frame.pc++ - case wazeroir.OperationKindCeil: + case operationKindCeil: if op.B1 == 0 { - // Float32 + // float32 v := moremath.WasmCompatCeilF32(math.Float32frombits(uint32(ce.popValue()))) ce.pushValue(uint64(math.Float32bits(v))) } else { - // Float64 + // float64 v := moremath.WasmCompatCeilF64(math.Float64frombits(ce.popValue())) ce.pushValue(math.Float64bits(v)) } frame.pc++ - case wazeroir.OperationKindFloor: + case operationKindFloor: if op.B1 == 0 { - // Float32 + // float32 v := moremath.WasmCompatFloorF32(math.Float32frombits(uint32(ce.popValue()))) ce.pushValue(uint64(math.Float32bits(v))) } else { - // Float64 + // float64 v := moremath.WasmCompatFloorF64(math.Float64frombits(ce.popValue())) ce.pushValue(math.Float64bits(v)) } frame.pc++ - case wazeroir.OperationKindTrunc: + case operationKindTrunc: if op.B1 == 0 { - // Float32 + // float32 v := moremath.WasmCompatTruncF32(math.Float32frombits(uint32(ce.popValue()))) ce.pushValue(uint64(math.Float32bits(v))) } else { - // Float64 + // float64 v := moremath.WasmCompatTruncF64(math.Float64frombits(ce.popValue())) ce.pushValue(math.Float64bits(v)) } frame.pc++ - case wazeroir.OperationKindNearest: + case operationKindNearest: if op.B1 == 0 { - // Float32 + // float32 f := math.Float32frombits(uint32(ce.popValue())) ce.pushValue(uint64(math.Float32bits(moremath.WasmCompatNearestF32(f)))) } else { - // Float64 + // float64 f := math.Float64frombits(ce.popValue()) ce.pushValue(math.Float64bits(moremath.WasmCompatNearestF64(f))) } frame.pc++ - case wazeroir.OperationKindSqrt: + case operationKindSqrt: if op.B1 == 0 { - // Float32 + // float32 v := math.Sqrt(float64(math.Float32frombits(uint32(ce.popValue())))) ce.pushValue(uint64(math.Float32bits(float32(v)))) } else { - // Float64 + // float64 v := math.Sqrt(math.Float64frombits(ce.popValue())) ce.pushValue(math.Float64bits(v)) } frame.pc++ - case wazeroir.OperationKindMin: + case operationKindMin: if op.B1 == 0 { - // Float32 - ce.pushValue(WasmCompatMin32bits(uint32(ce.popValue()), uint32(ce.popValue()))) + // float32 + ce.pushValue(wasmCompatMin32bits(uint32(ce.popValue()), uint32(ce.popValue()))) } else { v2 := math.Float64frombits(ce.popValue()) v1 := math.Float64frombits(ce.popValue()) ce.pushValue(math.Float64bits(moremath.WasmCompatMin64(v1, v2))) } frame.pc++ - case wazeroir.OperationKindMax: + case operationKindMax: if op.B1 == 0 { - ce.pushValue(WasmCompatMax32bits(uint32(ce.popValue()), uint32(ce.popValue()))) + ce.pushValue(wasmCompatMax32bits(uint32(ce.popValue()), uint32(ce.popValue()))) } else { - // Float64 + // float64 v2 := math.Float64frombits(ce.popValue()) v1 := math.Float64frombits(ce.popValue()) ce.pushValue(math.Float64bits(moremath.WasmCompatMax64(v1, v2))) } frame.pc++ - case wazeroir.OperationKindCopysign: + case operationKindCopysign: if op.B1 == 0 { - // Float32 + // float32 v2 := uint32(ce.popValue()) v1 := uint32(ce.popValue()) const signbit = 1 << 31 ce.pushValue(uint64(v1&^signbit | v2&signbit)) } else { - // Float64 + // float64 v2 := ce.popValue() v1 := ce.popValue() const signbit = 1 << 63 ce.pushValue(v1&^signbit | v2&signbit) } frame.pc++ - case wazeroir.OperationKindI32WrapFromI64: + case operationKindI32WrapFromI64: ce.pushValue(uint64(uint32(ce.popValue()))) frame.pc++ - case wazeroir.OperationKindITruncFromF: + case operationKindITruncFromF: if op.B1 == 0 { - // Float32 - switch wazeroir.SignedInt(op.B2) { - case wazeroir.SignedInt32: + // float32 + switch signedInt(op.B2) { + case signedInt32: v := math.Trunc(float64(math.Float32frombits(uint32(ce.popValue())))) if math.IsNaN(v) { // NaN cannot be compared with themselves, so we have to use IsNaN if op.B3 { @@ -1434,7 +1433,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance } } ce.pushValue(uint64(uint32(int32(v)))) - case wazeroir.SignedInt64: + case signedInt64: v := math.Trunc(float64(math.Float32frombits(uint32(ce.popValue())))) res := int64(v) if math.IsNaN(v) { // NaN cannot be compared with themselves, so we have to use IsNaN @@ -1459,7 +1458,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance } } ce.pushValue(uint64(res)) - case wazeroir.SignedUint32: + case signedUint32: v := math.Trunc(float64(math.Float32frombits(uint32(ce.popValue())))) if math.IsNaN(v) { // NaN cannot be compared with themselves, so we have to use IsNaN if op.B3 { @@ -1481,7 +1480,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance } } ce.pushValue(uint64(uint32(v))) - case wazeroir.SignedUint64: + case signedUint64: v := math.Trunc(float64(math.Float32frombits(uint32(ce.popValue())))) res := uint64(v) if math.IsNaN(v) { // NaN cannot be compared with themselves, so we have to use IsNaN @@ -1508,9 +1507,9 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(res) } } else { - // Float64 - switch wazeroir.SignedInt(op.B2) { - case wazeroir.SignedInt32: + // float64 + switch signedInt(op.B2) { + case signedInt32: v := math.Trunc(math.Float64frombits(ce.popValue())) if math.IsNaN(v) { // NaN cannot be compared with themselves, so we have to use IsNaN if op.B3 { @@ -1532,7 +1531,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance } } ce.pushValue(uint64(uint32(int32(v)))) - case wazeroir.SignedInt64: + case signedInt64: v := math.Trunc(math.Float64frombits(ce.popValue())) res := int64(v) if math.IsNaN(v) { // NaN cannot be compared with themselves, so we have to use IsNaN @@ -1557,7 +1556,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance } } ce.pushValue(uint64(res)) - case wazeroir.SignedUint32: + case signedUint32: v := math.Trunc(math.Float64frombits(ce.popValue())) if math.IsNaN(v) { // NaN cannot be compared with themselves, so we have to use IsNaN if op.B3 { @@ -1579,7 +1578,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance } } ce.pushValue(uint64(uint32(v))) - case wazeroir.SignedUint64: + case signedUint64: v := math.Trunc(math.Float64frombits(ce.popValue())) res := uint64(v) if math.IsNaN(v) { // NaN cannot be compared with themselves, so we have to use IsNaN @@ -1607,59 +1606,59 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance } } frame.pc++ - case wazeroir.OperationKindFConvertFromI: - switch wazeroir.SignedInt(op.B1) { - case wazeroir.SignedInt32: + case operationKindFConvertFromI: + switch signedInt(op.B1) { + case signedInt32: if op.B2 == 0 { - // Float32 + // float32 v := float32(int32(ce.popValue())) ce.pushValue(uint64(math.Float32bits(v))) } else { - // Float64 + // float64 v := float64(int32(ce.popValue())) ce.pushValue(math.Float64bits(v)) } - case wazeroir.SignedInt64: + case signedInt64: if op.B2 == 0 { - // Float32 + // float32 v := float32(int64(ce.popValue())) ce.pushValue(uint64(math.Float32bits(v))) } else { - // Float64 + // float64 v := float64(int64(ce.popValue())) ce.pushValue(math.Float64bits(v)) } - case wazeroir.SignedUint32: + case signedUint32: if op.B2 == 0 { - // Float32 + // float32 v := float32(uint32(ce.popValue())) ce.pushValue(uint64(math.Float32bits(v))) } else { - // Float64 + // float64 v := float64(uint32(ce.popValue())) ce.pushValue(math.Float64bits(v)) } - case wazeroir.SignedUint64: + case signedUint64: if op.B2 == 0 { - // Float32 + // float32 v := float32(ce.popValue()) ce.pushValue(uint64(math.Float32bits(v))) } else { - // Float64 + // float64 v := float64(ce.popValue()) ce.pushValue(math.Float64bits(v)) } } frame.pc++ - case wazeroir.OperationKindF32DemoteFromF64: + case operationKindF32DemoteFromF64: v := float32(math.Float64frombits(ce.popValue())) ce.pushValue(uint64(math.Float32bits(v))) frame.pc++ - case wazeroir.OperationKindF64PromoteFromF32: + case operationKindF64PromoteFromF32: v := float64(math.Float32frombits(uint32(ce.popValue()))) ce.pushValue(math.Float64bits(v)) frame.pc++ - case wazeroir.OperationKindExtend: + case operationKindExtend: if op.B1 == 1 { // Signed. v := int64(int32(ce.popValue())) @@ -1669,27 +1668,27 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(v) } frame.pc++ - case wazeroir.OperationKindSignExtend32From8: + case operationKindSignExtend32From8: v := uint32(int8(ce.popValue())) ce.pushValue(uint64(v)) frame.pc++ - case wazeroir.OperationKindSignExtend32From16: + case operationKindSignExtend32From16: v := uint32(int16(ce.popValue())) ce.pushValue(uint64(v)) frame.pc++ - case wazeroir.OperationKindSignExtend64From8: + case operationKindSignExtend64From8: v := int64(int8(ce.popValue())) ce.pushValue(uint64(v)) frame.pc++ - case wazeroir.OperationKindSignExtend64From16: + case operationKindSignExtend64From16: v := int64(int16(ce.popValue())) ce.pushValue(uint64(v)) frame.pc++ - case wazeroir.OperationKindSignExtend64From32: + case operationKindSignExtend64From32: v := int64(int32(ce.popValue())) ce.pushValue(uint64(v)) frame.pc++ - case wazeroir.OperationKindMemoryInit: + case operationKindMemoryInit: dataInstance := dataInstances[op.U1] copySize := ce.popValue() inDataOffset := ce.popValue() @@ -1701,10 +1700,10 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance copy(memoryInst.Buffer[inMemoryOffset:inMemoryOffset+copySize], dataInstance[inDataOffset:]) } frame.pc++ - case wazeroir.OperationKindDataDrop: + case operationKindDataDrop: dataInstances[op.U1] = nil frame.pc++ - case wazeroir.OperationKindMemoryCopy: + case operationKindMemoryCopy: memLen := uint64(len(memoryInst.Buffer)) copySize := ce.popValue() sourceOffset := ce.popValue() @@ -1716,7 +1715,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance memoryInst.Buffer[sourceOffset:sourceOffset+copySize]) } frame.pc++ - case wazeroir.OperationKindMemoryFill: + case operationKindMemoryFill: fillSize := ce.popValue() value := byte(ce.popValue()) offset := ce.popValue() @@ -1732,7 +1731,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance } } frame.pc++ - case wazeroir.OperationKindTableInit: + case operationKindTableInit: elementInstance := elementInstances[op.U1] copySize := ce.popValue() inElementOffset := ce.popValue() @@ -1745,10 +1744,10 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance copy(table.References[inTableOffset:inTableOffset+copySize], elementInstance[inElementOffset:]) } frame.pc++ - case wazeroir.OperationKindElemDrop: + case operationKindElemDrop: elementInstances[op.U1] = nil frame.pc++ - case wazeroir.OperationKindTableCopy: + case operationKindTableCopy: srcTable, dstTable := tables[op.U1].References, tables[op.U2].References copySize := ce.popValue() sourceOffset := ce.popValue() @@ -1759,10 +1758,10 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance copy(dstTable[destinationOffset:], srcTable[sourceOffset:sourceOffset+copySize]) } frame.pc++ - case wazeroir.OperationKindRefFunc: + case operationKindRefFunc: ce.pushValue(uint64(uintptr(unsafe.Pointer(&functions[op.U1])))) frame.pc++ - case wazeroir.OperationKindTableGet: + case operationKindTableGet: table := tables[op.U1] offset := ce.popValue() @@ -1772,7 +1771,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(uint64(table.References[offset])) frame.pc++ - case wazeroir.OperationKindTableSet: + case operationKindTableSet: table := tables[op.U1] ref := ce.popValue() @@ -1783,17 +1782,17 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance table.References[offset] = uintptr(ref) // externrefs are opaque uint64. frame.pc++ - case wazeroir.OperationKindTableSize: + case operationKindTableSize: table := tables[op.U1] ce.pushValue(uint64(len(table.References))) frame.pc++ - case wazeroir.OperationKindTableGrow: + case operationKindTableGrow: table := tables[op.U1] num, ref := ce.popValue(), ce.popValue() ret := table.Grow(uint32(num), uintptr(ref)) ce.pushValue(uint64(ret)) frame.pc++ - case wazeroir.OperationKindTableFill: + case operationKindTableFill: table := tables[op.U1] num := ce.popValue() ref := uintptr(ce.popValue()) @@ -1810,16 +1809,16 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance } } frame.pc++ - case wazeroir.OperationKindV128Const: + case operationKindV128Const: lo, hi := op.U1, op.U2 ce.pushValue(lo) ce.pushValue(hi) frame.pc++ - case wazeroir.OperationKindV128Add: + case operationKindV128Add: yHigh, yLow := ce.popValue(), ce.popValue() xHigh, xLow := ce.popValue(), ce.popValue() switch op.B1 { - case wazeroir.ShapeI8x16: + case shapeI8x16: ce.pushValue( uint64(uint8(xLow>>8)+uint8(yLow>>8))<<8 | uint64(uint8(xLow)+uint8(yLow)) | uint64(uint8(xLow>>24)+uint8(yLow>>24))<<24 | uint64(uint8(xLow>>16)+uint8(yLow>>16))<<16 | @@ -1832,7 +1831,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance uint64(uint8(xHigh>>40)+uint8(yHigh>>40))<<40 | uint64(uint8(xHigh>>32)+uint8(yHigh>>32))<<32 | uint64(uint8(xHigh>>56)+uint8(yHigh>>56))<<56 | uint64(uint8(xHigh>>48)+uint8(yHigh>>48))<<48, ) - case wazeroir.ShapeI16x8: + case shapeI16x8: ce.pushValue( uint64(uint16(xLow>>16+yLow>>16))<<16 | uint64(uint16(xLow)+uint16(yLow)) | uint64(uint16(xLow>>48+yLow>>48))<<48 | uint64(uint16(xLow>>32+yLow>>32))<<32, @@ -1841,29 +1840,29 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance uint64(uint16(xHigh>>16)+uint16(yHigh>>16))<<16 | uint64(uint16(xHigh)+uint16(yHigh)) | uint64(uint16(xHigh>>48)+uint16(yHigh>>48))<<48 | uint64(uint16(xHigh>>32)+uint16(yHigh>>32))<<32, ) - case wazeroir.ShapeI32x4: + case shapeI32x4: ce.pushValue(uint64(uint32(xLow>>32)+uint32(yLow>>32))<<32 | uint64(uint32(xLow)+uint32(yLow))) ce.pushValue(uint64(uint32(xHigh>>32)+uint32(yHigh>>32))<<32 | uint64(uint32(xHigh)+uint32(yHigh))) - case wazeroir.ShapeI64x2: + case shapeI64x2: ce.pushValue(xLow + yLow) ce.pushValue(xHigh + yHigh) - case wazeroir.ShapeF32x4: + case shapeF32x4: ce.pushValue( addFloat32bits(uint32(xLow), uint32(yLow)) | addFloat32bits(uint32(xLow>>32), uint32(yLow>>32))<<32, ) ce.pushValue( addFloat32bits(uint32(xHigh), uint32(yHigh)) | addFloat32bits(uint32(xHigh>>32), uint32(yHigh>>32))<<32, ) - case wazeroir.ShapeF64x2: + case shapeF64x2: ce.pushValue(math.Float64bits(math.Float64frombits(xLow) + math.Float64frombits(yLow))) ce.pushValue(math.Float64bits(math.Float64frombits(xHigh) + math.Float64frombits(yHigh))) } frame.pc++ - case wazeroir.OperationKindV128Sub: + case operationKindV128Sub: yHigh, yLow := ce.popValue(), ce.popValue() xHigh, xLow := ce.popValue(), ce.popValue() switch op.B1 { - case wazeroir.ShapeI8x16: + case shapeI8x16: ce.pushValue( uint64(uint8(xLow>>8)-uint8(yLow>>8))<<8 | uint64(uint8(xLow)-uint8(yLow)) | uint64(uint8(xLow>>24)-uint8(yLow>>24))<<24 | uint64(uint8(xLow>>16)-uint8(yLow>>16))<<16 | @@ -1876,7 +1875,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance uint64(uint8(xHigh>>40)-uint8(yHigh>>40))<<40 | uint64(uint8(xHigh>>32)-uint8(yHigh>>32))<<32 | uint64(uint8(xHigh>>56)-uint8(yHigh>>56))<<56 | uint64(uint8(xHigh>>48)-uint8(yHigh>>48))<<48, ) - case wazeroir.ShapeI16x8: + case shapeI16x8: ce.pushValue( uint64(uint16(xLow>>16)-uint16(yLow>>16))<<16 | uint64(uint16(xLow)-uint16(yLow)) | uint64(uint16(xLow>>48)-uint16(yLow>>48))<<48 | uint64(uint16(xLow>>32)-uint16(yLow>>32))<<32, @@ -1885,28 +1884,28 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance uint64(uint16(xHigh>>16)-uint16(yHigh>>16))<<16 | uint64(uint16(xHigh)-uint16(yHigh)) | uint64(uint16(xHigh>>48)-uint16(yHigh>>48))<<48 | uint64(uint16(xHigh>>32)-uint16(yHigh>>32))<<32, ) - case wazeroir.ShapeI32x4: + case shapeI32x4: ce.pushValue(uint64(uint32(xLow>>32-yLow>>32))<<32 | uint64(uint32(xLow)-uint32(yLow))) ce.pushValue(uint64(uint32(xHigh>>32-yHigh>>32))<<32 | uint64(uint32(xHigh)-uint32(yHigh))) - case wazeroir.ShapeI64x2: + case shapeI64x2: ce.pushValue(xLow - yLow) ce.pushValue(xHigh - yHigh) - case wazeroir.ShapeF32x4: + case shapeF32x4: ce.pushValue( subFloat32bits(uint32(xLow), uint32(yLow)) | subFloat32bits(uint32(xLow>>32), uint32(yLow>>32))<<32, ) ce.pushValue( subFloat32bits(uint32(xHigh), uint32(yHigh)) | subFloat32bits(uint32(xHigh>>32), uint32(yHigh>>32))<<32, ) - case wazeroir.ShapeF64x2: + case shapeF64x2: ce.pushValue(math.Float64bits(math.Float64frombits(xLow) - math.Float64frombits(yLow))) ce.pushValue(math.Float64bits(math.Float64frombits(xHigh) - math.Float64frombits(yHigh))) } frame.pc++ - case wazeroir.OperationKindV128Load: + case operationKindV128Load: offset := ce.popMemoryOffset(op) switch op.B1 { - case wazeroir.V128LoadType128: + case v128LoadType128: lo, ok := memoryInst.ReadUint64Le(offset) if !ok { panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) @@ -1917,7 +1916,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) } ce.pushValue(hi) - case wazeroir.V128LoadType8x8s: + case v128LoadType8x8s: data, ok := memoryInst.Read(offset, 8) if !ok { panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) @@ -1928,7 +1927,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue( uint64(uint16(int8(data[7])))<<48 | uint64(uint16(int8(data[6])))<<32 | uint64(uint16(int8(data[5])))<<16 | uint64(uint16(int8(data[4]))), ) - case wazeroir.V128LoadType8x8u: + case v128LoadType8x8u: data, ok := memoryInst.Read(offset, 8) if !ok { panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) @@ -1939,7 +1938,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue( uint64(data[7])<<48 | uint64(data[6])<<32 | uint64(data[5])<<16 | uint64(data[4]), ) - case wazeroir.V128LoadType16x4s: + case v128LoadType16x4s: data, ok := memoryInst.Read(offset, 8) if !ok { panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) @@ -1952,7 +1951,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance uint64(uint32(int16(binary.LittleEndian.Uint16(data[6:]))))<<32 | uint64(uint32(int16(binary.LittleEndian.Uint16(data[4:])))), ) - case wazeroir.V128LoadType16x4u: + case v128LoadType16x4u: data, ok := memoryInst.Read(offset, 8) if !ok { panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) @@ -1963,21 +1962,21 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue( uint64(binary.LittleEndian.Uint16(data[6:]))<<32 | uint64(binary.LittleEndian.Uint16(data[4:])), ) - case wazeroir.V128LoadType32x2s: + case v128LoadType32x2s: data, ok := memoryInst.Read(offset, 8) if !ok { panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) } ce.pushValue(uint64(int32(binary.LittleEndian.Uint32(data)))) ce.pushValue(uint64(int32(binary.LittleEndian.Uint32(data[4:])))) - case wazeroir.V128LoadType32x2u: + case v128LoadType32x2u: data, ok := memoryInst.Read(offset, 8) if !ok { panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) } ce.pushValue(uint64(binary.LittleEndian.Uint32(data))) ce.pushValue(uint64(binary.LittleEndian.Uint32(data[4:]))) - case wazeroir.V128LoadType8Splat: + case v128LoadType8Splat: v, ok := memoryInst.ReadByte(offset) if !ok { panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) @@ -1986,7 +1985,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance uint64(v)<<24 | uint64(v)<<16 | uint64(v)<<8 | uint64(v) ce.pushValue(v8) ce.pushValue(v8) - case wazeroir.V128LoadType16Splat: + case v128LoadType16Splat: v, ok := memoryInst.ReadUint16Le(offset) if !ok { panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) @@ -1994,7 +1993,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance v4 := uint64(v)<<48 | uint64(v)<<32 | uint64(v)<<16 | uint64(v) ce.pushValue(v4) ce.pushValue(v4) - case wazeroir.V128LoadType32Splat: + case v128LoadType32Splat: v, ok := memoryInst.ReadUint32Le(offset) if !ok { panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) @@ -2002,21 +2001,21 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance vv := uint64(v)<<32 | uint64(v) ce.pushValue(vv) ce.pushValue(vv) - case wazeroir.V128LoadType64Splat: + case v128LoadType64Splat: lo, ok := memoryInst.ReadUint64Le(offset) if !ok { panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) } ce.pushValue(lo) ce.pushValue(lo) - case wazeroir.V128LoadType32zero: + case v128LoadType32zero: lo, ok := memoryInst.ReadUint32Le(offset) if !ok { panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) } ce.pushValue(uint64(lo)) ce.pushValue(0) - case wazeroir.V128LoadType64zero: + case v128LoadType64zero: lo, ok := memoryInst.ReadUint64Le(offset) if !ok { panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) @@ -2025,7 +2024,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(0) } frame.pc++ - case wazeroir.OperationKindV128LoadLane: + case operationKindV128LoadLane: hi, lo := ce.popValue(), ce.popValue() offset := ce.popMemoryOffset(op) switch op.B1 { @@ -2079,7 +2078,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(lo) ce.pushValue(hi) frame.pc++ - case wazeroir.OperationKindV128Store: + case operationKindV128Store: hi, lo := ce.popValue(), ce.popValue() offset := ce.popMemoryOffset(op) // Write the upper bytes first to trigger an early error if the memory access is out of bounds. @@ -2094,7 +2093,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) } frame.pc++ - case wazeroir.OperationKindV128StoreLane: + case operationKindV128StoreLane: hi, lo := ce.popValue(), ce.popValue() offset := ce.popMemoryOffset(op) var ok bool @@ -2128,11 +2127,11 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) } frame.pc++ - case wazeroir.OperationKindV128ReplaceLane: + case operationKindV128ReplaceLane: v := ce.popValue() hi, lo := ce.popValue(), ce.popValue() switch op.B1 { - case wazeroir.ShapeI8x16: + case shapeI8x16: if op.B2 < 8 { s := op.B2 << 3 lo = (lo & ^(0xff << s)) | uint64(byte(v))<> (op.B2 * 8)) @@ -2183,7 +2182,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance } else { v = uint64(u8) } - case wazeroir.ShapeI16x8: + case shapeI16x8: var u16 uint16 if op.B2 < 4 { u16 = uint16(lo >> (op.B2 * 16)) @@ -2196,13 +2195,13 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance } else { v = uint64(u16) } - case wazeroir.ShapeI32x4, wazeroir.ShapeF32x4: + case shapeI32x4, shapeF32x4: if op.B2 < 2 { v = uint64(uint32(lo >> (op.B2 * 32))) } else { v = uint64(uint32(hi >> ((op.B2 - 2) * 32))) } - case wazeroir.ShapeI64x2, wazeroir.ShapeF64x2: + case shapeI64x2, shapeF64x2: if op.B2 == 0 { v = lo } else { @@ -2211,27 +2210,27 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance } ce.pushValue(v) frame.pc++ - case wazeroir.OperationKindV128Splat: + case operationKindV128Splat: v := ce.popValue() var hi, lo uint64 switch op.B1 { - case wazeroir.ShapeI8x16: + case shapeI8x16: v8 := uint64(byte(v))<<56 | uint64(byte(v))<<48 | uint64(byte(v))<<40 | uint64(byte(v))<<32 | uint64(byte(v))<<24 | uint64(byte(v))<<16 | uint64(byte(v))<<8 | uint64(byte(v)) hi, lo = v8, v8 - case wazeroir.ShapeI16x8: + case shapeI16x8: v4 := uint64(uint16(v))<<48 | uint64(uint16(v))<<32 | uint64(uint16(v))<<16 | uint64(uint16(v)) hi, lo = v4, v4 - case wazeroir.ShapeI32x4, wazeroir.ShapeF32x4: + case shapeI32x4, shapeF32x4: v2 := uint64(uint32(v))<<32 | uint64(uint32(v)) lo, hi = v2, v2 - case wazeroir.ShapeI64x2, wazeroir.ShapeF64x2: + case shapeI64x2, shapeF64x2: lo, hi = v, v } ce.pushValue(lo) ce.pushValue(hi) frame.pc++ - case wazeroir.OperationKindV128Swizzle: + case operationKindV128Swizzle: idxHi, idxLo := ce.popValue(), ce.popValue() baseHi, baseLo := ce.popValue(), ce.popValue() var newVal [16]byte @@ -2251,7 +2250,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(binary.LittleEndian.Uint64(newVal[:8])) ce.pushValue(binary.LittleEndian.Uint64(newVal[8:])) frame.pc++ - case wazeroir.OperationKindV128Shuffle: + case operationKindV128Shuffle: xHi, xLo, yHi, yLo := ce.popValue(), ce.popValue(), ce.popValue(), ce.popValue() var newVal [16]byte for i, l := range op.Us { @@ -2268,7 +2267,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(binary.LittleEndian.Uint64(newVal[:8])) ce.pushValue(binary.LittleEndian.Uint64(newVal[8:])) frame.pc++ - case wazeroir.OperationKindV128AnyTrue: + case operationKindV128AnyTrue: hi, lo := ce.popValue(), ce.popValue() if hi != 0 || lo != 0 { ce.pushValue(1) @@ -2276,22 +2275,22 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(0) } frame.pc++ - case wazeroir.OperationKindV128AllTrue: + case operationKindV128AllTrue: hi, lo := ce.popValue(), ce.popValue() var ret bool switch op.B1 { - case wazeroir.ShapeI8x16: + case shapeI8x16: ret = (uint8(lo) != 0) && (uint8(lo>>8) != 0) && (uint8(lo>>16) != 0) && (uint8(lo>>24) != 0) && (uint8(lo>>32) != 0) && (uint8(lo>>40) != 0) && (uint8(lo>>48) != 0) && (uint8(lo>>56) != 0) && (uint8(hi) != 0) && (uint8(hi>>8) != 0) && (uint8(hi>>16) != 0) && (uint8(hi>>24) != 0) && (uint8(hi>>32) != 0) && (uint8(hi>>40) != 0) && (uint8(hi>>48) != 0) && (uint8(hi>>56) != 0) - case wazeroir.ShapeI16x8: + case shapeI16x8: ret = (uint16(lo) != 0) && (uint16(lo>>16) != 0) && (uint16(lo>>32) != 0) && (uint16(lo>>48) != 0) && (uint16(hi) != 0) && (uint16(hi>>16) != 0) && (uint16(hi>>32) != 0) && (uint16(hi>>48) != 0) - case wazeroir.ShapeI32x4: + case shapeI32x4: ret = (uint32(lo) != 0) && (uint32(lo>>32) != 0) && (uint32(hi) != 0) && (uint32(hi>>32) != 0) - case wazeroir.ShapeI64x2: + case shapeI64x2: ret = (lo != 0) && (hi != 0) } @@ -2301,12 +2300,12 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(0) } frame.pc++ - case wazeroir.OperationKindV128BitMask: + case operationKindV128BitMask: // https://github.com/WebAssembly/spec/blob/wg-2.0.draft1/proposals/simd/SIMD.md#bitmask-extraction hi, lo := ce.popValue(), ce.popValue() var res uint64 switch op.B1 { - case wazeroir.ShapeI8x16: + case shapeI8x16: for i := 0; i < 8; i++ { if int8(lo>>(i*8)) < 0 { res |= 1 << i @@ -2317,7 +2316,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance res |= 1 << (i + 8) } } - case wazeroir.ShapeI16x8: + case shapeI16x8: for i := 0; i < 4; i++ { if int16(lo>>(i*16)) < 0 { res |= 1 << i @@ -2328,7 +2327,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance res |= 1 << (i + 4) } } - case wazeroir.ShapeI32x4: + case shapeI32x4: for i := 0; i < 2; i++ { if int32(lo>>(i*32)) < 0 { res |= 1 << i @@ -2339,7 +2338,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance res |= 1 << (i + 2) } } - case wazeroir.ShapeI64x2: + case shapeI64x2: if int64(lo) < 0 { res |= 0b01 } @@ -2349,30 +2348,30 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance } ce.pushValue(res) frame.pc++ - case wazeroir.OperationKindV128And: + case operationKindV128And: x2Hi, x2Lo := ce.popValue(), ce.popValue() x1Hi, x1Lo := ce.popValue(), ce.popValue() ce.pushValue(x1Lo & x2Lo) ce.pushValue(x1Hi & x2Hi) frame.pc++ - case wazeroir.OperationKindV128Not: + case operationKindV128Not: hi, lo := ce.popValue(), ce.popValue() ce.pushValue(^lo) ce.pushValue(^hi) frame.pc++ - case wazeroir.OperationKindV128Or: + case operationKindV128Or: x2Hi, x2Lo := ce.popValue(), ce.popValue() x1Hi, x1Lo := ce.popValue(), ce.popValue() ce.pushValue(x1Lo | x2Lo) ce.pushValue(x1Hi | x2Hi) frame.pc++ - case wazeroir.OperationKindV128Xor: + case operationKindV128Xor: x2Hi, x2Lo := ce.popValue(), ce.popValue() x1Hi, x1Lo := ce.popValue(), ce.popValue() ce.pushValue(x1Lo ^ x2Lo) ce.pushValue(x1Hi ^ x2Hi) frame.pc++ - case wazeroir.OperationKindV128Bitselect: + case operationKindV128Bitselect: // https://github.com/WebAssembly/spec/blob/wg-2.0.draft1/proposals/simd/SIMD.md#bitwise-select cHi, cLo := ce.popValue(), ce.popValue() x2Hi, x2Lo := ce.popValue(), ce.popValue() @@ -2381,17 +2380,17 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue((x1Lo & cLo) | (x2Lo & (^cLo))) ce.pushValue((x1Hi & cHi) | (x2Hi & (^cHi))) frame.pc++ - case wazeroir.OperationKindV128AndNot: + case operationKindV128AndNot: x2Hi, x2Lo := ce.popValue(), ce.popValue() x1Hi, x1Lo := ce.popValue(), ce.popValue() ce.pushValue(x1Lo & (^x2Lo)) ce.pushValue(x1Hi & (^x2Hi)) frame.pc++ - case wazeroir.OperationKindV128Shl: + case operationKindV128Shl: s := ce.popValue() hi, lo := ce.popValue(), ce.popValue() switch op.B1 { - case wazeroir.ShapeI8x16: + case shapeI8x16: s = s % 8 lo = uint64(uint8(lo<>8)<>40)<>48)<>56)<>16)<>16)<>32)<>48)<>32)<>32)<>s)) | @@ -2472,7 +2471,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance uint64(uint8(hi>>48)>>s)<<48 | uint64(uint8(hi>>56)>>s)<<56 } - case wazeroir.ShapeI16x8: + case shapeI16x8: s = s % 16 if op.B3 { // signed lo = uint64(uint16(int16(lo)>>s)) | @@ -2493,7 +2492,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance uint64(uint16(hi>>32)>>s)<<32 | uint64(uint16(hi>>48)>>s)<<48 } - case wazeroir.ShapeI32x4: + case shapeI32x4: s = s % 32 if op.B3 { lo = uint64(uint32(int32(lo)>>s)) | uint64(uint32(int32(lo>>32)>>s))<<32 @@ -2502,7 +2501,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance lo = uint64(uint32(lo)>>s) | uint64(uint32(lo>>32)>>s)<<32 hi = uint64(uint32(hi)>>s) | uint64(uint32(hi>>32)>>s)<<32 } - case wazeroir.ShapeI64x2: + case shapeI64x2: s = s % 64 if op.B3 { // signed lo = uint64(int64(lo) >> s) @@ -2516,12 +2515,12 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(lo) ce.pushValue(hi) frame.pc++ - case wazeroir.OperationKindV128Cmp: + case operationKindV128Cmp: x2Hi, x2Lo := ce.popValue(), ce.popValue() x1Hi, x1Lo := ce.popValue(), ce.popValue() var result []bool switch op.B1 { - case wazeroir.V128CmpTypeI8x16Eq: + case v128CmpTypeI8x16Eq: result = []bool{ byte(x1Lo>>0) == byte(x2Lo>>0), byte(x1Lo>>8) == byte(x2Lo>>8), byte(x1Lo>>16) == byte(x2Lo>>16), byte(x1Lo>>24) == byte(x2Lo>>24), @@ -2532,7 +2531,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance byte(x1Hi>>32) == byte(x2Hi>>32), byte(x1Hi>>40) == byte(x2Hi>>40), byte(x1Hi>>48) == byte(x2Hi>>48), byte(x1Hi>>56) == byte(x2Hi>>56), } - case wazeroir.V128CmpTypeI8x16Ne: + case v128CmpTypeI8x16Ne: result = []bool{ byte(x1Lo>>0) != byte(x2Lo>>0), byte(x1Lo>>8) != byte(x2Lo>>8), byte(x1Lo>>16) != byte(x2Lo>>16), byte(x1Lo>>24) != byte(x2Lo>>24), @@ -2543,7 +2542,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance byte(x1Hi>>32) != byte(x2Hi>>32), byte(x1Hi>>40) != byte(x2Hi>>40), byte(x1Hi>>48) != byte(x2Hi>>48), byte(x1Hi>>56) != byte(x2Hi>>56), } - case wazeroir.V128CmpTypeI8x16LtS: + case v128CmpTypeI8x16LtS: result = []bool{ int8(x1Lo>>0) < int8(x2Lo>>0), int8(x1Lo>>8) < int8(x2Lo>>8), int8(x1Lo>>16) < int8(x2Lo>>16), int8(x1Lo>>24) < int8(x2Lo>>24), @@ -2554,7 +2553,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance int8(x1Hi>>32) < int8(x2Hi>>32), int8(x1Hi>>40) < int8(x2Hi>>40), int8(x1Hi>>48) < int8(x2Hi>>48), int8(x1Hi>>56) < int8(x2Hi>>56), } - case wazeroir.V128CmpTypeI8x16LtU: + case v128CmpTypeI8x16LtU: result = []bool{ byte(x1Lo>>0) < byte(x2Lo>>0), byte(x1Lo>>8) < byte(x2Lo>>8), byte(x1Lo>>16) < byte(x2Lo>>16), byte(x1Lo>>24) < byte(x2Lo>>24), @@ -2565,7 +2564,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance byte(x1Hi>>32) < byte(x2Hi>>32), byte(x1Hi>>40) < byte(x2Hi>>40), byte(x1Hi>>48) < byte(x2Hi>>48), byte(x1Hi>>56) < byte(x2Hi>>56), } - case wazeroir.V128CmpTypeI8x16GtS: + case v128CmpTypeI8x16GtS: result = []bool{ int8(x1Lo>>0) > int8(x2Lo>>0), int8(x1Lo>>8) > int8(x2Lo>>8), int8(x1Lo>>16) > int8(x2Lo>>16), int8(x1Lo>>24) > int8(x2Lo>>24), @@ -2576,7 +2575,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance int8(x1Hi>>32) > int8(x2Hi>>32), int8(x1Hi>>40) > int8(x2Hi>>40), int8(x1Hi>>48) > int8(x2Hi>>48), int8(x1Hi>>56) > int8(x2Hi>>56), } - case wazeroir.V128CmpTypeI8x16GtU: + case v128CmpTypeI8x16GtU: result = []bool{ byte(x1Lo>>0) > byte(x2Lo>>0), byte(x1Lo>>8) > byte(x2Lo>>8), byte(x1Lo>>16) > byte(x2Lo>>16), byte(x1Lo>>24) > byte(x2Lo>>24), @@ -2587,7 +2586,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance byte(x1Hi>>32) > byte(x2Hi>>32), byte(x1Hi>>40) > byte(x2Hi>>40), byte(x1Hi>>48) > byte(x2Hi>>48), byte(x1Hi>>56) > byte(x2Hi>>56), } - case wazeroir.V128CmpTypeI8x16LeS: + case v128CmpTypeI8x16LeS: result = []bool{ int8(x1Lo>>0) <= int8(x2Lo>>0), int8(x1Lo>>8) <= int8(x2Lo>>8), int8(x1Lo>>16) <= int8(x2Lo>>16), int8(x1Lo>>24) <= int8(x2Lo>>24), @@ -2598,7 +2597,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance int8(x1Hi>>32) <= int8(x2Hi>>32), int8(x1Hi>>40) <= int8(x2Hi>>40), int8(x1Hi>>48) <= int8(x2Hi>>48), int8(x1Hi>>56) <= int8(x2Hi>>56), } - case wazeroir.V128CmpTypeI8x16LeU: + case v128CmpTypeI8x16LeU: result = []bool{ byte(x1Lo>>0) <= byte(x2Lo>>0), byte(x1Lo>>8) <= byte(x2Lo>>8), byte(x1Lo>>16) <= byte(x2Lo>>16), byte(x1Lo>>24) <= byte(x2Lo>>24), @@ -2609,7 +2608,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance byte(x1Hi>>32) <= byte(x2Hi>>32), byte(x1Hi>>40) <= byte(x2Hi>>40), byte(x1Hi>>48) <= byte(x2Hi>>48), byte(x1Hi>>56) <= byte(x2Hi>>56), } - case wazeroir.V128CmpTypeI8x16GeS: + case v128CmpTypeI8x16GeS: result = []bool{ int8(x1Lo>>0) >= int8(x2Lo>>0), int8(x1Lo>>8) >= int8(x2Lo>>8), int8(x1Lo>>16) >= int8(x2Lo>>16), int8(x1Lo>>24) >= int8(x2Lo>>24), @@ -2620,7 +2619,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance int8(x1Hi>>32) >= int8(x2Hi>>32), int8(x1Hi>>40) >= int8(x2Hi>>40), int8(x1Hi>>48) >= int8(x2Hi>>48), int8(x1Hi>>56) >= int8(x2Hi>>56), } - case wazeroir.V128CmpTypeI8x16GeU: + case v128CmpTypeI8x16GeU: result = []bool{ byte(x1Lo>>0) >= byte(x2Lo>>0), byte(x1Lo>>8) >= byte(x2Lo>>8), byte(x1Lo>>16) >= byte(x2Lo>>16), byte(x1Lo>>24) >= byte(x2Lo>>24), @@ -2631,206 +2630,206 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance byte(x1Hi>>32) >= byte(x2Hi>>32), byte(x1Hi>>40) >= byte(x2Hi>>40), byte(x1Hi>>48) >= byte(x2Hi>>48), byte(x1Hi>>56) >= byte(x2Hi>>56), } - case wazeroir.V128CmpTypeI16x8Eq: + case v128CmpTypeI16x8Eq: result = []bool{ uint16(x1Lo>>0) == uint16(x2Lo>>0), uint16(x1Lo>>16) == uint16(x2Lo>>16), uint16(x1Lo>>32) == uint16(x2Lo>>32), uint16(x1Lo>>48) == uint16(x2Lo>>48), uint16(x1Hi>>0) == uint16(x2Hi>>0), uint16(x1Hi>>16) == uint16(x2Hi>>16), uint16(x1Hi>>32) == uint16(x2Hi>>32), uint16(x1Hi>>48) == uint16(x2Hi>>48), } - case wazeroir.V128CmpTypeI16x8Ne: + case v128CmpTypeI16x8Ne: result = []bool{ uint16(x1Lo>>0) != uint16(x2Lo>>0), uint16(x1Lo>>16) != uint16(x2Lo>>16), uint16(x1Lo>>32) != uint16(x2Lo>>32), uint16(x1Lo>>48) != uint16(x2Lo>>48), uint16(x1Hi>>0) != uint16(x2Hi>>0), uint16(x1Hi>>16) != uint16(x2Hi>>16), uint16(x1Hi>>32) != uint16(x2Hi>>32), uint16(x1Hi>>48) != uint16(x2Hi>>48), } - case wazeroir.V128CmpTypeI16x8LtS: + case v128CmpTypeI16x8LtS: result = []bool{ int16(x1Lo>>0) < int16(x2Lo>>0), int16(x1Lo>>16) < int16(x2Lo>>16), int16(x1Lo>>32) < int16(x2Lo>>32), int16(x1Lo>>48) < int16(x2Lo>>48), int16(x1Hi>>0) < int16(x2Hi>>0), int16(x1Hi>>16) < int16(x2Hi>>16), int16(x1Hi>>32) < int16(x2Hi>>32), int16(x1Hi>>48) < int16(x2Hi>>48), } - case wazeroir.V128CmpTypeI16x8LtU: + case v128CmpTypeI16x8LtU: result = []bool{ uint16(x1Lo>>0) < uint16(x2Lo>>0), uint16(x1Lo>>16) < uint16(x2Lo>>16), uint16(x1Lo>>32) < uint16(x2Lo>>32), uint16(x1Lo>>48) < uint16(x2Lo>>48), uint16(x1Hi>>0) < uint16(x2Hi>>0), uint16(x1Hi>>16) < uint16(x2Hi>>16), uint16(x1Hi>>32) < uint16(x2Hi>>32), uint16(x1Hi>>48) < uint16(x2Hi>>48), } - case wazeroir.V128CmpTypeI16x8GtS: + case v128CmpTypeI16x8GtS: result = []bool{ int16(x1Lo>>0) > int16(x2Lo>>0), int16(x1Lo>>16) > int16(x2Lo>>16), int16(x1Lo>>32) > int16(x2Lo>>32), int16(x1Lo>>48) > int16(x2Lo>>48), int16(x1Hi>>0) > int16(x2Hi>>0), int16(x1Hi>>16) > int16(x2Hi>>16), int16(x1Hi>>32) > int16(x2Hi>>32), int16(x1Hi>>48) > int16(x2Hi>>48), } - case wazeroir.V128CmpTypeI16x8GtU: + case v128CmpTypeI16x8GtU: result = []bool{ uint16(x1Lo>>0) > uint16(x2Lo>>0), uint16(x1Lo>>16) > uint16(x2Lo>>16), uint16(x1Lo>>32) > uint16(x2Lo>>32), uint16(x1Lo>>48) > uint16(x2Lo>>48), uint16(x1Hi>>0) > uint16(x2Hi>>0), uint16(x1Hi>>16) > uint16(x2Hi>>16), uint16(x1Hi>>32) > uint16(x2Hi>>32), uint16(x1Hi>>48) > uint16(x2Hi>>48), } - case wazeroir.V128CmpTypeI16x8LeS: + case v128CmpTypeI16x8LeS: result = []bool{ int16(x1Lo>>0) <= int16(x2Lo>>0), int16(x1Lo>>16) <= int16(x2Lo>>16), int16(x1Lo>>32) <= int16(x2Lo>>32), int16(x1Lo>>48) <= int16(x2Lo>>48), int16(x1Hi>>0) <= int16(x2Hi>>0), int16(x1Hi>>16) <= int16(x2Hi>>16), int16(x1Hi>>32) <= int16(x2Hi>>32), int16(x1Hi>>48) <= int16(x2Hi>>48), } - case wazeroir.V128CmpTypeI16x8LeU: + case v128CmpTypeI16x8LeU: result = []bool{ uint16(x1Lo>>0) <= uint16(x2Lo>>0), uint16(x1Lo>>16) <= uint16(x2Lo>>16), uint16(x1Lo>>32) <= uint16(x2Lo>>32), uint16(x1Lo>>48) <= uint16(x2Lo>>48), uint16(x1Hi>>0) <= uint16(x2Hi>>0), uint16(x1Hi>>16) <= uint16(x2Hi>>16), uint16(x1Hi>>32) <= uint16(x2Hi>>32), uint16(x1Hi>>48) <= uint16(x2Hi>>48), } - case wazeroir.V128CmpTypeI16x8GeS: + case v128CmpTypeI16x8GeS: result = []bool{ int16(x1Lo>>0) >= int16(x2Lo>>0), int16(x1Lo>>16) >= int16(x2Lo>>16), int16(x1Lo>>32) >= int16(x2Lo>>32), int16(x1Lo>>48) >= int16(x2Lo>>48), int16(x1Hi>>0) >= int16(x2Hi>>0), int16(x1Hi>>16) >= int16(x2Hi>>16), int16(x1Hi>>32) >= int16(x2Hi>>32), int16(x1Hi>>48) >= int16(x2Hi>>48), } - case wazeroir.V128CmpTypeI16x8GeU: + case v128CmpTypeI16x8GeU: result = []bool{ uint16(x1Lo>>0) >= uint16(x2Lo>>0), uint16(x1Lo>>16) >= uint16(x2Lo>>16), uint16(x1Lo>>32) >= uint16(x2Lo>>32), uint16(x1Lo>>48) >= uint16(x2Lo>>48), uint16(x1Hi>>0) >= uint16(x2Hi>>0), uint16(x1Hi>>16) >= uint16(x2Hi>>16), uint16(x1Hi>>32) >= uint16(x2Hi>>32), uint16(x1Hi>>48) >= uint16(x2Hi>>48), } - case wazeroir.V128CmpTypeI32x4Eq: + case v128CmpTypeI32x4Eq: result = []bool{ uint32(x1Lo>>0) == uint32(x2Lo>>0), uint32(x1Lo>>32) == uint32(x2Lo>>32), uint32(x1Hi>>0) == uint32(x2Hi>>0), uint32(x1Hi>>32) == uint32(x2Hi>>32), } - case wazeroir.V128CmpTypeI32x4Ne: + case v128CmpTypeI32x4Ne: result = []bool{ uint32(x1Lo>>0) != uint32(x2Lo>>0), uint32(x1Lo>>32) != uint32(x2Lo>>32), uint32(x1Hi>>0) != uint32(x2Hi>>0), uint32(x1Hi>>32) != uint32(x2Hi>>32), } - case wazeroir.V128CmpTypeI32x4LtS: + case v128CmpTypeI32x4LtS: result = []bool{ int32(x1Lo>>0) < int32(x2Lo>>0), int32(x1Lo>>32) < int32(x2Lo>>32), int32(x1Hi>>0) < int32(x2Hi>>0), int32(x1Hi>>32) < int32(x2Hi>>32), } - case wazeroir.V128CmpTypeI32x4LtU: + case v128CmpTypeI32x4LtU: result = []bool{ uint32(x1Lo>>0) < uint32(x2Lo>>0), uint32(x1Lo>>32) < uint32(x2Lo>>32), uint32(x1Hi>>0) < uint32(x2Hi>>0), uint32(x1Hi>>32) < uint32(x2Hi>>32), } - case wazeroir.V128CmpTypeI32x4GtS: + case v128CmpTypeI32x4GtS: result = []bool{ int32(x1Lo>>0) > int32(x2Lo>>0), int32(x1Lo>>32) > int32(x2Lo>>32), int32(x1Hi>>0) > int32(x2Hi>>0), int32(x1Hi>>32) > int32(x2Hi>>32), } - case wazeroir.V128CmpTypeI32x4GtU: + case v128CmpTypeI32x4GtU: result = []bool{ uint32(x1Lo>>0) > uint32(x2Lo>>0), uint32(x1Lo>>32) > uint32(x2Lo>>32), uint32(x1Hi>>0) > uint32(x2Hi>>0), uint32(x1Hi>>32) > uint32(x2Hi>>32), } - case wazeroir.V128CmpTypeI32x4LeS: + case v128CmpTypeI32x4LeS: result = []bool{ int32(x1Lo>>0) <= int32(x2Lo>>0), int32(x1Lo>>32) <= int32(x2Lo>>32), int32(x1Hi>>0) <= int32(x2Hi>>0), int32(x1Hi>>32) <= int32(x2Hi>>32), } - case wazeroir.V128CmpTypeI32x4LeU: + case v128CmpTypeI32x4LeU: result = []bool{ uint32(x1Lo>>0) <= uint32(x2Lo>>0), uint32(x1Lo>>32) <= uint32(x2Lo>>32), uint32(x1Hi>>0) <= uint32(x2Hi>>0), uint32(x1Hi>>32) <= uint32(x2Hi>>32), } - case wazeroir.V128CmpTypeI32x4GeS: + case v128CmpTypeI32x4GeS: result = []bool{ int32(x1Lo>>0) >= int32(x2Lo>>0), int32(x1Lo>>32) >= int32(x2Lo>>32), int32(x1Hi>>0) >= int32(x2Hi>>0), int32(x1Hi>>32) >= int32(x2Hi>>32), } - case wazeroir.V128CmpTypeI32x4GeU: + case v128CmpTypeI32x4GeU: result = []bool{ uint32(x1Lo>>0) >= uint32(x2Lo>>0), uint32(x1Lo>>32) >= uint32(x2Lo>>32), uint32(x1Hi>>0) >= uint32(x2Hi>>0), uint32(x1Hi>>32) >= uint32(x2Hi>>32), } - case wazeroir.V128CmpTypeI64x2Eq: + case v128CmpTypeI64x2Eq: result = []bool{x1Lo == x2Lo, x1Hi == x2Hi} - case wazeroir.V128CmpTypeI64x2Ne: + case v128CmpTypeI64x2Ne: result = []bool{x1Lo != x2Lo, x1Hi != x2Hi} - case wazeroir.V128CmpTypeI64x2LtS: + case v128CmpTypeI64x2LtS: result = []bool{int64(x1Lo) < int64(x2Lo), int64(x1Hi) < int64(x2Hi)} - case wazeroir.V128CmpTypeI64x2GtS: + case v128CmpTypeI64x2GtS: result = []bool{int64(x1Lo) > int64(x2Lo), int64(x1Hi) > int64(x2Hi)} - case wazeroir.V128CmpTypeI64x2LeS: + case v128CmpTypeI64x2LeS: result = []bool{int64(x1Lo) <= int64(x2Lo), int64(x1Hi) <= int64(x2Hi)} - case wazeroir.V128CmpTypeI64x2GeS: + case v128CmpTypeI64x2GeS: result = []bool{int64(x1Lo) >= int64(x2Lo), int64(x1Hi) >= int64(x2Hi)} - case wazeroir.V128CmpTypeF32x4Eq: + case v128CmpTypeF32x4Eq: result = []bool{ math.Float32frombits(uint32(x1Lo>>0)) == math.Float32frombits(uint32(x2Lo>>0)), math.Float32frombits(uint32(x1Lo>>32)) == math.Float32frombits(uint32(x2Lo>>32)), math.Float32frombits(uint32(x1Hi>>0)) == math.Float32frombits(uint32(x2Hi>>0)), math.Float32frombits(uint32(x1Hi>>32)) == math.Float32frombits(uint32(x2Hi>>32)), } - case wazeroir.V128CmpTypeF32x4Ne: + case v128CmpTypeF32x4Ne: result = []bool{ math.Float32frombits(uint32(x1Lo>>0)) != math.Float32frombits(uint32(x2Lo>>0)), math.Float32frombits(uint32(x1Lo>>32)) != math.Float32frombits(uint32(x2Lo>>32)), math.Float32frombits(uint32(x1Hi>>0)) != math.Float32frombits(uint32(x2Hi>>0)), math.Float32frombits(uint32(x1Hi>>32)) != math.Float32frombits(uint32(x2Hi>>32)), } - case wazeroir.V128CmpTypeF32x4Lt: + case v128CmpTypeF32x4Lt: result = []bool{ math.Float32frombits(uint32(x1Lo>>0)) < math.Float32frombits(uint32(x2Lo>>0)), math.Float32frombits(uint32(x1Lo>>32)) < math.Float32frombits(uint32(x2Lo>>32)), math.Float32frombits(uint32(x1Hi>>0)) < math.Float32frombits(uint32(x2Hi>>0)), math.Float32frombits(uint32(x1Hi>>32)) < math.Float32frombits(uint32(x2Hi>>32)), } - case wazeroir.V128CmpTypeF32x4Gt: + case v128CmpTypeF32x4Gt: result = []bool{ math.Float32frombits(uint32(x1Lo>>0)) > math.Float32frombits(uint32(x2Lo>>0)), math.Float32frombits(uint32(x1Lo>>32)) > math.Float32frombits(uint32(x2Lo>>32)), math.Float32frombits(uint32(x1Hi>>0)) > math.Float32frombits(uint32(x2Hi>>0)), math.Float32frombits(uint32(x1Hi>>32)) > math.Float32frombits(uint32(x2Hi>>32)), } - case wazeroir.V128CmpTypeF32x4Le: + case v128CmpTypeF32x4Le: result = []bool{ math.Float32frombits(uint32(x1Lo>>0)) <= math.Float32frombits(uint32(x2Lo>>0)), math.Float32frombits(uint32(x1Lo>>32)) <= math.Float32frombits(uint32(x2Lo>>32)), math.Float32frombits(uint32(x1Hi>>0)) <= math.Float32frombits(uint32(x2Hi>>0)), math.Float32frombits(uint32(x1Hi>>32)) <= math.Float32frombits(uint32(x2Hi>>32)), } - case wazeroir.V128CmpTypeF32x4Ge: + case v128CmpTypeF32x4Ge: result = []bool{ math.Float32frombits(uint32(x1Lo>>0)) >= math.Float32frombits(uint32(x2Lo>>0)), math.Float32frombits(uint32(x1Lo>>32)) >= math.Float32frombits(uint32(x2Lo>>32)), math.Float32frombits(uint32(x1Hi>>0)) >= math.Float32frombits(uint32(x2Hi>>0)), math.Float32frombits(uint32(x1Hi>>32)) >= math.Float32frombits(uint32(x2Hi>>32)), } - case wazeroir.V128CmpTypeF64x2Eq: + case v128CmpTypeF64x2Eq: result = []bool{ math.Float64frombits(x1Lo) == math.Float64frombits(x2Lo), math.Float64frombits(x1Hi) == math.Float64frombits(x2Hi), } - case wazeroir.V128CmpTypeF64x2Ne: + case v128CmpTypeF64x2Ne: result = []bool{ math.Float64frombits(x1Lo) != math.Float64frombits(x2Lo), math.Float64frombits(x1Hi) != math.Float64frombits(x2Hi), } - case wazeroir.V128CmpTypeF64x2Lt: + case v128CmpTypeF64x2Lt: result = []bool{ math.Float64frombits(x1Lo) < math.Float64frombits(x2Lo), math.Float64frombits(x1Hi) < math.Float64frombits(x2Hi), } - case wazeroir.V128CmpTypeF64x2Gt: + case v128CmpTypeF64x2Gt: result = []bool{ math.Float64frombits(x1Lo) > math.Float64frombits(x2Lo), math.Float64frombits(x1Hi) > math.Float64frombits(x2Hi), } - case wazeroir.V128CmpTypeF64x2Le: + case v128CmpTypeF64x2Le: result = []bool{ math.Float64frombits(x1Lo) <= math.Float64frombits(x2Lo), math.Float64frombits(x1Hi) <= math.Float64frombits(x2Hi), } - case wazeroir.V128CmpTypeF64x2Ge: + case v128CmpTypeF64x2Ge: result = []bool{ math.Float64frombits(x1Lo) >= math.Float64frombits(x2Lo), math.Float64frombits(x1Hi) >= math.Float64frombits(x2Hi), @@ -2882,7 +2881,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(retLo) ce.pushValue(retHi) frame.pc++ - case wazeroir.OperationKindV128AddSat: + case operationKindV128AddSat: x2hi, x2Lo := ce.popValue(), ce.popValue() x1hi, x1Lo := ce.popValue(), ce.popValue() @@ -2891,7 +2890,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance // Lane-wise addition while saturating the overflowing values. // https://github.com/WebAssembly/spec/blob/wg-2.0.draft1/proposals/simd/SIMD.md#saturating-integer-addition switch op.B1 { - case wazeroir.ShapeI8x16: + case shapeI8x16: for i := 0; i < 16; i++ { var v, w byte if i < 8 { @@ -2925,7 +2924,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance retHi |= uv << ((i - 8) * 8) } } - case wazeroir.ShapeI16x8: + case shapeI16x8: for i := 0; i < 8; i++ { var v, w uint16 if i < 4 { @@ -2964,7 +2963,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(retLo) ce.pushValue(retHi) frame.pc++ - case wazeroir.OperationKindV128SubSat: + case operationKindV128SubSat: x2hi, x2Lo := ce.popValue(), ce.popValue() x1hi, x1Lo := ce.popValue(), ce.popValue() @@ -2973,7 +2972,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance // Lane-wise subtraction while saturating the overflowing values. // https://github.com/WebAssembly/spec/blob/wg-2.0.draft1/proposals/simd/SIMD.md#saturating-integer-subtraction switch op.B1 { - case wazeroir.ShapeI8x16: + case shapeI8x16: for i := 0; i < 16; i++ { var v, w byte if i < 8 { @@ -3007,7 +3006,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance retHi |= uv << ((i - 8) * 8) } } - case wazeroir.ShapeI16x8: + case shapeI16x8: for i := 0; i < 8; i++ { var v, w uint16 if i < 4 { @@ -3046,37 +3045,37 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(retLo) ce.pushValue(retHi) frame.pc++ - case wazeroir.OperationKindV128Mul: + case operationKindV128Mul: x2hi, x2lo := ce.popValue(), ce.popValue() x1hi, x1lo := ce.popValue(), ce.popValue() var retLo, retHi uint64 switch op.B1 { - case wazeroir.ShapeI16x8: + case shapeI16x8: retHi = uint64(uint16(x1hi)*uint16(x2hi)) | (uint64(uint16(x1hi>>16)*uint16(x2hi>>16)) << 16) | (uint64(uint16(x1hi>>32)*uint16(x2hi>>32)) << 32) | (uint64(uint16(x1hi>>48)*uint16(x2hi>>48)) << 48) retLo = uint64(uint16(x1lo)*uint16(x2lo)) | (uint64(uint16(x1lo>>16)*uint16(x2lo>>16)) << 16) | (uint64(uint16(x1lo>>32)*uint16(x2lo>>32)) << 32) | (uint64(uint16(x1lo>>48)*uint16(x2lo>>48)) << 48) - case wazeroir.ShapeI32x4: + case shapeI32x4: retHi = uint64(uint32(x1hi)*uint32(x2hi)) | (uint64(uint32(x1hi>>32)*uint32(x2hi>>32)) << 32) retLo = uint64(uint32(x1lo)*uint32(x2lo)) | (uint64(uint32(x1lo>>32)*uint32(x2lo>>32)) << 32) - case wazeroir.ShapeI64x2: + case shapeI64x2: retHi = x1hi * x2hi retLo = x1lo * x2lo - case wazeroir.ShapeF32x4: + case shapeF32x4: retHi = mulFloat32bits(uint32(x1hi), uint32(x2hi)) | mulFloat32bits(uint32(x1hi>>32), uint32(x2hi>>32))<<32 retLo = mulFloat32bits(uint32(x1lo), uint32(x2lo)) | mulFloat32bits(uint32(x1lo>>32), uint32(x2lo>>32))<<32 - case wazeroir.ShapeF64x2: + case shapeF64x2: retHi = math.Float64bits(math.Float64frombits(x1hi) * math.Float64frombits(x2hi)) retLo = math.Float64bits(math.Float64frombits(x1lo) * math.Float64frombits(x2lo)) } ce.pushValue(retLo) ce.pushValue(retHi) frame.pc++ - case wazeroir.OperationKindV128Div: + case operationKindV128Div: x2hi, x2lo := ce.popValue(), ce.popValue() x1hi, x1lo := ce.popValue(), ce.popValue() var retLo, retHi uint64 - if op.B1 == wazeroir.ShapeF64x2 { + if op.B1 == shapeF64x2 { retHi = math.Float64bits(math.Float64frombits(x1hi) / math.Float64frombits(x2hi)) retLo = math.Float64bits(math.Float64frombits(x1lo) / math.Float64frombits(x2lo)) } else { @@ -3086,10 +3085,10 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(retLo) ce.pushValue(retHi) frame.pc++ - case wazeroir.OperationKindV128Neg: + case operationKindV128Neg: hi, lo := ce.popValue(), ce.popValue() switch op.B1 { - case wazeroir.ShapeI8x16: + case shapeI8x16: lo = uint64(-byte(lo)) | (uint64(-byte(lo>>8)) << 8) | (uint64(-byte(lo>>16)) << 16) | (uint64(-byte(lo>>24)) << 24) | (uint64(-byte(lo>>32)) << 32) | (uint64(-byte(lo>>40)) << 40) | @@ -3098,32 +3097,32 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance (uint64(-byte(hi>>16)) << 16) | (uint64(-byte(hi>>24)) << 24) | (uint64(-byte(hi>>32)) << 32) | (uint64(-byte(hi>>40)) << 40) | (uint64(-byte(hi>>48)) << 48) | (uint64(-byte(hi>>56)) << 56) - case wazeroir.ShapeI16x8: + case shapeI16x8: hi = uint64(-uint16(hi)) | (uint64(-uint16(hi>>16)) << 16) | (uint64(-uint16(hi>>32)) << 32) | (uint64(-uint16(hi>>48)) << 48) lo = uint64(-uint16(lo)) | (uint64(-uint16(lo>>16)) << 16) | (uint64(-uint16(lo>>32)) << 32) | (uint64(-uint16(lo>>48)) << 48) - case wazeroir.ShapeI32x4: + case shapeI32x4: hi = uint64(-uint32(hi)) | (uint64(-uint32(hi>>32)) << 32) lo = uint64(-uint32(lo)) | (uint64(-uint32(lo>>32)) << 32) - case wazeroir.ShapeI64x2: + case shapeI64x2: hi = -hi lo = -lo - case wazeroir.ShapeF32x4: + case shapeF32x4: hi = uint64(math.Float32bits(-math.Float32frombits(uint32(hi)))) | (uint64(math.Float32bits(-math.Float32frombits(uint32(hi>>32)))) << 32) lo = uint64(math.Float32bits(-math.Float32frombits(uint32(lo)))) | (uint64(math.Float32bits(-math.Float32frombits(uint32(lo>>32)))) << 32) - case wazeroir.ShapeF64x2: + case shapeF64x2: hi = math.Float64bits(-math.Float64frombits(hi)) lo = math.Float64bits(-math.Float64frombits(lo)) } ce.pushValue(lo) ce.pushValue(hi) frame.pc++ - case wazeroir.OperationKindV128Sqrt: + case operationKindV128Sqrt: hi, lo := ce.popValue(), ce.popValue() - if op.B1 == wazeroir.ShapeF64x2 { + if op.B1 == shapeF64x2 { hi = math.Float64bits(math.Sqrt(math.Float64frombits(hi))) lo = math.Float64bits(math.Sqrt(math.Float64frombits(lo))) } else { @@ -3135,10 +3134,10 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(lo) ce.pushValue(hi) frame.pc++ - case wazeroir.OperationKindV128Abs: + case operationKindV128Abs: hi, lo := ce.popValue(), ce.popValue() switch op.B1 { - case wazeroir.ShapeI8x16: + case shapeI8x16: lo = uint64(i8Abs(byte(lo))) | (uint64(i8Abs(byte(lo>>8))) << 8) | (uint64(i8Abs(byte(lo>>16))) << 16) | (uint64(i8Abs(byte(lo>>24))) << 24) | (uint64(i8Abs(byte(lo>>32))) << 32) | (uint64(i8Abs(byte(lo>>40))) << 40) | @@ -3147,32 +3146,32 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance (uint64(i8Abs(byte(hi>>16))) << 16) | (uint64(i8Abs(byte(hi>>24))) << 24) | (uint64(i8Abs(byte(hi>>32))) << 32) | (uint64(i8Abs(byte(hi>>40))) << 40) | (uint64(i8Abs(byte(hi>>48))) << 48) | (uint64(i8Abs(byte(hi>>56))) << 56) - case wazeroir.ShapeI16x8: + case shapeI16x8: hi = uint64(i16Abs(uint16(hi))) | (uint64(i16Abs(uint16(hi>>16))) << 16) | (uint64(i16Abs(uint16(hi>>32))) << 32) | (uint64(i16Abs(uint16(hi>>48))) << 48) lo = uint64(i16Abs(uint16(lo))) | (uint64(i16Abs(uint16(lo>>16))) << 16) | (uint64(i16Abs(uint16(lo>>32))) << 32) | (uint64(i16Abs(uint16(lo>>48))) << 48) - case wazeroir.ShapeI32x4: + case shapeI32x4: hi = uint64(i32Abs(uint32(hi))) | (uint64(i32Abs(uint32(hi>>32))) << 32) lo = uint64(i32Abs(uint32(lo))) | (uint64(i32Abs(uint32(lo>>32))) << 32) - case wazeroir.ShapeI64x2: + case shapeI64x2: if int64(hi) < 0 { hi = -hi } if int64(lo) < 0 { lo = -lo } - case wazeroir.ShapeF32x4: + case shapeF32x4: hi = hi &^ (1<<31 | 1<<63) lo = lo &^ (1<<31 | 1<<63) - case wazeroir.ShapeF64x2: + case shapeF64x2: hi = hi &^ (1 << 63) lo = lo &^ (1 << 63) } ce.pushValue(lo) ce.pushValue(hi) frame.pc++ - case wazeroir.OperationKindV128Popcnt: + case operationKindV128Popcnt: hi, lo := ce.popValue(), ce.popValue() var retLo, retHi uint64 for i := 0; i < 16; i++ { @@ -3199,12 +3198,12 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(retLo) ce.pushValue(retHi) frame.pc++ - case wazeroir.OperationKindV128Min: + case operationKindV128Min: x2hi, x2lo := ce.popValue(), ce.popValue() x1hi, x1lo := ce.popValue(), ce.popValue() var retLo, retHi uint64 switch op.B1 { - case wazeroir.ShapeI8x16: + case shapeI8x16: if op.B3 { // signed retLo = uint64(i8MinS(uint8(x1lo>>8), uint8(x2lo>>8)))<<8 | uint64(i8MinS(uint8(x1lo), uint8(x2lo))) | uint64(i8MinS(uint8(x1lo>>24), uint8(x2lo>>24)))<<24 | uint64(i8MinS(uint8(x1lo>>16), uint8(x2lo>>16)))<<16 | @@ -3224,7 +3223,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance uint64(i8MinU(uint8(x1hi>>40), uint8(x2hi>>40)))<<40 | uint64(i8MinU(uint8(x1hi>>32), uint8(x2hi>>32)))<<32 | uint64(i8MinU(uint8(x1hi>>56), uint8(x2hi>>56)))<<56 | uint64(i8MinU(uint8(x1hi>>48), uint8(x2hi>>48)))<<48 } - case wazeroir.ShapeI16x8: + case shapeI16x8: if op.B3 { // signed retLo = uint64(i16MinS(uint16(x1lo), uint16(x2lo))) | uint64(i16MinS(uint16(x1lo>>16), uint16(x2lo>>16)))<<16 | @@ -3244,7 +3243,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance uint64(i16MinU(uint16(x1hi>>32), uint16(x2hi>>32)))<<32 | uint64(i16MinU(uint16(x1hi>>48), uint16(x2hi>>48)))<<48 } - case wazeroir.ShapeI32x4: + case shapeI32x4: if op.B3 { // signed retLo = uint64(i32MinS(uint32(x1lo), uint32(x2lo))) | uint64(i32MinS(uint32(x1lo>>32), uint32(x2lo>>32)))<<32 @@ -3256,12 +3255,12 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance retHi = uint64(i32MinU(uint32(x1hi), uint32(x2hi))) | uint64(i32MinU(uint32(x1hi>>32), uint32(x2hi>>32)))<<32 } - case wazeroir.ShapeF32x4: - retHi = WasmCompatMin32bits(uint32(x1hi), uint32(x2hi)) | - WasmCompatMin32bits(uint32(x1hi>>32), uint32(x2hi>>32))<<32 - retLo = WasmCompatMin32bits(uint32(x1lo), uint32(x2lo)) | - WasmCompatMin32bits(uint32(x1lo>>32), uint32(x2lo>>32))<<32 - case wazeroir.ShapeF64x2: + case shapeF32x4: + retHi = wasmCompatMin32bits(uint32(x1hi), uint32(x2hi)) | + wasmCompatMin32bits(uint32(x1hi>>32), uint32(x2hi>>32))<<32 + retLo = wasmCompatMin32bits(uint32(x1lo), uint32(x2lo)) | + wasmCompatMin32bits(uint32(x1lo>>32), uint32(x2lo>>32))<<32 + case shapeF64x2: retHi = math.Float64bits(moremath.WasmCompatMin64( math.Float64frombits(x1hi), math.Float64frombits(x2hi), @@ -3274,12 +3273,12 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(retLo) ce.pushValue(retHi) frame.pc++ - case wazeroir.OperationKindV128Max: + case operationKindV128Max: x2hi, x2lo := ce.popValue(), ce.popValue() x1hi, x1lo := ce.popValue(), ce.popValue() var retLo, retHi uint64 switch op.B1 { - case wazeroir.ShapeI8x16: + case shapeI8x16: if op.B3 { // signed retLo = uint64(i8MaxS(uint8(x1lo>>8), uint8(x2lo>>8)))<<8 | uint64(i8MaxS(uint8(x1lo), uint8(x2lo))) | uint64(i8MaxS(uint8(x1lo>>24), uint8(x2lo>>24)))<<24 | uint64(i8MaxS(uint8(x1lo>>16), uint8(x2lo>>16)))<<16 | @@ -3299,7 +3298,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance uint64(i8MaxU(uint8(x1hi>>40), uint8(x2hi>>40)))<<40 | uint64(i8MaxU(uint8(x1hi>>32), uint8(x2hi>>32)))<<32 | uint64(i8MaxU(uint8(x1hi>>56), uint8(x2hi>>56)))<<56 | uint64(i8MaxU(uint8(x1hi>>48), uint8(x2hi>>48)))<<48 } - case wazeroir.ShapeI16x8: + case shapeI16x8: if op.B3 { // signed retLo = uint64(i16MaxS(uint16(x1lo), uint16(x2lo))) | uint64(i16MaxS(uint16(x1lo>>16), uint16(x2lo>>16)))<<16 | @@ -3319,7 +3318,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance uint64(i16MaxU(uint16(x1hi>>32), uint16(x2hi>>32)))<<32 | uint64(i16MaxU(uint16(x1hi>>48), uint16(x2hi>>48)))<<48 } - case wazeroir.ShapeI32x4: + case shapeI32x4: if op.B3 { // signed retLo = uint64(i32MaxS(uint32(x1lo), uint32(x2lo))) | uint64(i32MaxS(uint32(x1lo>>32), uint32(x2lo>>32)))<<32 @@ -3331,12 +3330,12 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance retHi = uint64(i32MaxU(uint32(x1hi), uint32(x2hi))) | uint64(i32MaxU(uint32(x1hi>>32), uint32(x2hi>>32)))<<32 } - case wazeroir.ShapeF32x4: - retHi = WasmCompatMax32bits(uint32(x1hi), uint32(x2hi)) | - WasmCompatMax32bits(uint32(x1hi>>32), uint32(x2hi>>32))<<32 - retLo = WasmCompatMax32bits(uint32(x1lo), uint32(x2lo)) | - WasmCompatMax32bits(uint32(x1lo>>32), uint32(x2lo>>32))<<32 - case wazeroir.ShapeF64x2: + case shapeF32x4: + retHi = wasmCompatMax32bits(uint32(x1hi), uint32(x2hi)) | + wasmCompatMax32bits(uint32(x1hi>>32), uint32(x2hi>>32))<<32 + retLo = wasmCompatMax32bits(uint32(x1lo), uint32(x2lo)) | + wasmCompatMax32bits(uint32(x1lo>>32), uint32(x2lo>>32))<<32 + case shapeF64x2: retHi = math.Float64bits(moremath.WasmCompatMax64( math.Float64frombits(x1hi), math.Float64frombits(x2hi), @@ -3349,12 +3348,12 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(retLo) ce.pushValue(retHi) frame.pc++ - case wazeroir.OperationKindV128AvgrU: + case operationKindV128AvgrU: x2hi, x2lo := ce.popValue(), ce.popValue() x1hi, x1lo := ce.popValue(), ce.popValue() var retLo, retHi uint64 switch op.B1 { - case wazeroir.ShapeI8x16: + case shapeI8x16: retLo = uint64(i8RoundingAverage(uint8(x1lo>>8), uint8(x2lo>>8)))<<8 | uint64(i8RoundingAverage(uint8(x1lo), uint8(x2lo))) | uint64(i8RoundingAverage(uint8(x1lo>>24), uint8(x2lo>>24)))<<24 | uint64(i8RoundingAverage(uint8(x1lo>>16), uint8(x2lo>>16)))<<16 | uint64(i8RoundingAverage(uint8(x1lo>>40), uint8(x2lo>>40)))<<40 | uint64(i8RoundingAverage(uint8(x1lo>>32), uint8(x2lo>>32)))<<32 | @@ -3363,7 +3362,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance uint64(i8RoundingAverage(uint8(x1hi>>24), uint8(x2hi>>24)))<<24 | uint64(i8RoundingAverage(uint8(x1hi>>16), uint8(x2hi>>16)))<<16 | uint64(i8RoundingAverage(uint8(x1hi>>40), uint8(x2hi>>40)))<<40 | uint64(i8RoundingAverage(uint8(x1hi>>32), uint8(x2hi>>32)))<<32 | uint64(i8RoundingAverage(uint8(x1hi>>56), uint8(x2hi>>56)))<<56 | uint64(i8RoundingAverage(uint8(x1hi>>48), uint8(x2hi>>48)))<<48 - case wazeroir.ShapeI16x8: + case shapeI16x8: retLo = uint64(i16RoundingAverage(uint16(x1lo), uint16(x2lo))) | uint64(i16RoundingAverage(uint16(x1lo>>16), uint16(x2lo>>16)))<<16 | uint64(i16RoundingAverage(uint16(x1lo>>32), uint16(x2lo>>32)))<<32 | @@ -3376,11 +3375,11 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(retLo) ce.pushValue(retHi) frame.pc++ - case wazeroir.OperationKindV128Pmin: + case operationKindV128Pmin: x2hi, x2lo := ce.popValue(), ce.popValue() x1hi, x1lo := ce.popValue(), ce.popValue() var retLo, retHi uint64 - if op.B1 == wazeroir.ShapeF32x4 { + if op.B1 == shapeF32x4 { if flt32(math.Float32frombits(uint32(x2lo)), math.Float32frombits(uint32(x1lo))) { retLo = x2lo & 0x00000000_ffffffff } else { @@ -3416,11 +3415,11 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(retLo) ce.pushValue(retHi) frame.pc++ - case wazeroir.OperationKindV128Pmax: + case operationKindV128Pmax: x2hi, x2lo := ce.popValue(), ce.popValue() x1hi, x1lo := ce.popValue(), ce.popValue() var retLo, retHi uint64 - if op.B1 == wazeroir.ShapeF32x4 { + if op.B1 == shapeF32x4 { if flt32(math.Float32frombits(uint32(x1lo)), math.Float32frombits(uint32(x2lo))) { retLo = x2lo & 0x00000000_ffffffff } else { @@ -3456,9 +3455,9 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(retLo) ce.pushValue(retHi) frame.pc++ - case wazeroir.OperationKindV128Ceil: + case operationKindV128Ceil: hi, lo := ce.popValue(), ce.popValue() - if op.B1 == wazeroir.ShapeF32x4 { + if op.B1 == shapeF32x4 { lo = uint64(math.Float32bits(moremath.WasmCompatCeilF32(math.Float32frombits(uint32(lo))))) | (uint64(math.Float32bits(moremath.WasmCompatCeilF32(math.Float32frombits(uint32(lo>>32))))) << 32) hi = uint64(math.Float32bits(moremath.WasmCompatCeilF32(math.Float32frombits(uint32(hi))))) | @@ -3470,9 +3469,9 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(lo) ce.pushValue(hi) frame.pc++ - case wazeroir.OperationKindV128Floor: + case operationKindV128Floor: hi, lo := ce.popValue(), ce.popValue() - if op.B1 == wazeroir.ShapeF32x4 { + if op.B1 == shapeF32x4 { lo = uint64(math.Float32bits(moremath.WasmCompatFloorF32(math.Float32frombits(uint32(lo))))) | (uint64(math.Float32bits(moremath.WasmCompatFloorF32(math.Float32frombits(uint32(lo>>32))))) << 32) hi = uint64(math.Float32bits(moremath.WasmCompatFloorF32(math.Float32frombits(uint32(hi))))) | @@ -3484,9 +3483,9 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(lo) ce.pushValue(hi) frame.pc++ - case wazeroir.OperationKindV128Trunc: + case operationKindV128Trunc: hi, lo := ce.popValue(), ce.popValue() - if op.B1 == wazeroir.ShapeF32x4 { + if op.B1 == shapeF32x4 { lo = uint64(math.Float32bits(moremath.WasmCompatTruncF32(math.Float32frombits(uint32(lo))))) | (uint64(math.Float32bits(moremath.WasmCompatTruncF32(math.Float32frombits(uint32(lo>>32))))) << 32) hi = uint64(math.Float32bits(moremath.WasmCompatTruncF32(math.Float32frombits(uint32(hi))))) | @@ -3498,9 +3497,9 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(lo) ce.pushValue(hi) frame.pc++ - case wazeroir.OperationKindV128Nearest: + case operationKindV128Nearest: hi, lo := ce.popValue(), ce.popValue() - if op.B1 == wazeroir.ShapeF32x4 { + if op.B1 == shapeF32x4 { lo = uint64(math.Float32bits(moremath.WasmCompatNearestF32(math.Float32frombits(uint32(lo))))) | (uint64(math.Float32bits(moremath.WasmCompatNearestF32(math.Float32frombits(uint32(lo>>32))))) << 32) hi = uint64(math.Float32bits(moremath.WasmCompatNearestF32(math.Float32frombits(uint32(hi))))) | @@ -3512,7 +3511,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(lo) ce.pushValue(hi) frame.pc++ - case wazeroir.OperationKindV128Extend: + case operationKindV128Extend: hi, lo := ce.popValue(), ce.popValue() var origin uint64 if op.B3 { // use lower 64 bits @@ -3525,7 +3524,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance var retHi, retLo uint64 switch op.B1 { - case wazeroir.ShapeI8x16: + case shapeI8x16: for i := 0; i < 8; i++ { v8 := byte(origin >> (i * 8)) @@ -3542,7 +3541,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance retHi |= uint64(v16) << ((i - 4) * 16) } } - case wazeroir.ShapeI16x8: + case shapeI16x8: for i := 0; i < 4; i++ { v16 := uint16(origin >> (i * 16)) @@ -3559,7 +3558,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance retHi |= uint64(v32) << ((i - 2) * 32) } } - case wazeroir.ShapeI32x4: + case shapeI32x4: v32Lo := uint32(origin) v32Hi := uint32(origin >> 32) if signed { @@ -3573,7 +3572,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(retLo) ce.pushValue(retHi) frame.pc++ - case wazeroir.OperationKindV128ExtMul: + case operationKindV128ExtMul: x2Hi, x2Lo := ce.popValue(), ce.popValue() x1Hi, x1Lo := ce.popValue(), ce.popValue() var x1, x2 uint64 @@ -3587,7 +3586,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance var retLo, retHi uint64 switch op.B1 { - case wazeroir.ShapeI8x16: + case shapeI8x16: for i := 0; i < 8; i++ { v1, v2 := byte(x1>>(i*8)), byte(x2>>(i*8)) @@ -3604,7 +3603,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance retHi |= uint64(v16) << ((i - 4) * 16) } } - case wazeroir.ShapeI16x8: + case shapeI16x8: for i := 0; i < 4; i++ { v1, v2 := uint16(x1>>(i*16)), uint16(x2>>(i*16)) @@ -3621,7 +3620,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance retHi |= uint64(v32) << ((i - 2) * 32) } } - case wazeroir.ShapeI32x4: + case shapeI32x4: v1Lo, v2Lo := uint32(x1), uint32(x2) v1Hi, v2Hi := uint32(x1>>32), uint32(x2>>32) if signed { @@ -3636,7 +3635,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(retLo) ce.pushValue(retHi) frame.pc++ - case wazeroir.OperationKindV128Q15mulrSatS: + case operationKindV128Q15mulrSatS: x2hi, x2Lo := ce.popValue(), ce.popValue() x1hi, x1Lo := ce.popValue(), ce.popValue() var retLo, retHi uint64 @@ -3668,14 +3667,14 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(retLo) ce.pushValue(retHi) frame.pc++ - case wazeroir.OperationKindV128ExtAddPairwise: + case operationKindV128ExtAddPairwise: hi, lo := ce.popValue(), ce.popValue() signed := op.B3 var retLo, retHi uint64 switch op.B1 { - case wazeroir.ShapeI8x16: + case shapeI8x16: for i := 0; i < 8; i++ { var v1, v2 byte if i < 4 { @@ -3697,7 +3696,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance retHi |= uint64(v16) << ((i - 4) * 16) } } - case wazeroir.ShapeI16x8: + case shapeI16x8: for i := 0; i < 4; i++ { var v1, v2 uint16 if i < 2 { @@ -3723,12 +3722,12 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(retLo) ce.pushValue(retHi) frame.pc++ - case wazeroir.OperationKindV128FloatPromote: + case operationKindV128FloatPromote: _, toPromote := ce.popValue(), ce.popValue() ce.pushValue(math.Float64bits(float64(math.Float32frombits(uint32(toPromote))))) ce.pushValue(math.Float64bits(float64(math.Float32frombits(uint32(toPromote >> 32))))) frame.pc++ - case wazeroir.OperationKindV128FloatDemote: + case operationKindV128FloatDemote: hi, lo := ce.popValue(), ce.popValue() ce.pushValue( uint64(math.Float32bits(float32(math.Float64frombits(lo)))) | @@ -3736,14 +3735,14 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ) ce.pushValue(0) frame.pc++ - case wazeroir.OperationKindV128FConvertFromI: + case operationKindV128FConvertFromI: hi, lo := ce.popValue(), ce.popValue() v1, v2, v3, v4 := uint32(lo), uint32(lo>>32), uint32(hi), uint32(hi>>32) signed := op.B3 var retLo, retHi uint64 switch op.B1 { // Destination shape. - case wazeroir.ShapeF32x4: // f32x4 from signed/unsigned i32x4 + case shapeF32x4: // f32x4 from signed/unsigned i32x4 if signed { retLo = uint64(math.Float32bits(float32(int32(v1)))) | (uint64(math.Float32bits(float32(int32(v2)))) << 32) @@ -3755,7 +3754,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance retHi = uint64(math.Float32bits(float32(v3))) | (uint64(math.Float32bits(float32(v4))) << 32) } - case wazeroir.ShapeF64x2: // f64x2 from signed/unsigned i32x4 + case shapeF64x2: // f64x2 from signed/unsigned i32x4 if signed { retLo, retHi = math.Float64bits(float64(int32(v1))), math.Float64bits(float64(int32(v2))) } else { @@ -3766,14 +3765,14 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(retLo) ce.pushValue(retHi) frame.pc++ - case wazeroir.OperationKindV128Narrow: + case operationKindV128Narrow: x2Hi, x2Lo := ce.popValue(), ce.popValue() x1Hi, x1Lo := ce.popValue(), ce.popValue() signed := op.B3 var retLo, retHi uint64 switch op.B1 { - case wazeroir.ShapeI16x8: // signed/unsigned i16x8 to i8x16 + case shapeI16x8: // signed/unsigned i16x8 to i8x16 for i := 0; i < 8; i++ { var v16 uint16 if i < 4 { @@ -3832,7 +3831,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance } retHi |= uint64(v) << (i * 8) } - case wazeroir.ShapeI32x4: // signed/unsigned i32x4 to i16x8 + case shapeI32x4: // signed/unsigned i32x4 to i16x8 for i := 0; i < 4; i++ { var v32 uint32 if i < 2 { @@ -3896,7 +3895,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(retLo) ce.pushValue(retHi) frame.pc++ - case wazeroir.OperationKindV128Dot: + case operationKindV128Dot: x2Hi, x2Lo := ce.popValue(), ce.popValue() x1Hi, x1Lo := ce.popValue(), ce.popValue() ce.pushValue( @@ -3908,13 +3907,13 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance (uint64(uint32(int32(int16(x1Hi>>32))*int32(int16(x2Hi>>32))+int32(int16(x1Hi>>48))*int32(int16(x2Hi>>48)))) << 32), ) frame.pc++ - case wazeroir.OperationKindV128ITruncSatFromF: + case operationKindV128ITruncSatFromF: hi, lo := ce.popValue(), ce.popValue() signed := op.B3 var retLo, retHi uint64 switch op.B1 { - case wazeroir.ShapeF32x4: // f32x4 to i32x4 + case shapeF32x4: // f32x4 to i32x4 for i, f64 := range [4]float64{ math.Trunc(float64(math.Float32frombits(uint32(lo)))), math.Trunc(float64(math.Float32frombits(uint32(lo >> 32)))), @@ -3948,7 +3947,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance } } - case wazeroir.ShapeF64x2: // f64x2 to i32x4 + case shapeF64x2: // f64x2 to i32x4 for i, f := range [2]float64{ math.Trunc(math.Float64frombits(lo)), math.Trunc(math.Float64frombits(hi)), @@ -3979,7 +3978,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(retLo) ce.pushValue(retHi) frame.pc++ - case wazeroir.OperationKindAtomicMemoryWait: + case operationKindAtomicMemoryWait: timeout := int64(ce.popValue()) exp := ce.popValue() offset := ce.popMemoryOffset(op) @@ -3989,8 +3988,8 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance panic(wasmruntime.ErrRuntimeExpectedSharedMemory) } - switch wazeroir.UnsignedType(op.B1) { - case wazeroir.UnsignedTypeI32: + switch unsignedType(op.B1) { + case unsignedTypeI32: if offset%4 != 0 { panic(wasmruntime.ErrRuntimeUnalignedAtomic) } @@ -4003,7 +4002,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance value, _ := mem.ReadUint32Le(offset) return value })) - case wazeroir.UnsignedTypeI64: + case unsignedTypeI64: if offset%8 != 0 { panic(wasmruntime.ErrRuntimeUnalignedAtomic) } @@ -4018,7 +4017,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance })) } frame.pc++ - case wazeroir.OperationKindAtomicMemoryNotify: + case operationKindAtomicMemoryNotify: count := ce.popValue() offset := ce.popMemoryOffset(op) if offset%4 != 0 { @@ -4031,7 +4030,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance res := memoryInst.Notify(offset, uint32(count)) ce.pushValue(uint64(res)) frame.pc++ - case wazeroir.OperationKindAtomicFence: + case operationKindAtomicFence: // Memory not required for fence only if memoryInst != nil { // An empty critical section can be used as a synchronization primitive, which is what @@ -4040,10 +4039,10 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance memoryInst.Mux.Unlock() //nolint:staticcheck } frame.pc++ - case wazeroir.OperationKindAtomicLoad: + case operationKindAtomicLoad: offset := ce.popMemoryOffset(op) - switch wazeroir.UnsignedType(op.B1) { - case wazeroir.UnsignedTypeI32: + switch unsignedType(op.B1) { + case unsignedTypeI32: if offset%4 != 0 { panic(wasmruntime.ErrRuntimeUnalignedAtomic) } @@ -4054,7 +4053,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) } ce.pushValue(uint64(val)) - case wazeroir.UnsignedTypeI64: + case unsignedTypeI64: if offset%8 != 0 { panic(wasmruntime.ErrRuntimeUnalignedAtomic) } @@ -4067,7 +4066,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(val) } frame.pc++ - case wazeroir.OperationKindAtomicLoad8: + case operationKindAtomicLoad8: offset := ce.popMemoryOffset(op) memoryInst.Mux.Lock() val, ok := memoryInst.ReadByte(offset) @@ -4077,7 +4076,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance } ce.pushValue(uint64(val)) frame.pc++ - case wazeroir.OperationKindAtomicLoad16: + case operationKindAtomicLoad16: offset := ce.popMemoryOffset(op) if offset%2 != 0 { panic(wasmruntime.ErrRuntimeUnalignedAtomic) @@ -4090,11 +4089,11 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance } ce.pushValue(uint64(val)) frame.pc++ - case wazeroir.OperationKindAtomicStore: + case operationKindAtomicStore: val := ce.popValue() offset := ce.popMemoryOffset(op) - switch wazeroir.UnsignedType(op.B1) { - case wazeroir.UnsignedTypeI32: + switch unsignedType(op.B1) { + case unsignedTypeI32: if offset%4 != 0 { panic(wasmruntime.ErrRuntimeUnalignedAtomic) } @@ -4104,7 +4103,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance if !ok { panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) } - case wazeroir.UnsignedTypeI64: + case unsignedTypeI64: if offset%8 != 0 { panic(wasmruntime.ErrRuntimeUnalignedAtomic) } @@ -4116,7 +4115,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance } } frame.pc++ - case wazeroir.OperationKindAtomicStore8: + case operationKindAtomicStore8: val := byte(ce.popValue()) offset := ce.popMemoryOffset(op) memoryInst.Mux.Lock() @@ -4126,7 +4125,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) } frame.pc++ - case wazeroir.OperationKindAtomicStore16: + case operationKindAtomicStore16: val := uint16(ce.popValue()) offset := ce.popMemoryOffset(op) if offset%2 != 0 { @@ -4139,11 +4138,11 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) } frame.pc++ - case wazeroir.OperationKindAtomicRMW: + case operationKindAtomicRMW: val := ce.popValue() offset := ce.popMemoryOffset(op) - switch wazeroir.UnsignedType(op.B1) { - case wazeroir.UnsignedTypeI32: + switch unsignedType(op.B1) { + case unsignedTypeI32: if offset%4 != 0 { panic(wasmruntime.ErrRuntimeUnalignedAtomic) } @@ -4154,24 +4153,24 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) } var newVal uint32 - switch wazeroir.AtomicArithmeticOp(op.B2) { - case wazeroir.AtomicArithmeticOpAdd: + switch atomicArithmeticOp(op.B2) { + case atomicArithmeticOpAdd: newVal = old + uint32(val) - case wazeroir.AtomicArithmeticOpSub: + case atomicArithmeticOpSub: newVal = old - uint32(val) - case wazeroir.AtomicArithmeticOpAnd: + case atomicArithmeticOpAnd: newVal = old & uint32(val) - case wazeroir.AtomicArithmeticOpOr: + case atomicArithmeticOpOr: newVal = old | uint32(val) - case wazeroir.AtomicArithmeticOpXor: + case atomicArithmeticOpXor: newVal = old ^ uint32(val) - case wazeroir.AtomicArithmeticOpNop: + case atomicArithmeticOpNop: newVal = uint32(val) } memoryInst.WriteUint32Le(offset, newVal) memoryInst.Mux.Unlock() ce.pushValue(uint64(old)) - case wazeroir.UnsignedTypeI64: + case unsignedTypeI64: if offset%8 != 0 { panic(wasmruntime.ErrRuntimeUnalignedAtomic) } @@ -4182,18 +4181,18 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) } var newVal uint64 - switch wazeroir.AtomicArithmeticOp(op.B2) { - case wazeroir.AtomicArithmeticOpAdd: + switch atomicArithmeticOp(op.B2) { + case atomicArithmeticOpAdd: newVal = old + val - case wazeroir.AtomicArithmeticOpSub: + case atomicArithmeticOpSub: newVal = old - val - case wazeroir.AtomicArithmeticOpAnd: + case atomicArithmeticOpAnd: newVal = old & val - case wazeroir.AtomicArithmeticOpOr: + case atomicArithmeticOpOr: newVal = old | val - case wazeroir.AtomicArithmeticOpXor: + case atomicArithmeticOpXor: newVal = old ^ val - case wazeroir.AtomicArithmeticOpNop: + case atomicArithmeticOpNop: newVal = val } memoryInst.WriteUint64Le(offset, newVal) @@ -4201,7 +4200,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(old) } frame.pc++ - case wazeroir.OperationKindAtomicRMW8: + case operationKindAtomicRMW8: val := ce.popValue() offset := ce.popMemoryOffset(op) memoryInst.Mux.Lock() @@ -4212,25 +4211,25 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance } arg := byte(val) var newVal byte - switch wazeroir.AtomicArithmeticOp(op.B2) { - case wazeroir.AtomicArithmeticOpAdd: + switch atomicArithmeticOp(op.B2) { + case atomicArithmeticOpAdd: newVal = old + arg - case wazeroir.AtomicArithmeticOpSub: + case atomicArithmeticOpSub: newVal = old - arg - case wazeroir.AtomicArithmeticOpAnd: + case atomicArithmeticOpAnd: newVal = old & arg - case wazeroir.AtomicArithmeticOpOr: + case atomicArithmeticOpOr: newVal = old | arg - case wazeroir.AtomicArithmeticOpXor: + case atomicArithmeticOpXor: newVal = old ^ arg - case wazeroir.AtomicArithmeticOpNop: + case atomicArithmeticOpNop: newVal = arg } memoryInst.WriteByte(offset, newVal) memoryInst.Mux.Unlock() ce.pushValue(uint64(old)) frame.pc++ - case wazeroir.OperationKindAtomicRMW16: + case operationKindAtomicRMW16: val := ce.popValue() offset := ce.popMemoryOffset(op) if offset%2 != 0 { @@ -4244,30 +4243,30 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance } arg := uint16(val) var newVal uint16 - switch wazeroir.AtomicArithmeticOp(op.B2) { - case wazeroir.AtomicArithmeticOpAdd: + switch atomicArithmeticOp(op.B2) { + case atomicArithmeticOpAdd: newVal = old + arg - case wazeroir.AtomicArithmeticOpSub: + case atomicArithmeticOpSub: newVal = old - arg - case wazeroir.AtomicArithmeticOpAnd: + case atomicArithmeticOpAnd: newVal = old & arg - case wazeroir.AtomicArithmeticOpOr: + case atomicArithmeticOpOr: newVal = old | arg - case wazeroir.AtomicArithmeticOpXor: + case atomicArithmeticOpXor: newVal = old ^ arg - case wazeroir.AtomicArithmeticOpNop: + case atomicArithmeticOpNop: newVal = arg } memoryInst.WriteUint16Le(offset, newVal) memoryInst.Mux.Unlock() ce.pushValue(uint64(old)) frame.pc++ - case wazeroir.OperationKindAtomicRMWCmpxchg: + case operationKindAtomicRMWCmpxchg: rep := ce.popValue() exp := ce.popValue() offset := ce.popMemoryOffset(op) - switch wazeroir.UnsignedType(op.B1) { - case wazeroir.UnsignedTypeI32: + switch unsignedType(op.B1) { + case unsignedTypeI32: if offset%4 != 0 { panic(wasmruntime.ErrRuntimeUnalignedAtomic) } @@ -4282,7 +4281,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance } memoryInst.Mux.Unlock() ce.pushValue(uint64(old)) - case wazeroir.UnsignedTypeI64: + case unsignedTypeI64: if offset%8 != 0 { panic(wasmruntime.ErrRuntimeUnalignedAtomic) } @@ -4299,7 +4298,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.pushValue(old) } frame.pc++ - case wazeroir.OperationKindAtomicRMW8Cmpxchg: + case operationKindAtomicRMW8Cmpxchg: rep := byte(ce.popValue()) exp := byte(ce.popValue()) offset := ce.popMemoryOffset(op) @@ -4315,7 +4314,7 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance memoryInst.Mux.Unlock() ce.pushValue(uint64(old)) frame.pc++ - case wazeroir.OperationKindAtomicRMW16Cmpxchg: + case operationKindAtomicRMW16Cmpxchg: rep := uint16(ce.popValue()) exp := uint16(ce.popValue()) offset := ce.popMemoryOffset(op) @@ -4341,14 +4340,14 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, m *wasm.ModuleInstance ce.popFrame() } -func WasmCompatMax32bits(v1, v2 uint32) uint64 { +func wasmCompatMax32bits(v1, v2 uint32) uint64 { return uint64(math.Float32bits(moremath.WasmCompatMax32( math.Float32frombits(v1), math.Float32frombits(v2), ))) } -func WasmCompatMin32bits(v1, v2 uint32) uint64 { +func wasmCompatMin32bits(v1, v2 uint32) uint64 { return uint64(math.Float32bits(moremath.WasmCompatMin32( math.Float32frombits(v1), math.Float32frombits(v2), @@ -4550,7 +4549,7 @@ func (ce *callEngine) callNativeFuncWithListener(ctx context.Context, m *wasm.Mo // popMemoryOffset takes a memory offset off the stack for use in load and store instructions. // As the top of stack value is 64-bit, this ensures it is in range before returning it. -func (ce *callEngine) popMemoryOffset(op *wazeroir.UnionOperation) uint32 { +func (ce *callEngine) popMemoryOffset(op *unionOperation) uint32 { offset := op.U2 + ce.popValue() if offset > math.MaxUint32 { panic(wasmruntime.ErrRuntimeOutOfBoundsMemoryAccess) diff --git a/internal/engine/interpreter/interpreter_test.go b/internal/engine/interpreter/interpreter_test.go index 13f47af7f4..6ac98909b3 100644 --- a/internal/engine/interpreter/interpreter_test.go +++ b/internal/engine/interpreter/interpreter_test.go @@ -10,7 +10,6 @@ import ( "github.com/tetratelabs/wazero/api" "github.com/tetratelabs/wazero/internal/testing/require" "github.com/tetratelabs/wazero/internal/wasm" - "github.com/tetratelabs/wazero/internal/wazeroir" ) // testCtx is an arbitrary, non-default context. Non-nil also prevents linter errors. @@ -67,8 +66,8 @@ func TestInterpreter_NonTrappingFloatToIntConversion(t *testing.T) { tests := []struct { op wasm.OpcodeMisc - inputType wazeroir.Float - outputType wazeroir.SignedInt + inputType float + outputType signedInt input32bit []float32 input64bit []float64 expected32bit []int32 @@ -77,8 +76,8 @@ func TestInterpreter_NonTrappingFloatToIntConversion(t *testing.T) { { // https://github.com/WebAssembly/spec/blob/c8fd933fa51eb0b511bce027b573aef7ee373726/test/core/conversions.wast#L261-L282 op: wasm.OpcodeMiscI32TruncSatF32S, - inputType: wazeroir.Float32, - outputType: wazeroir.SignedInt32, + inputType: f32, + outputType: signedInt32, input32bit: []float32{ 0.0, 0.0, 0x1p-149, -0x1p-149, 1.0, 0x1.19999ap+0, 1.5, -1.0, -0x1.19999ap+0, -1.5, -1.9, -2.0, 2147483520.0, -2147483648.0, 2147483648.0, -2147483904.0, @@ -93,8 +92,8 @@ func TestInterpreter_NonTrappingFloatToIntConversion(t *testing.T) { { // https://github.com/WebAssembly/spec/blob/c8fd933fa51eb0b511bce027b573aef7ee373726/test/core/conversions.wast#L284-L304 op: wasm.OpcodeMiscI32TruncSatF32U, - inputType: wazeroir.Float32, - outputType: wazeroir.SignedUint32, + inputType: f32, + outputType: signedUint32, input32bit: []float32{ 0.0, 0.0, 0x1p-149, -0x1p-149, 1.0, 0x1.19999ap+0, 1.5, 1.9, 2.0, 2147483648, 4294967040.0, -0x1.ccccccp-1, -0x1.fffffep-1, 4294967296.0, -1.0, float32(math.Inf(1)), float32(math.Inf(-1)), @@ -108,8 +107,8 @@ func TestInterpreter_NonTrappingFloatToIntConversion(t *testing.T) { { // https://github.com/WebAssembly/spec/blob/c8fd933fa51eb0b511bce027b573aef7ee373726/test/core/conversions.wast#L355-L378 op: wasm.OpcodeMiscI64TruncSatF32S, - inputType: wazeroir.Float32, - outputType: wazeroir.SignedInt64, + inputType: f32, + outputType: signedInt64, input32bit: []float32{ 0.0, 0.0, 0x1p-149, -0x1p-149, 1.0, 0x1.19999ap+0, 1.5, -1.0, -0x1.19999ap+0, -1.5, -1.9, -2.0, 4294967296, -4294967296, 9223371487098961920.0, -9223372036854775808.0, 9223372036854775808.0, -9223373136366403584.0, @@ -124,8 +123,8 @@ func TestInterpreter_NonTrappingFloatToIntConversion(t *testing.T) { { // https://github.com/WebAssembly/spec/blob/c8fd933fa51eb0b511bce027b573aef7ee373726/test/core/conversions.wast#L380-L398 op: wasm.OpcodeMiscI64TruncSatF32U, - inputType: wazeroir.Float32, - outputType: wazeroir.SignedUint64, + inputType: f32, + outputType: signedUint64, input32bit: []float32{ 0.0, 0.0, 0x1p-149, -0x1p-149, 1.0, 0x1.19999ap+0, 1.5, 4294967296, 18446742974197923840.0, -0x1.ccccccp-1, -0x1.fffffep-1, 18446744073709551616.0, -1.0, @@ -141,8 +140,8 @@ func TestInterpreter_NonTrappingFloatToIntConversion(t *testing.T) { { // https://github.com/WebAssembly/spec/blob/c8fd933fa51eb0b511bce027b573aef7ee373726/test/core/conversions.wast#L306-L327 op: wasm.OpcodeMiscI32TruncSatF64S, - inputType: wazeroir.Float64, - outputType: wazeroir.SignedInt32, + inputType: f64, + outputType: signedInt32, input64bit: []float64{ 0.0, 0.0, 0x0.0000000000001p-1022, -0x0.0000000000001p-1022, 1.0, 0x1.199999999999ap+0, 1.5, -1.0, -0x1.199999999999ap+0, -1.5, -1.9, -2.0, 2147483647.0, -2147483648.0, 2147483648.0, @@ -157,8 +156,8 @@ func TestInterpreter_NonTrappingFloatToIntConversion(t *testing.T) { { // https://github.com/WebAssembly/spec/blob/c8fd933fa51eb0b511bce027b573aef7ee373726/test/core/conversions.wast#L329-L353 op: wasm.OpcodeMiscI32TruncSatF64U, - inputType: wazeroir.Float64, - outputType: wazeroir.SignedUint32, + inputType: f64, + outputType: signedUint32, input64bit: []float64{ 0.0, 0.0, 0x0.0000000000001p-1022, -0x0.0000000000001p-1022, 1.0, 0x1.199999999999ap+0, 1.5, 1.9, 2.0, 2147483648, 4294967295.0, -0x1.ccccccccccccdp-1, -0x1.fffffffffffffp-1, 1e8, 4294967296.0, -1.0, 1e16, 1e30, @@ -173,8 +172,8 @@ func TestInterpreter_NonTrappingFloatToIntConversion(t *testing.T) { { // https://github.com/WebAssembly/spec/blob/c8fd933fa51eb0b511bce027b573aef7ee373726/test/core/conversions.wast#L400-L423 op: wasm.OpcodeMiscI64TruncSatF64S, - inputType: wazeroir.Float64, - outputType: wazeroir.SignedInt64, + inputType: f64, + outputType: signedInt64, input64bit: []float64{ 0.0, 0.0, 0x0.0000000000001p-1022, -0x0.0000000000001p-1022, 1.0, 0x1.199999999999ap+0, 1.5, -1.0, -0x1.199999999999ap+0, -1.5, -1.9, -2.0, 4294967296, -4294967296, 9223372036854774784.0, -9223372036854775808.0, @@ -190,8 +189,8 @@ func TestInterpreter_NonTrappingFloatToIntConversion(t *testing.T) { { // https://github.com/WebAssembly/spec/blob/c8fd933fa51eb0b511bce027b573aef7ee373726/test/core/conversions.wast#L425-L447 op: wasm.OpcodeMiscI64TruncSatF64U, - inputType: wazeroir.Float64, - outputType: wazeroir.SignedUint64, + inputType: f64, + outputType: signedUint64, input64bit: []float64{ 0.0, 0.0, 0x0.0000000000001p-1022, -0x0.0000000000001p-1022, 1.0, 0x1.199999999999ap+0, 1.5, 4294967295, 4294967296, 18446744073709549568.0, -0x1.ccccccccccccdp-1, -0x1.fffffffffffffp-1, 1e8, 1e16, 9223372036854775808, @@ -216,21 +215,21 @@ func TestInterpreter_NonTrappingFloatToIntConversion(t *testing.T) { for i := 0; i < casenum; i++ { i := i t.Run(strconv.Itoa(i), func(t *testing.T) { - var body []wazeroir.UnionOperation + var body []unionOperation if in32bit { - body = append(body, wazeroir.UnionOperation{ - Kind: wazeroir.OperationKindConstF32, + body = append(body, unionOperation{ + Kind: operationKindConstF32, U1: uint64(math.Float32bits(tc.input32bit[i])), }) } else { - body = append(body, wazeroir.UnionOperation{ - Kind: wazeroir.OperationKindConstF64, - U1: uint64(math.Float64bits(tc.input64bit[i])), + body = append(body, unionOperation{ + Kind: operationKindConstF64, + U1: math.Float64bits(tc.input64bit[i]), }) } - body = append(body, wazeroir.UnionOperation{ - Kind: wazeroir.OperationKindITruncFromF, + body = append(body, unionOperation{ + Kind: operationKindITruncFromF, B1: byte(tc.inputType), B2: byte(tc.outputType), B3: true, // NonTrapping = true. @@ -238,7 +237,7 @@ func TestInterpreter_NonTrappingFloatToIntConversion(t *testing.T) { // Return from function. body = append(body, - wazeroir.UnionOperation{Kind: wazeroir.OperationKindBr, U1: uint64(math.MaxUint64)}, + unionOperation{Kind: operationKindBr, U1: uint64(math.MaxUint64)}, ) ce := &callEngine{} @@ -261,18 +260,18 @@ func TestInterpreter_NonTrappingFloatToIntConversion(t *testing.T) { } func TestInterpreter_CallEngine_callNativeFunc_signExtend(t *testing.T) { - translateToIROperationKind := func(op wasm.Opcode) (kind wazeroir.OperationKind) { + translateToIRoperationKind := func(op wasm.Opcode) (kind operationKind) { switch op { case wasm.OpcodeI32Extend8S: - kind = wazeroir.OperationKindSignExtend32From8 + kind = operationKindSignExtend32From8 case wasm.OpcodeI32Extend16S: - kind = wazeroir.OperationKindSignExtend32From16 + kind = operationKindSignExtend32From16 case wasm.OpcodeI64Extend8S: - kind = wazeroir.OperationKindSignExtend64From8 + kind = operationKindSignExtend64From8 case wasm.OpcodeI64Extend16S: - kind = wazeroir.OperationKindSignExtend64From16 + kind = operationKindSignExtend64From16 case wasm.OpcodeI64Extend32S: - kind = wazeroir.OperationKindSignExtend64From32 + kind = operationKindSignExtend64From32 } return } @@ -307,10 +306,10 @@ func TestInterpreter_CallEngine_callNativeFunc_signExtend(t *testing.T) { ce := &callEngine{} f := &function{ moduleInstance: &wasm.ModuleInstance{Engine: &moduleEngine{}}, - parent: &compiledFunction{body: []wazeroir.UnionOperation{ - {Kind: wazeroir.OperationKindConstI32, U1: uint64(uint32(tc.in))}, - {Kind: translateToIROperationKind(tc.opcode)}, - {Kind: wazeroir.OperationKindBr, U1: uint64(math.MaxUint64)}, + parent: &compiledFunction{body: []unionOperation{ + {Kind: operationKindConstI32, U1: uint64(uint32(tc.in))}, + {Kind: translateToIRoperationKind(tc.opcode)}, + {Kind: operationKindBr, U1: uint64(math.MaxUint64)}, }}, } ce.callNativeFunc(testCtx, &wasm.ModuleInstance{}, f) @@ -361,10 +360,10 @@ func TestInterpreter_CallEngine_callNativeFunc_signExtend(t *testing.T) { ce := &callEngine{} f := &function{ moduleInstance: &wasm.ModuleInstance{Engine: &moduleEngine{}}, - parent: &compiledFunction{body: []wazeroir.UnionOperation{ - {Kind: wazeroir.OperationKindConstI64, U1: uint64(tc.in)}, - {Kind: translateToIROperationKind(tc.opcode)}, - {Kind: wazeroir.OperationKindBr, U1: uint64(math.MaxUint64)}, + parent: &compiledFunction{body: []unionOperation{ + {Kind: operationKindConstI64, U1: uint64(tc.in)}, + {Kind: translateToIRoperationKind(tc.opcode)}, + {Kind: operationKindBr, U1: uint64(math.MaxUint64)}, }}, } ce.callNativeFunc(testCtx, &wasm.ModuleInstance{}, f) @@ -433,8 +432,8 @@ func TestInterpreter_Compile(t *testing.T) { func TestEngine_CachedCompiledFunctionPerModule(t *testing.T) { e := NewEngine(testCtx, api.CoreFeaturesV1, nil).(*engine) exp := []compiledFunction{ - {body: []wazeroir.UnionOperation{}}, - {body: []wazeroir.UnionOperation{}}, + {body: []unionOperation{}}, + {body: []unionOperation{}}, } m := &wasm.Module{} diff --git a/internal/engine/interpreter/operations.go b/internal/engine/interpreter/operations.go new file mode 100644 index 0000000000..3087a718ff --- /dev/null +++ b/internal/engine/interpreter/operations.go @@ -0,0 +1,2812 @@ +package interpreter + +import ( + "fmt" + "math" + "strings" +) + +// unsignedInt represents unsigned 32-bit or 64-bit integers. +type unsignedInt byte + +const ( + unsignedInt32 unsignedInt = iota + unsignedInt64 +) + +// String implements fmt.Stringer. +func (s unsignedInt) String() (ret string) { + switch s { + case unsignedInt32: + ret = "i32" + case unsignedInt64: + ret = "i64" + } + return +} + +// signedInt represents signed or unsigned integers. +type signedInt byte + +const ( + signedInt32 signedInt = iota + signedInt64 + signedUint32 + signedUint64 +) + +// String implements fmt.Stringer. +func (s signedInt) String() (ret string) { + switch s { + case signedUint32: + ret = "u32" + case signedUint64: + ret = "u64" + case signedInt32: + ret = "s32" + case signedInt64: + ret = "s64" + } + return +} + +// float represents the scalar double or single precision floating points. +type float byte + +const ( + f32 float = iota + f64 +) + +// String implements fmt.Stringer. +func (s float) String() (ret string) { + switch s { + case f32: + ret = "f32" + case f64: + ret = "f64" + } + return +} + +// unsignedType is the union of unsignedInt, float and V128 vector type. +type unsignedType byte + +const ( + unsignedTypeI32 unsignedType = iota + unsignedTypeI64 + unsignedTypeF32 + unsignedTypeF64 + unsignedTypeV128 + unsignedTypeUnknown +) + +// String implements fmt.Stringer. +func (s unsignedType) String() (ret string) { + switch s { + case unsignedTypeI32: + ret = "i32" + case unsignedTypeI64: + ret = "i64" + case unsignedTypeF32: + ret = "f32" + case unsignedTypeF64: + ret = "f64" + case unsignedTypeV128: + ret = "v128" + case unsignedTypeUnknown: + ret = "unknown" + } + return +} + +// signedType is the union of signedInt and float types. +type signedType byte + +const ( + signedTypeInt32 signedType = iota + signedTypeUint32 + signedTypeInt64 + signedTypeUint64 + signedTypeFloat32 + signedTypeFloat64 +) + +// String implements fmt.Stringer. +func (s signedType) String() (ret string) { + switch s { + case signedTypeInt32: + ret = "s32" + case signedTypeUint32: + ret = "u32" + case signedTypeInt64: + ret = "s64" + case signedTypeUint64: + ret = "u64" + case signedTypeFloat32: + ret = "f32" + case signedTypeFloat64: + ret = "f64" + } + return +} + +// operationKind is the Kind of each implementation of Operation interface. +type operationKind uint16 + +// String implements fmt.Stringer. +func (o operationKind) String() (ret string) { + switch o { + case operationKindUnreachable: + ret = "Unreachable" + case operationKindLabel: + ret = "label" + case operationKindBr: + ret = "Br" + case operationKindBrIf: + ret = "BrIf" + case operationKindBrTable: + ret = "BrTable" + case operationKindCall: + ret = "Call" + case operationKindCallIndirect: + ret = "CallIndirect" + case operationKindDrop: + ret = "Drop" + case operationKindSelect: + ret = "Select" + case operationKindPick: + ret = "Pick" + case operationKindSet: + ret = "Swap" + case operationKindGlobalGet: + ret = "GlobalGet" + case operationKindGlobalSet: + ret = "GlobalSet" + case operationKindLoad: + ret = "Load" + case operationKindLoad8: + ret = "Load8" + case operationKindLoad16: + ret = "Load16" + case operationKindLoad32: + ret = "Load32" + case operationKindStore: + ret = "Store" + case operationKindStore8: + ret = "Store8" + case operationKindStore16: + ret = "Store16" + case operationKindStore32: + ret = "Store32" + case operationKindMemorySize: + ret = "MemorySize" + case operationKindMemoryGrow: + ret = "MemoryGrow" + case operationKindConstI32: + ret = "ConstI32" + case operationKindConstI64: + ret = "ConstI64" + case operationKindConstF32: + ret = "ConstF32" + case operationKindConstF64: + ret = "ConstF64" + case operationKindEq: + ret = "Eq" + case operationKindNe: + ret = "Ne" + case operationKindEqz: + ret = "Eqz" + case operationKindLt: + ret = "Lt" + case operationKindGt: + ret = "Gt" + case operationKindLe: + ret = "Le" + case operationKindGe: + ret = "Ge" + case operationKindAdd: + ret = "Add" + case operationKindSub: + ret = "Sub" + case operationKindMul: + ret = "Mul" + case operationKindClz: + ret = "Clz" + case operationKindCtz: + ret = "Ctz" + case operationKindPopcnt: + ret = "Popcnt" + case operationKindDiv: + ret = "Div" + case operationKindRem: + ret = "Rem" + case operationKindAnd: + ret = "And" + case operationKindOr: + ret = "Or" + case operationKindXor: + ret = "Xor" + case operationKindShl: + ret = "Shl" + case operationKindShr: + ret = "Shr" + case operationKindRotl: + ret = "Rotl" + case operationKindRotr: + ret = "Rotr" + case operationKindAbs: + ret = "Abs" + case operationKindNeg: + ret = "Neg" + case operationKindCeil: + ret = "Ceil" + case operationKindFloor: + ret = "Floor" + case operationKindTrunc: + ret = "Trunc" + case operationKindNearest: + ret = "Nearest" + case operationKindSqrt: + ret = "Sqrt" + case operationKindMin: + ret = "Min" + case operationKindMax: + ret = "Max" + case operationKindCopysign: + ret = "Copysign" + case operationKindI32WrapFromI64: + ret = "I32WrapFromI64" + case operationKindITruncFromF: + ret = "ITruncFromF" + case operationKindFConvertFromI: + ret = "FConvertFromI" + case operationKindF32DemoteFromF64: + ret = "F32DemoteFromF64" + case operationKindF64PromoteFromF32: + ret = "F64PromoteFromF32" + case operationKindI32ReinterpretFromF32: + ret = "I32ReinterpretFromF32" + case operationKindI64ReinterpretFromF64: + ret = "I64ReinterpretFromF64" + case operationKindF32ReinterpretFromI32: + ret = "F32ReinterpretFromI32" + case operationKindF64ReinterpretFromI64: + ret = "F64ReinterpretFromI64" + case operationKindExtend: + ret = "Extend" + case operationKindMemoryInit: + ret = "MemoryInit" + case operationKindDataDrop: + ret = "DataDrop" + case operationKindMemoryCopy: + ret = "MemoryCopy" + case operationKindMemoryFill: + ret = "MemoryFill" + case operationKindTableInit: + ret = "TableInit" + case operationKindElemDrop: + ret = "ElemDrop" + case operationKindTableCopy: + ret = "TableCopy" + case operationKindRefFunc: + ret = "RefFunc" + case operationKindTableGet: + ret = "TableGet" + case operationKindTableSet: + ret = "TableSet" + case operationKindTableSize: + ret = "TableSize" + case operationKindTableGrow: + ret = "TableGrow" + case operationKindTableFill: + ret = "TableFill" + case operationKindV128Const: + ret = "ConstV128" + case operationKindV128Add: + ret = "V128Add" + case operationKindV128Sub: + ret = "V128Sub" + case operationKindV128Load: + ret = "V128Load" + case operationKindV128LoadLane: + ret = "V128LoadLane" + case operationKindV128Store: + ret = "V128Store" + case operationKindV128StoreLane: + ret = "V128StoreLane" + case operationKindV128ExtractLane: + ret = "V128ExtractLane" + case operationKindV128ReplaceLane: + ret = "V128ReplaceLane" + case operationKindV128Splat: + ret = "V128Splat" + case operationKindV128Shuffle: + ret = "V128Shuffle" + case operationKindV128Swizzle: + ret = "V128Swizzle" + case operationKindV128AnyTrue: + ret = "V128AnyTrue" + case operationKindV128AllTrue: + ret = "V128AllTrue" + case operationKindV128And: + ret = "V128And" + case operationKindV128Not: + ret = "V128Not" + case operationKindV128Or: + ret = "V128Or" + case operationKindV128Xor: + ret = "V128Xor" + case operationKindV128Bitselect: + ret = "V128Bitselect" + case operationKindV128AndNot: + ret = "V128AndNot" + case operationKindV128BitMask: + ret = "V128BitMask" + case operationKindV128Shl: + ret = "V128Shl" + case operationKindV128Shr: + ret = "V128Shr" + case operationKindV128Cmp: + ret = "V128Cmp" + case operationKindSignExtend32From8: + ret = "SignExtend32From8" + case operationKindSignExtend32From16: + ret = "SignExtend32From16" + case operationKindSignExtend64From8: + ret = "SignExtend64From8" + case operationKindSignExtend64From16: + ret = "SignExtend64From16" + case operationKindSignExtend64From32: + ret = "SignExtend64From32" + case operationKindV128AddSat: + ret = "V128AddSat" + case operationKindV128SubSat: + ret = "V128SubSat" + case operationKindV128Mul: + ret = "V128Mul" + case operationKindV128Div: + ret = "V128Div" + case operationKindV128Neg: + ret = "V128Neg" + case operationKindV128Sqrt: + ret = "V128Sqrt" + case operationKindV128Abs: + ret = "V128Abs" + case operationKindV128Popcnt: + ret = "V128Popcnt" + case operationKindV128Min: + ret = "V128Min" + case operationKindV128Max: + ret = "V128Max" + case operationKindV128AvgrU: + ret = "V128AvgrU" + case operationKindV128Ceil: + ret = "V128Ceil" + case operationKindV128Floor: + ret = "V128Floor" + case operationKindV128Trunc: + ret = "V128Trunc" + case operationKindV128Nearest: + ret = "V128Nearest" + case operationKindV128Pmin: + ret = "V128Pmin" + case operationKindV128Pmax: + ret = "V128Pmax" + case operationKindV128Extend: + ret = "V128Extend" + case operationKindV128ExtMul: + ret = "V128ExtMul" + case operationKindV128Q15mulrSatS: + ret = "V128Q15mulrSatS" + case operationKindV128ExtAddPairwise: + ret = "V128ExtAddPairwise" + case operationKindV128FloatPromote: + ret = "V128FloatPromote" + case operationKindV128FloatDemote: + ret = "V128FloatDemote" + case operationKindV128FConvertFromI: + ret = "V128FConvertFromI" + case operationKindV128Dot: + ret = "V128Dot" + case operationKindV128Narrow: + ret = "V128Narrow" + case operationKindV128ITruncSatFromF: + ret = "V128ITruncSatFromF" + case operationKindBuiltinFunctionCheckExitCode: + ret = "BuiltinFunctionCheckExitCode" + case operationKindAtomicMemoryWait: + ret = "operationKindAtomicMemoryWait" + case operationKindAtomicMemoryNotify: + ret = "operationKindAtomicMemoryNotify" + case operationKindAtomicFence: + ret = "operationKindAtomicFence" + case operationKindAtomicLoad: + ret = "operationKindAtomicLoad" + case operationKindAtomicLoad8: + ret = "operationKindAtomicLoad8" + case operationKindAtomicLoad16: + ret = "operationKindAtomicLoad16" + case operationKindAtomicStore: + ret = "operationKindAtomicStore" + case operationKindAtomicStore8: + ret = "operationKindAtomicStore8" + case operationKindAtomicStore16: + ret = "operationKindAtomicStore16" + case operationKindAtomicRMW: + ret = "operationKindAtomicRMW" + case operationKindAtomicRMW8: + ret = "operationKindAtomicRMW8" + case operationKindAtomicRMW16: + ret = "operationKindAtomicRMW16" + case operationKindAtomicRMWCmpxchg: + ret = "operationKindAtomicRMWCmpxchg" + case operationKindAtomicRMW8Cmpxchg: + ret = "operationKindAtomicRMW8Cmpxchg" + case operationKindAtomicRMW16Cmpxchg: + ret = "operationKindAtomicRMW16Cmpxchg" + default: + panic(fmt.Errorf("unknown operation %d", o)) + } + return +} + +const ( + // operationKindUnreachable is the Kind for NewOperationUnreachable. + operationKindUnreachable operationKind = iota + // operationKindLabel is the Kind for NewOperationLabel. + operationKindLabel + // operationKindBr is the Kind for NewOperationBr. + operationKindBr + // operationKindBrIf is the Kind for NewOperationBrIf. + operationKindBrIf + // operationKindBrTable is the Kind for NewOperationBrTable. + operationKindBrTable + // operationKindCall is the Kind for NewOperationCall. + operationKindCall + // operationKindCallIndirect is the Kind for NewOperationCallIndirect. + operationKindCallIndirect + // operationKindDrop is the Kind for NewOperationDrop. + operationKindDrop + // operationKindSelect is the Kind for NewOperationSelect. + operationKindSelect + // operationKindPick is the Kind for NewOperationPick. + operationKindPick + // operationKindSet is the Kind for NewOperationSet. + operationKindSet + // operationKindGlobalGet is the Kind for NewOperationGlobalGet. + operationKindGlobalGet + // operationKindGlobalSet is the Kind for NewOperationGlobalSet. + operationKindGlobalSet + // operationKindLoad is the Kind for NewOperationLoad. + operationKindLoad + // operationKindLoad8 is the Kind for NewOperationLoad8. + operationKindLoad8 + // operationKindLoad16 is the Kind for NewOperationLoad16. + operationKindLoad16 + // operationKindLoad32 is the Kind for NewOperationLoad32. + operationKindLoad32 + // operationKindStore is the Kind for NewOperationStore. + operationKindStore + // operationKindStore8 is the Kind for NewOperationStore8. + operationKindStore8 + // operationKindStore16 is the Kind for NewOperationStore16. + operationKindStore16 + // operationKindStore32 is the Kind for NewOperationStore32. + operationKindStore32 + // operationKindMemorySize is the Kind for NewOperationMemorySize. + operationKindMemorySize + // operationKindMemoryGrow is the Kind for NewOperationMemoryGrow. + operationKindMemoryGrow + // operationKindConstI32 is the Kind for NewOperationConstI32. + operationKindConstI32 + // operationKindConstI64 is the Kind for NewOperationConstI64. + operationKindConstI64 + // operationKindConstF32 is the Kind for NewOperationConstF32. + operationKindConstF32 + // operationKindConstF64 is the Kind for NewOperationConstF64. + operationKindConstF64 + // operationKindEq is the Kind for NewOperationEq. + operationKindEq + // operationKindNe is the Kind for NewOperationNe. + operationKindNe + // operationKindEqz is the Kind for NewOperationEqz. + operationKindEqz + // operationKindLt is the Kind for NewOperationLt. + operationKindLt + // operationKindGt is the Kind for NewOperationGt. + operationKindGt + // operationKindLe is the Kind for NewOperationLe. + operationKindLe + // operationKindGe is the Kind for NewOperationGe. + operationKindGe + // operationKindAdd is the Kind for NewOperationAdd. + operationKindAdd + // operationKindSub is the Kind for NewOperationSub. + operationKindSub + // operationKindMul is the Kind for NewOperationMul. + operationKindMul + // operationKindClz is the Kind for NewOperationClz. + operationKindClz + // operationKindCtz is the Kind for NewOperationCtz. + operationKindCtz + // operationKindPopcnt is the Kind for NewOperationPopcnt. + operationKindPopcnt + // operationKindDiv is the Kind for NewOperationDiv. + operationKindDiv + // operationKindRem is the Kind for NewOperationRem. + operationKindRem + // operationKindAnd is the Kind for NewOperationAnd. + operationKindAnd + // operationKindOr is the Kind for NewOperationOr. + operationKindOr + // operationKindXor is the Kind for NewOperationXor. + operationKindXor + // operationKindShl is the Kind for NewOperationShl. + operationKindShl + // operationKindShr is the Kind for NewOperationShr. + operationKindShr + // operationKindRotl is the Kind for NewOperationRotl. + operationKindRotl + // operationKindRotr is the Kind for NewOperationRotr. + operationKindRotr + // operationKindAbs is the Kind for NewOperationAbs. + operationKindAbs + // operationKindNeg is the Kind for NewOperationNeg. + operationKindNeg + // operationKindCeil is the Kind for NewOperationCeil. + operationKindCeil + // operationKindFloor is the Kind for NewOperationFloor. + operationKindFloor + // operationKindTrunc is the Kind for NewOperationTrunc. + operationKindTrunc + // operationKindNearest is the Kind for NewOperationNearest. + operationKindNearest + // operationKindSqrt is the Kind for NewOperationSqrt. + operationKindSqrt + // operationKindMin is the Kind for NewOperationMin. + operationKindMin + // operationKindMax is the Kind for NewOperationMax. + operationKindMax + // operationKindCopysign is the Kind for NewOperationCopysign. + operationKindCopysign + // operationKindI32WrapFromI64 is the Kind for NewOperationI32WrapFromI64. + operationKindI32WrapFromI64 + // operationKindITruncFromF is the Kind for NewOperationITruncFromF. + operationKindITruncFromF + // operationKindFConvertFromI is the Kind for NewOperationFConvertFromI. + operationKindFConvertFromI + // operationKindF32DemoteFromF64 is the Kind for NewOperationF32DemoteFromF64. + operationKindF32DemoteFromF64 + // operationKindF64PromoteFromF32 is the Kind for NewOperationF64PromoteFromF32. + operationKindF64PromoteFromF32 + // operationKindI32ReinterpretFromF32 is the Kind for NewOperationI32ReinterpretFromF32. + operationKindI32ReinterpretFromF32 + // operationKindI64ReinterpretFromF64 is the Kind for NewOperationI64ReinterpretFromF64. + operationKindI64ReinterpretFromF64 + // operationKindF32ReinterpretFromI32 is the Kind for NewOperationF32ReinterpretFromI32. + operationKindF32ReinterpretFromI32 + // operationKindF64ReinterpretFromI64 is the Kind for NewOperationF64ReinterpretFromI64. + operationKindF64ReinterpretFromI64 + // operationKindExtend is the Kind for NewOperationExtend. + operationKindExtend + // operationKindSignExtend32From8 is the Kind for NewOperationSignExtend32From8. + operationKindSignExtend32From8 + // operationKindSignExtend32From16 is the Kind for NewOperationSignExtend32From16. + operationKindSignExtend32From16 + // operationKindSignExtend64From8 is the Kind for NewOperationSignExtend64From8. + operationKindSignExtend64From8 + // operationKindSignExtend64From16 is the Kind for NewOperationSignExtend64From16. + operationKindSignExtend64From16 + // operationKindSignExtend64From32 is the Kind for NewOperationSignExtend64From32. + operationKindSignExtend64From32 + // operationKindMemoryInit is the Kind for NewOperationMemoryInit. + operationKindMemoryInit + // operationKindDataDrop is the Kind for NewOperationDataDrop. + operationKindDataDrop + // operationKindMemoryCopy is the Kind for NewOperationMemoryCopy. + operationKindMemoryCopy + // operationKindMemoryFill is the Kind for NewOperationMemoryFill. + operationKindMemoryFill + // operationKindTableInit is the Kind for NewOperationTableInit. + operationKindTableInit + // operationKindElemDrop is the Kind for NewOperationElemDrop. + operationKindElemDrop + // operationKindTableCopy is the Kind for NewOperationTableCopy. + operationKindTableCopy + // operationKindRefFunc is the Kind for NewOperationRefFunc. + operationKindRefFunc + // operationKindTableGet is the Kind for NewOperationTableGet. + operationKindTableGet + // operationKindTableSet is the Kind for NewOperationTableSet. + operationKindTableSet + // operationKindTableSize is the Kind for NewOperationTableSize. + operationKindTableSize + // operationKindTableGrow is the Kind for NewOperationTableGrow. + operationKindTableGrow + // operationKindTableFill is the Kind for NewOperationTableFill. + operationKindTableFill + + // Vector value related instructions are prefixed by V128. + + // operationKindV128Const is the Kind for NewOperationV128Const. + operationKindV128Const + // operationKindV128Add is the Kind for NewOperationV128Add. + operationKindV128Add + // operationKindV128Sub is the Kind for NewOperationV128Sub. + operationKindV128Sub + // operationKindV128Load is the Kind for NewOperationV128Load. + operationKindV128Load + // operationKindV128LoadLane is the Kind for NewOperationV128LoadLane. + operationKindV128LoadLane + // operationKindV128Store is the Kind for NewOperationV128Store. + operationKindV128Store + // operationKindV128StoreLane is the Kind for NewOperationV128StoreLane. + operationKindV128StoreLane + // operationKindV128ExtractLane is the Kind for NewOperationV128ExtractLane. + operationKindV128ExtractLane + // operationKindV128ReplaceLane is the Kind for NewOperationV128ReplaceLane. + operationKindV128ReplaceLane + // operationKindV128Splat is the Kind for NewOperationV128Splat. + operationKindV128Splat + // operationKindV128Shuffle is the Kind for NewOperationV128Shuffle. + operationKindV128Shuffle + // operationKindV128Swizzle is the Kind for NewOperationV128Swizzle. + operationKindV128Swizzle + // operationKindV128AnyTrue is the Kind for NewOperationV128AnyTrue. + operationKindV128AnyTrue + // operationKindV128AllTrue is the Kind for NewOperationV128AllTrue. + operationKindV128AllTrue + // operationKindV128BitMask is the Kind for NewOperationV128BitMask. + operationKindV128BitMask + // operationKindV128And is the Kind for NewOperationV128And. + operationKindV128And + // operationKindV128Not is the Kind for NewOperationV128Not. + operationKindV128Not + // operationKindV128Or is the Kind for NewOperationV128Or. + operationKindV128Or + // operationKindV128Xor is the Kind for NewOperationV128Xor. + operationKindV128Xor + // operationKindV128Bitselect is the Kind for NewOperationV128Bitselect. + operationKindV128Bitselect + // operationKindV128AndNot is the Kind for NewOperationV128AndNot. + operationKindV128AndNot + // operationKindV128Shl is the Kind for NewOperationV128Shl. + operationKindV128Shl + // operationKindV128Shr is the Kind for NewOperationV128Shr. + operationKindV128Shr + // operationKindV128Cmp is the Kind for NewOperationV128Cmp. + operationKindV128Cmp + // operationKindV128AddSat is the Kind for NewOperationV128AddSat. + operationKindV128AddSat + // operationKindV128SubSat is the Kind for NewOperationV128SubSat. + operationKindV128SubSat + // operationKindV128Mul is the Kind for NewOperationV128Mul. + operationKindV128Mul + // operationKindV128Div is the Kind for NewOperationV128Div. + operationKindV128Div + // operationKindV128Neg is the Kind for NewOperationV128Neg. + operationKindV128Neg + // operationKindV128Sqrt is the Kind for NewOperationV128Sqrt. + operationKindV128Sqrt + // operationKindV128Abs is the Kind for NewOperationV128Abs. + operationKindV128Abs + // operationKindV128Popcnt is the Kind for NewOperationV128Popcnt. + operationKindV128Popcnt + // operationKindV128Min is the Kind for NewOperationV128Min. + operationKindV128Min + // operationKindV128Max is the Kind for NewOperationV128Max. + operationKindV128Max + // operationKindV128AvgrU is the Kind for NewOperationV128AvgrU. + operationKindV128AvgrU + // operationKindV128Pmin is the Kind for NewOperationV128Pmin. + operationKindV128Pmin + // operationKindV128Pmax is the Kind for NewOperationV128Pmax. + operationKindV128Pmax + // operationKindV128Ceil is the Kind for NewOperationV128Ceil. + operationKindV128Ceil + // operationKindV128Floor is the Kind for NewOperationV128Floor. + operationKindV128Floor + // operationKindV128Trunc is the Kind for NewOperationV128Trunc. + operationKindV128Trunc + // operationKindV128Nearest is the Kind for NewOperationV128Nearest. + operationKindV128Nearest + // operationKindV128Extend is the Kind for NewOperationV128Extend. + operationKindV128Extend + // operationKindV128ExtMul is the Kind for NewOperationV128ExtMul. + operationKindV128ExtMul + // operationKindV128Q15mulrSatS is the Kind for NewOperationV128Q15mulrSatS. + operationKindV128Q15mulrSatS + // operationKindV128ExtAddPairwise is the Kind for NewOperationV128ExtAddPairwise. + operationKindV128ExtAddPairwise + // operationKindV128FloatPromote is the Kind for NewOperationV128FloatPromote. + operationKindV128FloatPromote + // operationKindV128FloatDemote is the Kind for NewOperationV128FloatDemote. + operationKindV128FloatDemote + // operationKindV128FConvertFromI is the Kind for NewOperationV128FConvertFromI. + operationKindV128FConvertFromI + // operationKindV128Dot is the Kind for NewOperationV128Dot. + operationKindV128Dot + // operationKindV128Narrow is the Kind for NewOperationV128Narrow. + operationKindV128Narrow + // operationKindV128ITruncSatFromF is the Kind for NewOperationV128ITruncSatFromF. + operationKindV128ITruncSatFromF + + // operationKindBuiltinFunctionCheckExitCode is the Kind for NewOperationBuiltinFunctionCheckExitCode. + operationKindBuiltinFunctionCheckExitCode + + // operationKindAtomicMemoryWait is the kind for NewOperationAtomicMemoryWait. + operationKindAtomicMemoryWait + // operationKindAtomicMemoryNotify is the kind for NewOperationAtomicMemoryNotify. + operationKindAtomicMemoryNotify + // operationKindAtomicFence is the kind for NewOperationAtomicFence. + operationKindAtomicFence + // operationKindAtomicLoad is the kind for NewOperationAtomicLoad. + operationKindAtomicLoad + // operationKindAtomicLoad8 is the kind for NewOperationAtomicLoad8. + operationKindAtomicLoad8 + // operationKindAtomicLoad16 is the kind for NewOperationAtomicLoad16. + operationKindAtomicLoad16 + // operationKindAtomicStore is the kind for NewOperationAtomicStore. + operationKindAtomicStore + // operationKindAtomicStore8 is the kind for NewOperationAtomicStore8. + operationKindAtomicStore8 + // operationKindAtomicStore16 is the kind for NewOperationAtomicStore16. + operationKindAtomicStore16 + + // operationKindAtomicRMW is the kind for NewOperationAtomicRMW. + operationKindAtomicRMW + // operationKindAtomicRMW8 is the kind for NewOperationAtomicRMW8. + operationKindAtomicRMW8 + // operationKindAtomicRMW16 is the kind for NewOperationAtomicRMW16. + operationKindAtomicRMW16 + + // operationKindAtomicRMWCmpxchg is the kind for NewOperationAtomicRMWCmpxchg. + operationKindAtomicRMWCmpxchg + // operationKindAtomicRMW8Cmpxchg is the kind for NewOperationAtomicRMW8Cmpxchg. + operationKindAtomicRMW8Cmpxchg + // operationKindAtomicRMW16Cmpxchg is the kind for NewOperationAtomicRMW16Cmpxchg. + operationKindAtomicRMW16Cmpxchg + + // operationKindEnd is always placed at the bottom of this iota definition to be used in the test. + operationKindEnd +) + +// NewOperationBuiltinFunctionCheckExitCode is a constructor for unionOperation with Kind operationKindBuiltinFunctionCheckExitCode. +// +// OperationBuiltinFunctionCheckExitCode corresponds to the instruction to check the api.Module is already closed due to +// context.DeadlineExceeded, context.Canceled, or the explicit call of CloseWithExitCode on api.Module. +func newOperationBuiltinFunctionCheckExitCode() unionOperation { + return unionOperation{Kind: operationKindBuiltinFunctionCheckExitCode} +} + +// label is the unique identifier for each block in a single function in interpreterir +// where "block" consists of multiple operations, and must End with branching operations +// (e.g. operationKindBr or operationKindBrIf). +type label uint64 + +// Kind returns the labelKind encoded in this label. +func (l label) Kind() labelKind { + return labelKind(uint32(l)) +} + +// FrameID returns the frame id encoded in this label. +func (l label) FrameID() int { + return int(uint32(l >> 32)) +} + +// NewLabel is a constructor for a label. +func newLabel(kind labelKind, frameID uint32) label { + return label(kind) | label(frameID)<<32 +} + +// String implements fmt.Stringer. +func (l label) String() (ret string) { + frameID := l.FrameID() + switch l.Kind() { + case labelKindHeader: + ret = fmt.Sprintf(".L%d", frameID) + case labelKindElse: + ret = fmt.Sprintf(".L%d_else", frameID) + case labelKindContinuation: + ret = fmt.Sprintf(".L%d_cont", frameID) + case labelKindReturn: + return ".return" + } + return +} + +func (l label) IsReturnTarget() bool { + return l.Kind() == labelKindReturn +} + +// labelKind is the Kind of the label. +type labelKind = byte + +const ( + // labelKindHeader is the header for various blocks. For example, the "then" block of + // wasm.OpcodeIfName in Wasm has the label of this Kind. + labelKindHeader labelKind = iota + // labelKindElse is the Kind of label for "else" block of wasm.OpcodeIfName in Wasm. + labelKindElse + // labelKindContinuation is the Kind of label which is the continuation of blocks. + // For example, for wasm text like + // (func + // .... + // (if (local.get 0) (then (nop)) (else (nop))) + // return + // ) + // we have the continuation block (of if-block) corresponding to "return" opcode. + labelKindContinuation + labelKindReturn + labelKindNum +) + +// unionOperation implements Operation and is the compilation (engine.lowerIR) result of a interpreterir.Operation. +// +// Not all operations result in a unionOperation, e.g. interpreterir.OperationI32ReinterpretFromF32, and some operations are +// more complex than others, e.g. interpreterir.NewOperationBrTable. +// +// Note: This is a form of union type as it can store fields needed for any operation. Hence, most fields are opaque and +// only relevant when in context of its kind. +type unionOperation struct { + // Kind determines how to interpret the other fields in this struct. + Kind operationKind + B1, B2 byte + B3 bool + U1, U2 uint64 + U3 uint64 + Us []uint64 +} + +// String implements fmt.Stringer. +func (o unionOperation) String() string { + switch o.Kind { + case operationKindUnreachable, + operationKindSelect, + operationKindMemorySize, + operationKindMemoryGrow, + operationKindI32WrapFromI64, + operationKindF32DemoteFromF64, + operationKindF64PromoteFromF32, + operationKindI32ReinterpretFromF32, + operationKindI64ReinterpretFromF64, + operationKindF32ReinterpretFromI32, + operationKindF64ReinterpretFromI64, + operationKindSignExtend32From8, + operationKindSignExtend32From16, + operationKindSignExtend64From8, + operationKindSignExtend64From16, + operationKindSignExtend64From32, + operationKindMemoryInit, + operationKindDataDrop, + operationKindMemoryCopy, + operationKindMemoryFill, + operationKindTableInit, + operationKindElemDrop, + operationKindTableCopy, + operationKindRefFunc, + operationKindTableGet, + operationKindTableSet, + operationKindTableSize, + operationKindTableGrow, + operationKindTableFill, + operationKindBuiltinFunctionCheckExitCode: + return o.Kind.String() + + case operationKindCall, + operationKindGlobalGet, + operationKindGlobalSet: + return fmt.Sprintf("%s %d", o.Kind, o.B1) + + case operationKindLabel: + return label(o.U1).String() + + case operationKindBr: + return fmt.Sprintf("%s %s", o.Kind, label(o.U1).String()) + + case operationKindBrIf: + thenTarget := label(o.U1) + elseTarget := label(o.U2) + return fmt.Sprintf("%s %s, %s", o.Kind, thenTarget, elseTarget) + + case operationKindBrTable: + var targets []string + var defaultLabel label + if len(o.Us) > 0 { + targets = make([]string, len(o.Us)-1) + for i, t := range o.Us[1:] { + targets[i] = label(t).String() + } + defaultLabel = label(o.Us[0]) + } + return fmt.Sprintf("%s [%s] %s", o.Kind, strings.Join(targets, ","), defaultLabel) + + case operationKindCallIndirect: + return fmt.Sprintf("%s: type=%d, table=%d", o.Kind, o.U1, o.U2) + + case operationKindDrop: + start := int64(o.U1) + end := int64(o.U2) + return fmt.Sprintf("%s %d..%d", o.Kind, start, end) + + case operationKindPick, operationKindSet: + return fmt.Sprintf("%s %d (is_vector=%v)", o.Kind, o.U1, o.B3) + + case operationKindLoad, operationKindStore: + return fmt.Sprintf("%s.%s (align=%d, offset=%d)", unsignedType(o.B1), o.Kind, o.U1, o.U2) + + case operationKindLoad8, + operationKindLoad16: + return fmt.Sprintf("%s.%s (align=%d, offset=%d)", signedType(o.B1), o.Kind, o.U1, o.U2) + + case operationKindStore8, + operationKindStore16, + operationKindStore32: + return fmt.Sprintf("%s (align=%d, offset=%d)", o.Kind, o.U1, o.U2) + + case operationKindLoad32: + var t string + if o.B1 == 1 { + t = "i64" + } else { + t = "u64" + } + return fmt.Sprintf("%s.%s (align=%d, offset=%d)", t, o.Kind, o.U1, o.U2) + + case operationKindEq, + operationKindNe, + operationKindAdd, + operationKindSub, + operationKindMul: + return fmt.Sprintf("%s.%s", unsignedType(o.B1), o.Kind) + + case operationKindEqz, + operationKindClz, + operationKindCtz, + operationKindPopcnt, + operationKindAnd, + operationKindOr, + operationKindXor, + operationKindShl, + operationKindRotl, + operationKindRotr: + return fmt.Sprintf("%s.%s", unsignedInt(o.B1), o.Kind) + + case operationKindRem, operationKindShr: + return fmt.Sprintf("%s.%s", signedInt(o.B1), o.Kind) + + case operationKindLt, + operationKindGt, + operationKindLe, + operationKindGe, + operationKindDiv: + return fmt.Sprintf("%s.%s", signedType(o.B1), o.Kind) + + case operationKindAbs, + operationKindNeg, + operationKindCeil, + operationKindFloor, + operationKindTrunc, + operationKindNearest, + operationKindSqrt, + operationKindMin, + operationKindMax, + operationKindCopysign: + return fmt.Sprintf("%s.%s", float(o.B1), o.Kind) + + case operationKindConstI32, + operationKindConstI64: + return fmt.Sprintf("%s %#x", o.Kind, o.U1) + + case operationKindConstF32: + return fmt.Sprintf("%s %f", o.Kind, math.Float32frombits(uint32(o.U1))) + case operationKindConstF64: + return fmt.Sprintf("%s %f", o.Kind, math.Float64frombits(o.U1)) + + case operationKindITruncFromF: + return fmt.Sprintf("%s.%s.%s (non_trapping=%v)", signedInt(o.B2), o.Kind, float(o.B1), o.B3) + case operationKindFConvertFromI: + return fmt.Sprintf("%s.%s.%s", float(o.B2), o.Kind, signedInt(o.B1)) + case operationKindExtend: + var in, out string + if o.B3 { + in = "i32" + out = "i64" + } else { + in = "u32" + out = "u64" + } + return fmt.Sprintf("%s.%s.%s", out, o.Kind, in) + + case operationKindV128Const: + return fmt.Sprintf("%s [%#x, %#x]", o.Kind, o.U1, o.U2) + case operationKindV128Add, + operationKindV128Sub: + return fmt.Sprintf("%s (shape=%s)", o.Kind, shapeName(o.B1)) + case operationKindV128Load, + operationKindV128LoadLane, + operationKindV128Store, + operationKindV128StoreLane, + operationKindV128ExtractLane, + operationKindV128ReplaceLane, + operationKindV128Splat, + operationKindV128Shuffle, + operationKindV128Swizzle, + operationKindV128AnyTrue, + operationKindV128AllTrue, + operationKindV128BitMask, + operationKindV128And, + operationKindV128Not, + operationKindV128Or, + operationKindV128Xor, + operationKindV128Bitselect, + operationKindV128AndNot, + operationKindV128Shl, + operationKindV128Shr, + operationKindV128Cmp, + operationKindV128AddSat, + operationKindV128SubSat, + operationKindV128Mul, + operationKindV128Div, + operationKindV128Neg, + operationKindV128Sqrt, + operationKindV128Abs, + operationKindV128Popcnt, + operationKindV128Min, + operationKindV128Max, + operationKindV128AvgrU, + operationKindV128Pmin, + operationKindV128Pmax, + operationKindV128Ceil, + operationKindV128Floor, + operationKindV128Trunc, + operationKindV128Nearest, + operationKindV128Extend, + operationKindV128ExtMul, + operationKindV128Q15mulrSatS, + operationKindV128ExtAddPairwise, + operationKindV128FloatPromote, + operationKindV128FloatDemote, + operationKindV128FConvertFromI, + operationKindV128Dot, + operationKindV128Narrow: + return o.Kind.String() + + case operationKindV128ITruncSatFromF: + if o.B3 { + return fmt.Sprintf("%s.%sS", o.Kind, shapeName(o.B1)) + } else { + return fmt.Sprintf("%s.%sU", o.Kind, shapeName(o.B1)) + } + + case operationKindAtomicMemoryWait, + operationKindAtomicMemoryNotify, + operationKindAtomicFence, + operationKindAtomicLoad, + operationKindAtomicLoad8, + operationKindAtomicLoad16, + operationKindAtomicStore, + operationKindAtomicStore8, + operationKindAtomicStore16, + operationKindAtomicRMW, + operationKindAtomicRMW8, + operationKindAtomicRMW16, + operationKindAtomicRMWCmpxchg, + operationKindAtomicRMW8Cmpxchg, + operationKindAtomicRMW16Cmpxchg: + return o.Kind.String() + + default: + panic(fmt.Sprintf("TODO: %v", o.Kind)) + } +} + +// NewOperationUnreachable is a constructor for unionOperation with operationKindUnreachable +// +// This corresponds to wasm.OpcodeUnreachable. +// +// The engines are expected to exit the execution with wasmruntime.ErrRuntimeUnreachable error. +func newOperationUnreachable() unionOperation { + return unionOperation{Kind: operationKindUnreachable} +} + +// NewOperationLabel is a constructor for unionOperation with operationKindLabel. +// +// This is used to inform the engines of the beginning of a label. +func newOperationLabel(label label) unionOperation { + return unionOperation{Kind: operationKindLabel, U1: uint64(label)} +} + +// NewOperationBr is a constructor for unionOperation with operationKindBr. +// +// The engines are expected to branch into U1 label. +func newOperationBr(target label) unionOperation { + return unionOperation{Kind: operationKindBr, U1: uint64(target)} +} + +// NewOperationBrIf is a constructor for unionOperation with operationKindBrIf. +// +// The engines are expected to pop a value and branch into U1 label if the value equals 1. +// Otherwise, the code branches into U2 label. +func newOperationBrIf(thenTarget, elseTarget label, thenDrop inclusiveRange) unionOperation { + return unionOperation{ + Kind: operationKindBrIf, + U1: uint64(thenTarget), + U2: uint64(elseTarget), + U3: thenDrop.AsU64(), + } +} + +// NewOperationBrTable is a constructor for unionOperation with operationKindBrTable. +// +// This corresponds to wasm.OpcodeBrTableName except that the label +// here means the interpreterir level, not the ones of Wasm. +// +// The engines are expected to do the br_table operation based on the default (Us[len(Us)-1], Us[len(Us)-2]) and +// targets (Us[:len(Us)-1], Rs[:len(Us)-1]). More precisely, this pops a value from the stack (called "index") +// and decides which branch we go into next based on the value. +// +// For example, assume we have operations like {default: L_DEFAULT, targets: [L0, L1, L2]}. +// If "index" >= len(defaults), then branch into the L_DEFAULT label. +// Otherwise, we enter label of targets[index]. +func newOperationBrTable(targetLabelsAndRanges []uint64) unionOperation { + return unionOperation{ + Kind: operationKindBrTable, + Us: targetLabelsAndRanges, + } +} + +// NewOperationCall is a constructor for unionOperation with operationKindCall. +// +// This corresponds to wasm.OpcodeCallName, and engines are expected to +// enter into a function whose index equals OperationCall.FunctionIndex. +func newOperationCall(functionIndex uint32) unionOperation { + return unionOperation{Kind: operationKindCall, U1: uint64(functionIndex)} +} + +// NewOperationCallIndirect implements Operation. +// +// This corresponds to wasm.OpcodeCallIndirectName, and engines are expected to +// consume the one value from the top of stack (called "offset"), +// and make a function call against the function whose function address equals +// Tables[OperationCallIndirect.TableIndex][offset]. +// +// Note: This is called indirect function call in the sense that the target function is indirectly +// determined by the current state (top value) of the stack. +// Therefore, two checks are performed at runtime before entering the target function: +// 1) whether "offset" exceeds the length of table Tables[OperationCallIndirect.TableIndex]. +// 2) whether the type of the function table[offset] matches the function type specified by OperationCallIndirect.TypeIndex. +func newOperationCallIndirect(typeIndex, tableIndex uint32) unionOperation { + return unionOperation{Kind: operationKindCallIndirect, U1: uint64(typeIndex), U2: uint64(tableIndex)} +} + +// inclusiveRange is the range which spans across the value stack starting from the top to the bottom, and +// both boundary are included in the range. +type inclusiveRange struct { + Start, End int32 +} + +// AsU64 is be used to convert inclusiveRange to uint64 so that it can be stored in unionOperation. +func (i inclusiveRange) AsU64() uint64 { + return uint64(uint32(i.Start))<<32 | uint64(uint32(i.End)) +} + +// inclusiveRangeFromU64 retrieves inclusiveRange from the given uint64 which is stored in unionOperation. +func inclusiveRangeFromU64(v uint64) inclusiveRange { + return inclusiveRange{ + Start: int32(uint32(v >> 32)), + End: int32(uint32(v)), + } +} + +// nopinclusiveRange is inclusiveRange which corresponds to no-operation. +var nopinclusiveRange = inclusiveRange{Start: -1, End: -1} + +// NewOperationDrop is a constructor for unionOperation with operationKindDrop. +// +// The engines are expected to discard the values selected by NewOperationDrop.Depth which +// starts from the top of the stack to the bottom. +// +// depth spans across the uint64 value stack at runtime to be dropped by this operation. +func newOperationDrop(depth inclusiveRange) unionOperation { + return unionOperation{Kind: operationKindDrop, U1: depth.AsU64()} +} + +// NewOperationSelect is a constructor for unionOperation with operationKindSelect. +// +// This corresponds to wasm.OpcodeSelect. +// +// The engines are expected to pop three values, say [..., x2, x1, c], then if the value "c" equals zero, +// "x1" is pushed back onto the stack and, otherwise "x2" is pushed back. +// +// isTargetVector true if the selection target value's type is wasm.ValueTypeV128. +func newOperationSelect(isTargetVector bool) unionOperation { + return unionOperation{Kind: operationKindSelect, B3: isTargetVector} +} + +// NewOperationPick is a constructor for unionOperation with operationKindPick. +// +// The engines are expected to copy a value pointed by depth, and push the +// copied value onto the top of the stack. +// +// depth is the location of the pick target in the uint64 value stack at runtime. +// If isTargetVector=true, this points to the location of the lower 64-bits of the vector. +func newOperationPick(depth int, isTargetVector bool) unionOperation { + return unionOperation{Kind: operationKindPick, U1: uint64(depth), B3: isTargetVector} +} + +// NewOperationSet is a constructor for unionOperation with operationKindSet. +// +// The engines are expected to set the top value of the stack to the location specified by +// depth. +// +// depth is the location of the set target in the uint64 value stack at runtime. +// If isTargetVector=true, this points the location of the lower 64-bits of the vector. +func newOperationSet(depth int, isTargetVector bool) unionOperation { + return unionOperation{Kind: operationKindSet, U1: uint64(depth), B3: isTargetVector} +} + +// NewOperationGlobalGet is a constructor for unionOperation with operationKindGlobalGet. +// +// The engines are expected to read the global value specified by OperationGlobalGet.Index, +// and push the copy of the value onto the stack. +// +// See wasm.OpcodeGlobalGet. +func newOperationGlobalGet(index uint32) unionOperation { + return unionOperation{Kind: operationKindGlobalGet, U1: uint64(index)} +} + +// NewOperationGlobalSet is a constructor for unionOperation with operationKindGlobalSet. +// +// The engines are expected to consume the value from the top of the stack, +// and write the value into the global specified by OperationGlobalSet.Index. +// +// See wasm.OpcodeGlobalSet. +func newOperationGlobalSet(index uint32) unionOperation { + return unionOperation{Kind: operationKindGlobalSet, U1: uint64(index)} +} + +// memoryArg is the "memarg" to all memory instructions. +// +// See https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/#memory-instructions%E2%91%A0 +type memoryArg struct { + // Alignment the expected alignment (expressed as the exponent of a power of 2). Default to the natural alignment. + // + // "Natural alignment" is defined here as the smallest power of two that can hold the size of the value type. Ex + // wasm.ValueTypeI64 is encoded in 8 little-endian bytes. 2^3 = 8, so the natural alignment is three. + Alignment uint32 + + // Offset is the address offset added to the instruction's dynamic address operand, yielding a 33-bit effective + // address that is the zero-based index at which the memory is accessed. Default to zero. + Offset uint32 +} + +// NewOperationLoad is a constructor for unionOperation with operationKindLoad. +// +// This corresponds to wasm.OpcodeI32LoadName wasm.OpcodeI64LoadName wasm.OpcodeF32LoadName and wasm.OpcodeF64LoadName. +// +// The engines are expected to check the boundary of memory length, and exit the execution if this exceeds the boundary, +// otherwise load the corresponding value following the semantics of the corresponding WebAssembly instruction. +func newOperationLoad(unsignedType unsignedType, arg memoryArg) unionOperation { + return unionOperation{Kind: operationKindLoad, B1: byte(unsignedType), U1: uint64(arg.Alignment), U2: uint64(arg.Offset)} +} + +// NewOperationLoad8 is a constructor for unionOperation with operationKindLoad8. +// +// This corresponds to wasm.OpcodeI32Load8SName wasm.OpcodeI32Load8UName wasm.OpcodeI64Load8SName wasm.OpcodeI64Load8UName. +// +// The engines are expected to check the boundary of memory length, and exit the execution if this exceeds the boundary, +// otherwise load the corresponding value following the semantics of the corresponding WebAssembly instruction. +func newOperationLoad8(signedInt signedInt, arg memoryArg) unionOperation { + return unionOperation{Kind: operationKindLoad8, B1: byte(signedInt), U1: uint64(arg.Alignment), U2: uint64(arg.Offset)} +} + +// NewOperationLoad16 is a constructor for unionOperation with operationKindLoad16. +// +// This corresponds to wasm.OpcodeI32Load16SName wasm.OpcodeI32Load16UName wasm.OpcodeI64Load16SName wasm.OpcodeI64Load16UName. +// +// The engines are expected to check the boundary of memory length, and exit the execution if this exceeds the boundary, +// otherwise load the corresponding value following the semantics of the corresponding WebAssembly instruction. +func newOperationLoad16(signedInt signedInt, arg memoryArg) unionOperation { + return unionOperation{Kind: operationKindLoad16, B1: byte(signedInt), U1: uint64(arg.Alignment), U2: uint64(arg.Offset)} +} + +// NewOperationLoad32 is a constructor for unionOperation with operationKindLoad32. +// +// This corresponds to wasm.OpcodeI64Load32SName wasm.OpcodeI64Load32UName. +// +// The engines are expected to check the boundary of memory length, and exit the execution if this exceeds the boundary, +// otherwise load the corresponding value following the semantics of the corresponding WebAssembly instruction. +func newOperationLoad32(signed bool, arg memoryArg) unionOperation { + sigB := byte(0) + if signed { + sigB = 1 + } + return unionOperation{Kind: operationKindLoad32, B1: sigB, U1: uint64(arg.Alignment), U2: uint64(arg.Offset)} +} + +// NewOperationStore is a constructor for unionOperation with operationKindStore. +// +// # This corresponds to wasm.OpcodeI32StoreName wasm.OpcodeI64StoreName wasm.OpcodeF32StoreName wasm.OpcodeF64StoreName +// +// The engines are expected to check the boundary of memory length, and exit the execution if this exceeds the boundary, +// otherwise store the corresponding value following the semantics of the corresponding WebAssembly instruction. +func newOperationStore(unsignedType unsignedType, arg memoryArg) unionOperation { + return unionOperation{Kind: operationKindStore, B1: byte(unsignedType), U1: uint64(arg.Alignment), U2: uint64(arg.Offset)} +} + +// NewOperationStore8 is a constructor for unionOperation with operationKindStore8. +// +// # This corresponds to wasm.OpcodeI32Store8Name wasm.OpcodeI64Store8Name +// +// The engines are expected to check the boundary of memory length, and exit the execution if this exceeds the boundary, +// otherwise store the corresponding value following the semantics of the corresponding WebAssembly instruction. +func newOperationStore8(arg memoryArg) unionOperation { + return unionOperation{Kind: operationKindStore8, U1: uint64(arg.Alignment), U2: uint64(arg.Offset)} +} + +// NewOperationStore16 is a constructor for unionOperation with operationKindStore16. +// +// # This corresponds to wasm.OpcodeI32Store16Name wasm.OpcodeI64Store16Name +// +// The engines are expected to check the boundary of memory length, and exit the execution if this exceeds the boundary, +// otherwise store the corresponding value following the semantics of the corresponding WebAssembly instruction. +func newOperationStore16(arg memoryArg) unionOperation { + return unionOperation{Kind: operationKindStore16, U1: uint64(arg.Alignment), U2: uint64(arg.Offset)} +} + +// NewOperationStore32 is a constructor for unionOperation with operationKindStore32. +// +// # This corresponds to wasm.OpcodeI64Store32Name +// +// The engines are expected to check the boundary of memory length, and exit the execution if this exceeds the boundary, +// otherwise store the corresponding value following the semantics of the corresponding WebAssembly instruction. +func newOperationStore32(arg memoryArg) unionOperation { + return unionOperation{Kind: operationKindStore32, U1: uint64(arg.Alignment), U2: uint64(arg.Offset)} +} + +// NewOperationMemorySize is a constructor for unionOperation with operationKindMemorySize. +// +// This corresponds to wasm.OpcodeMemorySize. +// +// The engines are expected to push the current page size of the memory onto the stack. +func newOperationMemorySize() unionOperation { + return unionOperation{Kind: operationKindMemorySize} +} + +// NewOperationMemoryGrow is a constructor for unionOperation with operationKindMemoryGrow. +// +// This corresponds to wasm.OpcodeMemoryGrow. +// +// The engines are expected to pop one value from the top of the stack, then +// execute wasm.MemoryInstance Grow with the value, and push the previous +// page size of the memory onto the stack. +func newOperationMemoryGrow() unionOperation { + return unionOperation{Kind: operationKindMemoryGrow} +} + +// NewOperationConstI32 is a constructor for unionOperation with OperationConstI32. +// +// This corresponds to wasm.OpcodeI32Const. +func newOperationConstI32(value uint32) unionOperation { + return unionOperation{Kind: operationKindConstI32, U1: uint64(value)} +} + +// NewOperationConstI64 is a constructor for unionOperation with OperationConstI64. +// +// This corresponds to wasm.OpcodeI64Const. +func newOperationConstI64(value uint64) unionOperation { + return unionOperation{Kind: operationKindConstI64, U1: value} +} + +// NewOperationConstF32 is a constructor for unionOperation with OperationConstF32. +// +// This corresponds to wasm.OpcodeF32Const. +func newOperationConstF32(value float32) unionOperation { + return unionOperation{Kind: operationKindConstF32, U1: uint64(math.Float32bits(value))} +} + +// NewOperationConstF64 is a constructor for unionOperation with OperationConstF64. +// +// This corresponds to wasm.OpcodeF64Const. +func newOperationConstF64(value float64) unionOperation { + return unionOperation{Kind: operationKindConstF64, U1: math.Float64bits(value)} +} + +// NewOperationEq is a constructor for unionOperation with operationKindEq. +// +// This corresponds to wasm.OpcodeI32EqName wasm.OpcodeI64EqName wasm.OpcodeF32EqName wasm.OpcodeF64EqName +func newOperationEq(b unsignedType) unionOperation { + return unionOperation{Kind: operationKindEq, B1: byte(b)} +} + +// NewOperationNe is a constructor for unionOperation with operationKindNe. +// +// This corresponds to wasm.OpcodeI32NeName wasm.OpcodeI64NeName wasm.OpcodeF32NeName wasm.OpcodeF64NeName +func newOperationNe(b unsignedType) unionOperation { + return unionOperation{Kind: operationKindNe, B1: byte(b)} +} + +// NewOperationEqz is a constructor for unionOperation with operationKindEqz. +// +// This corresponds to wasm.OpcodeI32EqzName wasm.OpcodeI64EqzName +func newOperationEqz(b unsignedInt) unionOperation { + return unionOperation{Kind: operationKindEqz, B1: byte(b)} +} + +// NewOperationLt is a constructor for unionOperation with operationKindLt. +// +// This corresponds to wasm.OpcodeI32LtS wasm.OpcodeI32LtU wasm.OpcodeI64LtS wasm.OpcodeI64LtU wasm.OpcodeF32Lt wasm.OpcodeF64Lt +func newOperationLt(b signedType) unionOperation { + return unionOperation{Kind: operationKindLt, B1: byte(b)} +} + +// NewOperationGt is a constructor for unionOperation with operationKindGt. +// +// This corresponds to wasm.OpcodeI32GtS wasm.OpcodeI32GtU wasm.OpcodeI64GtS wasm.OpcodeI64GtU wasm.OpcodeF32Gt wasm.OpcodeF64Gt +func newOperationGt(b signedType) unionOperation { + return unionOperation{Kind: operationKindGt, B1: byte(b)} +} + +// NewOperationLe is a constructor for unionOperation with operationKindLe. +// +// This corresponds to wasm.OpcodeI32LeS wasm.OpcodeI32LeU wasm.OpcodeI64LeS wasm.OpcodeI64LeU wasm.OpcodeF32Le wasm.OpcodeF64Le +func newOperationLe(b signedType) unionOperation { + return unionOperation{Kind: operationKindLe, B1: byte(b)} +} + +// NewOperationGe is a constructor for unionOperation with operationKindGe. +// +// This corresponds to wasm.OpcodeI32GeS wasm.OpcodeI32GeU wasm.OpcodeI64GeS wasm.OpcodeI64GeU wasm.OpcodeF32Ge wasm.OpcodeF64Ge +// NewOperationGe is the constructor for OperationGe +func newOperationGe(b signedType) unionOperation { + return unionOperation{Kind: operationKindGe, B1: byte(b)} +} + +// NewOperationAdd is a constructor for unionOperation with operationKindAdd. +// +// This corresponds to wasm.OpcodeI32AddName wasm.OpcodeI64AddName wasm.OpcodeF32AddName wasm.OpcodeF64AddName. +func newOperationAdd(b unsignedType) unionOperation { + return unionOperation{Kind: operationKindAdd, B1: byte(b)} +} + +// NewOperationSub is a constructor for unionOperation with operationKindSub. +// +// This corresponds to wasm.OpcodeI32SubName wasm.OpcodeI64SubName wasm.OpcodeF32SubName wasm.OpcodeF64SubName. +func newOperationSub(b unsignedType) unionOperation { + return unionOperation{Kind: operationKindSub, B1: byte(b)} +} + +// NewOperationMul is a constructor for unionOperation with wperationKindMul. +// +// This corresponds to wasm.OpcodeI32MulName wasm.OpcodeI64MulName wasm.OpcodeF32MulName wasm.OpcodeF64MulName. +// NewOperationMul is the constructor for OperationMul +func newOperationMul(b unsignedType) unionOperation { + return unionOperation{Kind: operationKindMul, B1: byte(b)} +} + +// NewOperationClz is a constructor for unionOperation with operationKindClz. +// +// This corresponds to wasm.OpcodeI32ClzName wasm.OpcodeI64ClzName. +// +// The engines are expected to count up the leading zeros in the +// current top of the stack, and push the count result. +// For example, stack of [..., 0x00_ff_ff_ff] results in [..., 8]. +// See wasm.OpcodeI32Clz wasm.OpcodeI64Clz +func newOperationClz(b unsignedInt) unionOperation { + return unionOperation{Kind: operationKindClz, B1: byte(b)} +} + +// NewOperationCtz is a constructor for unionOperation with operationKindCtz. +// +// This corresponds to wasm.OpcodeI32CtzName wasm.OpcodeI64CtzName. +// +// The engines are expected to count up the trailing zeros in the +// current top of the stack, and push the count result. +// For example, stack of [..., 0xff_ff_ff_00] results in [..., 8]. +func newOperationCtz(b unsignedInt) unionOperation { + return unionOperation{Kind: operationKindCtz, B1: byte(b)} +} + +// NewOperationPopcnt is a constructor for unionOperation with operationKindPopcnt. +// +// This corresponds to wasm.OpcodeI32PopcntName wasm.OpcodeI64PopcntName. +// +// The engines are expected to count up the number of set bits in the +// current top of the stack, and push the count result. +// For example, stack of [..., 0b00_00_00_11] results in [..., 2]. +func newOperationPopcnt(b unsignedInt) unionOperation { + return unionOperation{Kind: operationKindPopcnt, B1: byte(b)} +} + +// NewOperationDiv is a constructor for unionOperation with operationKindDiv. +// +// This corresponds to wasm.OpcodeI32DivS wasm.OpcodeI32DivU wasm.OpcodeI64DivS +// +// wasm.OpcodeI64DivU wasm.OpcodeF32Div wasm.OpcodeF64Div. +func newOperationDiv(b signedType) unionOperation { + return unionOperation{Kind: operationKindDiv, B1: byte(b)} +} + +// NewOperationRem is a constructor for unionOperation with operationKindRem. +// +// This corresponds to wasm.OpcodeI32RemS wasm.OpcodeI32RemU wasm.OpcodeI64RemS wasm.OpcodeI64RemU. +// +// The engines are expected to perform division on the top +// two values of integer type on the stack and puts the remainder of the result +// onto the stack. For example, stack [..., 10, 3] results in [..., 1] where +// the quotient is discarded. +// NewOperationRem is the constructor for OperationRem +func newOperationRem(b signedInt) unionOperation { + return unionOperation{Kind: operationKindRem, B1: byte(b)} +} + +// NewOperationAnd is a constructor for unionOperation with operationKindAnd. +// +// # This corresponds to wasm.OpcodeI32AndName wasm.OpcodeI64AndName +// +// The engines are expected to perform "And" operation on +// top two values on the stack, and pushes the result. +func newOperationAnd(b unsignedInt) unionOperation { + return unionOperation{Kind: operationKindAnd, B1: byte(b)} +} + +// NewOperationOr is a constructor for unionOperation with operationKindOr. +// +// # This corresponds to wasm.OpcodeI32OrName wasm.OpcodeI64OrName +// +// The engines are expected to perform "Or" operation on +// top two values on the stack, and pushes the result. +func newOperationOr(b unsignedInt) unionOperation { + return unionOperation{Kind: operationKindOr, B1: byte(b)} +} + +// NewOperationXor is a constructor for unionOperation with operationKindXor. +// +// # This corresponds to wasm.OpcodeI32XorName wasm.OpcodeI64XorName +// +// The engines are expected to perform "Xor" operation on +// top two values on the stack, and pushes the result. +func newOperationXor(b unsignedInt) unionOperation { + return unionOperation{Kind: operationKindXor, B1: byte(b)} +} + +// NewOperationShl is a constructor for unionOperation with operationKindShl. +// +// # This corresponds to wasm.OpcodeI32ShlName wasm.OpcodeI64ShlName +// +// The engines are expected to perform "Shl" operation on +// top two values on the stack, and pushes the result. +func newOperationShl(b unsignedInt) unionOperation { + return unionOperation{Kind: operationKindShl, B1: byte(b)} +} + +// NewOperationShr is a constructor for unionOperation with operationKindShr. +// +// # This corresponds to wasm.OpcodeI32ShrSName wasm.OpcodeI32ShrUName wasm.OpcodeI64ShrSName wasm.OpcodeI64ShrUName +// +// If OperationShr.Type is signed integer, then, the engines are expected to perform arithmetic right shift on the two +// top values on the stack, otherwise do the logical right shift. +func newOperationShr(b signedInt) unionOperation { + return unionOperation{Kind: operationKindShr, B1: byte(b)} +} + +// NewOperationRotl is a constructor for unionOperation with operationKindRotl. +// +// # This corresponds to wasm.OpcodeI32RotlName wasm.OpcodeI64RotlName +// +// The engines are expected to perform "Rotl" operation on +// top two values on the stack, and pushes the result. +func newOperationRotl(b unsignedInt) unionOperation { + return unionOperation{Kind: operationKindRotl, B1: byte(b)} +} + +// NewOperationRotr is a constructor for unionOperation with operationKindRotr. +// +// # This corresponds to wasm.OpcodeI32RotrName wasm.OpcodeI64RotrName +// +// The engines are expected to perform "Rotr" operation on +// top two values on the stack, and pushes the result. +func newOperationRotr(b unsignedInt) unionOperation { + return unionOperation{Kind: operationKindRotr, B1: byte(b)} +} + +// NewOperationAbs is a constructor for unionOperation with operationKindAbs. +// +// This corresponds to wasm.OpcodeF32Abs wasm.OpcodeF64Abs +func newOperationAbs(b float) unionOperation { + return unionOperation{Kind: operationKindAbs, B1: byte(b)} +} + +// NewOperationNeg is a constructor for unionOperation with operationKindNeg. +// +// This corresponds to wasm.OpcodeF32Neg wasm.OpcodeF64Neg +func newOperationNeg(b float) unionOperation { + return unionOperation{Kind: operationKindNeg, B1: byte(b)} +} + +// NewOperationCeil is a constructor for unionOperation with operationKindCeil. +// +// This corresponds to wasm.OpcodeF32CeilName wasm.OpcodeF64CeilName +func newOperationCeil(b float) unionOperation { + return unionOperation{Kind: operationKindCeil, B1: byte(b)} +} + +// NewOperationFloor is a constructor for unionOperation with operationKindFloor. +// +// This corresponds to wasm.OpcodeF32FloorName wasm.OpcodeF64FloorName +func newOperationFloor(b float) unionOperation { + return unionOperation{Kind: operationKindFloor, B1: byte(b)} +} + +// NewOperationTrunc is a constructor for unionOperation with operationKindTrunc. +// +// This corresponds to wasm.OpcodeF32TruncName wasm.OpcodeF64TruncName +func newOperationTrunc(b float) unionOperation { + return unionOperation{Kind: operationKindTrunc, B1: byte(b)} +} + +// NewOperationNearest is a constructor for unionOperation with operationKindNearest. +// +// # This corresponds to wasm.OpcodeF32NearestName wasm.OpcodeF64NearestName +// +// Note: this is *not* equivalent to math.Round and instead has the same +// the semantics of LLVM's rint intrinsic. See https://llvm.org/docs/LangRef.html#llvm-rint-intrinsic. +// For example, math.Round(-4.5) produces -5 while we want to produce -4. +func newOperationNearest(b float) unionOperation { + return unionOperation{Kind: operationKindNearest, B1: byte(b)} +} + +// NewOperationSqrt is a constructor for unionOperation with operationKindSqrt. +// +// This corresponds to wasm.OpcodeF32SqrtName wasm.OpcodeF64SqrtName +func newOperationSqrt(b float) unionOperation { + return unionOperation{Kind: operationKindSqrt, B1: byte(b)} +} + +// NewOperationMin is a constructor for unionOperation with operationKindMin. +// +// # This corresponds to wasm.OpcodeF32MinName wasm.OpcodeF64MinName +// +// The engines are expected to pop two values from the stack, and push back the maximum of +// these two values onto the stack. For example, stack [..., 100.1, 1.9] results in [..., 1.9]. +// +// Note: WebAssembly specifies that min/max must always return NaN if one of values is NaN, +// which is a different behavior different from math.Min. +func newOperationMin(b float) unionOperation { + return unionOperation{Kind: operationKindMin, B1: byte(b)} +} + +// NewOperationMax is a constructor for unionOperation with operationKindMax. +// +// # This corresponds to wasm.OpcodeF32MaxName wasm.OpcodeF64MaxName +// +// The engines are expected to pop two values from the stack, and push back the maximum of +// these two values onto the stack. For example, stack [..., 100.1, 1.9] results in [..., 100.1]. +// +// Note: WebAssembly specifies that min/max must always return NaN if one of values is NaN, +// which is a different behavior different from math.Max. +func newOperationMax(b float) unionOperation { + return unionOperation{Kind: operationKindMax, B1: byte(b)} +} + +// NewOperationCopysign is a constructor for unionOperation with operationKindCopysign. +// +// # This corresponds to wasm.OpcodeF32CopysignName wasm.OpcodeF64CopysignName +// +// The engines are expected to pop two float values from the stack, and copy the signbit of +// the first-popped value to the last one. +// For example, stack [..., 1.213, -5.0] results in [..., -1.213]. +func newOperationCopysign(b float) unionOperation { + return unionOperation{Kind: operationKindCopysign, B1: byte(b)} +} + +// NewOperationI32WrapFromI64 is a constructor for unionOperation with operationKindI32WrapFromI64. +// +// This corresponds to wasm.OpcodeI32WrapI64 and equivalent to uint64(uint32(v)) in Go. +// +// The engines are expected to replace the 64-bit int on top of the stack +// with the corresponding 32-bit integer. +func newOperationI32WrapFromI64() unionOperation { + return unionOperation{Kind: operationKindI32WrapFromI64} +} + +// NewOperationITruncFromF is a constructor for unionOperation with operationKindITruncFromF. +// +// This corresponds to +// +// wasm.OpcodeI32TruncF32SName wasm.OpcodeI32TruncF32UName wasm.OpcodeI32TruncF64SName +// wasm.OpcodeI32TruncF64UName wasm.OpcodeI64TruncF32SName wasm.OpcodeI64TruncF32UName wasm.OpcodeI64TruncF64SName +// wasm.OpcodeI64TruncF64UName. wasm.OpcodeI32TruncSatF32SName wasm.OpcodeI32TruncSatF32UName +// wasm.OpcodeI32TruncSatF64SName wasm.OpcodeI32TruncSatF64UName wasm.OpcodeI64TruncSatF32SName +// wasm.OpcodeI64TruncSatF32UName wasm.OpcodeI64TruncSatF64SName wasm.OpcodeI64TruncSatF64UName +// +// See [1] and [2] for when we encounter undefined behavior in the WebAssembly specification if NewOperationITruncFromF.NonTrapping == false. +// To summarize, if the source float value is NaN or doesn't fit in the destination range of integers (incl. +=Inf), +// then the runtime behavior is undefined. In wazero, the engines are expected to exit the execution in these undefined cases with +// wasmruntime.ErrRuntimeInvalidConversionToInteger error. +// +// [1] https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/#-hrefop-trunc-umathrmtruncmathsfu_m-n-z for unsigned integers. +// [2] https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/#-hrefop-trunc-smathrmtruncmathsfs_m-n-z for signed integers. +// +// nonTrapping true if this conversion is "nontrapping" in the sense of the +// https://github.com/WebAssembly/spec/blob/ce4b6c4d47eb06098cc7ab2e81f24748da822f20/proposals/nontrapping-float-to-int-conversion/Overview.md +func newOperationITruncFromF(inputType float, outputType signedInt, nonTrapping bool) unionOperation { + return unionOperation{ + Kind: operationKindITruncFromF, + B1: byte(inputType), + B2: byte(outputType), + B3: nonTrapping, + } +} + +// NewOperationFConvertFromI is a constructor for unionOperation with operationKindFConvertFromI. +// +// This corresponds to +// +// wasm.OpcodeF32ConvertI32SName wasm.OpcodeF32ConvertI32UName wasm.OpcodeF32ConvertI64SName wasm.OpcodeF32ConvertI64UName +// wasm.OpcodeF64ConvertI32SName wasm.OpcodeF64ConvertI32UName wasm.OpcodeF64ConvertI64SName wasm.OpcodeF64ConvertI64UName +// +// and equivalent to float32(uint32(x)), float32(int32(x)), etc in Go. +func newOperationFConvertFromI(inputType signedInt, outputType float) unionOperation { + return unionOperation{ + Kind: operationKindFConvertFromI, + B1: byte(inputType), + B2: byte(outputType), + } +} + +// NewOperationF32DemoteFromF64 is a constructor for unionOperation with operationKindF32DemoteFromF64. +// +// This corresponds to wasm.OpcodeF32DemoteF64 and is equivalent float32(float64(v)). +func newOperationF32DemoteFromF64() unionOperation { + return unionOperation{Kind: operationKindF32DemoteFromF64} +} + +// NewOperationF64PromoteFromF32 is a constructor for unionOperation with operationKindF64PromoteFromF32. +// +// This corresponds to wasm.OpcodeF64PromoteF32 and is equivalent float64(float32(v)). +func newOperationF64PromoteFromF32() unionOperation { + return unionOperation{Kind: operationKindF64PromoteFromF32} +} + +// NewOperationI32ReinterpretFromF32 is a constructor for unionOperation with operationKindI32ReinterpretFromF32. +// +// This corresponds to wasm.OpcodeI32ReinterpretF32Name. +func newOperationI32ReinterpretFromF32() unionOperation { + return unionOperation{Kind: operationKindI32ReinterpretFromF32} +} + +// NewOperationI64ReinterpretFromF64 is a constructor for unionOperation with operationKindI64ReinterpretFromF64. +// +// This corresponds to wasm.OpcodeI64ReinterpretF64Name. +func newOperationI64ReinterpretFromF64() unionOperation { + return unionOperation{Kind: operationKindI64ReinterpretFromF64} +} + +// NewOperationF32ReinterpretFromI32 is a constructor for unionOperation with operationKindF32ReinterpretFromI32. +// +// This corresponds to wasm.OpcodeF32ReinterpretI32Name. +func newOperationF32ReinterpretFromI32() unionOperation { + return unionOperation{Kind: operationKindF32ReinterpretFromI32} +} + +// NewOperationF64ReinterpretFromI64 is a constructor for unionOperation with operationKindF64ReinterpretFromI64. +// +// This corresponds to wasm.OpcodeF64ReinterpretI64Name. +func newOperationF64ReinterpretFromI64() unionOperation { + return unionOperation{Kind: operationKindF64ReinterpretFromI64} +} + +// NewOperationExtend is a constructor for unionOperation with operationKindExtend. +// +// # This corresponds to wasm.OpcodeI64ExtendI32SName wasm.OpcodeI64ExtendI32UName +// +// The engines are expected to extend the 32-bit signed or unsigned int on top of the stack +// as a 64-bit integer of corresponding signedness. For unsigned case, this is just reinterpreting the +// underlying bit pattern as 64-bit integer. For signed case, this is sign-extension which preserves the +// original integer's sign. +func newOperationExtend(signed bool) unionOperation { + op := unionOperation{Kind: operationKindExtend} + if signed { + op.B1 = 1 + } + return op +} + +// NewOperationSignExtend32From8 is a constructor for unionOperation with operationKindSignExtend32From8. +// +// This corresponds to wasm.OpcodeI32Extend8SName. +// +// The engines are expected to sign-extend the first 8-bits of 32-bit in as signed 32-bit int. +func newOperationSignExtend32From8() unionOperation { + return unionOperation{Kind: operationKindSignExtend32From8} +} + +// NewOperationSignExtend32From16 is a constructor for unionOperation with operationKindSignExtend32From16. +// +// This corresponds to wasm.OpcodeI32Extend16SName. +// +// The engines are expected to sign-extend the first 16-bits of 32-bit in as signed 32-bit int. +func newOperationSignExtend32From16() unionOperation { + return unionOperation{Kind: operationKindSignExtend32From16} +} + +// NewOperationSignExtend64From8 is a constructor for unionOperation with operationKindSignExtend64From8. +// +// This corresponds to wasm.OpcodeI64Extend8SName. +// +// The engines are expected to sign-extend the first 8-bits of 64-bit in as signed 32-bit int. +func newOperationSignExtend64From8() unionOperation { + return unionOperation{Kind: operationKindSignExtend64From8} +} + +// NewOperationSignExtend64From16 is a constructor for unionOperation with operationKindSignExtend64From16. +// +// This corresponds to wasm.OpcodeI64Extend16SName. +// +// The engines are expected to sign-extend the first 16-bits of 64-bit in as signed 32-bit int. +func newOperationSignExtend64From16() unionOperation { + return unionOperation{Kind: operationKindSignExtend64From16} +} + +// NewOperationSignExtend64From32 is a constructor for unionOperation with operationKindSignExtend64From32. +// +// This corresponds to wasm.OpcodeI64Extend32SName. +// +// The engines are expected to sign-extend the first 32-bits of 64-bit in as signed 32-bit int. +func newOperationSignExtend64From32() unionOperation { + return unionOperation{Kind: operationKindSignExtend64From32} +} + +// NewOperationMemoryInit is a constructor for unionOperation with operationKindMemoryInit. +// +// This corresponds to wasm.OpcodeMemoryInitName. +// +// dataIndex is the index of the data instance in ModuleInstance.DataInstances +// by which this operation instantiates a part of the memory. +func newOperationMemoryInit(dataIndex uint32) unionOperation { + return unionOperation{Kind: operationKindMemoryInit, U1: uint64(dataIndex)} +} + +// NewOperationDataDrop implements Operation. +// +// This corresponds to wasm.OpcodeDataDropName. +// +// dataIndex is the index of the data instance in ModuleInstance.DataInstances +// which this operation drops. +func newOperationDataDrop(dataIndex uint32) unionOperation { + return unionOperation{Kind: operationKindDataDrop, U1: uint64(dataIndex)} +} + +// NewOperationMemoryCopy is a consuctor for unionOperation with operationKindMemoryCopy. +// +// This corresponds to wasm.OpcodeMemoryCopyName. +func newOperationMemoryCopy() unionOperation { + return unionOperation{Kind: operationKindMemoryCopy} +} + +// NewOperationMemoryFill is a consuctor for unionOperation with operationKindMemoryFill. +func newOperationMemoryFill() unionOperation { + return unionOperation{Kind: operationKindMemoryFill} +} + +// NewOperationTableInit is a constructor for unionOperation with operationKindTableInit. +// +// This corresponds to wasm.OpcodeTableInitName. +// +// elemIndex is the index of the element by which this operation initializes a part of the table. +// tableIndex is the index of the table on which this operation initialize by the target element. +func newOperationTableInit(elemIndex, tableIndex uint32) unionOperation { + return unionOperation{Kind: operationKindTableInit, U1: uint64(elemIndex), U2: uint64(tableIndex)} +} + +// NewOperationElemDrop is a constructor for unionOperation with operationKindElemDrop. +// +// This corresponds to wasm.OpcodeElemDropName. +// +// elemIndex is the index of the element which this operation drops. +func newOperationElemDrop(elemIndex uint32) unionOperation { + return unionOperation{Kind: operationKindElemDrop, U1: uint64(elemIndex)} +} + +// NewOperationTableCopy implements Operation. +// +// This corresponds to wasm.OpcodeTableCopyName. +func newOperationTableCopy(srcTableIndex, dstTableIndex uint32) unionOperation { + return unionOperation{Kind: operationKindTableCopy, U1: uint64(srcTableIndex), U2: uint64(dstTableIndex)} +} + +// NewOperationRefFunc constructor for unionOperation with operationKindRefFunc. +// +// This corresponds to wasm.OpcodeRefFuncName, and engines are expected to +// push the opaque pointer value of engine specific func for the given FunctionIndex. +// +// Note: in wazero, we express any reference types (funcref or externref) as opaque pointers which is uint64. +// Therefore, the engine implementations emit instructions to push the address of *function onto the stack. +func newOperationRefFunc(functionIndex uint32) unionOperation { + return unionOperation{Kind: operationKindRefFunc, U1: uint64(functionIndex)} +} + +// NewOperationTableGet constructor for unionOperation with operationKindTableGet. +// +// This corresponds to wasm.OpcodeTableGetName. +func newOperationTableGet(tableIndex uint32) unionOperation { + return unionOperation{Kind: operationKindTableGet, U1: uint64(tableIndex)} +} + +// NewOperationTableSet constructor for unionOperation with operationKindTableSet. +// +// This corresponds to wasm.OpcodeTableSetName. +func newOperationTableSet(tableIndex uint32) unionOperation { + return unionOperation{Kind: operationKindTableSet, U1: uint64(tableIndex)} +} + +// NewOperationTableSize constructor for unionOperation with operationKindTableSize. +// +// This corresponds to wasm.OpcodeTableSizeName. +func newOperationTableSize(tableIndex uint32) unionOperation { + return unionOperation{Kind: operationKindTableSize, U1: uint64(tableIndex)} +} + +// NewOperationTableGrow constructor for unionOperation with operationKindTableGrow. +// +// This corresponds to wasm.OpcodeTableGrowName. +func newOperationTableGrow(tableIndex uint32) unionOperation { + return unionOperation{Kind: operationKindTableGrow, U1: uint64(tableIndex)} +} + +// NewOperationTableFill constructor for unionOperation with operationKindTableFill. +// +// This corresponds to wasm.OpcodeTableFillName. +func newOperationTableFill(tableIndex uint32) unionOperation { + return unionOperation{Kind: operationKindTableFill, U1: uint64(tableIndex)} +} + +// NewOperationV128Const constructor for unionOperation with operationKindV128Const +func newOperationV128Const(lo, hi uint64) unionOperation { + return unionOperation{Kind: operationKindV128Const, U1: lo, U2: hi} +} + +// shape corresponds to a shape of v128 values. +// https://webassembly.github.io/spec/core/syntax/instructions.html#syntax-shape +type shape = byte + +const ( + shapeI8x16 shape = iota + shapeI16x8 + shapeI32x4 + shapeI64x2 + shapeF32x4 + shapeF64x2 +) + +func shapeName(s shape) (ret string) { + switch s { + case shapeI8x16: + ret = "I8x16" + case shapeI16x8: + ret = "I16x8" + case shapeI32x4: + ret = "I32x4" + case shapeI64x2: + ret = "I64x2" + case shapeF32x4: + ret = "F32x4" + case shapeF64x2: + ret = "F64x2" + } + return +} + +// NewOperationV128Add constructor for unionOperation with operationKindV128Add. +// +// This corresponds to wasm.OpcodeVecI8x16AddName wasm.OpcodeVecI16x8AddName wasm.OpcodeVecI32x4AddName +// +// wasm.OpcodeVecI64x2AddName wasm.OpcodeVecF32x4AddName wasm.OpcodeVecF64x2AddName +func newOperationV128Add(shape shape) unionOperation { + return unionOperation{Kind: operationKindV128Add, B1: shape} +} + +// NewOperationV128Sub constructor for unionOperation with operationKindV128Sub. +// +// This corresponds to wasm.OpcodeVecI8x16SubName wasm.OpcodeVecI16x8SubName wasm.OpcodeVecI32x4SubName +// +// wasm.OpcodeVecI64x2SubName wasm.OpcodeVecF32x4SubName wasm.OpcodeVecF64x2SubName +func newOperationV128Sub(shape shape) unionOperation { + return unionOperation{Kind: operationKindV128Sub, B1: shape} +} + +// v128LoadType represents a type of wasm.OpcodeVecV128Load* instructions. +type v128LoadType = byte + +const ( + // v128LoadType128 corresponds to wasm.OpcodeVecV128LoadName. + v128LoadType128 v128LoadType = iota + // v128LoadType8x8s corresponds to wasm.OpcodeVecV128Load8x8SName. + v128LoadType8x8s + // v128LoadType8x8u corresponds to wasm.OpcodeVecV128Load8x8UName. + v128LoadType8x8u + // v128LoadType16x4s corresponds to wasm.OpcodeVecV128Load16x4SName + v128LoadType16x4s + // v128LoadType16x4u corresponds to wasm.OpcodeVecV128Load16x4UName + v128LoadType16x4u + // v128LoadType32x2s corresponds to wasm.OpcodeVecV128Load32x2SName + v128LoadType32x2s + // v128LoadType32x2u corresponds to wasm.OpcodeVecV128Load32x2UName + v128LoadType32x2u + // v128LoadType8Splat corresponds to wasm.OpcodeVecV128Load8SplatName + v128LoadType8Splat + // v128LoadType16Splat corresponds to wasm.OpcodeVecV128Load16SplatName + v128LoadType16Splat + // v128LoadType32Splat corresponds to wasm.OpcodeVecV128Load32SplatName + v128LoadType32Splat + // v128LoadType64Splat corresponds to wasm.OpcodeVecV128Load64SplatName + v128LoadType64Splat + // v128LoadType32zero corresponds to wasm.OpcodeVecV128Load32zeroName + v128LoadType32zero + // v128LoadType64zero corresponds to wasm.OpcodeVecV128Load64zeroName + v128LoadType64zero +) + +// NewOperationV128Load is a constructor for unionOperation with operationKindV128Load. +// +// This corresponds to +// +// wasm.OpcodeVecV128LoadName wasm.OpcodeVecV128Load8x8SName wasm.OpcodeVecV128Load8x8UName +// wasm.OpcodeVecV128Load16x4SName wasm.OpcodeVecV128Load16x4UName wasm.OpcodeVecV128Load32x2SName +// wasm.OpcodeVecV128Load32x2UName wasm.OpcodeVecV128Load8SplatName wasm.OpcodeVecV128Load16SplatName +// wasm.OpcodeVecV128Load32SplatName wasm.OpcodeVecV128Load64SplatName wasm.OpcodeVecV128Load32zeroName +// wasm.OpcodeVecV128Load64zeroName +func newOperationV128Load(loadType v128LoadType, arg memoryArg) unionOperation { + return unionOperation{Kind: operationKindV128Load, B1: loadType, U1: uint64(arg.Alignment), U2: uint64(arg.Offset)} +} + +// NewOperationV128LoadLane is a constructor for unionOperation with operationKindV128LoadLane. +// +// This corresponds to wasm.OpcodeVecV128Load8LaneName wasm.OpcodeVecV128Load16LaneName +// +// wasm.OpcodeVecV128Load32LaneName wasm.OpcodeVecV128Load64LaneName. +// +// laneIndex is >=0 && <(128/LaneSize). +// laneSize is either 8, 16, 32, or 64. +func newOperationV128LoadLane(laneIndex, laneSize byte, arg memoryArg) unionOperation { + return unionOperation{Kind: operationKindV128LoadLane, B1: laneSize, B2: laneIndex, U1: uint64(arg.Alignment), U2: uint64(arg.Offset)} +} + +// NewOperationV128Store is a constructor for unionOperation with operationKindV128Store. +// +// This corresponds to wasm.OpcodeVecV128Load8LaneName wasm.OpcodeVecV128Load16LaneName +// +// wasm.OpcodeVecV128Load32LaneName wasm.OpcodeVecV128Load64LaneName. +func newOperationV128Store(arg memoryArg) unionOperation { + return unionOperation{ + Kind: operationKindV128Store, + U1: uint64(arg.Alignment), + U2: uint64(arg.Offset), + } +} + +// NewOperationV128StoreLane implements Operation. +// +// This corresponds to wasm.OpcodeVecV128Load8LaneName wasm.OpcodeVecV128Load16LaneName +// +// wasm.OpcodeVecV128Load32LaneName wasm.OpcodeVecV128Load64LaneName. +// +// laneIndex is >=0 && <(128/LaneSize). +// laneSize is either 8, 16, 32, or 64. +func newOperationV128StoreLane(laneIndex byte, laneSize byte, arg memoryArg) unionOperation { + return unionOperation{ + Kind: operationKindV128StoreLane, + B1: laneSize, + B2: laneIndex, + U1: uint64(arg.Alignment), + U2: uint64(arg.Offset), + } +} + +// NewOperationV128ExtractLane is a constructor for unionOperation with operationKindV128ExtractLane. +// +// This corresponds to +// +// wasm.OpcodeVecI8x16ExtractLaneSName wasm.OpcodeVecI8x16ExtractLaneUName +// wasm.OpcodeVecI16x8ExtractLaneSName wasm.OpcodeVecI16x8ExtractLaneUName +// wasm.OpcodeVecI32x4ExtractLaneName wasm.OpcodeVecI64x2ExtractLaneName +// wasm.OpcodeVecF32x4ExtractLaneName wasm.OpcodeVecF64x2ExtractLaneName. +// +// laneIndex is >=0 && =0 && > 32)) -} - -// NewLabel is a constructor for a Label. -func NewLabel(kind LabelKind, frameID uint32) Label { - return Label(kind) | Label(frameID)<<32 -} - -// String implements fmt.Stringer. -func (l Label) String() (ret string) { - frameID := l.FrameID() - switch l.Kind() { - case LabelKindHeader: - ret = fmt.Sprintf(".L%d", frameID) - case LabelKindElse: - ret = fmt.Sprintf(".L%d_else", frameID) - case LabelKindContinuation: - ret = fmt.Sprintf(".L%d_cont", frameID) - case LabelKindReturn: - return ".return" - } - return -} - -func (l Label) IsReturnTarget() bool { - return l.Kind() == LabelKindReturn -} - -// LabelKind is the Kind of the label. -type LabelKind = byte - -const ( - // LabelKindHeader is the header for various blocks. For example, the "then" block of - // wasm.OpcodeIfName in Wasm has the label of this Kind. - LabelKindHeader LabelKind = iota - // LabelKindElse is the Kind of label for "else" block of wasm.OpcodeIfName in Wasm. - LabelKindElse - // LabelKindContinuation is the Kind of label which is the continuation of blocks. - // For example, for wasm text like - // (func - // .... - // (if (local.get 0) (then (nop)) (else (nop))) - // return - // ) - // we have the continuation block (of if-block) corresponding to "return" opcode. - LabelKindContinuation - LabelKindReturn - LabelKindNum -) - -// UnionOperation implements Operation and is the compilation (engine.lowerIR) result of a wazeroir.Operation. -// -// Not all operations result in a UnionOperation, e.g. wazeroir.OperationI32ReinterpretFromF32, and some operations are -// more complex than others, e.g. wazeroir.NewOperationBrTable. -// -// Note: This is a form of union type as it can store fields needed for any operation. Hence, most fields are opaque and -// only relevant when in context of its kind. -type UnionOperation struct { - // Kind determines how to interpret the other fields in this struct. - Kind OperationKind - B1, B2 byte - B3 bool - U1, U2 uint64 - U3 uint64 - Us []uint64 -} - -// String implements fmt.Stringer. -func (o UnionOperation) String() string { - switch o.Kind { - case OperationKindUnreachable, - OperationKindSelect, - OperationKindMemorySize, - OperationKindMemoryGrow, - OperationKindI32WrapFromI64, - OperationKindF32DemoteFromF64, - OperationKindF64PromoteFromF32, - OperationKindI32ReinterpretFromF32, - OperationKindI64ReinterpretFromF64, - OperationKindF32ReinterpretFromI32, - OperationKindF64ReinterpretFromI64, - OperationKindSignExtend32From8, - OperationKindSignExtend32From16, - OperationKindSignExtend64From8, - OperationKindSignExtend64From16, - OperationKindSignExtend64From32, - OperationKindMemoryInit, - OperationKindDataDrop, - OperationKindMemoryCopy, - OperationKindMemoryFill, - OperationKindTableInit, - OperationKindElemDrop, - OperationKindTableCopy, - OperationKindRefFunc, - OperationKindTableGet, - OperationKindTableSet, - OperationKindTableSize, - OperationKindTableGrow, - OperationKindTableFill, - OperationKindBuiltinFunctionCheckExitCode: - return o.Kind.String() - - case OperationKindCall, - OperationKindGlobalGet, - OperationKindGlobalSet: - return fmt.Sprintf("%s %d", o.Kind, o.B1) - - case OperationKindLabel: - return Label(o.U1).String() - - case OperationKindBr: - return fmt.Sprintf("%s %s", o.Kind, Label(o.U1).String()) - - case OperationKindBrIf: - thenTarget := Label(o.U1) - elseTarget := Label(o.U2) - return fmt.Sprintf("%s %s, %s", o.Kind, thenTarget, elseTarget) - - case OperationKindBrTable: - var targets []string - var defaultLabel Label - if len(o.Us) > 0 { - targets = make([]string, len(o.Us)-1) - for i, t := range o.Us[1:] { - targets[i] = Label(t).String() - } - defaultLabel = Label(o.Us[0]) - } - return fmt.Sprintf("%s [%s] %s", o.Kind, strings.Join(targets, ","), defaultLabel) - - case OperationKindCallIndirect: - return fmt.Sprintf("%s: type=%d, table=%d", o.Kind, o.U1, o.U2) - - case OperationKindDrop: - start := int64(o.U1) - end := int64(o.U2) - return fmt.Sprintf("%s %d..%d", o.Kind, start, end) - - case OperationKindPick, OperationKindSet: - return fmt.Sprintf("%s %d (is_vector=%v)", o.Kind, o.U1, o.B3) - - case OperationKindLoad, OperationKindStore: - return fmt.Sprintf("%s.%s (align=%d, offset=%d)", UnsignedType(o.B1), o.Kind, o.U1, o.U2) - - case OperationKindLoad8, - OperationKindLoad16: - return fmt.Sprintf("%s.%s (align=%d, offset=%d)", SignedType(o.B1), o.Kind, o.U1, o.U2) - - case OperationKindStore8, - OperationKindStore16, - OperationKindStore32: - return fmt.Sprintf("%s (align=%d, offset=%d)", o.Kind, o.U1, o.U2) - - case OperationKindLoad32: - var t string - if o.B1 == 1 { - t = "i64" - } else { - t = "u64" - } - return fmt.Sprintf("%s.%s (align=%d, offset=%d)", t, o.Kind, o.U1, o.U2) - - case OperationKindEq, - OperationKindNe, - OperationKindAdd, - OperationKindSub, - OperationKindMul: - return fmt.Sprintf("%s.%s", UnsignedType(o.B1), o.Kind) - - case OperationKindEqz, - OperationKindClz, - OperationKindCtz, - OperationKindPopcnt, - OperationKindAnd, - OperationKindOr, - OperationKindXor, - OperationKindShl, - OperationKindRotl, - OperationKindRotr: - return fmt.Sprintf("%s.%s", UnsignedInt(o.B1), o.Kind) - - case OperationKindRem, OperationKindShr: - return fmt.Sprintf("%s.%s", SignedInt(o.B1), o.Kind) - - case OperationKindLt, - OperationKindGt, - OperationKindLe, - OperationKindGe, - OperationKindDiv: - return fmt.Sprintf("%s.%s", SignedType(o.B1), o.Kind) - - case OperationKindAbs, - OperationKindNeg, - OperationKindCeil, - OperationKindFloor, - OperationKindTrunc, - OperationKindNearest, - OperationKindSqrt, - OperationKindMin, - OperationKindMax, - OperationKindCopysign: - return fmt.Sprintf("%s.%s", Float(o.B1), o.Kind) - - case OperationKindConstI32, - OperationKindConstI64: - return fmt.Sprintf("%s %#x", o.Kind, o.U1) - - case OperationKindConstF32: - return fmt.Sprintf("%s %f", o.Kind, math.Float32frombits(uint32(o.U1))) - case OperationKindConstF64: - return fmt.Sprintf("%s %f", o.Kind, math.Float64frombits(o.U1)) - - case OperationKindITruncFromF: - return fmt.Sprintf("%s.%s.%s (non_trapping=%v)", SignedInt(o.B2), o.Kind, Float(o.B1), o.B3) - case OperationKindFConvertFromI: - return fmt.Sprintf("%s.%s.%s", Float(o.B2), o.Kind, SignedInt(o.B1)) - case OperationKindExtend: - var in, out string - if o.B3 { - in = "i32" - out = "i64" - } else { - in = "u32" - out = "u64" - } - return fmt.Sprintf("%s.%s.%s", out, o.Kind, in) - - case OperationKindV128Const: - return fmt.Sprintf("%s [%#x, %#x]", o.Kind, o.U1, o.U2) - case OperationKindV128Add, - OperationKindV128Sub: - return fmt.Sprintf("%s (shape=%s)", o.Kind, shapeName(o.B1)) - case OperationKindV128Load, - OperationKindV128LoadLane, - OperationKindV128Store, - OperationKindV128StoreLane, - OperationKindV128ExtractLane, - OperationKindV128ReplaceLane, - OperationKindV128Splat, - OperationKindV128Shuffle, - OperationKindV128Swizzle, - OperationKindV128AnyTrue, - OperationKindV128AllTrue, - OperationKindV128BitMask, - OperationKindV128And, - OperationKindV128Not, - OperationKindV128Or, - OperationKindV128Xor, - OperationKindV128Bitselect, - OperationKindV128AndNot, - OperationKindV128Shl, - OperationKindV128Shr, - OperationKindV128Cmp, - OperationKindV128AddSat, - OperationKindV128SubSat, - OperationKindV128Mul, - OperationKindV128Div, - OperationKindV128Neg, - OperationKindV128Sqrt, - OperationKindV128Abs, - OperationKindV128Popcnt, - OperationKindV128Min, - OperationKindV128Max, - OperationKindV128AvgrU, - OperationKindV128Pmin, - OperationKindV128Pmax, - OperationKindV128Ceil, - OperationKindV128Floor, - OperationKindV128Trunc, - OperationKindV128Nearest, - OperationKindV128Extend, - OperationKindV128ExtMul, - OperationKindV128Q15mulrSatS, - OperationKindV128ExtAddPairwise, - OperationKindV128FloatPromote, - OperationKindV128FloatDemote, - OperationKindV128FConvertFromI, - OperationKindV128Dot, - OperationKindV128Narrow: - return o.Kind.String() - - case OperationKindV128ITruncSatFromF: - if o.B3 { - return fmt.Sprintf("%s.%sS", o.Kind, shapeName(o.B1)) - } else { - return fmt.Sprintf("%s.%sU", o.Kind, shapeName(o.B1)) - } - - case OperationKindAtomicMemoryWait, - OperationKindAtomicMemoryNotify, - OperationKindAtomicFence, - OperationKindAtomicLoad, - OperationKindAtomicLoad8, - OperationKindAtomicLoad16, - OperationKindAtomicStore, - OperationKindAtomicStore8, - OperationKindAtomicStore16, - OperationKindAtomicRMW, - OperationKindAtomicRMW8, - OperationKindAtomicRMW16, - OperationKindAtomicRMWCmpxchg, - OperationKindAtomicRMW8Cmpxchg, - OperationKindAtomicRMW16Cmpxchg: - return o.Kind.String() - - default: - panic(fmt.Sprintf("TODO: %v", o.Kind)) - } -} - -// NewOperationUnreachable is a constructor for UnionOperation with OperationKindUnreachable -// -// This corresponds to wasm.OpcodeUnreachable. -// -// The engines are expected to exit the execution with wasmruntime.ErrRuntimeUnreachable error. -func NewOperationUnreachable() UnionOperation { - return UnionOperation{Kind: OperationKindUnreachable} -} - -// NewOperationLabel is a constructor for UnionOperation with OperationKindLabel. -// -// This is used to inform the engines of the beginning of a label. -func NewOperationLabel(label Label) UnionOperation { - return UnionOperation{Kind: OperationKindLabel, U1: uint64(label)} -} - -// NewOperationBr is a constructor for UnionOperation with OperationKindBr. -// -// The engines are expected to branch into U1 label. -func NewOperationBr(target Label) UnionOperation { - return UnionOperation{Kind: OperationKindBr, U1: uint64(target)} -} - -// NewOperationBrIf is a constructor for UnionOperation with OperationKindBrIf. -// -// The engines are expected to pop a value and branch into U1 label if the value equals 1. -// Otherwise, the code branches into U2 label. -func NewOperationBrIf(thenTarget, elseTarget Label, thenDrop InclusiveRange) UnionOperation { - return UnionOperation{ - Kind: OperationKindBrIf, - U1: uint64(thenTarget), - U2: uint64(elseTarget), - U3: thenDrop.AsU64(), - } -} - -// NewOperationBrTable is a constructor for UnionOperation with OperationKindBrTable. -// -// This corresponds to wasm.OpcodeBrTableName except that the label -// here means the wazeroir level, not the ones of Wasm. -// -// The engines are expected to do the br_table operation based on the default (Us[len(Us)-1], Us[len(Us)-2]) and -// targets (Us[:len(Us)-1], Rs[:len(Us)-1]). More precisely, this pops a value from the stack (called "index") -// and decides which branch we go into next based on the value. -// -// For example, assume we have operations like {default: L_DEFAULT, targets: [L0, L1, L2]}. -// If "index" >= len(defaults), then branch into the L_DEFAULT label. -// Otherwise, we enter label of targets[index]. -func NewOperationBrTable(targetLabelsAndRanges []uint64) UnionOperation { - return UnionOperation{ - Kind: OperationKindBrTable, - Us: targetLabelsAndRanges, - } -} - -// NewOperationCall is a constructor for UnionOperation with OperationKindCall. -// -// This corresponds to wasm.OpcodeCallName, and engines are expected to -// enter into a function whose index equals OperationCall.FunctionIndex. -func NewOperationCall(functionIndex uint32) UnionOperation { - return UnionOperation{Kind: OperationKindCall, U1: uint64(functionIndex)} -} - -// NewOperationCallIndirect implements Operation. -// -// This corresponds to wasm.OpcodeCallIndirectName, and engines are expected to -// consume the one value from the top of stack (called "offset"), -// and make a function call against the function whose function address equals -// Tables[OperationCallIndirect.TableIndex][offset]. -// -// Note: This is called indirect function call in the sense that the target function is indirectly -// determined by the current state (top value) of the stack. -// Therefore, two checks are performed at runtime before entering the target function: -// 1) whether "offset" exceeds the length of table Tables[OperationCallIndirect.TableIndex]. -// 2) whether the type of the function table[offset] matches the function type specified by OperationCallIndirect.TypeIndex. -func NewOperationCallIndirect(typeIndex, tableIndex uint32) UnionOperation { - return UnionOperation{Kind: OperationKindCallIndirect, U1: uint64(typeIndex), U2: uint64(tableIndex)} -} - -// InclusiveRange is the range which spans across the value stack starting from the top to the bottom, and -// both boundary are included in the range. -type InclusiveRange struct { - Start, End int32 -} - -// AsU64 is be used to convert InclusiveRange to uint64 so that it can be stored in UnionOperation. -func (i InclusiveRange) AsU64() uint64 { - return uint64(uint32(i.Start))<<32 | uint64(uint32(i.End)) -} - -// InclusiveRangeFromU64 retrieves InclusiveRange from the given uint64 which is stored in UnionOperation. -func InclusiveRangeFromU64(v uint64) InclusiveRange { - return InclusiveRange{ - Start: int32(uint32(v >> 32)), - End: int32(uint32(v)), - } -} - -// NopInclusiveRange is InclusiveRange which corresponds to no-operation. -var NopInclusiveRange = InclusiveRange{Start: -1, End: -1} - -// NewOperationDrop is a constructor for UnionOperation with OperationKindDrop. -// -// The engines are expected to discard the values selected by NewOperationDrop.Depth which -// starts from the top of the stack to the bottom. -// -// depth spans across the uint64 value stack at runtime to be dropped by this operation. -func NewOperationDrop(depth InclusiveRange) UnionOperation { - return UnionOperation{Kind: OperationKindDrop, U1: depth.AsU64()} -} - -// NewOperationSelect is a constructor for UnionOperation with OperationKindSelect. -// -// This corresponds to wasm.OpcodeSelect. -// -// The engines are expected to pop three values, say [..., x2, x1, c], then if the value "c" equals zero, -// "x1" is pushed back onto the stack and, otherwise "x2" is pushed back. -// -// isTargetVector true if the selection target value's type is wasm.ValueTypeV128. -func NewOperationSelect(isTargetVector bool) UnionOperation { - return UnionOperation{Kind: OperationKindSelect, B3: isTargetVector} -} - -// NewOperationPick is a constructor for UnionOperation with OperationKindPick. -// -// The engines are expected to copy a value pointed by depth, and push the -// copied value onto the top of the stack. -// -// depth is the location of the pick target in the uint64 value stack at runtime. -// If isTargetVector=true, this points to the location of the lower 64-bits of the vector. -func NewOperationPick(depth int, isTargetVector bool) UnionOperation { - return UnionOperation{Kind: OperationKindPick, U1: uint64(depth), B3: isTargetVector} -} - -// NewOperationSet is a constructor for UnionOperation with OperationKindSet. -// -// The engines are expected to set the top value of the stack to the location specified by -// depth. -// -// depth is the location of the set target in the uint64 value stack at runtime. -// If isTargetVector=true, this points the location of the lower 64-bits of the vector. -func NewOperationSet(depth int, isTargetVector bool) UnionOperation { - return UnionOperation{Kind: OperationKindSet, U1: uint64(depth), B3: isTargetVector} -} - -// NewOperationGlobalGet is a constructor for UnionOperation with OperationKindGlobalGet. -// -// The engines are expected to read the global value specified by OperationGlobalGet.Index, -// and push the copy of the value onto the stack. -// -// See wasm.OpcodeGlobalGet. -func NewOperationGlobalGet(index uint32) UnionOperation { - return UnionOperation{Kind: OperationKindGlobalGet, U1: uint64(index)} -} - -// NewOperationGlobalSet is a constructor for UnionOperation with OperationKindGlobalSet. -// -// The engines are expected to consume the value from the top of the stack, -// and write the value into the global specified by OperationGlobalSet.Index. -// -// See wasm.OpcodeGlobalSet. -func NewOperationGlobalSet(index uint32) UnionOperation { - return UnionOperation{Kind: OperationKindGlobalSet, U1: uint64(index)} -} - -// MemoryArg is the "memarg" to all memory instructions. -// -// See https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/#memory-instructions%E2%91%A0 -type MemoryArg struct { - // Alignment the expected alignment (expressed as the exponent of a power of 2). Default to the natural alignment. - // - // "Natural alignment" is defined here as the smallest power of two that can hold the size of the value type. Ex - // wasm.ValueTypeI64 is encoded in 8 little-endian bytes. 2^3 = 8, so the natural alignment is three. - Alignment uint32 - - // Offset is the address offset added to the instruction's dynamic address operand, yielding a 33-bit effective - // address that is the zero-based index at which the memory is accessed. Default to zero. - Offset uint32 -} - -// NewOperationLoad is a constructor for UnionOperation with OperationKindLoad. -// -// This corresponds to wasm.OpcodeI32LoadName wasm.OpcodeI64LoadName wasm.OpcodeF32LoadName and wasm.OpcodeF64LoadName. -// -// The engines are expected to check the boundary of memory length, and exit the execution if this exceeds the boundary, -// otherwise load the corresponding value following the semantics of the corresponding WebAssembly instruction. -func NewOperationLoad(unsignedType UnsignedType, arg MemoryArg) UnionOperation { - return UnionOperation{Kind: OperationKindLoad, B1: byte(unsignedType), U1: uint64(arg.Alignment), U2: uint64(arg.Offset)} -} - -// NewOperationLoad8 is a constructor for UnionOperation with OperationKindLoad8. -// -// This corresponds to wasm.OpcodeI32Load8SName wasm.OpcodeI32Load8UName wasm.OpcodeI64Load8SName wasm.OpcodeI64Load8UName. -// -// The engines are expected to check the boundary of memory length, and exit the execution if this exceeds the boundary, -// otherwise load the corresponding value following the semantics of the corresponding WebAssembly instruction. -func NewOperationLoad8(signedInt SignedInt, arg MemoryArg) UnionOperation { - return UnionOperation{Kind: OperationKindLoad8, B1: byte(signedInt), U1: uint64(arg.Alignment), U2: uint64(arg.Offset)} -} - -// NewOperationLoad16 is a constructor for UnionOperation with OperationKindLoad16. -// -// This corresponds to wasm.OpcodeI32Load16SName wasm.OpcodeI32Load16UName wasm.OpcodeI64Load16SName wasm.OpcodeI64Load16UName. -// -// The engines are expected to check the boundary of memory length, and exit the execution if this exceeds the boundary, -// otherwise load the corresponding value following the semantics of the corresponding WebAssembly instruction. -func NewOperationLoad16(signedInt SignedInt, arg MemoryArg) UnionOperation { - return UnionOperation{Kind: OperationKindLoad16, B1: byte(signedInt), U1: uint64(arg.Alignment), U2: uint64(arg.Offset)} -} - -// NewOperationLoad32 is a constructor for UnionOperation with OperationKindLoad32. -// -// This corresponds to wasm.OpcodeI64Load32SName wasm.OpcodeI64Load32UName. -// -// The engines are expected to check the boundary of memory length, and exit the execution if this exceeds the boundary, -// otherwise load the corresponding value following the semantics of the corresponding WebAssembly instruction. -func NewOperationLoad32(signed bool, arg MemoryArg) UnionOperation { - sigB := byte(0) - if signed { - sigB = 1 - } - return UnionOperation{Kind: OperationKindLoad32, B1: sigB, U1: uint64(arg.Alignment), U2: uint64(arg.Offset)} -} - -// NewOperationStore is a constructor for UnionOperation with OperationKindStore. -// -// # This corresponds to wasm.OpcodeI32StoreName wasm.OpcodeI64StoreName wasm.OpcodeF32StoreName wasm.OpcodeF64StoreName -// -// The engines are expected to check the boundary of memory length, and exit the execution if this exceeds the boundary, -// otherwise store the corresponding value following the semantics of the corresponding WebAssembly instruction. -func NewOperationStore(unsignedType UnsignedType, arg MemoryArg) UnionOperation { - return UnionOperation{Kind: OperationKindStore, B1: byte(unsignedType), U1: uint64(arg.Alignment), U2: uint64(arg.Offset)} -} - -// NewOperationStore8 is a constructor for UnionOperation with OperationKindStore8. -// -// # This corresponds to wasm.OpcodeI32Store8Name wasm.OpcodeI64Store8Name -// -// The engines are expected to check the boundary of memory length, and exit the execution if this exceeds the boundary, -// otherwise store the corresponding value following the semantics of the corresponding WebAssembly instruction. -func NewOperationStore8(arg MemoryArg) UnionOperation { - return UnionOperation{Kind: OperationKindStore8, U1: uint64(arg.Alignment), U2: uint64(arg.Offset)} -} - -// NewOperationStore16 is a constructor for UnionOperation with OperationKindStore16. -// -// # This corresponds to wasm.OpcodeI32Store16Name wasm.OpcodeI64Store16Name -// -// The engines are expected to check the boundary of memory length, and exit the execution if this exceeds the boundary, -// otherwise store the corresponding value following the semantics of the corresponding WebAssembly instruction. -func NewOperationStore16(arg MemoryArg) UnionOperation { - return UnionOperation{Kind: OperationKindStore16, U1: uint64(arg.Alignment), U2: uint64(arg.Offset)} -} - -// NewOperationStore32 is a constructor for UnionOperation with OperationKindStore32. -// -// # This corresponds to wasm.OpcodeI64Store32Name -// -// The engines are expected to check the boundary of memory length, and exit the execution if this exceeds the boundary, -// otherwise store the corresponding value following the semantics of the corresponding WebAssembly instruction. -func NewOperationStore32(arg MemoryArg) UnionOperation { - return UnionOperation{Kind: OperationKindStore32, U1: uint64(arg.Alignment), U2: uint64(arg.Offset)} -} - -// NewOperationMemorySize is a constructor for UnionOperation with OperationKindMemorySize. -// -// This corresponds to wasm.OpcodeMemorySize. -// -// The engines are expected to push the current page size of the memory onto the stack. -func NewOperationMemorySize() UnionOperation { - return UnionOperation{Kind: OperationKindMemorySize} -} - -// NewOperationMemoryGrow is a constructor for UnionOperation with OperationKindMemoryGrow. -// -// This corresponds to wasm.OpcodeMemoryGrow. -// -// The engines are expected to pop one value from the top of the stack, then -// execute wasm.MemoryInstance Grow with the value, and push the previous -// page size of the memory onto the stack. -func NewOperationMemoryGrow() UnionOperation { - return UnionOperation{Kind: OperationKindMemoryGrow} -} - -// NewOperationConstI32 is a constructor for UnionOperation with OperationConstI32. -// -// This corresponds to wasm.OpcodeI32Const. -func NewOperationConstI32(value uint32) UnionOperation { - return UnionOperation{Kind: OperationKindConstI32, U1: uint64(value)} -} - -// NewOperationConstI64 is a constructor for UnionOperation with OperationConstI64. -// -// This corresponds to wasm.OpcodeI64Const. -func NewOperationConstI64(value uint64) UnionOperation { - return UnionOperation{Kind: OperationKindConstI64, U1: value} -} - -// NewOperationConstF32 is a constructor for UnionOperation with OperationConstF32. -// -// This corresponds to wasm.OpcodeF32Const. -func NewOperationConstF32(value float32) UnionOperation { - return UnionOperation{Kind: OperationKindConstF32, U1: uint64(math.Float32bits(value))} -} - -// NewOperationConstF64 is a constructor for UnionOperation with OperationConstF64. -// -// This corresponds to wasm.OpcodeF64Const. -func NewOperationConstF64(value float64) UnionOperation { - return UnionOperation{Kind: OperationKindConstF64, U1: math.Float64bits(value)} -} - -// NewOperationEq is a constructor for UnionOperation with OperationKindEq. -// -// This corresponds to wasm.OpcodeI32EqName wasm.OpcodeI64EqName wasm.OpcodeF32EqName wasm.OpcodeF64EqName -func NewOperationEq(b UnsignedType) UnionOperation { - return UnionOperation{Kind: OperationKindEq, B1: byte(b)} -} - -// NewOperationNe is a constructor for UnionOperation with OperationKindNe. -// -// This corresponds to wasm.OpcodeI32NeName wasm.OpcodeI64NeName wasm.OpcodeF32NeName wasm.OpcodeF64NeName -func NewOperationNe(b UnsignedType) UnionOperation { - return UnionOperation{Kind: OperationKindNe, B1: byte(b)} -} - -// NewOperationEqz is a constructor for UnionOperation with OperationKindEqz. -// -// This corresponds to wasm.OpcodeI32EqzName wasm.OpcodeI64EqzName -func NewOperationEqz(b UnsignedInt) UnionOperation { - return UnionOperation{Kind: OperationKindEqz, B1: byte(b)} -} - -// NewOperationLt is a constructor for UnionOperation with OperationKindLt. -// -// This corresponds to wasm.OpcodeI32LtS wasm.OpcodeI32LtU wasm.OpcodeI64LtS wasm.OpcodeI64LtU wasm.OpcodeF32Lt wasm.OpcodeF64Lt -func NewOperationLt(b SignedType) UnionOperation { - return UnionOperation{Kind: OperationKindLt, B1: byte(b)} -} - -// NewOperationGt is a constructor for UnionOperation with OperationKindGt. -// -// This corresponds to wasm.OpcodeI32GtS wasm.OpcodeI32GtU wasm.OpcodeI64GtS wasm.OpcodeI64GtU wasm.OpcodeF32Gt wasm.OpcodeF64Gt -func NewOperationGt(b SignedType) UnionOperation { - return UnionOperation{Kind: OperationKindGt, B1: byte(b)} -} - -// NewOperationLe is a constructor for UnionOperation with OperationKindLe. -// -// This corresponds to wasm.OpcodeI32LeS wasm.OpcodeI32LeU wasm.OpcodeI64LeS wasm.OpcodeI64LeU wasm.OpcodeF32Le wasm.OpcodeF64Le -func NewOperationLe(b SignedType) UnionOperation { - return UnionOperation{Kind: OperationKindLe, B1: byte(b)} -} - -// NewOperationGe is a constructor for UnionOperation with OperationKindGe. -// -// This corresponds to wasm.OpcodeI32GeS wasm.OpcodeI32GeU wasm.OpcodeI64GeS wasm.OpcodeI64GeU wasm.OpcodeF32Ge wasm.OpcodeF64Ge -// NewOperationGe is the constructor for OperationGe -func NewOperationGe(b SignedType) UnionOperation { - return UnionOperation{Kind: OperationKindGe, B1: byte(b)} -} - -// NewOperationAdd is a constructor for UnionOperation with OperationKindAdd. -// -// This corresponds to wasm.OpcodeI32AddName wasm.OpcodeI64AddName wasm.OpcodeF32AddName wasm.OpcodeF64AddName. -func NewOperationAdd(b UnsignedType) UnionOperation { - return UnionOperation{Kind: OperationKindAdd, B1: byte(b)} -} - -// NewOperationSub is a constructor for UnionOperation with OperationKindSub. -// -// This corresponds to wasm.OpcodeI32SubName wasm.OpcodeI64SubName wasm.OpcodeF32SubName wasm.OpcodeF64SubName. -func NewOperationSub(b UnsignedType) UnionOperation { - return UnionOperation{Kind: OperationKindSub, B1: byte(b)} -} - -// NewOperationMul is a constructor for UnionOperation with wperationKindMul. -// -// This corresponds to wasm.OpcodeI32MulName wasm.OpcodeI64MulName wasm.OpcodeF32MulName wasm.OpcodeF64MulName. -// NewOperationMul is the constructor for OperationMul -func NewOperationMul(b UnsignedType) UnionOperation { - return UnionOperation{Kind: OperationKindMul, B1: byte(b)} -} - -// NewOperationClz is a constructor for UnionOperation with OperationKindClz. -// -// This corresponds to wasm.OpcodeI32ClzName wasm.OpcodeI64ClzName. -// -// The engines are expected to count up the leading zeros in the -// current top of the stack, and push the count result. -// For example, stack of [..., 0x00_ff_ff_ff] results in [..., 8]. -// See wasm.OpcodeI32Clz wasm.OpcodeI64Clz -func NewOperationClz(b UnsignedInt) UnionOperation { - return UnionOperation{Kind: OperationKindClz, B1: byte(b)} -} - -// NewOperationCtz is a constructor for UnionOperation with OperationKindCtz. -// -// This corresponds to wasm.OpcodeI32CtzName wasm.OpcodeI64CtzName. -// -// The engines are expected to count up the trailing zeros in the -// current top of the stack, and push the count result. -// For example, stack of [..., 0xff_ff_ff_00] results in [..., 8]. -func NewOperationCtz(b UnsignedInt) UnionOperation { - return UnionOperation{Kind: OperationKindCtz, B1: byte(b)} -} - -// NewOperationPopcnt is a constructor for UnionOperation with OperationKindPopcnt. -// -// This corresponds to wasm.OpcodeI32PopcntName wasm.OpcodeI64PopcntName. -// -// The engines are expected to count up the number of set bits in the -// current top of the stack, and push the count result. -// For example, stack of [..., 0b00_00_00_11] results in [..., 2]. -func NewOperationPopcnt(b UnsignedInt) UnionOperation { - return UnionOperation{Kind: OperationKindPopcnt, B1: byte(b)} -} - -// NewOperationDiv is a constructor for UnionOperation with OperationKindDiv. -// -// This corresponds to wasm.OpcodeI32DivS wasm.OpcodeI32DivU wasm.OpcodeI64DivS -// -// wasm.OpcodeI64DivU wasm.OpcodeF32Div wasm.OpcodeF64Div. -func NewOperationDiv(b SignedType) UnionOperation { - return UnionOperation{Kind: OperationKindDiv, B1: byte(b)} -} - -// NewOperationRem is a constructor for UnionOperation with OperationKindRem. -// -// This corresponds to wasm.OpcodeI32RemS wasm.OpcodeI32RemU wasm.OpcodeI64RemS wasm.OpcodeI64RemU. -// -// The engines are expected to perform division on the top -// two values of integer type on the stack and puts the remainder of the result -// onto the stack. For example, stack [..., 10, 3] results in [..., 1] where -// the quotient is discarded. -// NewOperationRem is the constructor for OperationRem -func NewOperationRem(b SignedInt) UnionOperation { - return UnionOperation{Kind: OperationKindRem, B1: byte(b)} -} - -// NewOperationAnd is a constructor for UnionOperation with OperationKindAnd. -// -// # This corresponds to wasm.OpcodeI32AndName wasm.OpcodeI64AndName -// -// The engines are expected to perform "And" operation on -// top two values on the stack, and pushes the result. -func NewOperationAnd(b UnsignedInt) UnionOperation { - return UnionOperation{Kind: OperationKindAnd, B1: byte(b)} -} - -// NewOperationOr is a constructor for UnionOperation with OperationKindOr. -// -// # This corresponds to wasm.OpcodeI32OrName wasm.OpcodeI64OrName -// -// The engines are expected to perform "Or" operation on -// top two values on the stack, and pushes the result. -func NewOperationOr(b UnsignedInt) UnionOperation { - return UnionOperation{Kind: OperationKindOr, B1: byte(b)} -} - -// NewOperationXor is a constructor for UnionOperation with OperationKindXor. -// -// # This corresponds to wasm.OpcodeI32XorName wasm.OpcodeI64XorName -// -// The engines are expected to perform "Xor" operation on -// top two values on the stack, and pushes the result. -func NewOperationXor(b UnsignedInt) UnionOperation { - return UnionOperation{Kind: OperationKindXor, B1: byte(b)} -} - -// NewOperationShl is a constructor for UnionOperation with OperationKindShl. -// -// # This corresponds to wasm.OpcodeI32ShlName wasm.OpcodeI64ShlName -// -// The engines are expected to perform "Shl" operation on -// top two values on the stack, and pushes the result. -func NewOperationShl(b UnsignedInt) UnionOperation { - return UnionOperation{Kind: OperationKindShl, B1: byte(b)} -} - -// NewOperationShr is a constructor for UnionOperation with OperationKindShr. -// -// # This corresponds to wasm.OpcodeI32ShrSName wasm.OpcodeI32ShrUName wasm.OpcodeI64ShrSName wasm.OpcodeI64ShrUName -// -// If OperationShr.Type is signed integer, then, the engines are expected to perform arithmetic right shift on the two -// top values on the stack, otherwise do the logical right shift. -func NewOperationShr(b SignedInt) UnionOperation { - return UnionOperation{Kind: OperationKindShr, B1: byte(b)} -} - -// NewOperationRotl is a constructor for UnionOperation with OperationKindRotl. -// -// # This corresponds to wasm.OpcodeI32RotlName wasm.OpcodeI64RotlName -// -// The engines are expected to perform "Rotl" operation on -// top two values on the stack, and pushes the result. -func NewOperationRotl(b UnsignedInt) UnionOperation { - return UnionOperation{Kind: OperationKindRotl, B1: byte(b)} -} - -// NewOperationRotr is a constructor for UnionOperation with OperationKindRotr. -// -// # This corresponds to wasm.OpcodeI32RotrName wasm.OpcodeI64RotrName -// -// The engines are expected to perform "Rotr" operation on -// top two values on the stack, and pushes the result. -func NewOperationRotr(b UnsignedInt) UnionOperation { - return UnionOperation{Kind: OperationKindRotr, B1: byte(b)} -} - -// NewOperationAbs is a constructor for UnionOperation with OperationKindAbs. -// -// This corresponds to wasm.OpcodeF32Abs wasm.OpcodeF64Abs -func NewOperationAbs(b Float) UnionOperation { - return UnionOperation{Kind: OperationKindAbs, B1: byte(b)} -} - -// NewOperationNeg is a constructor for UnionOperation with OperationKindNeg. -// -// This corresponds to wasm.OpcodeF32Neg wasm.OpcodeF64Neg -func NewOperationNeg(b Float) UnionOperation { - return UnionOperation{Kind: OperationKindNeg, B1: byte(b)} -} - -// NewOperationCeil is a constructor for UnionOperation with OperationKindCeil. -// -// This corresponds to wasm.OpcodeF32CeilName wasm.OpcodeF64CeilName -func NewOperationCeil(b Float) UnionOperation { - return UnionOperation{Kind: OperationKindCeil, B1: byte(b)} -} - -// NewOperationFloor is a constructor for UnionOperation with OperationKindFloor. -// -// This corresponds to wasm.OpcodeF32FloorName wasm.OpcodeF64FloorName -func NewOperationFloor(b Float) UnionOperation { - return UnionOperation{Kind: OperationKindFloor, B1: byte(b)} -} - -// NewOperationTrunc is a constructor for UnionOperation with OperationKindTrunc. -// -// This corresponds to wasm.OpcodeF32TruncName wasm.OpcodeF64TruncName -func NewOperationTrunc(b Float) UnionOperation { - return UnionOperation{Kind: OperationKindTrunc, B1: byte(b)} -} - -// NewOperationNearest is a constructor for UnionOperation with OperationKindNearest. -// -// # This corresponds to wasm.OpcodeF32NearestName wasm.OpcodeF64NearestName -// -// Note: this is *not* equivalent to math.Round and instead has the same -// the semantics of LLVM's rint intrinsic. See https://llvm.org/docs/LangRef.html#llvm-rint-intrinsic. -// For example, math.Round(-4.5) produces -5 while we want to produce -4. -func NewOperationNearest(b Float) UnionOperation { - return UnionOperation{Kind: OperationKindNearest, B1: byte(b)} -} - -// NewOperationSqrt is a constructor for UnionOperation with OperationKindSqrt. -// -// This corresponds to wasm.OpcodeF32SqrtName wasm.OpcodeF64SqrtName -func NewOperationSqrt(b Float) UnionOperation { - return UnionOperation{Kind: OperationKindSqrt, B1: byte(b)} -} - -// NewOperationMin is a constructor for UnionOperation with OperationKindMin. -// -// # This corresponds to wasm.OpcodeF32MinName wasm.OpcodeF64MinName -// -// The engines are expected to pop two values from the stack, and push back the maximum of -// these two values onto the stack. For example, stack [..., 100.1, 1.9] results in [..., 1.9]. -// -// Note: WebAssembly specifies that min/max must always return NaN if one of values is NaN, -// which is a different behavior different from math.Min. -func NewOperationMin(b Float) UnionOperation { - return UnionOperation{Kind: OperationKindMin, B1: byte(b)} -} - -// NewOperationMax is a constructor for UnionOperation with OperationKindMax. -// -// # This corresponds to wasm.OpcodeF32MaxName wasm.OpcodeF64MaxName -// -// The engines are expected to pop two values from the stack, and push back the maximum of -// these two values onto the stack. For example, stack [..., 100.1, 1.9] results in [..., 100.1]. -// -// Note: WebAssembly specifies that min/max must always return NaN if one of values is NaN, -// which is a different behavior different from math.Max. -func NewOperationMax(b Float) UnionOperation { - return UnionOperation{Kind: OperationKindMax, B1: byte(b)} -} - -// NewOperationCopysign is a constructor for UnionOperation with OperationKindCopysign. -// -// # This corresponds to wasm.OpcodeF32CopysignName wasm.OpcodeF64CopysignName -// -// The engines are expected to pop two float values from the stack, and copy the signbit of -// the first-popped value to the last one. -// For example, stack [..., 1.213, -5.0] results in [..., -1.213]. -func NewOperationCopysign(b Float) UnionOperation { - return UnionOperation{Kind: OperationKindCopysign, B1: byte(b)} -} - -// NewOperationI32WrapFromI64 is a constructor for UnionOperation with OperationKindI32WrapFromI64. -// -// This corresponds to wasm.OpcodeI32WrapI64 and equivalent to uint64(uint32(v)) in Go. -// -// The engines are expected to replace the 64-bit int on top of the stack -// with the corresponding 32-bit integer. -func NewOperationI32WrapFromI64() UnionOperation { - return UnionOperation{Kind: OperationKindI32WrapFromI64} -} - -// NewOperationITruncFromF is a constructor for UnionOperation with OperationKindITruncFromF. -// -// This corresponds to -// -// wasm.OpcodeI32TruncF32SName wasm.OpcodeI32TruncF32UName wasm.OpcodeI32TruncF64SName -// wasm.OpcodeI32TruncF64UName wasm.OpcodeI64TruncF32SName wasm.OpcodeI64TruncF32UName wasm.OpcodeI64TruncF64SName -// wasm.OpcodeI64TruncF64UName. wasm.OpcodeI32TruncSatF32SName wasm.OpcodeI32TruncSatF32UName -// wasm.OpcodeI32TruncSatF64SName wasm.OpcodeI32TruncSatF64UName wasm.OpcodeI64TruncSatF32SName -// wasm.OpcodeI64TruncSatF32UName wasm.OpcodeI64TruncSatF64SName wasm.OpcodeI64TruncSatF64UName -// -// See [1] and [2] for when we encounter undefined behavior in the WebAssembly specification if NewOperationITruncFromF.NonTrapping == false. -// To summarize, if the source float value is NaN or doesn't fit in the destination range of integers (incl. +=Inf), -// then the runtime behavior is undefined. In wazero, the engines are expected to exit the execution in these undefined cases with -// wasmruntime.ErrRuntimeInvalidConversionToInteger error. -// -// [1] https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/#-hrefop-trunc-umathrmtruncmathsfu_m-n-z for unsigned integers. -// [2] https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/#-hrefop-trunc-smathrmtruncmathsfs_m-n-z for signed integers. -// -// nonTrapping true if this conversion is "nontrapping" in the sense of the -// https://github.com/WebAssembly/spec/blob/ce4b6c4d47eb06098cc7ab2e81f24748da822f20/proposals/nontrapping-float-to-int-conversion/Overview.md -func NewOperationITruncFromF(inputType Float, outputType SignedInt, nonTrapping bool) UnionOperation { - return UnionOperation{ - Kind: OperationKindITruncFromF, - B1: byte(inputType), - B2: byte(outputType), - B3: nonTrapping, - } -} - -// NewOperationFConvertFromI is a constructor for UnionOperation with OperationKindFConvertFromI. -// -// This corresponds to -// -// wasm.OpcodeF32ConvertI32SName wasm.OpcodeF32ConvertI32UName wasm.OpcodeF32ConvertI64SName wasm.OpcodeF32ConvertI64UName -// wasm.OpcodeF64ConvertI32SName wasm.OpcodeF64ConvertI32UName wasm.OpcodeF64ConvertI64SName wasm.OpcodeF64ConvertI64UName -// -// and equivalent to float32(uint32(x)), float32(int32(x)), etc in Go. -func NewOperationFConvertFromI(inputType SignedInt, outputType Float) UnionOperation { - return UnionOperation{ - Kind: OperationKindFConvertFromI, - B1: byte(inputType), - B2: byte(outputType), - } -} - -// NewOperationF32DemoteFromF64 is a constructor for UnionOperation with OperationKindF32DemoteFromF64. -// -// This corresponds to wasm.OpcodeF32DemoteF64 and is equivalent float32(float64(v)). -func NewOperationF32DemoteFromF64() UnionOperation { - return UnionOperation{Kind: OperationKindF32DemoteFromF64} -} - -// NewOperationF64PromoteFromF32 is a constructor for UnionOperation with OperationKindF64PromoteFromF32. -// -// This corresponds to wasm.OpcodeF64PromoteF32 and is equivalent float64(float32(v)). -func NewOperationF64PromoteFromF32() UnionOperation { - return UnionOperation{Kind: OperationKindF64PromoteFromF32} -} - -// NewOperationI32ReinterpretFromF32 is a constructor for UnionOperation with OperationKindI32ReinterpretFromF32. -// -// This corresponds to wasm.OpcodeI32ReinterpretF32Name. -func NewOperationI32ReinterpretFromF32() UnionOperation { - return UnionOperation{Kind: OperationKindI32ReinterpretFromF32} -} - -// NewOperationI64ReinterpretFromF64 is a constructor for UnionOperation with OperationKindI64ReinterpretFromF64. -// -// This corresponds to wasm.OpcodeI64ReinterpretF64Name. -func NewOperationI64ReinterpretFromF64() UnionOperation { - return UnionOperation{Kind: OperationKindI64ReinterpretFromF64} -} - -// NewOperationF32ReinterpretFromI32 is a constructor for UnionOperation with OperationKindF32ReinterpretFromI32. -// -// This corresponds to wasm.OpcodeF32ReinterpretI32Name. -func NewOperationF32ReinterpretFromI32() UnionOperation { - return UnionOperation{Kind: OperationKindF32ReinterpretFromI32} -} - -// NewOperationF64ReinterpretFromI64 is a constructor for UnionOperation with OperationKindF64ReinterpretFromI64. -// -// This corresponds to wasm.OpcodeF64ReinterpretI64Name. -func NewOperationF64ReinterpretFromI64() UnionOperation { - return UnionOperation{Kind: OperationKindF64ReinterpretFromI64} -} - -// NewOperationExtend is a constructor for UnionOperation with OperationKindExtend. -// -// # This corresponds to wasm.OpcodeI64ExtendI32SName wasm.OpcodeI64ExtendI32UName -// -// The engines are expected to extend the 32-bit signed or unsigned int on top of the stack -// as a 64-bit integer of corresponding signedness. For unsigned case, this is just reinterpreting the -// underlying bit pattern as 64-bit integer. For signed case, this is sign-extension which preserves the -// original integer's sign. -func NewOperationExtend(signed bool) UnionOperation { - op := UnionOperation{Kind: OperationKindExtend} - if signed { - op.B1 = 1 - } - return op -} - -// NewOperationSignExtend32From8 is a constructor for UnionOperation with OperationKindSignExtend32From8. -// -// This corresponds to wasm.OpcodeI32Extend8SName. -// -// The engines are expected to sign-extend the first 8-bits of 32-bit in as signed 32-bit int. -func NewOperationSignExtend32From8() UnionOperation { - return UnionOperation{Kind: OperationKindSignExtend32From8} -} - -// NewOperationSignExtend32From16 is a constructor for UnionOperation with OperationKindSignExtend32From16. -// -// This corresponds to wasm.OpcodeI32Extend16SName. -// -// The engines are expected to sign-extend the first 16-bits of 32-bit in as signed 32-bit int. -func NewOperationSignExtend32From16() UnionOperation { - return UnionOperation{Kind: OperationKindSignExtend32From16} -} - -// NewOperationSignExtend64From8 is a constructor for UnionOperation with OperationKindSignExtend64From8. -// -// This corresponds to wasm.OpcodeI64Extend8SName. -// -// The engines are expected to sign-extend the first 8-bits of 64-bit in as signed 32-bit int. -func NewOperationSignExtend64From8() UnionOperation { - return UnionOperation{Kind: OperationKindSignExtend64From8} -} - -// NewOperationSignExtend64From16 is a constructor for UnionOperation with OperationKindSignExtend64From16. -// -// This corresponds to wasm.OpcodeI64Extend16SName. -// -// The engines are expected to sign-extend the first 16-bits of 64-bit in as signed 32-bit int. -func NewOperationSignExtend64From16() UnionOperation { - return UnionOperation{Kind: OperationKindSignExtend64From16} -} - -// NewOperationSignExtend64From32 is a constructor for UnionOperation with OperationKindSignExtend64From32. -// -// This corresponds to wasm.OpcodeI64Extend32SName. -// -// The engines are expected to sign-extend the first 32-bits of 64-bit in as signed 32-bit int. -func NewOperationSignExtend64From32() UnionOperation { - return UnionOperation{Kind: OperationKindSignExtend64From32} -} - -// NewOperationMemoryInit is a constructor for UnionOperation with OperationKindMemoryInit. -// -// This corresponds to wasm.OpcodeMemoryInitName. -// -// dataIndex is the index of the data instance in ModuleInstance.DataInstances -// by which this operation instantiates a part of the memory. -func NewOperationMemoryInit(dataIndex uint32) UnionOperation { - return UnionOperation{Kind: OperationKindMemoryInit, U1: uint64(dataIndex)} -} - -// NewOperationDataDrop implements Operation. -// -// This corresponds to wasm.OpcodeDataDropName. -// -// dataIndex is the index of the data instance in ModuleInstance.DataInstances -// which this operation drops. -func NewOperationDataDrop(dataIndex uint32) UnionOperation { - return UnionOperation{Kind: OperationKindDataDrop, U1: uint64(dataIndex)} -} - -// NewOperationMemoryCopy is a consuctor for UnionOperation with OperationKindMemoryCopy. -// -// This corresponds to wasm.OpcodeMemoryCopyName. -func NewOperationMemoryCopy() UnionOperation { - return UnionOperation{Kind: OperationKindMemoryCopy} -} - -// NewOperationMemoryFill is a consuctor for UnionOperation with OperationKindMemoryFill. -func NewOperationMemoryFill() UnionOperation { - return UnionOperation{Kind: OperationKindMemoryFill} -} - -// NewOperationTableInit is a constructor for UnionOperation with OperationKindTableInit. -// -// This corresponds to wasm.OpcodeTableInitName. -// -// elemIndex is the index of the element by which this operation initializes a part of the table. -// tableIndex is the index of the table on which this operation initialize by the target element. -func NewOperationTableInit(elemIndex, tableIndex uint32) UnionOperation { - return UnionOperation{Kind: OperationKindTableInit, U1: uint64(elemIndex), U2: uint64(tableIndex)} -} - -// NewOperationElemDrop is a constructor for UnionOperation with OperationKindElemDrop. -// -// This corresponds to wasm.OpcodeElemDropName. -// -// elemIndex is the index of the element which this operation drops. -func NewOperationElemDrop(elemIndex uint32) UnionOperation { - return UnionOperation{Kind: OperationKindElemDrop, U1: uint64(elemIndex)} -} - -// NewOperationTableCopy implements Operation. -// -// This corresponds to wasm.OpcodeTableCopyName. -func NewOperationTableCopy(srcTableIndex, dstTableIndex uint32) UnionOperation { - return UnionOperation{Kind: OperationKindTableCopy, U1: uint64(srcTableIndex), U2: uint64(dstTableIndex)} -} - -// NewOperationRefFunc constructor for UnionOperation with OperationKindRefFunc. -// -// This corresponds to wasm.OpcodeRefFuncName, and engines are expected to -// push the opaque pointer value of engine specific func for the given FunctionIndex. -// -// Note: in wazero, we express any reference types (funcref or externref) as opaque pointers which is uint64. -// Therefore, the engine implementations emit instructions to push the address of *function onto the stack. -func NewOperationRefFunc(functionIndex uint32) UnionOperation { - return UnionOperation{Kind: OperationKindRefFunc, U1: uint64(functionIndex)} -} - -// NewOperationTableGet constructor for UnionOperation with OperationKindTableGet. -// -// This corresponds to wasm.OpcodeTableGetName. -func NewOperationTableGet(tableIndex uint32) UnionOperation { - return UnionOperation{Kind: OperationKindTableGet, U1: uint64(tableIndex)} -} - -// NewOperationTableSet constructor for UnionOperation with OperationKindTableSet. -// -// This corresponds to wasm.OpcodeTableSetName. -func NewOperationTableSet(tableIndex uint32) UnionOperation { - return UnionOperation{Kind: OperationKindTableSet, U1: uint64(tableIndex)} -} - -// NewOperationTableSize constructor for UnionOperation with OperationKindTableSize. -// -// This corresponds to wasm.OpcodeTableSizeName. -func NewOperationTableSize(tableIndex uint32) UnionOperation { - return UnionOperation{Kind: OperationKindTableSize, U1: uint64(tableIndex)} -} - -// NewOperationTableGrow constructor for UnionOperation with OperationKindTableGrow. -// -// This corresponds to wasm.OpcodeTableGrowName. -func NewOperationTableGrow(tableIndex uint32) UnionOperation { - return UnionOperation{Kind: OperationKindTableGrow, U1: uint64(tableIndex)} -} - -// NewOperationTableFill constructor for UnionOperation with OperationKindTableFill. -// -// This corresponds to wasm.OpcodeTableFillName. -func NewOperationTableFill(tableIndex uint32) UnionOperation { - return UnionOperation{Kind: OperationKindTableFill, U1: uint64(tableIndex)} -} - -// NewOperationV128Const constructor for UnionOperation with OperationKindV128Const -func NewOperationV128Const(lo, hi uint64) UnionOperation { - return UnionOperation{Kind: OperationKindV128Const, U1: lo, U2: hi} -} - -// Shape corresponds to a shape of v128 values. -// https://webassembly.github.io/spec/core/syntax/instructions.html#syntax-shape -type Shape = byte - -const ( - ShapeI8x16 Shape = iota - ShapeI16x8 - ShapeI32x4 - ShapeI64x2 - ShapeF32x4 - ShapeF64x2 -) - -func shapeName(s Shape) (ret string) { - switch s { - case ShapeI8x16: - ret = "I8x16" - case ShapeI16x8: - ret = "I16x8" - case ShapeI32x4: - ret = "I32x4" - case ShapeI64x2: - ret = "I64x2" - case ShapeF32x4: - ret = "F32x4" - case ShapeF64x2: - ret = "F64x2" - } - return -} - -// NewOperationV128Add constructor for UnionOperation with OperationKindV128Add. -// -// This corresponds to wasm.OpcodeVecI8x16AddName wasm.OpcodeVecI16x8AddName wasm.OpcodeVecI32x4AddName -// -// wasm.OpcodeVecI64x2AddName wasm.OpcodeVecF32x4AddName wasm.OpcodeVecF64x2AddName -func NewOperationV128Add(shape Shape) UnionOperation { - return UnionOperation{Kind: OperationKindV128Add, B1: shape} -} - -// NewOperationV128Sub constructor for UnionOperation with OperationKindV128Sub. -// -// This corresponds to wasm.OpcodeVecI8x16SubName wasm.OpcodeVecI16x8SubName wasm.OpcodeVecI32x4SubName -// -// wasm.OpcodeVecI64x2SubName wasm.OpcodeVecF32x4SubName wasm.OpcodeVecF64x2SubName -func NewOperationV128Sub(shape Shape) UnionOperation { - return UnionOperation{Kind: OperationKindV128Sub, B1: shape} -} - -// V128LoadType represents a type of wasm.OpcodeVecV128Load* instructions. -type V128LoadType = byte - -const ( - // V128LoadType128 corresponds to wasm.OpcodeVecV128LoadName. - V128LoadType128 V128LoadType = iota - // V128LoadType8x8s corresponds to wasm.OpcodeVecV128Load8x8SName. - V128LoadType8x8s - // V128LoadType8x8u corresponds to wasm.OpcodeVecV128Load8x8UName. - V128LoadType8x8u - // V128LoadType16x4s corresponds to wasm.OpcodeVecV128Load16x4SName - V128LoadType16x4s - // V128LoadType16x4u corresponds to wasm.OpcodeVecV128Load16x4UName - V128LoadType16x4u - // V128LoadType32x2s corresponds to wasm.OpcodeVecV128Load32x2SName - V128LoadType32x2s - // V128LoadType32x2u corresponds to wasm.OpcodeVecV128Load32x2UName - V128LoadType32x2u - // V128LoadType8Splat corresponds to wasm.OpcodeVecV128Load8SplatName - V128LoadType8Splat - // V128LoadType16Splat corresponds to wasm.OpcodeVecV128Load16SplatName - V128LoadType16Splat - // V128LoadType32Splat corresponds to wasm.OpcodeVecV128Load32SplatName - V128LoadType32Splat - // V128LoadType64Splat corresponds to wasm.OpcodeVecV128Load64SplatName - V128LoadType64Splat - // V128LoadType32zero corresponds to wasm.OpcodeVecV128Load32zeroName - V128LoadType32zero - // V128LoadType64zero corresponds to wasm.OpcodeVecV128Load64zeroName - V128LoadType64zero -) - -// NewOperationV128Load is a constructor for UnionOperation with OperationKindV128Load. -// -// This corresponds to -// -// wasm.OpcodeVecV128LoadName wasm.OpcodeVecV128Load8x8SName wasm.OpcodeVecV128Load8x8UName -// wasm.OpcodeVecV128Load16x4SName wasm.OpcodeVecV128Load16x4UName wasm.OpcodeVecV128Load32x2SName -// wasm.OpcodeVecV128Load32x2UName wasm.OpcodeVecV128Load8SplatName wasm.OpcodeVecV128Load16SplatName -// wasm.OpcodeVecV128Load32SplatName wasm.OpcodeVecV128Load64SplatName wasm.OpcodeVecV128Load32zeroName -// wasm.OpcodeVecV128Load64zeroName -func NewOperationV128Load(loadType V128LoadType, arg MemoryArg) UnionOperation { - return UnionOperation{Kind: OperationKindV128Load, B1: loadType, U1: uint64(arg.Alignment), U2: uint64(arg.Offset)} -} - -// NewOperationV128LoadLane is a constructor for UnionOperation with OperationKindV128LoadLane. -// -// This corresponds to wasm.OpcodeVecV128Load8LaneName wasm.OpcodeVecV128Load16LaneName -// -// wasm.OpcodeVecV128Load32LaneName wasm.OpcodeVecV128Load64LaneName. -// -// laneIndex is >=0 && <(128/LaneSize). -// laneSize is either 8, 16, 32, or 64. -func NewOperationV128LoadLane(laneIndex, laneSize byte, arg MemoryArg) UnionOperation { - return UnionOperation{Kind: OperationKindV128LoadLane, B1: laneSize, B2: laneIndex, U1: uint64(arg.Alignment), U2: uint64(arg.Offset)} -} - -// NewOperationV128Store is a constructor for UnionOperation with OperationKindV128Store. -// -// This corresponds to wasm.OpcodeVecV128Load8LaneName wasm.OpcodeVecV128Load16LaneName -// -// wasm.OpcodeVecV128Load32LaneName wasm.OpcodeVecV128Load64LaneName. -func NewOperationV128Store(arg MemoryArg) UnionOperation { - return UnionOperation{ - Kind: OperationKindV128Store, - U1: uint64(arg.Alignment), - U2: uint64(arg.Offset), - } -} - -// NewOperationV128StoreLane implements Operation. -// -// This corresponds to wasm.OpcodeVecV128Load8LaneName wasm.OpcodeVecV128Load16LaneName -// -// wasm.OpcodeVecV128Load32LaneName wasm.OpcodeVecV128Load64LaneName. -// -// laneIndex is >=0 && <(128/LaneSize). -// laneSize is either 8, 16, 32, or 64. -func NewOperationV128StoreLane(laneIndex byte, laneSize byte, arg MemoryArg) UnionOperation { - return UnionOperation{ - Kind: OperationKindV128StoreLane, - B1: laneSize, - B2: laneIndex, - U1: uint64(arg.Alignment), - U2: uint64(arg.Offset), - } -} - -// NewOperationV128ExtractLane is a constructor for UnionOperation with OperationKindV128ExtractLane. -// -// This corresponds to -// -// wasm.OpcodeVecI8x16ExtractLaneSName wasm.OpcodeVecI8x16ExtractLaneUName -// wasm.OpcodeVecI16x8ExtractLaneSName wasm.OpcodeVecI16x8ExtractLaneUName -// wasm.OpcodeVecI32x4ExtractLaneName wasm.OpcodeVecI64x2ExtractLaneName -// wasm.OpcodeVecF32x4ExtractLaneName wasm.OpcodeVecF64x2ExtractLaneName. -// -// laneIndex is >=0 && =0 &&