fix(asm): encode the arm64 bitfield aliases with their own opc

Assisted-by: GLM 5.3 Flash
This commit is contained in:
petrbalvin committed 2026-10-07 02:36:24 +02:00
1 parent 8ab99c9b0c
commit 2b2a72d54e
2 files changed
+40 -1

No files matched your search

+36
View File
@@ -2186,3 +2186,39 @@ func TestArm64ZRNameNotNumber(t *testing.T) {
}
}
// TestArm64BitfieldAlias pins the bitfield alias encodings against
// `go tool asm` words: BFI rides the BFM opc at every lsb (asm7.go case 43
// routes ABFI to ABFM), SBFIZ keeps SBFM and UBFIZ keeps UBFM at the spelled
// width.
func TestArm64BitfieldAlias(t *testing.T) {
got := arm64Words(t,
"\tBFI $0, R1, $1, R2\n"+
"\tBFIW $0, R1, $1, R2\n"+
"\tBFI $4, R1, $4, R2\n"+
"\tSBFIZ $0, R1, $1, R2\n"+
"\tSBFIZW $0, R1, $1, R2\n"+
"\tUBFIZ $0, R1, $1, R2\n"+
"\tUBFIZW $0, R1, $1, R2\n"+
"\tUBFIZ $4, R1, $4, R2\n"+
"\tBFXIL $0, R1, $8, R2\n")
want := []uint32{
0xb3400022, // BFM X2, X1, #0, #0 (BFI lsb 0)
0x33000022, // BFM W2, W1, #0, #0 (BFIW lsb 0)
0xb37c0c22, // BFM X2, X1, #28, #3 (BFI lsb 4)
0x93400022, // SBFM X2, X1, #0, #0 (SBFIZ lsb 0)
0x13000022, // SBFM W2, W1, #0, #0 (SBFIZW lsb 0)
0xd3400022, // UBFM X2, X1, #0, #0 (UBFIZ lsb 0)
0x53000022, // UBFM W2, W1, #0, #0 (UBFIZW lsb 0)
0xd37c0c22, // UBFM X2, X1, #28, #3 (UBFIZ lsb 4)
0xb3401c22, // BFM X2, X1, #0, #7 (BFXIL lsb 0)
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])
}
}
}