feat(asm): take the loong64 register-pair spellings the toolchain parses

Assisted-by: GLM 5.3 Flash
This commit is contained in:
petrbalvin authored and Petr Balvín committed 2026-10-07 21:42:14 +02:00
1 parent 1031cd9ae7
commit a3eaa82f87
5 files changed
+237 -18

No files matched your search

+47
View File
@@ -1058,3 +1058,50 @@ TEXT ·bytes(SB), NOSPLIT, $0
}
}
}
// TestLOONG64PairSugar pins the toolchain's register-pair spellings: a
// top-level colon between two registers splits the operand in two with the
// halves swapped, so INSTR R4:R5, R6 encodes exactly as INSTR R5, R4, R6.
// Each row is pinned two ways: against the word GOARCH=loong64 go tool asm
// emits for the pair spelling, and against gasm's own encoding of the
// direct spelling, which must be the same bytes.
func TestLOONG64PairSugar(t *testing.T) {
for _, tt := range []struct {
pair, direct string
want uint32 // the word go tool asm emits for the pair
}{
{"MULV R4:R5, R6", "MULV R5, R4, R6", 0x001D9486},
{"MULV R4:R5", "MULV R5, R4", 0x001D9484},
{"MULV R6, R4:R5", "MULV R6, R5, R4", 0x001D98A4},
{"DIVV R4:R5, R6", "DIVV R5, R4, R6", 0x00221486},
{"MULHV R4:R5, R6", "MULHV R5, R4, R6", 0x001E1486},
{"ADDV R4:R5, R6", "ADDV R5, R4, R6", 0x00109486},
{"AND R4:R5, R6", "AND R5, R4, R6", 0x00149486},
{"MOVV R4:R5", "MOVV R5, R4", 0x001500A4},
{"MULD F4:F5, F6", "MULD F5, F4, F6", 0x01051486},
{"VADDW V1:V2, V3", "VADDW V2, V1, V3", 0x700B0823},
} {
t.Run(tt.pair, func(t *testing.T) {
pair := assembleLOONG64Helper(t, firstTextLOONG64(t, `#include "textflag.h"
TEXT ·p(SB), NOSPLIT, $0
`+tt.pair+`
RET
`))
direct := assembleLOONG64Helper(t, firstTextLOONG64(t, `#include "textflag.h"
TEXT ·d(SB), NOSPLIT, $0
`+tt.direct+`
RET
`))
if len(pair) < 4 {
t.Fatalf("pair spelling produced %d bytes", len(pair))
}
got := binary.LittleEndian.Uint32(pair)
if got != tt.want {
t.Errorf("pair word = %08x, want %08x (go tool asm)", got, tt.want)
}
if len(direct) < 4 || !bytes.Equal(pair[:4], direct[:4]) {
t.Errorf("pair bytes % x differ from the direct spelling's % x", pair[:4], direct[:4])
}
})
}
}