Files
d54d2cd820 gcasm: keep the x64 const-shuffle emulation inside the scratch set (#54)
* gcasm: keep the x64 const-shuffle emulation inside the scratch set

The fused-tree emission of i8x16_shuffle_const staged its biased
PSHUFB patterns in X4/X5, outside the splicer's X0-X3 scratch set.
Pool values live in X4+ for the whole loop body and the window
path's relocate-out-of-reach scan does not run there, so any value
the allocator parked in those registers was corrupted — on the
repack gemv loop the activation-scale splat died and every output
came out garbage on amd64 builds with the splices enabled
(GOAMD64=v2+; v1 uses the pure fallback and CI only ran v1-shaped
suites for this path until the numeric kernel tests landed).

Reload the pattern from the constant pool instead of holding a
second biased copy and apply the bias constants as memory operands:
three registers suffice and the emulation stays inside X0-X2. The
regression test emits a loop whose splat must survive a
const-shuffle and rejects any X4+ mention in the emulation body.
Verified end to end under GOAMD64=v2: the repack numeric kernel
tests and the full engine suite pass against a bundle transpiled
with this fix; arm64 output is byte-identical.

Co-Authored-By: Claude Fable 5 <[email protected]>

* ci: execute the amd64 splices under GOAMD64=v2

The default job builds at v1, whose binaries keep the pure fallback
— the spliced amd64 code paths were never executed by any CI until
a consumer suite tripped over them. Run the execution-heavy suites
with GOAMD64=v2 so the splices run on the runner AVX2 hardware.

Co-Authored-By: Claude Fable 5 <[email protected]>

* ci: scope the GOAMD64=v2 job to the full-backend suites

codegen.Translate output carries its pure bodies under the
asm-dormancy tag with no asm bundle by design, so internal/codegen
runtime tests cannot build at v2; the spliced execution surface is
the transpile backend and gcasm.

Co-Authored-By: Claude Fable 5 <[email protected]>

* ci: execute the arm64 splices on native hardware

The flagship arm64 backend (SDOT/SMMLA splices, the fused loops)
had the same execution blind spot the amd64-v2 job just closed:
nothing in this repo ever RAN it. Run the full-backend suites on a
native arm64 runner, mirroring the v2 job scope.

Co-Authored-By: Claude Fable 5 <[email protected]>

* gcasm: skip the amd64-fixture harnesses on other hosts

The direct-asm gate/jump-table/perf fixtures generate amd64-only
assembly and build+run it on the host, so they can only execute on
amd64; on the new native arm64 CI runner the generated package has
no bodies (the pure fallback is tagged out) and vet fails with
undefined symbols. Declare the host requirement with an explicit
skip. The arm64 job still executes the full transpile backend and
the arch-neutral gcasm suites natively.

Co-Authored-By: Claude Fable 5 <[email protected]>

---------

Co-authored-by: Claude Fable 5 <[email protected]>
2026-08-25 09:08:12 +09:00

109 lines
2.8 KiB
Go

package gcasm
import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"
)
// TestStackArgCallGate executes the ABIInternal stack-argument
// marshal: a transformed caller invoking a 12-int-arg callee (which
// itself stays pure — its own params stack-assign). Gate 3a validated
// that such call sites TRANSFORM; this gate validates they RUN.
func TestStackArgCallGate(t *testing.T) {
if runtime.GOARCH != "amd64" {
t.Skip("fixture emits amd64-only asm; the harness builds and runs it on the host")
}
dir := t.TempDir()
libSrc := `package lib
//go:noinline
func Wide(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11 int32) int32 {
return a0 + a1*2 + a2*3 + a3*5 + a4*7 + a5*11 + a6*13 + a7*17 + a8*19 + a9*23 + a10*29 + a11*31
}
//go:noinline
func Caller(x int32) int32 {
return Wide(x, x+1, x+2, x-3, x+4, x+5, x-6, x+7, x+8, x-9, x+10, x+11)
}
`
for name, content := range map[string]string{
"go.mod": "module sagate\n\ngo 1.25.0\n",
"lib/lib.go": libSrc,
} {
p := filepath.Join(dir, name)
if err := os.MkdirAll(filepath.Dir(p), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(p, []byte(content), 0o644); err != nil {
t.Fatal(err)
}
}
fns, _, err := Capture(dir, "sagate/lib")
if err != nil {
t.Fatal(err)
}
var fn *Fn
for _, f := range fns {
if strings.HasSuffix(f.Name, ".Caller") {
fn = f
}
}
if fn == nil {
t.Fatal("Caller not captured")
}
wideSig := make([]ArgKind, 12)
for i := range wideSig {
wideSig[i] = ArgI32
}
body, err := Transform(fn, TransformOptions{
SymName: "callerAsm",
CalleeSig: func(sym string) ([]ArgKind, bool, ArgKind, string, bool) {
if strings.HasSuffix(sym, ".Wide") {
return wideSig, true, ArgI32, "·Wide", true
}
return nil, false, 0, "", false
},
Params: []ArgKind{ArgI32},
HasResult: true,
Result: ArgI32,
ArgNames: []string{"x"},
})
if err != nil {
t.Fatal(err)
}
run := t.TempDir()
files := map[string]string{
"go.mod": "module sarun\n\ngo 1.25.0\n",
"lib.go": strings.Replace(libSrc, "package lib", "package sarun", 1) + "\nfunc callerAsm(x int32) (r0 int32)\n",
"body_amd64.s": "#include \"textflag.h\"\n#include \"funcdata.h\"\n\n" + body,
"run_test.go": `package sarun
import "testing"
func TestStackArgs(t *testing.T) {
for _, x := range []int32{0, 1, -7, 1000, -100000} {
if got, want := callerAsm(x), Caller(x); got != want {
t.Fatalf("callerAsm(%d)=%d want %d", x, got, want)
}
}
}
`,
}
for name, content := range files {
if err := os.WriteFile(filepath.Join(run, name), []byte(content), 0o644); err != nil {
t.Fatal(err)
}
}
cmd := exec.Command("go", "test", "-run", "TestStackArgs", ".")
cmd.Dir = run
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("stack-arg gate failed: %v\n%s\n--- transformed body ---\n%s", err, out, body)
}
}