wazevo: adds support for Select on v128 values (#1762)

Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
This commit is contained in:
Takeshi Yoneda
2023-10-06 10:09:09 +09:00
committed by GitHub
parent de928cd9bf
commit f2921d06f6
5 changed files with 94 additions and 66 deletions

View File

@@ -4,10 +4,13 @@ import (
"context"
"embed"
"fmt"
"runtime"
"strings"
"testing"
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/api"
"github.com/tetratelabs/wazero/internal/engine/wazevo"
"github.com/tetratelabs/wazero/internal/platform"
"github.com/tetratelabs/wazero/internal/testing/binaryencoding"
"github.com/tetratelabs/wazero/internal/testing/require"
@@ -44,9 +47,28 @@ func runWithInterpreter(t *testing.T, runner func(t *testing.T, r wazero.Runtime
})
}
func runWithWazevo(t *testing.T, runner func(t *testing.T, r wazero.Runtime)) {
t.Run("wazevo", func(t *testing.T) {
name := t.Name()
for _, skipTarget := range []string{"695", "701", "718"} {
if strings.Contains(name, skipTarget) {
t.Skip("TODO: skipping for wazevo until SIMD is completed")
}
}
config := wazero.NewRuntimeConfigInterpreter()
wazevo.ConfigureWazevo(config)
r := wazero.NewRuntimeWithConfig(ctx, config)
defer r.Close(ctx)
runner(t, r)
})
}
func run(t *testing.T, runner func(t *testing.T, r wazero.Runtime)) {
runWithInterpreter(t, runner)
runWithCompiler(t, runner)
if runtime.GOARCH == "arm64" {
runWithWazevo(t, runner)
}
}
// Test695 requires two functions to exit with "out of bounds memory access" consistently across the implementations.
@@ -66,20 +88,22 @@ func Test695(t *testing.T) {
}
func Test696(t *testing.T) {
functionNames := [4]string{
"select with 0 / after calling dummy",
"select with 0",
"typed select with 1 / after calling dummy",
"typed select with 1",
}
run(t, func(t *testing.T, r wazero.Runtime) {
module, err := r.Instantiate(ctx, getWasmBinary(t, 696))
require.NoError(t, err)
for _, name := range functionNames {
_, err := module.ExportedFunction(name).Call(ctx)
for _, tc := range []struct {
fnName string
in uint64
exp [2]uint64
}{
{fnName: "select", in: 1, exp: [2]uint64{0xffffffffffffffff, 0xeeeeeeeeeeeeeeee}},
{fnName: "select", in: 0, exp: [2]uint64{0x1111111111111111, 0x2222222222222222}},
{fnName: "typed select", in: 1, exp: [2]uint64{0xffffffffffffffff, 0xeeeeeeeeeeeeeeee}},
{fnName: "typed select", in: 0, exp: [2]uint64{0x1111111111111111, 0x2222222222222222}},
} {
res, err := module.ExportedFunction(tc.fnName).Call(ctx, tc.in)
require.NoError(t, err)
require.Equal(t, tc.exp[:], res)
}
})
}

View File

@@ -1,64 +1,18 @@
(module
(func $dummy)
(func (export "select with 0 / after calling dummy")
v128.const i64x2 0xffffffffffffffff 0xffffffffffffffff
v128.const i64x2 0xeeeeeeeeeeeeeeee 0xeeeeeeeeeeeeeeee
i32.const 0 ;; choose 0xeeeeeeeeeeeeeeee lane.
(func (export "select") (param i32) (result v128)
v128.const i64x2 0xffffffffffffffff 0xeeeeeeeeeeeeeeee
v128.const i64x2 0x1111111111111111 0x2222222222222222
local.get 0
call 0 ;; calling dummy function before select to
select
;; check the equality.
i64x2.extract_lane 0
i64.const 0xeeeeeeeeeeeeeeee
i64.eq
(if
(then)
(else unreachable)
)
)
(func (export "select with 0")
v128.const i64x2 0xffffffffffffffff 0xffffffffffffffff
v128.const i64x2 0xeeeeeeeeeeeeeeee 0xeeeeeeeeeeeeeeee
i32.const 0 ;; choose 0xeeeeeeeeeeeeeeee lane.
select
;; check the equality.
i64x2.extract_lane 0
i64.const 0xeeeeeeeeeeeeeeee
i64.eq
(if
(then)
(else unreachable)
)
)
(func (export "typed select with 1 / after calling dummy")
v128.const i64x2 0xffffffffffffffff 0xffffffffffffffff
v128.const i64x2 0xeeeeeeeeeeeeeeee 0xeeeeeeeeeeeeeeee
i32.const 1 ;; choose 0xffffffffffffffff lane.
(func (export "typed select") (param i32) (result v128)
v128.const i64x2 0xffffffffffffffff 0xeeeeeeeeeeeeeeee
v128.const i64x2 0x1111111111111111 0x2222222222222222
local.get 0
call 0 ;; calling dummy function before select to
select (result v128)
;; check the equality.
i64x2.extract_lane 0
i64.const 0xffffffffffffffff
i64.eq
(if
(then)
(else unreachable)
)
)
(func (export "typed select with 1")
v128.const i64x2 0xffffffffffffffff 0xffffffffffffffff
v128.const i64x2 0xeeeeeeeeeeeeeeee 0xeeeeeeeeeeeeeeee
i32.const 1 ;; choose 0xffffffffffffffff lane.
select (result v128)
;; check the equality.
i64x2.extract_lane 0
i64.const 0xffffffffffffffff
i64.eq
(if
(then)
(else unreachable)
)
)
)