Skip to content

Commit f95ae3d

Browse files
sophie-zhaogopherbot
authored andcommitted
cmd/asm: change register type for loong64 floating-point
On Loong64, the two input operands and one output operand of the ADDF instruction are both floating-point registers; and the floating-point comparison instruction CMPEQ{F,D}, CMPGE{F,D}, CMPGT{F,D} both input operands are floating-point registers, and the output operation is a floating-point condition register, currently, only FCC0 is used as the floating-point condition register. Example: ADDF F0, F1, F0 CMPEQF F0, F1, FCC0 Change-Id: I4c1c453e522d43f294a8dcab7b6b5247f41c9c68 Reviewed-on: https://go-review.googlesource.com/c/go/+/580281 Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: abner chenc <[email protected]> Auto-Submit: abner chenc <[email protected]> Reviewed-by: Michael Knyszek <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent aec5cc5 commit f95ae3d

File tree

5 files changed

+31
-27
lines changed

5 files changed

+31
-27
lines changed

src/cmd/asm/internal/arch/loong64.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,6 @@ func jumpLoong64(word string) bool {
2121
return false
2222
}
2323

24-
// IsLoong64CMP reports whether the op (as defined by an loong64.A* constant) is
25-
// one of the CMP instructions that require special handling.
26-
func IsLoong64CMP(op obj.As) bool {
27-
switch op {
28-
case loong64.ACMPEQF, loong64.ACMPEQD, loong64.ACMPGEF, loong64.ACMPGED,
29-
loong64.ACMPGTF, loong64.ACMPGTD:
30-
return true
31-
}
32-
return false
33-
}
34-
3524
// IsLoong64MUL reports whether the op (as defined by an loong64.A* constant) is
3625
// one of the MUL/DIV/REM instructions that require special handling.
3726
func IsLoong64MUL(op obj.As) bool {

src/cmd/asm/internal/asm/asm.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -642,12 +642,6 @@ func (p *Parser) asmInstruction(op obj.As, cond string, a []obj.Addr) {
642642
break
643643
}
644644
} else if p.arch.Family == sys.Loong64 {
645-
if arch.IsLoong64CMP(op) {
646-
prog.From = a[0]
647-
prog.Reg = p.getRegister(prog, op, &a[1])
648-
break
649-
}
650-
651645
if arch.IsLoong64RDTIME(op) {
652646
// The Loong64 RDTIME family of instructions is a bit special,
653647
// in that both its register operands are outputs

src/cmd/asm/internal/asm/testdata/loong64enc1.s

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ lable2:
5353
CLZ R4, R5 // 85140000
5454
CPUCFG R4, R5 // 856c0000
5555
ADDF F4, F5 // a5900001
56-
ADDF F4, R5, F6 // a6900001
57-
CMPEQF F4, R5 // a010120c
56+
ADDF F4, F5, F6 // a6900001
5857
ABSF F4, F5 // 85041401
5958
MOVVF F4, F5 // 85181d01
6059
MOVF F4, F5 // 85941401
@@ -220,11 +219,12 @@ lable2:
220219
MOVWR y+8(FP), R4 // 6440402e
221220
MOVWR 1(R5), R4 // a404402e
222221

223-
CMPGTF F4, R5 // a090110c
224-
CMPGTD F4, R5 // a090210c
225-
CMPGEF F4, R5 // a090130c
226-
CMPGED F4, R5 // a090230c
227-
CMPEQD F4, R5 // a010220c
222+
CMPEQF F4, F5, FCC0 // a010120c
223+
CMPGTF F4, F5, FCC1 // a190110c
224+
CMPGTD F4, F5, FCC2 // a290210c
225+
CMPGEF F4, F5, FCC3 // a390130c
226+
CMPGED F4, F5, FCC4 // a490230c
227+
CMPEQD F4, F5, FCC5 // a510220c
228228

229229
RDTIMELW R4, R0 // 80600000
230230
RDTIMEHW R4, R0 // 80640000

src/cmd/compile/internal/loong64/ssa.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
244244
p.From.Type = obj.TYPE_REG
245245
p.From.Reg = v.Args[0].Reg()
246246
p.Reg = v.Args[1].Reg()
247+
p.To.Type = obj.TYPE_REG
248+
p.To.Reg = loong64.REG_FCC0
247249
case ssa.OpLOONG64MOVVaddr:
248250
p := s.Prog(loong64.AMOVV)
249251
p.From.Type = obj.TYPE_ADDR

src/cmd/internal/obj/loong64/asm.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,14 @@ var optab = []Optab{
8282
{ACLO, C_REG, C_NONE, C_NONE, C_REG, C_NONE, 9, 4, 0, 0},
8383

8484
{AADDF, C_FREG, C_NONE, C_NONE, C_FREG, C_NONE, 32, 4, 0, 0},
85-
{AADDF, C_FREG, C_REG, C_NONE, C_FREG, C_NONE, 32, 4, 0, 0},
86-
{ACMPEQF, C_FREG, C_REG, C_NONE, C_NONE, C_NONE, 32, 4, 0, 0},
85+
{AADDF, C_FREG, C_FREG, C_NONE, C_FREG, C_NONE, 32, 4, 0, 0},
8786
{AABSF, C_FREG, C_NONE, C_NONE, C_FREG, C_NONE, 33, 4, 0, 0},
8887
{AMOVVF, C_FREG, C_NONE, C_NONE, C_FREG, C_NONE, 33, 4, 0, 0},
8988
{AMOVF, C_FREG, C_NONE, C_NONE, C_FREG, C_NONE, 33, 4, 0, 0},
9089
{AMOVD, C_FREG, C_NONE, C_NONE, C_FREG, C_NONE, 33, 4, 0, 0},
9190

91+
{ACMPEQF, C_FREG, C_FREG, C_NONE, C_FCCREG, C_NONE, 29, 4, 0, 0},
92+
9293
{AMOVW, C_REG, C_NONE, C_NONE, C_SEXT, C_NONE, 7, 4, 0, 0},
9394
{AMOVWU, C_REG, C_NONE, C_NONE, C_SEXT, C_NONE, 7, 4, 0, 0},
9495
{AMOVV, C_REG, C_NONE, C_NONE, C_SEXT, C_NONE, 7, 4, 0, 0},
@@ -850,6 +851,21 @@ func (c *ctxt0) aclass(a *obj.Addr) int {
850851
return C_GOK
851852
}
852853

854+
func (c *ctxt0) rclass(r int16) int {
855+
switch {
856+
case REG_R0 <= r && r <= REG_R31:
857+
return C_REG
858+
case REG_F0 <= r && r <= REG_F31:
859+
return C_FREG
860+
case REG_FCC0 <= r && r <= REG_FCC31:
861+
return C_FCCREG
862+
case REG_FCSR0 <= r && r <= REG_FCSR31:
863+
return C_FCSRREG
864+
}
865+
866+
return C_GOK
867+
}
868+
853869
func prasm(p *obj.Prog) {
854870
fmt.Printf("%v\n", p)
855871
}
@@ -883,7 +899,7 @@ func (c *ctxt0) oplook(p *obj.Prog) *Optab {
883899
// 2nd source operand
884900
a2 := C_NONE
885901
if p.Reg != 0 {
886-
a2 = C_REG
902+
a2 = c.rclass(p.Reg)
887903
}
888904

889905
// 2nd destination operand
@@ -1620,6 +1636,9 @@ func (c *ctxt0) asmout(p *obj.Prog, o *Optab, out []uint32) {
16201636
o1 = OP_12IRR(c.opirr(a), uint32(v), uint32(r), uint32(p.From.Reg))
16211637
}
16221638

1639+
case 29: // fcmp.cond.x fj, fk, fcc
1640+
o1 = OP_RRR(c.oprrr(p.As), uint32(p.From.Reg), uint32(p.Reg), uint32(p.To.Reg))
1641+
16231642
case 30: // movw r,fr
16241643
a := OP_TEN(8, 1321) // movgr2fr.w
16251644
o1 = OP_RR(a, uint32(p.From.Reg), uint32(p.To.Reg))

0 commit comments

Comments
 (0)