]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/asm: fix MOVK when constant has high bit set
authorKeith Randall <khr@golang.org>
Sun, 10 Apr 2022 16:12:43 +0000 (09:12 -0700)
committerGopher Robot <gobot@golang.org>
Mon, 11 Apr 2022 02:55:52 +0000 (02:55 +0000)
Fixes #52261

Change-Id: I1dc4c19c95a91f9e1e99d1e74afeb69f5bf8a979
Reviewed-on: https://go-review.googlesource.com/c/go/+/399455
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Eric Fang <eric.fang@arm.com>
src/cmd/internal/obj/arm64/asm7.go
src/cmd/internal/obj/arm64/asm_arm64_test.go
src/cmd/internal/obj/arm64/asm_arm64_test.s

index 72c4cd48ed092ef1eb60e58acf6aae700228ca02..57d4e7a8d32dd7c503bbda49f67600474872913d 100644 (file)
@@ -3977,7 +3977,7 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) {
                if (o1&S64) == 0 && s >= 2 {
                        c.ctxt.Diag("illegal bit position\n%v", p)
                }
-               if ((d >> uint(s*16)) >> 16) != 0 {
+               if ((uint64(d) >> uint(s*16)) >> 16) != 0 {
                        c.ctxt.Diag("requires uimm16\n%v", p)
                }
                rt := int(p.To.Reg)
index c6a00f5b941035a774649f49d3241809c18dafad..f468b6b0fe97ba30412b9460c526dd735c5bf183 100644 (file)
@@ -160,3 +160,14 @@ func TestVMOVQ(t *testing.T) {
                t.Errorf("TestVMOVQ got: a=0x%x, b=0x%x, want: a=0x7040201008040201, b=0x3040201008040201", a, b)
        }
 }
+
+func testmovk() uint64
+
+// TestMOVK makes sure MOVK with a very large constant works. See issue 52261.
+func TestMOVK(t *testing.T) {
+       x := testmovk()
+       want := uint64(40000 << 48)
+       if x != want {
+               t.Errorf("TestMOVK got %x want %x\n", x, want)
+       }
+}
index 9d337a4fd1a86862400bc811271425b29967a096..f85433c6e3ca3068721efcaa9d00d68bce71ccd8 100644 (file)
@@ -12,3 +12,10 @@ TEXT ·testvmovq(SB), NOSPLIT, $0-16
        MOVD    R0, r1+0(FP)
        MOVD    R1, r2+8(FP)
        RET
+
+// testmovk() uint64
+TEXT ·testmovk(SB), NOSPLIT, $0-8
+       MOVD    $0, R0
+       MOVK    $(40000<<48), R0
+       MOVD    R0, ret+0(FP)
+       RET