interpreter: fixes i32x4/i16x8 bit mask (#704)

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
This commit is contained in:
Takeshi Yoneda
2022-07-15 16:07:49 +09:00
committed by GitHub
parent a536716495
commit ff4a7ff4f9
4 changed files with 39 additions and 4 deletions

View File

@@ -2429,23 +2429,23 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, callCtx *wasm.CallCont
}
case wazeroir.ShapeI16x8:
for i := 0; i < 4; i++ {
if int8(lo>>(i*16)) < 0 {
if int16(lo>>(i*16)) < 0 {
res |= 1 << i
}
}
for i := 0; i < 4; i++ {
if int8(hi>>(i*16)) < 0 {
if int16(hi>>(i*16)) < 0 {
res |= 1 << (i + 4)
}
}
case wazeroir.ShapeI32x4:
for i := 0; i < 2; i++ {
if int8(lo>>(i*32)) < 0 {
if int32(lo>>(i*32)) < 0 {
res |= 1 << i
}
}
for i := 0; i < 2; i++ {
if int8(hi>>(i*32)) < 0 {
if int32(hi>>(i*32)) < 0 {
res |= 1 << (i + 2)
}
}

View File

@@ -21,6 +21,8 @@ var (
case699 []byte
//go:embed testdata/701.wasm
case701 []byte
//go:embed testdata/704.wasm
case704 []byte
)
func newRuntimeCompiler() wazero.Runtime {
@@ -142,3 +144,24 @@ func Test701(t *testing.T) {
})
}
}
func Test704(t *testing.T) {
if !platform.CompilerSupported() {
return
}
for _, tc := range []struct {
name string
r wazero.Runtime
}{
{name: "compiler", r: newRuntimeCompiler()},
{name: "interpreter", r: newRuntimeInterpreter()},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
defer tc.r.Close(ctx)
_, err := tc.r.InstantiateModuleFromBinary(ctx, case704)
require.NoError(t, err)
})
}
}

Binary file not shown.

View File

@@ -0,0 +1,12 @@
(module
(func
v128.const i8x16 0xff 0x00 0xff 0x00 0xff 0x00 0xff 0x00 0xff 0x00 0xff 0x00 0xff 0x00 0xff 0x00
i32x4.bitmask ;; if this checks as i8x16 lane, the result here becomes non-zero, therefore unreachable.
(if (then unreachable))
v128.const i8x16 0xff 0x00 0xff 0x00 0xff 0x00 0xff 0x00 0xff 0x00 0xff 0x00 0xff 0x00 0xff 0x00
i16x8.bitmask ;; if this treats as i8x16 lane, the result here becomes non-zero, therefore unreachable.
(if (then unreachable))
)
(start 0)
)