interpreter: fixes V128FloatPromote to use lower 64-bits. (#709)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
This commit is contained in:
@@ -3826,9 +3826,9 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, callCtx *wasm.CallCont
|
|||||||
ce.pushValue(retHi)
|
ce.pushValue(retHi)
|
||||||
frame.pc++
|
frame.pc++
|
||||||
case wazeroir.OperationKindV128FloatPromote:
|
case wazeroir.OperationKindV128FloatPromote:
|
||||||
hi, lo := ce.popValue(), ce.popValue()
|
_, toPromote := ce.popValue(), ce.popValue()
|
||||||
ce.pushValue(math.Float64bits(float64(math.Float32frombits(uint32(lo)))))
|
ce.pushValue(math.Float64bits(float64(math.Float32frombits(uint32(toPromote)))))
|
||||||
ce.pushValue(math.Float64bits(float64(math.Float32frombits(uint32(hi)))))
|
ce.pushValue(math.Float64bits(float64(math.Float32frombits(uint32(toPromote >> 32)))))
|
||||||
frame.pc++
|
frame.pc++
|
||||||
case wazeroir.OperationKindV128FloatDemote:
|
case wazeroir.OperationKindV128FloatDemote:
|
||||||
hi, lo := ce.popValue(), ce.popValue()
|
hi, lo := ce.popValue(), ce.popValue()
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ var (
|
|||||||
case704 []byte
|
case704 []byte
|
||||||
//go:embed testdata/708.wasm
|
//go:embed testdata/708.wasm
|
||||||
case708 []byte
|
case708 []byte
|
||||||
|
//go:embed testdata/709.wasm
|
||||||
|
case709 []byte
|
||||||
)
|
)
|
||||||
|
|
||||||
func newRuntimeCompiler() wazero.Runtime {
|
func newRuntimeCompiler() wazero.Runtime {
|
||||||
@@ -193,3 +195,32 @@ func Test708(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test709(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)
|
||||||
|
mod, err := tc.r.InstantiateModuleFromBinary(ctx, case709)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
f := mod.ExportedFunction("f64x2.promote_low_f32x4")
|
||||||
|
require.NotNil(t, f)
|
||||||
|
res, err := f.Call(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
require.NotEqual(t, uint64(0), res[0])
|
||||||
|
require.NotEqual(t, uint64(0), res[1])
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
BIN
internal/integration_test/fuzzcases/testdata/709.wasm
vendored
Normal file
BIN
internal/integration_test/fuzzcases/testdata/709.wasm
vendored
Normal file
Binary file not shown.
9
internal/integration_test/fuzzcases/testdata/709.wat
vendored
Normal file
9
internal/integration_test/fuzzcases/testdata/709.wat
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
(module
|
||||||
|
(func (result v128)
|
||||||
|
v128.const i32x4 0xffffffff 0xffffffff 0 0
|
||||||
|
;; This should promote two 32-bit floats on the lower 64-bits (0xffffffff x2)
|
||||||
|
;; Therefore, the returned vector must have non zero lower and higher 64-bits.
|
||||||
|
f64x2.promote_low_f32x4
|
||||||
|
)
|
||||||
|
(export "f64x2.promote_low_f32x4" (func 0))
|
||||||
|
)
|
||||||
@@ -2722,6 +2722,8 @@ func (OperationV128ExtAddPairwise) Kind() OperationKind {
|
|||||||
// OperationV128FloatPromote implements Operation.
|
// OperationV128FloatPromote implements Operation.
|
||||||
//
|
//
|
||||||
// This corresponds to wasm.OpcodeVecF64x2PromoteLowF32x4ZeroName
|
// This corresponds to wasm.OpcodeVecF64x2PromoteLowF32x4ZeroName
|
||||||
|
// This discards the higher 64-bit of a vector, and promotes two
|
||||||
|
// 32-bit floats in the lower 64-bit as two 64-bit floats.
|
||||||
type OperationV128FloatPromote struct{}
|
type OperationV128FloatPromote struct{}
|
||||||
|
|
||||||
// Kind implements Operation.Kind.
|
// Kind implements Operation.Kind.
|
||||||
|
|||||||
Reference in New Issue
Block a user