]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/obj/arm64: fix assemble movk bug
authorfanzha02 <fannie.zhang@arm.com>
Tue, 13 Jun 2017 10:16:41 +0000 (10:16 +0000)
committerCherry Zhang <cherryyz@google.com>
Tue, 22 Aug 2017 13:10:08 +0000 (13:10 +0000)
The current code gets shift arguments value from prog.From3.Offset.
But prog.From3.Offset is not assigned the shift arguments value in
instructions assemble process.

The fix calls movcon() function to get the correct value.

Uncomment the movk/movkw  cases.

Fixes #21398
Change-Id: I78d40c33c24bd4e3688a04622e4af7ddb5333fa6
Reviewed-on: https://go-review.googlesource.com/54990
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/asm/internal/asm/testdata/arm64enc.s
src/cmd/internal/obj/arm64/asm7.go

index 52663e2b52e906613b846f11068aa36c06c526a0..5c218b50a2a6d965e997f10b389b7838277b7845 100644 (file)
@@ -242,9 +242,9 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$-8
    ORRW $16252928, ZR, R21                    // f5130d32
    MOVD $-4260607558625, R11                  // eb6b16b2
    MOVD R30, R7                               // e7031eaa
-   // MOVKW $(3905<<0), R21                   // MOVKW $3905, R21              // 35e88172
-   // MOVKW $(3905<<16), R21                  // MOVKW $255918080, R21         // 35e8a172
-   // MOVK $(3905<<32), R21                   // MOVK $16771847290880, R21     // 35e8c1f2
+   MOVKW $(3905<<0), R21                      // MOVKW $3905, R21              // 35e88172
+   MOVKW $(3905<<16), R21                     // MOVKW $255918080, R21         // 35e8a172
+   MOVK $(3905<<32), R21                      // MOVK $16771847290880, R21     // 35e8c1f2
    MOVD $0, R5                                // 050080d2
    // MRS $4567, R16                          // f03a32d5
    // MRS $32345, R6                          // 26cb3fd5
index 4419909f69149e4c2c2f51644eefda4cd1663deb..f05150c87a83f4a54ad4fc05b23a3593ab0337fe 100644 (file)
@@ -2597,22 +2597,19 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) {
                o1 = c.opirr(p, p.As)
 
                d := p.From.Offset
-               if (d >> 16) != 0 {
-                       c.ctxt.Diag("requires uimm16\n%v", p)
+               s := movcon(d)
+               if s < 0 || s >= 4 {
+                       c.ctxt.Diag("bad constant for MOVK: %#x\n%v", uint64(d), p)
                }
-               s := 0
-               if p.From3Type() != obj.TYPE_NONE {
-                       if p.From3.Type != obj.TYPE_CONST {
-                               c.ctxt.Diag("missing bit position\n%v", p)
-                       }
-                       s = int(p.From3.Offset / 16)
-                       if (s*16&0xF) != 0 || s >= 4 || (o1&S64) == 0 && s >= 2 {
-                               c.ctxt.Diag("illegal bit position\n%v", p)
-                       }
+               if (o1&S64) == 0 && s >= 2 {
+                       c.ctxt.Diag("illegal bit position\n%v", p)
+               }
+               if ((d >> uint(s*16)) >> 16) != 0 {
+                       c.ctxt.Diag("requires uimm16\n%v",p)
                }
-
                rt := int(p.To.Reg)
-               o1 |= uint32(((d & 0xFFFF) << 5) | int64((uint32(s)&3)<<21) | int64(rt&31))
+
+               o1 |= uint32((((d >> uint(s*16)) & 0xFFFF) << 5) | int64((uint32(s)&3)<<21) | int64(rt&31))
 
        case 34: /* mov $lacon,R */
                o1 = c.omovlit(AMOVD, p, &p.From, REGTMP)