Repository: tetratelabs/wazero
Pull request #1980 (2024-01-30 17:14:47)

wazevo(amd64): pass all bulk memory tests


Patch:
diff --git a/internal/engine/wazevo/frontend/frontend.go b/internal/engine/wazevo/frontend/frontend.go
index 6aaffc87..60fd3fef 100644
--- a/internal/engine/wazevo/frontend/frontend.go
+++ b/internal/engine/wazevo/frontend/frontend.go
@@ -138,9 +138,12 @@ func (c *Compiler) declareSignatures(listenerOn bool) {
 
 	c.memmoveSig = ssa.Signature{
 		ID: c.refFuncSig.ID + 1,
-		// dst, src, and the byte count.
-		Params: []ssa.Type{ssa.TypeI64, ssa.TypeI64, ssa.TypeI32},
+		// dst, src, and the byte count where the order is depending on the architecture.
+		// https://github.com/golang/go/blob/65f056d07ad1db7dd4fb23c4d35cf7b8bd0d6008/src/runtime/memmove_amd64.s#L36-L41
+		// https://github.com/golang/go/blob/65f056d07ad1db7dd4fb23c4d35cf7b8bd0d6008/src/runtime/memmove_arm64.s#L11-L13
+		Params: []ssa.Type{ssa.TypeI64, ssa.TypeI64, ssa.TypeI64},
 	}
+
 	c.ssaBuilder.DeclareSignature(&c.memmoveSig)
 }
 
diff --git a/internal/engine/wazevo/frontend/lower.go b/internal/engine/wazevo/frontend/lower.go
index 0b71e670..4774991d 100644
--- a/internal/engine/wazevo/frontend/lower.go
+++ b/internal/engine/wazevo/frontend/lower.go
@@ -4,6 +4,7 @@ import (
 	"encoding/binary"
 	"fmt"
 	"math"
+	"runtime"
 	"strings"
 
 	"github.com/tetratelabs/wazero/api"
@@ -3424,7 +3425,18 @@ func (c *Compiler) memOpSetup(baseAddr ssa.Value, constOffset, operationSizeInBy
 }
 
 func (c *Compiler) callMemmove(dst, src, size ssa.Value) {
-	args := []ssa.Value{dst, src, size} // TODO: reuse the slice.
+	var args []ssa.Value
+	if runtime.GOARCH == "amd64" {
+		// https://github.com/golang/go/blob/65f056d07ad1db7dd4fb23c4d35cf7b8bd0d6008/src/runtime/memmove_amd64.s#L36-L41
+		args = []ssa.Value{dst, size, src} // TODO: reuse the slice.
+	} else {
+		// https://github.com/golang/go/blob/65f056d07ad1db7dd4fb23c4d35cf7b8bd0d6008/src/runtime/memmove_arm64.s#L11-L13
+		args = []ssa.Value{dst, src, size} // TODO: reuse the slice.
+	}
+
+	if size.Type() != ssa.TypeI64 {
+		panic("TODO: memmove size must be i64")
+	}
 
 	builder := c.ssaBuilder
 	memmovePtr := builder.AllocateInstruction().


Test patch:
diff --git a/internal/engine/wazevo/e2e_test.go b/internal/engine/wazevo/e2e_test.go
index f313bb61..5ff705fc 100644
--- a/internal/engine/wazevo/e2e_test.go
+++ b/internal/engine/wazevo/e2e_test.go
@@ -1312,32 +1312,32 @@ func TestSpectestV2(t *testing.T) {
 	for _, tc := range []struct {
 		name string
 	}{
-		//{"block"},
-		//{"bulk"},
-		//{"i32"},
-		//{"i64"},
+		{"block"},
+		{"bulk"},
+		{"i32"},
+		{"i64"},
 		{"br"},
-		//{"call"},
+		{"call"},
 		//{"call_indirect"},
 		//{"conversions"},
-		//{"global"},
-		//{"if"},
-		//{"linking"},
-		//{"loop"},
-		//{"memory_copy"},
-		//{"memory_fill"},
-		//{"memory_init"},
+		{"global"},
+		{"if"},
+		{"linking"},
+		{"loop"},
+		{"memory_copy"},
+		{"memory_fill"},
+		{"memory_init"},
 		{"memory_trap"},
 		{"ref_null"},
-		//{"ref_is_null"},
-		//{"ref_func"},
-		//{"table_copy"},
-		//{"table_fill"},
-		//{"table_get"},
-		//{"table_init"},
-		//{"table_set"},
+		{"ref_is_null"},
+		{"ref_func"},
+		{"table_copy"},
+		{"table_fill"},
+		{"table_get"},
+		{"table_init"},
+		{"table_set"},
 		{"table_size"},
-		//{"select"},
+		{"select"},
 		//{"simd_boolean"},
 		//{"simd_bit_shift"},
 		//{"simd_bitwise"},
diff --git a/internal/engine/wazevo/frontend/frontend_test.go b/internal/engine/wazevo/frontend/frontend_test.go
index 598241d8..826b7cf6 100644
--- a/internal/engine/wazevo/frontend/frontend_test.go
+++ b/internal/engine/wazevo/frontend/frontend_test.go
@@ -1716,7 +1716,7 @@ func TestCompiler_declareSignatures(t *testing.T) {
 			{ID: 5, Params: []ssa.Type{ssa.TypeI64}},
 			{ID: 6, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI32, ssa.TypeI32, ssa.TypeI64}, Results: []ssa.Type{ssa.TypeI32}},
 			{ID: 7, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI32}, Results: []ssa.Type{ssa.TypeI64}},
-			{ID: 8, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI64, ssa.TypeI32}},
+			{ID: 8, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI64, ssa.TypeI64}},
 		}
 
 		require.Equal(t, len(expected), len(declaredSigs))
@@ -1752,7 +1752,7 @@ func TestCompiler_declareSignatures(t *testing.T) {
 			{ID: 13, Params: []ssa.Type{ssa.TypeI64}},
 			{ID: 14, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI32, ssa.TypeI32, ssa.TypeI64}, Results: []ssa.Type{ssa.TypeI32}},
 			{ID: 15, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI32}, Results: []ssa.Type{ssa.TypeI64}},
-			{ID: 16, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI64, ssa.TypeI32}},
+			{ID: 16, Params: []ssa.Type{ssa.TypeI64, ssa.TypeI64, ssa.TypeI64}},
 		}
 		require.Equal(t, len(expected), len(declaredSigs))
 		for i := 0; i < len(declaredSigs); i++ {