cmd/asm: fix MOVK when constant has high bit set

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>
This commit is contained in:
Keith Randall 2022-04-10 09:12:43 -07:00 committed by Gopher Robot
parent b6fb3af6af
commit a6f6932b3e
3 changed files with 19 additions and 1 deletions

View 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)

View 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)
}
}

View 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