From b60bf8f8e131b026eb2691e736d3df9dce852297 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Thu, 14 Dec 2023 13:07:50 -0800 Subject: cmd/asm: fix encoding for arm right shift by constant 0 Right shifts, for some odd reasons, can encode shifts of constant 1-32 instead of 0-31. Left shifts, however, can encode shifts 0-31. When the shift amount is 0, arm recommends encoding right shifts using left shifts. Fixes #64715 Change-Id: Id3825349aa7195028037893dfe01fa0e405eaa51 Reviewed-on: https://go-review.googlesource.com/c/go/+/549955 Reviewed-by: Cherry Mui Reviewed-by: Cuong Manh Le LUCI-TryBot-Result: Go LUCI Reviewed-by: Keith Randall --- src/cmd/internal/obj/arm/asm5.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/cmd/internal/obj') diff --git a/src/cmd/internal/obj/arm/asm5.go b/src/cmd/internal/obj/arm/asm5.go index 24b9bdd980..9731bd4151 100644 --- a/src/cmd/internal/obj/arm/asm5.go +++ b/src/cmd/internal/obj/arm/asm5.go @@ -1099,6 +1099,14 @@ func (c *ctxt5) oplook(p *obj.Prog) *Optab { fmt.Printf("\t\t%d %d\n", p.From.Type, p.To.Type) } + if (p.As == ASRL || p.As == ASRA) && p.From.Type == obj.TYPE_CONST && p.From.Offset == 0 { + // Right shifts are weird - a shift that looks like "shift by constant 0" actually + // means "shift by constant 32". Use left shift in this situation instead. + // See issue 64715. + // TODO: rotate by 0? Not currently supported, but if we ever do then include it here. + p.As = ASLL + } + ops := oprange[p.As&obj.AMask] c1 := &xcmp[a1] c3 := &xcmp[a3] -- cgit v1.3