fix(asm): encode the flag-setting logicals to ZR and fold immediate expressions
Assisted-by: GLM 5.3 Flash
This commit is contained in:
1 parent
c1cef7b6e8
commit
5f6be4584d
2 files changed
+82
-31
No files matched your search
@@ -2596,3 +2596,49 @@ func TestArm64VTBLShapes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestArm64LogicalToZR pins the toolchain's split between the flag-setting
|
||||
// logicals, whose ZR destination keeps the bitmask fast path (asm7.go case
|
||||
// 53), and the plain forms, which materialise into REGTMP: `go tool asm`
|
||||
// encodes ANDSW $0x100, R13, ZR as one TSTW word and ANDW $1, R5, ZR as the
|
||||
// ORRW-plus-register pair.
|
||||
func TestArm64LogicalToZR(t *testing.T) {
|
||||
got := arm64Words(t, "\tANDSW $0x100, R13, ZR\n\tBICSW $1, R5, ZR\n\tANDSW $0x101, R13, ZR\n\tANDW $1, R5, ZR\n")
|
||||
want := []uint32{
|
||||
0x721801bf, // ANDS (bitmask) R13, ZR: the TSTW word
|
||||
0x721f78bf, // BICS (bitmask of $1) R5, ZR
|
||||
0x5280203b, // MOVW $257, R27: not a bitmask, materialised
|
||||
0x6a1b01bf, // ANDSW R27, R13
|
||||
0x320003fb, // ORRW $1, ZR, R27: the plain form materialises too
|
||||
0x0a1b00bf, // ANDW R27, R5, ZR
|
||||
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])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestArm64ImmediateExpression pins the folded arithmetic spellings the
|
||||
// parser leaves half-parsed: `$14*16` parses as the leading literal 14, and
|
||||
// the encoder must read the raw expression's 224 (`go tool asm` folds it).
|
||||
func TestArm64ImmediateExpression(t *testing.T) {
|
||||
got := arm64Words(t, "\tADD $14*16, R0\n\tMOVD $4*8+1, R1\n")
|
||||
want := []uint32{
|
||||
0x91038000, // ADD $224, R0
|
||||
0xd2800421, // MOVZ $33, R1: MOVD $con rides MOVZ for a movcon value
|
||||
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])
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user