wasmerio / wasmer-go

🐹🕸️ WebAssembly runtime for Go
https://pkg.go.dev/github.com/wasmerio/wasmer-go
MIT License
2.84k stars 161 forks source link

How to support simd instructions in wasmer-go? #383

Open orangeC23 opened 1 year ago

orangeC23 commented 1 year ago

Summary

Using wasmer-go to execute the following wat file:

(module
  (type (;0;) (func (result v128)))
  (func (;0;) (type 0) (result v128)
    v128.const i32x4 0x733c3e67 0x3c3e6776 0x3e677673 0x6776733c
    i64x2.abs
    i64x2.bitmask
    i8x16.splat
    v128.const i32x4 0x733c3e67 0x3c3e6776 0x3e677673 0x6776733c
    i64x2.ge_s
    f32x4.floor
    v128.not
    i16x8.extadd_pairwise_i8x16_u)
  (export "x" (func 0)))

The go file is :

package main

import (
    "fmt"
    "github.com/wasmerio/wasmer-go/wasmer"
    "io/ioutil"
)

func main() {
    wasmBytes, _ := ioutil.ReadFile("./tmp.wasm")

    engine := wasmer.NewEngine()
    store := wasmer.NewStore(engine)

    // Compiles the module
    module, err := wasmer.NewModule(store, wasmBytes)

    if err != nil {
        fmt.Println("Failed to compile module:", err)
    }

    // Instantiates the module
    importObject := wasmer.NewImportObject()
    instance, err := wasmer.NewInstance(module, importObject)

    if err != nil {
        panic(fmt.Sprintln("Failed to instantiate the module:", err))
    }

    // Gets the `sum` exported function from the WebAssembly instance.

    func1, err := instance.Exports.GetFunction("x")
    if err != nil {
        panic(fmt.Sprintln("Failed to get the `x` function:", err))
    }

    result, err := func1()

    if err != nil {
        panic(fmt.Sprintln("Failed to call the `x` function:", err))
    }

    fmt.Println(result)
}

Additional details

wat2wasm tmp.wat
go run tmp.go

It prints: Failed to compile module: WebAssembly translation error: Unsupported feature: proposed simd operator I16x8ExtAddPairwiseI8x16U panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x409560a]