aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/internal/obj/arm64
diff options
context:
space:
mode:
authorWei Xiao <wei.xiao@arm.com>2017-04-21 15:59:07 +0800
committerCherry Zhang <cherryyz@google.com>2017-04-27 13:35:59 +0000
commit2b6c58f6d559ef2621f677e016aba08a6b8aad19 (patch)
tree4e75f7f220909ef6d6710cfde6fcaf99f404cb66 /src/cmd/internal/obj/arm64
parent220e0e0f7383a79fda0ba61bd1bf2076f5f74d72 (diff)
downloadgo-2b6c58f6d559ef2621f677e016aba08a6b8aad19.tar.xz
cmd/internal/obj/arm64: fix encoding of condition
The current code treats condition as special register and write its raw data directly into instruction. The fix converts the raw data into correct condition encoding. Also fix the operand catogery of FCCMP. Add tests to cover all cases. Change-Id: Ib194041bd9017dd0edbc241564fe983082ac616b Reviewed-on: https://go-review.googlesource.com/41511 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'src/cmd/internal/obj/arm64')
-rw-r--r--src/cmd/internal/obj/arm64/asm7.go25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/cmd/internal/obj/arm64/asm7.go b/src/cmd/internal/obj/arm64/asm7.go
index b0510267fe..8218c6b333 100644
--- a/src/cmd/internal/obj/arm64/asm7.go
+++ b/src/cmd/internal/obj/arm64/asm7.go
@@ -495,7 +495,7 @@ var optab = []Optab{
{AFMOVD, C_FREG, C_NONE, C_REG, 29, 4, 0, 0, 0},
{AFCMPS, C_FREG, C_FREG, C_NONE, 56, 4, 0, 0, 0},
{AFCMPS, C_FCON, C_FREG, C_NONE, 56, 4, 0, 0, 0},
- {AFCCMPS, C_COND, C_REG, C_VCON, 57, 4, 0, 0, 0},
+ {AFCCMPS, C_COND, C_FREG, C_VCON, 57, 4, 0, 0, 0},
{AFCSELD, C_COND, C_REG, C_FREG, 18, 4, 0, 0, 0},
{AFCVTSD, C_FREG, C_NONE, C_FREG, 29, 4, 0, 0, 0},
{ACLREX, C_NONE, C_NONE, C_VCON, 38, 4, 0, 0, 0},
@@ -2224,6 +2224,12 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) {
o1 = c.oprrr(p, p.As)
cond := int(p.From.Reg)
+ if cond < COND_EQ || cond > COND_NV {
+ c.ctxt.Diag("invalid condition\n%v", p)
+ } else {
+ cond -= COND_EQ
+ }
+
r := int(p.Reg)
var rf int
if r != 0 {
@@ -2246,12 +2252,17 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) {
}
rt := int(p.To.Reg)
- o1 |= (uint32(rf&31) << 16) | (uint32(cond&31) << 12) | (uint32(r&31) << 5) | uint32(rt&31)
+ o1 |= (uint32(rf&31) << 16) | (uint32(cond&15) << 12) | (uint32(r&31) << 5) | uint32(rt&31)
case 19: /* CCMN cond, (Rm|uimm5),Rn, uimm4 -> ccmn Rn,Rm,uimm4,cond */
nzcv := int(p.To.Offset)
cond := int(p.From.Reg)
+ if cond < COND_EQ || cond > COND_NV {
+ c.ctxt.Diag("invalid condition\n%v", p)
+ } else {
+ cond -= COND_EQ
+ }
var rf int
if p.From3.Type == obj.TYPE_REG {
o1 = c.oprrr(p, p.As)
@@ -2261,7 +2272,7 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) {
rf = int(p.From3.Offset & 0x1F)
}
- o1 |= (uint32(rf&31) << 16) | (uint32(cond) << 12) | (uint32(p.Reg&31) << 5) | uint32(nzcv)
+ o1 |= (uint32(rf&31) << 16) | (uint32(cond&15) << 12) | (uint32(p.Reg&31) << 5) | uint32(nzcv)
case 20: /* movT R,O(R) -> strT */
v := int32(c.regoff(&p.To))
@@ -2794,6 +2805,12 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) {
o1 = c.oprrr(p, p.As)
cond := int(p.From.Reg)
+ if cond < COND_EQ || cond > COND_NV {
+ c.ctxt.Diag("invalid condition\n%v", p)
+ } else {
+ cond -= COND_EQ
+ }
+
nzcv := int(p.To.Offset)
if nzcv&^0xF != 0 {
c.ctxt.Diag("implausible condition\n%v", p)
@@ -2804,7 +2821,7 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) {
break
}
rt := int(p.From3.Reg)
- o1 |= uint32(rf&31)<<16 | uint32(cond)<<12 | uint32(rt&31)<<5 | uint32(nzcv)
+ o1 |= uint32(rf&31)<<16 | uint32(cond&15)<<12 | uint32(rt&31)<<5 | uint32(nzcv)
case 58: /* ldar/ldxr/ldaxr */
o1 = c.opload(p, p.As)