mirror of
https://github.com/golang/go
synced 2024-09-28 21:34:30 -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:
parent
f76fc28c6b
commit
e7c7f33263
@ -4678,27 +4678,15 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) {
|
|||||||
case 74:
|
case 74:
|
||||||
// add $O, R, Rtmp or sub $O, R, Rtmp
|
// add $O, R, Rtmp or sub $O, R, Rtmp
|
||||||
// ldp (Rtmp), (R1, R2)
|
// ldp (Rtmp), (R1, R2)
|
||||||
r := int(p.From.Reg)
|
rf := p.From.Reg
|
||||||
if r == obj.REG_NONE {
|
if rf == obj.REG_NONE {
|
||||||
r = int(o.param)
|
rf = o.param
|
||||||
}
|
}
|
||||||
if r == obj.REG_NONE {
|
if rf == obj.REG_NONE {
|
||||||
c.ctxt.Diag("invalid ldp source: %v", p)
|
c.ctxt.Diag("invalid ldp source: %v", p)
|
||||||
}
|
}
|
||||||
v := int32(c.regoff(&p.From))
|
v := int32(c.regoff(&p.From))
|
||||||
|
o1 = c.oaddi12(p, v, REGTMP, rf)
|
||||||
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)
|
|
||||||
}
|
|
||||||
o2 = c.opldpstp(p, o, 0, uint32(REGTMP), uint32(p.To.Reg), uint32(p.To.Offset), 1)
|
o2 = c.opldpstp(p, o, 0, uint32(REGTMP), uint32(p.To.Reg), uint32(p.To.Offset), 1)
|
||||||
|
|
||||||
case 75:
|
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 {
|
if p.From.Reg == REGTMP || p.From.Offset == REGTMP {
|
||||||
c.ctxt.Diag("cannot use REGTMP as source: %v", p)
|
c.ctxt.Diag("cannot use REGTMP as source: %v", p)
|
||||||
}
|
}
|
||||||
r := int(p.To.Reg)
|
rt := p.To.Reg
|
||||||
if r == obj.REG_NONE {
|
if rt == obj.REG_NONE {
|
||||||
r = int(o.param)
|
rt = o.param
|
||||||
}
|
}
|
||||||
if r == obj.REG_NONE {
|
if rt == obj.REG_NONE {
|
||||||
c.ctxt.Diag("invalid stp destination: %v", p)
|
c.ctxt.Diag("invalid stp destination: %v", p)
|
||||||
}
|
}
|
||||||
v := int32(c.regoff(&p.To))
|
v := int32(c.regoff(&p.To))
|
||||||
if v > 0 {
|
o1 = c.oaddi12(p, v, REGTMP, rt)
|
||||||
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)
|
|
||||||
}
|
|
||||||
o2 = c.opldpstp(p, o, 0, uint32(REGTMP), uint32(p.From.Reg), uint32(p.From.Offset), 0)
|
o2 = c.opldpstp(p, o, 0, uint32(REGTMP), uint32(p.From.Reg), uint32(p.From.Offset), 0)
|
||||||
|
|
||||||
case 77:
|
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)
|
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
|
* load a literal value into dr
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user