fix(asm): close the oracle parity gaps in frame addressing and calls

This commit is contained in:
2026-09-14 23:25:14 +02:00
parent 70218e84ba
commit 40476546df
18 changed files with 456 additions and 60 deletions
+2
View File
@@ -23,6 +23,8 @@ func TestGroundTruthARM64(t *testing.T) {
"../testdata/verify/movimm_arm64.s",
"../testdata/verify/branch_arm64.s",
"../testdata/verify/call_arm64.s",
"../testdata/verify/bigframe_arm64.s",
"../testdata/verify/guard_arm64.s",
} {
t.Run(path, func(t *testing.T) {
src, err := os.ReadFile(path)
+58
View File
@@ -4,9 +4,23 @@
package verify
import (
"bytes"
"os"
"testing"
"sourcedock.dev/petrbalvin/gasm-devkit/asm"
"sourcedock.dev/petrbalvin/gasm-devkit/parser"
)
func mustRead(t *testing.T, path string) string {
t.Helper()
b, err := os.ReadFile(path)
if err != nil {
t.Fatalf("read: %v", err)
}
return string(b)
}
func TestGroundTruthBasic(t *testing.T) {
// Use the simple test kernel — it assembles with go tool asm.
gt, err := GroundTruth("../testdata/verify/basic_amd64.s")
@@ -75,3 +89,47 @@ func keys(m map[string][]byte) []string {
}
return out
}
// TestGroundTruthAMD64 runs the amd64 kernels through the same live
// comparison the other arches use: gasm output versus go tool asm output,
// with relocation fields masked on both sides.
func TestGroundTruthAMD64(t *testing.T) {
for _, path := range []string{
"../testdata/verify/basic_amd64.s",
"../testdata/verify/bigframe_amd64.s",
"../testdata/verify/guard_amd64.s",
} {
t.Run(path, func(t *testing.T) {
f, errs := parser.Parse(path, mustRead(t, path))
if len(errs) > 0 {
t.Fatalf("parse: %v", errs)
}
img, err := asm.AssembleFile(f)
if err != nil {
t.Fatalf("AssembleFile: %v", err)
}
gt, err := GroundTruth(path)
if err != nil {
t.Fatalf("GroundTruth: %v", err)
}
matched := 0
for _, fn := range img.Funcs {
gasmCode := maskRelocs(append([]byte(nil), img.Code[fn.Offset:fn.Offset+fn.Size]...), fn.Relocs)
goCode, ok := gt[fn.Name]
if !ok {
t.Errorf("%s: not in ground truth (%d functions)", fn.Name, len(gt))
continue
}
goCode = maskRelocs(goCode, fn.Relocs)
if !bytes.Equal(gasmCode, goCode) {
t.Errorf("%s: MISMATCH gasm=%d go=%d bytes\n%s", fn.Name, len(gasmCode), len(goCode), diffHex(gasmCode, goCode))
continue
}
matched++
}
if matched == 0 {
t.Fatal("no functions matched")
}
})
}
}
+2
View File
@@ -22,6 +22,8 @@ func TestGroundTruthLOONG64(t *testing.T) {
for _, path := range []string{
"../testdata/verify/basic_loong64.s",
"../testdata/verify/fp_loong64.s",
"../testdata/verify/bigframe_loong64.s",
"../testdata/verify/guard_loong64.s",
} {
t.Run(path, func(t *testing.T) {
src, err := os.ReadFile(path)
+2
View File
@@ -25,6 +25,8 @@ func TestGroundTruthRISCV(t *testing.T) {
"../testdata/verify/movimm_riscv64.s",
"../testdata/verify/branch_riscv64.s",
"../testdata/verify/call_riscv64.s",
"../testdata/verify/bigframe_riscv64.s",
"../testdata/verify/guard_riscv64.s",
} {
t.Run(path, func(t *testing.T) {
testGroundTruthRISCVFile(t, path)