1
0
mirror of https://github.com/golang/go synced 2024-09-28 19:34:28 -06:00

cmd/internal/obj/arm64: factor out code generation for addition of 12 bit immediates

Factor out and simplify code that generates the addition of a 12 bit immediate
(the addition of a negative value is still handled via subtraction). This also
fixes the mishandling of the case where v is 0.

Change-Id: I6040f33d2fec87b772272531b3bf02390ae7f200
Reviewed-on: https://go-review.googlesource.com/c/go/+/461141
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Eric Fang <eric.fang@arm.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Joel Sing <joel@sing.id.au>
Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
Joel Sing 2023-01-09 04:21:37 +11:00
parent f76fc28c6b
commit e7c7f33263

View File

@ -4678,27 +4678,15 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) {
case 74:
// add $O, R, Rtmp or sub $O, R, Rtmp
// ldp (Rtmp), (R1, R2)
r := int(p.From.Reg)
if r == obj.REG_NONE {
r = int(o.param)
rf := p.From.Reg
if rf == obj.REG_NONE {
rf = o.param
}
if r == obj.REG_NONE {
if rf == obj.REG_NONE {
c.ctxt.Diag("invalid ldp source: %v", p)
}
v := int32(c.regoff(&p.From))
if v > 0 {
if v > 4095 {
c.ctxt.Diag("offset out of range: %v", p)
}
o1 = c.oaddi(p, int32(c.opirr(p, AADD)), v, r, REGTMP)
}
if v < 0 {
if v < -4095 {
c.ctxt.Diag("offset out of range: %v", p)
}
o1 = c.oaddi(p, int32(c.opirr(p, ASUB)), -v, r, REGTMP)
}
o1 = c.oaddi12(p, v, REGTMP, rf)
o2 = c.opldpstp(p, o, 0, uint32(REGTMP), uint32(p.To.Reg), uint32(p.To.Offset), 1)
case 75:
@ -4728,26 +4716,15 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) {
if p.From.Reg == REGTMP || p.From.Offset == REGTMP {
c.ctxt.Diag("cannot use REGTMP as source: %v", p)
}
r := int(p.To.Reg)
if r == obj.REG_NONE {
r = int(o.param)
rt := p.To.Reg
if rt == obj.REG_NONE {
rt = o.param
}
if r == obj.REG_NONE {
if rt == obj.REG_NONE {
c.ctxt.Diag("invalid stp destination: %v", p)
}
v := int32(c.regoff(&p.To))
if v > 0 {
if v > 4095 {
c.ctxt.Diag("offset out of range: %v", p)
}
o1 = c.oaddi(p, int32(c.opirr(p, AADD)), v, r, REGTMP)
}
if v < 0 {
if v < -4095 {
c.ctxt.Diag("offset out of range: %v", p)
}
o1 = c.oaddi(p, int32(c.opirr(p, ASUB)), -v, r, REGTMP)
}
o1 = c.oaddi12(p, v, REGTMP, rt)
o2 = c.opldpstp(p, o, 0, uint32(REGTMP), uint32(p.From.Reg), uint32(p.From.Offset), 0)
case 77:
@ -7146,6 +7123,19 @@ func (c *ctxt7) oaddi(p *obj.Prog, o1 int32, v int32, r int, rt int) uint32 {
return uint32(o1)
}
func (c *ctxt7) oaddi12(p *obj.Prog, v int32, rd, rn int16) uint32 {
if v < -4095 || v > 4095 {
c.ctxt.Diag("%v is not a 12 bit immediate: %v", v, p)
return 0
}
a := AADD
if v < 0 {
a = ASUB
v = -v
}
return c.oaddi(p, int32(c.opirr(p, a)), v, int(rn), int(rd))
}
/*
* load a literal value into dr
*/