From ef324e8b9daa46899bccc310cbd55b63d1359dae Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 21 May 2024 17:09:18 +0000 Subject: [PATCH] Bump github.com/tetratelabs/wazero from 1.7.1 to 1.7.2 Bumps [github.com/tetratelabs/wazero](https://github.com/tetratelabs/wazero) from 1.7.1 to 1.7.2. - [Release notes](https://github.com/tetratelabs/wazero/releases) - [Commits](https://github.com/tetratelabs/wazero/compare/v1.7.1...v1.7.2) --- updated-dependencies: - dependency-name: github.com/tetratelabs/wazero dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 +- .../tetratelabs/wazero/RATIONALE.md | 38 +- .../github.com/tetratelabs/wazero/config.go | 2 +- .../wazero/experimental/sys/file.go | 5 +- .../tetratelabs/wazero/experimental/sys/fs.go | 5 +- .../github.com/tetratelabs/wazero/fsconfig.go | 2 - .../interpreter}/compiler.go | 1280 ++++---- .../interpreter}/format.go | 10 +- .../engine/interpreter/interpreter.go | 1056 +++---- .../internal/engine/interpreter/operations.go | 2812 +++++++++++++++++ .../interpreter}/signature.go | 272 +- .../wazero/internal/engine/wazevo/README.md | 1 - .../engine/wazevo/backend/isa/amd64/instr.go | 16 +- .../backend/isa/amd64/instr_encoding.go | 2 +- .../wazevo/backend/isa/amd64/machine.go | 22 +- .../engine/wazevo/backend/isa/arm64/abi.go | 2 +- .../backend/isa/arm64/machine_relocation.go | 7 +- .../internal/engine/wazevo/backend/machine.go | 4 +- .../wazero/internal/engine/wazevo/engine.go | 34 +- .../internal/engine/wazevo/frontend/lower.go | 2 +- .../engine/wazevo/ssa/instructions.go | 10 +- .../tetratelabs/wazero/internal/sys/fs.go | 23 +- .../wazero/internal/sysfs/sysfs.go | 2 +- .../wazero/internal/wasip1/errno.go | 2 +- .../wazero/internal/wasm/memory.go | 11 +- .../tetratelabs/wazero/internal/wasm/store.go | 5 +- .../wazero/internal/wasmdebug/debug.go | 19 +- .../wazero/internal/wazeroir/operations.go | 2812 ----------------- .../wazero/internal/wazeroir/wazeroir.go | 8 - vendor/modules.txt | 3 +- 31 files changed, 4221 insertions(+), 4252 deletions(-) rename vendor/github.com/tetratelabs/wazero/internal/{wazeroir => engine/interpreter}/compiler.go (70%) rename vendor/github.com/tetratelabs/wazero/internal/{wazeroir => engine/interpreter}/format.go (55%) create mode 100644 vendor/github.com/tetratelabs/wazero/internal/engine/interpreter/operations.go rename vendor/github.com/tetratelabs/wazero/internal/{wazeroir => engine/interpreter}/signature.go (79%) delete mode 100644 vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/README.md delete mode 100644 vendor/github.com/tetratelabs/wazero/internal/wazeroir/operations.go delete mode 100644 vendor/github.com/tetratelabs/wazero/internal/wazeroir/wazeroir.go diff --git a/go.mod b/go.mod index 59aefca1cc..081a84fee0 100644 --- a/go.mod +++ b/go.mod @@ -42,7 +42,7 @@ require ( github.com/spf13/cobra v1.8.0 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.9.0 - github.com/tetratelabs/wazero v1.7.1 + github.com/tetratelabs/wazero v1.7.2 github.com/things-go/go-socks5 v0.0.5 github.com/ulikunitz/xz v0.5.12 github.com/xlab/treeprint v1.2.0 diff --git a/go.sum b/go.sum index 2acab2c402..8606e108b5 100644 --- a/go.sum +++ b/go.sum @@ -385,8 +385,8 @@ github.com/tc-hib/winres v0.2.1 h1:YDE0FiP0VmtRaDn7+aaChp1KiF4owBiJa5l964l5ujA= github.com/tc-hib/winres v0.2.1/go.mod h1:C/JaNhH3KBvhNKVbvdlDWkbMDO9H4fKKDaN7/07SSuk= github.com/tcnksm/go-httpstat v0.2.0 h1:rP7T5e5U2HfmOBmZzGgGZjBQ5/GluWUylujl0tJ04I0= github.com/tcnksm/go-httpstat v0.2.0/go.mod h1:s3JVJFtQxtBEBC9dwcdTTXS9xFnM3SXAZwPG41aurT8= -github.com/tetratelabs/wazero v1.7.1 h1:QtSfd6KLc41DIMpDYlJdoMc6k7QTN246DM2+n2Y/Dx8= -github.com/tetratelabs/wazero v1.7.1/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y= +github.com/tetratelabs/wazero v1.7.2 h1:1+z5nXJNwMLPAWaTePFi49SSTL0IMx/i3Fg8Yc25GDc= +github.com/tetratelabs/wazero v1.7.2/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y= github.com/thedevsaddam/gojsonq/v2 v2.5.2 h1:CoMVaYyKFsVj6TjU6APqAhAvC07hTI6IQen8PHzHYY0= github.com/thedevsaddam/gojsonq/v2 v2.5.2/go.mod h1:bv6Xa7kWy82uT0LnXPE2SzGqTj33TAEeR560MdJkiXs= github.com/things-go/go-socks5 v0.0.5 h1:qvKaGcBkfDrUL33SchHN93srAmYGzb4CxSM2DPYufe8= diff --git a/vendor/github.com/tetratelabs/wazero/RATIONALE.md b/vendor/github.com/tetratelabs/wazero/RATIONALE.md index 484e1f525f..8d783cb448 100644 --- a/vendor/github.com/tetratelabs/wazero/RATIONALE.md +++ b/vendor/github.com/tetratelabs/wazero/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? @@ -568,8 +557,7 @@ In short, wazero defined system configuration in `ModuleConfig`, not a WASI type one spec to another with minimal impact. This has other helpful benefits, as centralized resources are simpler to close coherently (ex via `Module.Close`). -In reflection, this worked well as more ABI became usable in wazero. For example, `GOOS=js GOARCH=wasm` code uses the -same `ModuleConfig` (and `FSConfig`) WASI uses, and in compatible ways. +In reflection, this worked well as more ABI became usable in wazero. ### Background on `ModuleConfig` design @@ -753,8 +741,7 @@ independent of the root file system. This intended to help separate concerns like mutability of files, but it didn't work and was removed. Compilers that target wasm act differently with regard to the working -directory. For example, while `GOOS=js` uses host functions to track the -working directory, WASI host functions do not. wasi-libc, used by TinyGo, +directory. For example, wasi-libc, used by TinyGo, tracks working directory changes in compiled wasm instead: initially "/" until code calls `chdir`. Zig assumes the first pre-opened file descriptor is the working directory. @@ -829,10 +816,7 @@ The main reason is that `os.DirFS` is a virtual filesystem abstraction while WASI is an abstraction over syscalls. For example, the signature of `fs.Open` does not permit use of flags. This creates conflict on what default behaviors to take when Go implemented `os.DirFS`. On the other hand, `path_open` can pass -flags, and in fact tests require them to be honored in specific ways. This -extends beyond WASI as even `GOOS=js GOARCH=wasm` compiled code requires -certain flags passed to `os.OpenFile` which are impossible to pass due to the -signature of `fs.FS`. +flags, and in fact tests require them to be honored in specific ways. This conflict requires us to choose what to be more compatible with, and which type of user to surprise the least. We assume there will be more developers @@ -840,10 +824,6 @@ compiling code to wasm than developers of custom filesystem plugins, and those compiling code to wasm will be better served if we are compatible with WASI. Hence on conflict, we prefer WASI behavior vs the behavior of `os.DirFS`. -Meanwhile, it is possible that Go will one day compile to `GOOS=wasi` in -addition to `GOOS=js`. When there is shared stake in WASI, we expect gaps like -these to be easier to close. - See https://github.com/WebAssembly/wasi-testsuite See https://github.com/golang/go/issues/58141 @@ -1205,10 +1185,7 @@ See https://gruss.cc/files/fantastictimers.pdf for an example attacks. ### Why does fake time increase on reading? Both the fake nanotime and walltime increase by 1ms on reading. Particularly in -the case of nanotime, this prevents spinning. For example, when Go compiles -`time.Sleep` using `GOOS=js GOARCH=wasm`, nanotime is used in a loop. If that -never increases, the gouroutine is mistaken for being busy. This would be worse -if a compiler implement sleep using nanotime, yet doesn't check for spinning! +the case of nanotime, this prevents spinning. ### Why not `time.Clock`? @@ -1266,8 +1243,7 @@ pub fn main() !void { ``` Besides Zig, this is also the case with TinyGo (`-target=wasi`) and Rust -(`--target wasm32-wasi`). This isn't the case with Go (`GOOS=js GOARCH=wasm`), -though. In the latter case, wasm loops on `sys.Nanotime`. +(`--target wasm32-wasi`). We decided to expose `sys.Nanosleep` to allow overriding the implementation used in the common case, even if it isn't used by Go, because this gives an @@ -1558,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/vendor/github.com/tetratelabs/wazero/config.go b/vendor/github.com/tetratelabs/wazero/config.go index 04bce10e3c..819a76df5e 100644 --- a/vendor/github.com/tetratelabs/wazero/config.go +++ b/vendor/github.com/tetratelabs/wazero/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/vendor/github.com/tetratelabs/wazero/experimental/sys/file.go b/vendor/github.com/tetratelabs/wazero/experimental/sys/file.go index 22671d0a01..b6bfbcfebb 100644 --- a/vendor/github.com/tetratelabs/wazero/experimental/sys/file.go +++ b/vendor/github.com/tetratelabs/wazero/experimental/sys/file.go @@ -3,7 +3,7 @@ package sys import "github.com/tetratelabs/wazero/sys" // File is a writeable fs.File bridge backed by syscall functions needed for ABI -// including WASI and runtime.GOOS=js. +// including WASI. // // Implementations should embed UnimplementedFile for forward compatibility. Any // unsupported method or parameter should return ENOSYS. @@ -14,8 +14,7 @@ import "github.com/tetratelabs/wazero/sys" // on success. // // Restricting to Errno matches current WebAssembly host functions, -// which are constrained to well-known error codes. For example, `GOOS=js` maps -// hard coded values and panics otherwise. More commonly, WASI maps syscall +// which are constrained to well-known error codes. For example, WASI maps syscall // errors to u32 numeric values. // // # Notes diff --git a/vendor/github.com/tetratelabs/wazero/experimental/sys/fs.go b/vendor/github.com/tetratelabs/wazero/experimental/sys/fs.go index 23be92f1c1..87810510ab 100644 --- a/vendor/github.com/tetratelabs/wazero/experimental/sys/fs.go +++ b/vendor/github.com/tetratelabs/wazero/experimental/sys/fs.go @@ -7,7 +7,7 @@ import ( ) // FS is a writeable fs.FS bridge backed by syscall functions needed for ABI -// including WASI and runtime.GOOS=js. +// including WASI. // // Implementations should embed UnimplementedFS for forward compatibility. Any // unsupported method or parameter should return ENO @@ -18,8 +18,7 @@ import ( // on success. // // Restricting to Errno matches current WebAssembly host functions, -// which are constrained to well-known error codes. For example, `GOOS=js` maps -// hard coded values and panics otherwise. More commonly, WASI maps syscall +// which are constrained to well-known error codes. For example, WASI maps syscall // errors to u32 numeric values. // // # Notes diff --git a/vendor/github.com/tetratelabs/wazero/fsconfig.go b/vendor/github.com/tetratelabs/wazero/fsconfig.go index 583696cb9b..c21b6e80b9 100644 --- a/vendor/github.com/tetratelabs/wazero/fsconfig.go +++ b/vendor/github.com/tetratelabs/wazero/fsconfig.go @@ -30,8 +30,6 @@ import ( // current directory prior to requesting files. // // More notes on `guestPath` -// - Go compiled with runtime.GOOS=js do not pay attention to this value. -// It only works with root mounts (""). // - Working directories are typically tracked in wasm, though possible some // relative paths are requested. For example, TinyGo may attempt to resolve // a path "../.." in unit tests. diff --git a/vendor/github.com/tetratelabs/wazero/internal/wazeroir/compiler.go b/vendor/github.com/tetratelabs/wazero/internal/engine/interpreter/compiler.go similarity index 70% rename from vendor/github.com/tetratelabs/wazero/internal/wazeroir/compiler.go rename to vendor/github.com/tetratelabs/wazero/internal/engine/interpreter/compiler.go index 2699cb876c..56dfac6206 100644 --- a/vendor/github.com/tetratelabs/wazero/internal/wazeroir/compiler.go +++ b/vendor/github.com/tetratelabs/wazero/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/vendor/github.com/tetratelabs/wazero/internal/wazeroir/format.go b/vendor/github.com/tetratelabs/wazero/internal/engine/interpreter/format.go similarity index 55% rename from vendor/github.com/tetratelabs/wazero/internal/wazeroir/format.go rename to vendor/github.com/tetratelabs/wazero/internal/engine/interpreter/format.go index 789de00297..8af1d94b0c 100644 --- a/vendor/github.com/tetratelabs/wazero/internal/wazeroir/format.go +++ b/vendor/github.com/tetratelabs/wazero/internal/engine/interpreter/format.go @@ -1,19 +1,17 @@ -package wazeroir +package interpreter import ( "bytes" ) -const EntrypointLabel = ".entrypoint" - -func Format(ops []UnionOperation) string { +func format(ops []unionOperation) string { buf := bytes.NewBuffer(nil) - _, _ = buf.WriteString(EntrypointLabel + "\n") + _, _ = buf.WriteString(".entrypoint\n") for i := range ops { op := &ops[i] str := op.String() - isLabel := op.Kind == OperationKindLabel + isLabel := op.Kind == operationKindLabel if !isLabel { const indent = "\t" str = indent + str diff --git a/vendor/github.com/tetratelabs/wazero/internal/engine/interpreter/interpreter.go b/vendor/github.com/tetratelabs/wazero/internal/engine/interpreter/interpreter.go index 9436a8394c..a89ddc4573 100644 --- a/vendor/github.com/tetratelabs/wazero/internal/engine/interpreter/interpreter.go +++ b/vendor/github.com/tetratelabs/wazero/internal/engine/interpreter/interpreter.go @@ -19,7 +19,6 @@ import ( "github.com/tetratelabs/wazero/internal/wasm" "github.com/tetratelabs/wazero/internal/wasmdebug" "github.com/tetratelabs/wazero/internal/wasmruntime" - "github.com/tetratelabs/wazero/internal/wazeroir" ) // callStackCeiling is the maximum WebAssembly call frame stack height. This allows wazero to raise @@ -33,8 +32,6 @@ type engine struct { enabledFeatures api.CoreFeatures compiledFunctions map[wasm.ModuleID][]compiledFunction // guarded by mutex. mux sync.RWMutex - // labelAddressResolutionCache is the temporary cache used to map LabelKind -> FrameID -> the index to the body. - labelAddressResolutionCache [wazeroir.LabelKindNum][]uint64 } func NewEngine(_ context.Context, enabledFeatures api.CoreFeatures, _ filecache.Cache) wasm.Engine { @@ -139,7 +136,7 @@ func (ce *callEngine) popValue() (v uint64) { // as we can assume that all the operations // are valid thanks to validateFunction // at module validation phase - // and wazeroir translation + // and interpreterir translation // before compilation. stackTopIndex := len(ce.stack) - 1 v = ce.stack[stackTopIndex] @@ -163,7 +160,7 @@ func (ce *callEngine) peekValues(count int) []uint64 { } func (ce *callEngine) drop(raw uint64) { - r := wazeroir.InclusiveRangeFromU64(raw) + r := inclusiveRangeFromU64(raw) if r.Start == -1 { return } else if r.Start == 0 { @@ -184,7 +181,7 @@ func (ce *callEngine) pushFrame(frame *callFrame) { func (ce *callEngine) popFrame() (frame *callFrame) { // No need to check stack bound as we can assume that all the operations are valid thanks to validateFunction at - // module validation phase and wazeroir translation before compilation. + // module validation phase and interpreterir translation before compilation. oneLess := len(ce.frames) - 1 frame = ce.frames[oneLess] ce.frames = ce.frames[:oneLess] @@ -203,7 +200,7 @@ type callFrame struct { type compiledFunction struct { source *wasm.Module - body []wazeroir.UnionOperation + body []unionOperation listener experimental.FunctionListener offsetsInWasmBinary []uint64 hostFn interface{} @@ -361,7 +358,7 @@ func (e *engine) CompileModule(_ context.Context, module *wasm.Module, listeners } funcs := make([]compiledFunction, len(module.FunctionSection)) - irCompiler, err := wazeroir.NewCompiler(e.enabledFeatures, callFrameStackSize, module, ensureTermination) + irCompiler, err := newCompiler(e.enabledFeatures, callFrameStackSize, module, ensureTermination) if err != nil { return err } @@ -375,7 +372,7 @@ func (e *engine) CompileModule(_ context.Context, module *wasm.Module, listeners compiled := &funcs[i] // If this is the host function, there's nothing to do as the runtime representation of // host function in interpreter is its Go function itself as opposed to Wasm functions, - // which need to be compiled down to wazeroir. + // which need to be compiled down to if codeSeg := &module.CodeSection[i]; codeSeg.GoFunc != nil { compiled.hostFn = codeSeg.GoFunc } else { @@ -386,7 +383,7 @@ func (e *engine) CompileModule(_ context.Context, module *wasm.Module, listeners err = e.lowerIR(ir, compiled) if err != nil { def := module.FunctionDefinition(uint32(i) + module.ImportFunctionCount) - return fmt.Errorf("failed to lower func[%s] to wazeroir: %w", def.DebugName(), err) + return fmt.Errorf("failed to lower func[%s] to interpreterir: %w", def.DebugName(), err) } } compiled.source = module @@ -424,10 +421,10 @@ func (e *engine) NewModuleEngine(module *wasm.Module, instance *wasm.ModuleInsta return me, nil } -// lowerIR lowers the wazeroir operations to engine friendly struct. -func (e *engine) lowerIR(ir *wazeroir.CompilationResult, ret *compiledFunction) error { +// lowerIR lowers the interpreterir operations to engine friendly struct. +func (e *engine) lowerIR(ir *compilationResult, ret *compiledFunction) error { // Copy the body from the result. - ret.body = make([]wazeroir.UnionOperation, len(ir.Operations)) + ret.body = make([]unionOperation, len(ir.Operations)) copy(ret.body, ir.Operations) // Also copy the offsets if necessary. if offsets := ir.IROperationSourceOffsetsInWasmBinary; len(offsets) > 0 { @@ -435,16 +432,18 @@ func (e *engine) lowerIR(ir *wazeroir.CompilationResult, ret *compiledFunction) copy(ret.offsetsInWasmBinary, offsets) } + 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() - frameToAddresses := e.labelAddressResolutionCache[label.Kind()] + frameToAddresses := labelAddressResolutions[label.Kind()] // Expand the slice if necessary. if diff := fid - len(frameToAddresses) + 1; diff > 0 { for j := 0; j < diff; j++ { @@ -452,7 +451,7 @@ func (e *engine) lowerIR(ir *wazeroir.CompilationResult, ret *compiledFunction) } } frameToAddresses[fid] = address - e.labelAddressResolutionCache[kind] = frameToAddresses + labelAddressResolutions[kind] = frameToAddresses } } @@ -460,32 +459,27 @@ 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)) - case wazeroir.OperationKindBrIf: - e.setLabelAddress(&op.U1, wazeroir.Label(op.U1)) - e.setLabelAddress(&op.U2, wazeroir.Label(op.U2)) - 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)) + e.setLabelAddress(&op.Us[j], label(target), labelAddressResolutions) } } } - - // Reuses the slices for the subsequent compilation, so clear the content here. - for i := range e.labelAddressResolutionCache { - e.labelAddressResolutionCache[i] = e.labelAddressResolutionCache[i][:0] - } return nil } -func (e *engine) setLabelAddress(op *uint64, label wazeroir.Label) { +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 } else { - *op = e.labelAddressResolutionCache[label.Kind()][label.FrameID()] + *op = labelAddressResolutions[label.Kind()][label.FrameID()] } } @@ -717,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 { @@ -742,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() { @@ -761,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)) { @@ -779,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() @@ -799,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 @@ -817,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 { @@ -848,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) @@ -891,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. @@ -937,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) } @@ -963,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) } @@ -982,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 { @@ -1011,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 { @@ -1033,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 { @@ -1055,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 { @@ -1077,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) @@ -1166,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 { @@ -1439,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 @@ -1464,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 { @@ -1486,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 @@ -1513,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 { @@ -1537,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 @@ -1562,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 { @@ -1584,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 @@ -1612,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())) @@ -1674,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() @@ -1706,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() @@ -1721,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() @@ -1737,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() @@ -1750,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() @@ -1764,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() @@ -1777,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() @@ -1788,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()) @@ -1815,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 | @@ -1837,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, @@ -1846,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 | @@ -1881,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, @@ -1890,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) @@ -1922,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) @@ -1933,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) @@ -1944,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) @@ -1957,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) @@ -1968,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) @@ -1991,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) @@ -1999,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) @@ -2007,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) @@ -2030,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 { @@ -2084,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. @@ -2099,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 @@ -2133,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)) @@ -2188,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)) @@ -2201,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 { @@ -2216,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 @@ -2256,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 { @@ -2273,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) @@ -2281,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) } @@ -2306,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 @@ -2322,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 @@ -2333,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 @@ -2344,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 } @@ -2354,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() @@ -2386,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)) | @@ -2477,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)) | @@ -2498,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 @@ -2507,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) @@ -2521,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), @@ -2537,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), @@ -2548,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), @@ -2559,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), @@ -2570,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), @@ -2581,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), @@ -2592,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), @@ -2603,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), @@ -2614,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), @@ -2625,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), @@ -2636,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), @@ -2887,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() @@ -2896,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 { @@ -2930,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 { @@ -2969,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() @@ -2978,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 { @@ -3012,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 { @@ -3051,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 { @@ -3091,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) | @@ -3103,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 { @@ -3140,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) | @@ -3152,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++ { @@ -3204,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 | @@ -3229,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 | @@ -3249,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 @@ -3261,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), @@ -3279,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 | @@ -3304,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 | @@ -3324,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 @@ -3336,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), @@ -3354,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 | @@ -3368,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 | @@ -3381,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 { @@ -3421,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 { @@ -3461,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))))) | @@ -3475,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))))) | @@ -3489,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))))) | @@ -3503,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))))) | @@ -3517,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 @@ -3530,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)) @@ -3547,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)) @@ -3564,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 { @@ -3578,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 @@ -3592,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)) @@ -3609,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)) @@ -3626,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 { @@ -3641,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 @@ -3673,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 { @@ -3702,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 { @@ -3728,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)))) | @@ -3741,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) @@ -3760,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 { @@ -3771,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 { @@ -3837,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 { @@ -3901,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( @@ -3913,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)))), @@ -3953,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)), @@ -3984,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) @@ -3994,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) } @@ -4008,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) } @@ -4023,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 { @@ -4036,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 @@ -4045,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) } @@ -4059,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) } @@ -4072,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) @@ -4082,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) @@ -4095,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) } @@ -4109,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) } @@ -4121,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() @@ -4131,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 { @@ -4144,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) } @@ -4159,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) } @@ -4187,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) @@ -4206,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() @@ -4217,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 { @@ -4249,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) } @@ -4287,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) } @@ -4304,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) @@ -4320,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) @@ -4346,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), @@ -4555,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/vendor/github.com/tetratelabs/wazero/internal/engine/interpreter/operations.go b/vendor/github.com/tetratelabs/wazero/internal/engine/interpreter/operations.go new file mode 100644 index 0000000000..3087a718ff --- /dev/null +++ b/vendor/github.com/tetratelabs/wazero/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 && math.MaxInt32 || diff < math.MinInt32 { // This case even amd64 can't handle. 4GB is too big. diff --git a/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/machine.go b/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/machine.go index cf45ea55f7..54ce89e468 100644 --- a/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/machine.go +++ b/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/machine.go @@ -59,12 +59,12 @@ type ( PostRegAlloc() // ResolveRelocations resolves the relocations after emitting machine code. - // * refToBinaryOffset: the map from the function reference to the executable offset. + // * refToBinaryOffset: the map from the function reference (ssa.FuncRef) to the executable offset. // * executable: the binary to resolve the relocations. // * relocations: the relocations to resolve. // * callTrampolineIslandOffsets: the offsets of the trampoline islands in the executable. ResolveRelocations( - refToBinaryOffset map[ssa.FuncRef]int, + refToBinaryOffset []int, executable []byte, relocations []RelocationInfo, callTrampolineIslandOffsets []int, diff --git a/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/engine.go b/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/engine.go index 60bb4a3c4c..f02b905fc4 100644 --- a/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/engine.go +++ b/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/engine.go @@ -31,10 +31,6 @@ type ( // sortedCompiledModules is a list of compiled modules sorted by the initial address of the executable. sortedCompiledModules []*compiledModule mux sync.RWMutex - // rels is a list of relocations to be resolved. This is reused for each compilation to avoid allocation. - rels []backend.RelocationInfo - // refToBinaryOffset is reused for each compilation to avoid allocation. - refToBinaryOffset map[ssa.FuncRef]int // sharedFunctions is compiled functions shared by all modules. sharedFunctions *sharedFunctions // setFinalizer defaults to runtime.SetFinalizer, but overridable for tests. @@ -109,12 +105,12 @@ func NewEngine(ctx context.Context, _ api.CoreFeatures, fc filecache.Cache) wasm machine := newMachine() be := backend.NewCompiler(ctx, machine, ssa.NewBuilder()) e := &engine{ - compiledModules: make(map[wasm.ModuleID]*compiledModule), refToBinaryOffset: make(map[ssa.FuncRef]int), - setFinalizer: runtime.SetFinalizer, - machine: machine, - be: be, - fileCache: fc, - wazeroVersion: version.GetWazeroVersion(), + compiledModules: make(map[wasm.ModuleID]*compiledModule), + setFinalizer: runtime.SetFinalizer, + machine: machine, + be: be, + fileCache: fc, + wazeroVersion: version.GetWazeroVersion(), } e.compileSharedFunctions() return e @@ -186,7 +182,6 @@ func (exec *executables) compileEntryPreambles(m *wasm.Module, machine backend.M func (e *engine) compileModule(ctx context.Context, module *wasm.Module, listeners []experimental.FunctionListener, ensureTermination bool) (*compiledModule, error) { withListener := len(listeners) > 0 - e.rels = e.rels[:0] cm := &compiledModule{ offsets: wazevoapi.NewModuleContextOffsetData(module, withListener), parent: e, module: module, ensureTermination: ensureTermination, @@ -202,6 +197,9 @@ func (e *engine) compileModule(ctx context.Context, module *wasm.Module, listene return cm, nil } + rels := make([]backend.RelocationInfo, 0) + refToBinaryOffset := make([]int, importedFns+localFns) + if wazevoapi.DeterministicCompilationVerifierEnabled { // The compilation must be deterministic regardless of the order of functions being compiled. wazevoapi.DeterministicCompilationVerifierRandomizeIndexes(ctx) @@ -246,7 +244,7 @@ func (e *engine) compileModule(ctx context.Context, module *wasm.Module, listene } needListener := len(listeners) > 0 && listeners[i] != nil - body, rels, err := e.compileLocalWasmFunction(ctx, module, wasm.Index(i), fe, ssaBuilder, be, needListener) + body, relsPerFunc, err := e.compileLocalWasmFunction(ctx, module, wasm.Index(i), fe, ssaBuilder, be, needListener) if err != nil { return nil, fmt.Errorf("compile function %d/%d: %v", i, len(module.CodeSection)-1, err) } @@ -268,13 +266,13 @@ func (e *engine) compileModule(ctx context.Context, module *wasm.Module, listene } fref := frontend.FunctionIndexToFuncRef(fidx) - e.refToBinaryOffset[fref] = totalSize + refToBinaryOffset[fref] = totalSize // At this point, relocation offsets are relative to the start of the function body, // so we adjust it to the start of the executable. - for _, r := range rels { + for _, r := range relsPerFunc { r.Offset += int64(totalSize) - e.rels = append(e.rels, r) + rels = append(rels, r) } bodies[i] = body @@ -315,8 +313,8 @@ func (e *engine) compileModule(ctx context.Context, module *wasm.Module, listene } // Resolve relocations for local function calls. - if len(e.rels) > 0 { - machine.ResolveRelocations(e.refToBinaryOffset, executable, e.rels, callTrampolineIslandOffsets) + if len(rels) > 0 { + machine.ResolveRelocations(refToBinaryOffset, executable, rels, callTrampolineIslandOffsets) } if runtime.GOARCH == "arm64" { @@ -571,7 +569,7 @@ func (e *engine) NewModuleEngine(m *wasm.Module, mi *wasm.ModuleInstance) (wasm. // Note: imported functions are resolved in moduleEngine.ResolveImportedFunction. me.importedFunctions = make([]importedFunction, m.ImportFunctionCount) - compiled, ok := e.compiledModules[m.ID] + compiled, ok := e.getCompiledModuleFromMemory(m) if !ok { return nil, errors.New("source module must be compiled before instantiation") } diff --git a/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/lower.go b/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/lower.go index 11a9dbc454..5096a63652 100644 --- a/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/lower.go +++ b/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/lower.go @@ -3743,7 +3743,7 @@ func (c *Compiler) callMemmove(dst, src, size ssa.Value) { wazevoapi.ExecutionContextOffsetMemmoveAddress.U32(), ssa.TypeI64, ).Insert(builder).Return() - builder.AllocateInstruction().AsCallIndirect(memmovePtr, &c.memmoveSig, args).Insert(builder) + builder.AllocateInstruction().AsCallGoRuntimeMemmove(memmovePtr, &c.memmoveSig, args).Insert(builder) } func (c *Compiler) reloadAfterCall() { diff --git a/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/instructions.go b/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/instructions.go index b49fdd1619..3e3482efc4 100644 --- a/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/instructions.go +++ b/vendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/instructions.go @@ -2180,14 +2180,22 @@ func (i *Instruction) AsCallIndirect(funcPtr Value, sig *Signature, args Values) return i } +// AsCallGoRuntimeMemmove is the same as AsCallIndirect, but with a special flag set to indicate that it is a call to the Go runtime memmove function. +func (i *Instruction) AsCallGoRuntimeMemmove(funcPtr Value, sig *Signature, args Values) *Instruction { + i.AsCallIndirect(funcPtr, sig, args) + i.u2 = 1 + return i +} + // CallIndirectData returns the call indirect data for this instruction necessary for backends. -func (i *Instruction) CallIndirectData() (funcPtr Value, sigID SignatureID, args []Value) { +func (i *Instruction) CallIndirectData() (funcPtr Value, sigID SignatureID, args []Value, isGoMemmove bool) { if i.opcode != OpcodeCallIndirect { panic("BUG: CallIndirectData only available for OpcodeCallIndirect") } funcPtr = i.v sigID = SignatureID(i.u1) args = i.vs.View() + isGoMemmove = i.u2 == 1 return } diff --git a/vendor/github.com/tetratelabs/wazero/internal/sys/fs.go b/vendor/github.com/tetratelabs/wazero/internal/sys/fs.go index 332a952626..157de788f3 100644 --- a/vendor/github.com/tetratelabs/wazero/internal/sys/fs.go +++ b/vendor/github.com/tetratelabs/wazero/internal/sys/fs.go @@ -251,9 +251,6 @@ func (d *DirentCache) cachedDirents(n uint32) []sys.Dirent { } type FSContext struct { - // rootFS is the root ("/") mount. - rootFS sys.FS - // openedFiles is a map of file descriptor numbers (>=FdPreopen) to open files // (or directories) and defaults to empty. // TODO: This is unguarded, so not goroutine-safe! @@ -264,19 +261,6 @@ type FSContext struct { // descriptors to file entries. type FileTable = descriptor.Table[int32, *FileEntry] -// RootFS returns a possibly unimplemented root filesystem. Any files that -// should be added to the table should be inserted via InsertFile. -// -// TODO: This is only used by GOOS=js and tests: Remove when we remove GOOS=js -// (after Go 1.22 is released). -func (c *FSContext) RootFS() sys.FS { - if rootFS := c.rootFS; rootFS == nil { - return sys.UnimplementedFS{} - } else { - return rootFS - } -} - // LookupFile returns a file if it is in the table. func (c *FSContext) LookupFile(fd int32) (*FileEntry, bool) { return c.openedFiles.Lookup(fd) @@ -412,19 +396,18 @@ func (c *Context) InitFSContext( } c.fsc.openedFiles.Insert(errWriter) - for i, fs := range fs { + for i, f := range fs { guestPath := guestPaths[i] if StripPrefixesAndTrailingSlash(guestPath) == "" { // Default to bind to '/' when guestPath is effectively empty. guestPath = "/" - c.fsc.rootFS = fs } c.fsc.openedFiles.Insert(&FileEntry{ - FS: fs, + FS: f, Name: guestPath, IsPreopen: true, - File: &lazyDir{fs: fs}, + File: &lazyDir{fs: f}, }) } diff --git a/vendor/github.com/tetratelabs/wazero/internal/sysfs/sysfs.go b/vendor/github.com/tetratelabs/wazero/internal/sysfs/sysfs.go index e0ebfe5b9f..dd0a8882e5 100644 --- a/vendor/github.com/tetratelabs/wazero/internal/sysfs/sysfs.go +++ b/vendor/github.com/tetratelabs/wazero/internal/sysfs/sysfs.go @@ -1,5 +1,5 @@ // Package sysfs includes a low-level filesystem interface and utilities needed -// for WebAssembly host functions (ABI) such as WASI and runtime.GOOS=js. +// for WebAssembly host functions (ABI) such as WASI. // // The name sysfs was chosen because wazero's public API has a "sys" package, // which was named after https://github.com/golang/sys. diff --git a/vendor/github.com/tetratelabs/wazero/internal/wasip1/errno.go b/vendor/github.com/tetratelabs/wazero/internal/wasip1/errno.go index 701c2aa4f2..028573d2fe 100644 --- a/vendor/github.com/tetratelabs/wazero/internal/wasip1/errno.go +++ b/vendor/github.com/tetratelabs/wazero/internal/wasip1/errno.go @@ -262,7 +262,7 @@ var errnoToString = [...]string{ // ToErrno coerces the error to a WASI Errno. // // Note: Coercion isn't centralized in sys.FSContext because ABI use different -// error codes. For example, wasi-filesystem and GOOS=js don't map to these +// error codes. For example, wasi-filesystem doesn't map to these // Errno. func ToErrno(errno sys.Errno) Errno { switch errno { diff --git a/vendor/github.com/tetratelabs/wazero/internal/wasm/memory.go b/vendor/github.com/tetratelabs/wazero/internal/wasm/memory.go index ac2ee2eda1..5cc5012dae 100644 --- a/vendor/github.com/tetratelabs/wazero/internal/wasm/memory.go +++ b/vendor/github.com/tetratelabs/wazero/internal/wasm/memory.go @@ -241,7 +241,7 @@ func (m *MemoryInstance) Grow(delta uint32) (result uint32, ok bool) { // We assume grow is called under a guest lock. // But the memory length is accessed elsewhere, // so use atomic to make the new length visible across threads. - atomicStoreLength(&m.Buffer, uintptr(len(buffer))) + atomicStoreLengthAndCap(&m.Buffer, uintptr(len(buffer)), uintptr(cap(buffer))) m.Cap = memoryBytesNumToPages(uint64(cap(buffer))) } else { m.Buffer = buffer @@ -294,6 +294,15 @@ func PagesToUnitOfBytes(pages uint32) string { // Below are raw functions used to implement the api.Memory API: +// Uses atomic write to update the length of a slice. +func atomicStoreLengthAndCap(slice *[]byte, length uintptr, cap uintptr) { + slicePtr := (*reflect.SliceHeader)(unsafe.Pointer(slice)) + capPtr := (*uintptr)(unsafe.Pointer(&slicePtr.Cap)) + atomic.StoreUintptr(capPtr, cap) + lenPtr := (*uintptr)(unsafe.Pointer(&slicePtr.Len)) + atomic.StoreUintptr(lenPtr, length) +} + // Uses atomic write to update the length of a slice. func atomicStoreLength(slice *[]byte, length uintptr) { slicePtr := (*reflect.SliceHeader)(unsafe.Pointer(slice)) diff --git a/vendor/github.com/tetratelabs/wazero/internal/wasm/store.go b/vendor/github.com/tetratelabs/wazero/internal/wasm/store.go index 33489f2dd8..1db661e853 100644 --- a/vendor/github.com/tetratelabs/wazero/internal/wasm/store.go +++ b/vendor/github.com/tetratelabs/wazero/internal/wasm/store.go @@ -363,10 +363,7 @@ func (s *Store) instantiate( return nil, err } - var allocator experimental.MemoryAllocator - if ctx != nil { - allocator, _ = ctx.Value(expctxkeys.MemoryAllocatorKey{}).(experimental.MemoryAllocator) - } + allocator, _ := ctx.Value(expctxkeys.MemoryAllocatorKey{}).(experimental.MemoryAllocator) m.buildGlobals(module, m.Engine.FunctionInstanceReference) m.buildMemory(module, allocator) diff --git a/vendor/github.com/tetratelabs/wazero/internal/wasmdebug/debug.go b/vendor/github.com/tetratelabs/wazero/internal/wasmdebug/debug.go index deb6749381..ff0e0cccc9 100644 --- a/vendor/github.com/tetratelabs/wazero/internal/wasmdebug/debug.go +++ b/vendor/github.com/tetratelabs/wazero/internal/wasmdebug/debug.go @@ -109,7 +109,10 @@ func NewErrorBuilder() ErrorBuilder { } type stackTrace struct { - frames []string + // frameCount is the number of stack frame currently pushed into lines. + frameCount int + // lines contains the stack trace and possibly the inlined source code information. + lines []string } // GoRuntimeErrorTracePrefix is the prefix coming before the Go runtime stack trace included in the face of runtime.Error. @@ -125,7 +128,7 @@ func (s *stackTrace) FromRecovered(recovered interface{}) error { return exitErr } - stack := strings.Join(s.frames, "\n\t") + stack := strings.Join(s.lines, "\n\t") // If the error was internal, don't mention it was recovered. if wasmErr, ok := recovered.(*wasmruntime.Error); ok { @@ -152,12 +155,16 @@ const MaxFrames = 30 // AddFrame implements ErrorBuilder.AddFrame func (s *stackTrace) AddFrame(funcName string, paramTypes, resultTypes []api.ValueType, sources []string) { + if s.frameCount == MaxFrames { + return + } + s.frameCount++ sig := signature(funcName, paramTypes, resultTypes) - s.frames = append(s.frames, sig) + s.lines = append(s.lines, sig) for _, source := range sources { - s.frames = append(s.frames, "\t"+source) + s.lines = append(s.lines, "\t"+source) } - if len(s.frames) == MaxFrames { - s.frames = append(s.frames, "... maybe followed by omitted frames") + if s.frameCount == MaxFrames { + s.lines = append(s.lines, "... maybe followed by omitted frames") } } diff --git a/vendor/github.com/tetratelabs/wazero/internal/wazeroir/operations.go b/vendor/github.com/tetratelabs/wazero/internal/wazeroir/operations.go deleted file mode 100644 index d27dc0b707..0000000000 --- a/vendor/github.com/tetratelabs/wazero/internal/wazeroir/operations.go +++ /dev/null @@ -1,2812 +0,0 @@ -package wazeroir - -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 ( - Float32 Float = iota - Float64 -) - -// String implements fmt.Stringer. -func (s Float) String() (ret string) { - switch s { - case Float32: - ret = "f32" - case Float64: - 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 wazeroir -// 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 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 &&