feat(asm): encode the arm64 Q-width FP load and store
FMOVQ routes through the MOV load/store machinery in the plain, post-index, pre-index and static-symbol forms. The Q width carries its size in the opc field, so the store spelling is opc=10 and the access scales by sixteen; both come from helpers now instead of the size exponent. The static-symbol form takes the toolchain's twelve-byte ADRP + ADD + access fallback with the R_ADDRARM64 pair. The register-to-register and immediate forms stay rejected, matching the toolchain's own table. Assisted-by: GLM 5.3 Flash
This commit is contained in:
1 parent
a6bd9c1ebe
commit
daf7fad5b9
5 files changed
+161
-9
No files matched your search
+59
-8
@@ -228,11 +228,12 @@ func arm64PCAlignPad(pos int, instr *ast.Instr) int {
|
||||
}
|
||||
|
||||
// isARM64MovMnemonic reports whether m is one of the MOV-family spellings the
|
||||
// arm64 encoder treats as the MOV pseudo-instruction.
|
||||
// arm64 encoder treats as the MOV pseudo-instruction. FMOVQ rides the same
|
||||
// load/store machinery but carries no register-move or immediate form.
|
||||
func isARM64MovMnemonic(m string) bool {
|
||||
switch m {
|
||||
case "MOV", "MOVD", "MOVW", "MOVWU", "MOVH", "MOVHU", "MOVB", "MOVBU",
|
||||
"FMOVS", "FMOVD":
|
||||
"FMOVS", "FMOVD", "FMOVQ":
|
||||
return true
|
||||
}
|
||||
return false
|
||||
@@ -279,7 +280,7 @@ func arm64InstrSize(instr *ast.Instr, fi arm64FrameInfo, pos int) int {
|
||||
}
|
||||
switch mnem {
|
||||
case "MOV", "MOVD", "MOVW", "MOVWU", "MOVH", "MOVHU", "MOVB", "MOVBU",
|
||||
"FMOVS", "FMOVD":
|
||||
"FMOVS", "FMOVD", "FMOVQ":
|
||||
return arm64MovSize(mnem, ops, fi)
|
||||
case "ADD", "ADDW", "SUB", "SUBW", "CMP", "CMPW", "CMN", "CMNW",
|
||||
"ADDS", "ADDSW", "SUBS", "SUBSW":
|
||||
@@ -354,7 +355,7 @@ func encodeARM64Instr(instr *ast.Instr, pc int, offsets map[string]int, fi arm64
|
||||
case "BL", "CALL":
|
||||
return encodeARM64Branch(mnem, ops, pc, offsets, true, relocs, resolve)
|
||||
case "MOV", "MOVD", "MOVW", "MOVWU", "MOVH", "MOVHU", "MOVB", "MOVBU",
|
||||
"FMOVS", "FMOVD":
|
||||
"FMOVS", "FMOVD", "FMOVQ":
|
||||
return encodeARM64Mov(instr, mnem, "", fi, relocs)
|
||||
}
|
||||
|
||||
@@ -1479,6 +1480,20 @@ func encodeARM64Mov(instr *ast.Instr, mnem string, wb string, fi arm64FrameInfo,
|
||||
}
|
||||
src, dst := ops[0], ops[1]
|
||||
|
||||
if mnem == "FMOVQ" {
|
||||
// The 128-bit FP move is a pure memory access in the toolchain: its
|
||||
// table carries no register-to-register or immediate row, and both
|
||||
// spellings are rejected ("illegal combination"), so only the
|
||||
// load/store and static-symbol forms exist here either.
|
||||
loadOK := arm64IsMemOperand(src) && !arm64IsMemOperand(dst) && !isImmOperand(src)
|
||||
storeOK := arm64IsMemOperand(dst) && !arm64IsMemOperand(src) && !isImmOperand(src)
|
||||
sbLoad := src.Addr.Sym != nil && src.Addr.Sym.Pseudo == "SB"
|
||||
sbStore := dst.Addr.Sym != nil && dst.Addr.Sym.Pseudo == "SB"
|
||||
if !loadOK && !storeOK && !sbLoad && !sbStore {
|
||||
return nil, fmt.Errorf("%s: only the memory load and store forms exist", mnem)
|
||||
}
|
||||
}
|
||||
|
||||
if wb != "" {
|
||||
switch {
|
||||
case isMemOperand(src) && !isMemOperand(dst):
|
||||
@@ -1609,8 +1624,14 @@ func arm64MovSize(mnem string, ops []*ast.Operand, fi arm64FrameInfo) int {
|
||||
}
|
||||
return len(b)
|
||||
case src.Addr.Sym != nil && src.Addr.Sym.Pseudo == "SB":
|
||||
if mnem == "FMOVQ" {
|
||||
return 12 // ADRP + ADD + LDR: the unaligned-access fallback
|
||||
}
|
||||
return 8 // ADRP + LDR
|
||||
case dst.Addr.Sym != nil && dst.Addr.Sym.Pseudo == "SB":
|
||||
if mnem == "FMOVQ" {
|
||||
return 12 // ADRP + ADD + STR: the unaligned-access fallback
|
||||
}
|
||||
return 8 // ADRP + STR
|
||||
case isMemOperand(src) || isMemOperand(dst):
|
||||
mem := src
|
||||
@@ -1623,7 +1644,7 @@ func arm64MovSize(mnem string, ops []*ast.Operand, fi arm64FrameInfo) int {
|
||||
if !ok {
|
||||
lt = a64LoadTable["MOVD"] // the MOV pseudo is a 64-bit access
|
||||
}
|
||||
scale := int64(1) << uint(lt.size)
|
||||
scale := a64LSScale(lt)
|
||||
if off >= 0 && off%scale == 0 && off/scale < 4096 {
|
||||
return 4
|
||||
}
|
||||
@@ -1876,7 +1897,7 @@ func encodeARM64MemOp(mnem string, mem *ast.Operand, reg int, load bool, fi arm6
|
||||
lt = a64LoadTable["MOVD"]
|
||||
}
|
||||
|
||||
scale := int64(1) << uint(lt.size)
|
||||
scale := a64LSScale(lt)
|
||||
storeOpc := a64StoreOpc(lt)
|
||||
var opc int
|
||||
if load {
|
||||
@@ -1963,12 +1984,27 @@ func encodeARM64SBAddr(sym *ast.Symbol, rd int, relocs *[]Reloc) []byte {
|
||||
|
||||
// encodeARM64SBLoad emits ADRP R27, 0; LDR Rd, [R27, 0] with relocations,
|
||||
// matching the toolchain: the scratch register is REGTMP (R27) and the pair
|
||||
// carries R_ARM64_PCREL_LDST64.
|
||||
// carries R_ARM64_PCREL_LDST64. FMOVQ has no LDST relocation width, so it
|
||||
// takes the toolchain's unaligned-access fallback instead (asm7.go case 65):
|
||||
// ADRP R27, 0; ADD R27, R27, 0; LDR with the R_ADDRARM64 pair.
|
||||
func encodeARM64SBLoad(sym *ast.Symbol, rd int, mnem string, relocs *[]Reloc) ([]byte, error) {
|
||||
lt, ok := a64LoadTable[mnem]
|
||||
if !ok {
|
||||
lt = a64LoadTable["MOVD"]
|
||||
}
|
||||
if mnem == "FMOVQ" {
|
||||
if relocs != nil {
|
||||
*relocs = append(*relocs,
|
||||
Reloc{Off: 0, After: 0, Name: sym.Name, Kind: RelArm64Addr, Addend: sym.Offset},
|
||||
Reloc{Off: 4, After: 4, Name: sym.Name, Kind: RelArm64Addr, Addend: sym.Offset},
|
||||
)
|
||||
}
|
||||
return a64WordsLE(
|
||||
a64ADR(1, 0, 0, 27), // ADRP R27, 0
|
||||
a64AddSub(1, 0, 0, 0, 0, 27, 27), // ADD $0, R27, R27
|
||||
a64LSU(uint32(lt.size), uint32(lt.V), uint32(lt.opc), 0, 27, uint32(rd)), // LDR Rd, (R27)
|
||||
), nil
|
||||
}
|
||||
if relocs != nil {
|
||||
*relocs = append(*relocs,
|
||||
Reloc{Off: 0, After: 8, Name: sym.Name, Kind: RelArm64LDST64, Addend: sym.Offset},
|
||||
@@ -1981,13 +2017,28 @@ func encodeARM64SBLoad(sym *ast.Symbol, rd int, mnem string, relocs *[]Reloc) ([
|
||||
}
|
||||
|
||||
// encodeARM64SBStore emits ADRP R27, 0; STR Rs, [R27, 0] with relocations,
|
||||
// matching the toolchain's R27 scratch and R_ARM64_PCREL_LDST64 pair.
|
||||
// matching the toolchain's R27 scratch and R_ARM64_PCREL_LDST64 pair. FMOVQ
|
||||
// takes the twelve-byte ADRP + ADD + STR fallback with the R_ADDRARM64 pair,
|
||||
// the store-side twin of the load above (asm7.go case 64).
|
||||
func encodeARM64SBStore(sym *ast.Symbol, rs int, mnem string, relocs *[]Reloc) ([]byte, error) {
|
||||
lt, ok := a64LoadTable[mnem]
|
||||
if !ok {
|
||||
lt = a64LoadTable["MOVD"]
|
||||
}
|
||||
storeOpc := a64StoreOpc(lt)
|
||||
if mnem == "FMOVQ" {
|
||||
if relocs != nil {
|
||||
*relocs = append(*relocs,
|
||||
Reloc{Off: 0, After: 0, Name: sym.Name, Kind: RelArm64Addr, Addend: sym.Offset},
|
||||
Reloc{Off: 4, After: 4, Name: sym.Name, Kind: RelArm64Addr, Addend: sym.Offset},
|
||||
)
|
||||
}
|
||||
return a64WordsLE(
|
||||
a64ADR(1, 0, 0, 27), // ADRP R27, 0
|
||||
a64AddSub(1, 0, 0, 0, 0, 27, 27), // ADD $0, R27, R27
|
||||
a64LSU(uint32(lt.size), uint32(lt.V), uint32(storeOpc), 0, 27, uint32(rs)), // STR Rs, (R27)
|
||||
), nil
|
||||
}
|
||||
if relocs != nil {
|
||||
*relocs = append(*relocs,
|
||||
Reloc{Off: 0, After: 8, Name: sym.Name, Kind: RelArm64LDST64, Addend: sym.Offset},
|
||||
|
||||
Reference in new issue
Block a user