feat(asm): encode the arm64 FP immediate moves

Assisted-by: GLM 5.3 Flash
This commit is contained in:
petrbalvin committed 2026-10-07 02:36:24 +02:00
1 parent a9b54b6868
commit fbdad8424f
4 files changed
+181

No files matched your search

+50
View File
@@ -2069,3 +2069,53 @@ func TestArm64ConRnRejections(t *testing.T) {
}
}
}
// TestArm64FPImmediate pins the FP immediate moves against `go tool asm`
// words: the FMOV (immediate) instruction for the 8-bit encodable values and
// the FMOV-from-ZR move for zero, plus the rejections the toolchain raises
// (integer immediates to FP registers, FMOVQ immediates) and the values that
// only the toolchain's $f64 pool reaches.
func TestArm64FPImmediate(t *testing.T) {
got := arm64Words(t,
"\tFMOVS $(4.0), F0\n"+
"\tFMOVD $(4.0), F0\n"+
"\tFMOVS $(0.265625), F1\n"+
"\tFMOVD $(0.1796875), F2\n"+
"\tFMOVD $(28.0), F4\n"+
"\tFMOVD $(-4.0), F6\n"+
"\tFMOVD $0, F0\n"+
"\tFMOVD $(0.0), F5\n")
want := []uint32{
0x1e221000, // FMOV S0, #4.0
0x1e621000, // FMOV D0, #4.0
0x1e2a3001, // FMOV S1, #0.265625
0x1e68f002, // FMOV D2, #0.1796875
0x1e679004, // FMOV D4, #28.0
0x1e721006, // FMOV D6, #-4.0
0x9e6703e0, // FMOV D0, XZR
0x9e6703e5, // FMOV D5, XZR
0xd65f03c0, // RET
}
if len(got) != len(want) {
t.Fatalf("word count = %d, want %d", len(got), len(want))
}
for i := range want {
if got[i] != want[i] {
t.Errorf("word %d = %08x, want %08x", i, got[i], want[i])
}
}
for _, src := range []string{
"\tFMOVD\t$5, F0\n",
"\tFMOVS\t$4, F0\n",
"\tFMOVQ\t$(4.0), F0\n",
"\tFMOVD\t$(2.0), F0\n",
} {
f, errs := parser.Parse("test_arm64.s", "#include \"textflag.h\"\n\nTEXT ·f(SB), NOSPLIT, $0-0\n"+src+"\tRET\n")
if len(errs) > 0 {
continue // a parse rejection is a rejection
}
if _, err := AssembleFileARM64(f); err == nil {
t.Errorf("expected rejection for %q, got nil", strings.TrimSpace(src))
}
}
}