Skip to content

Commit

Permalink
cmd/compile: implement constant rotates on arm64
Browse files Browse the repository at this point in the history
Explicit constant rotates work, but constant arguments to
bits.RotateLeft* needed the additional rule.

Fixes #48465

Change-Id: Ia7544f21d0e7587b6b6506f72421459cd769aea6
Reviewed-on: https://go-review.googlesource.com/c/go/+/350909
Trust: Keith Randall <[email protected]>
Trust: Josh Bleecher Snyder <[email protected]>
Run-TryBot: Keith Randall <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Josh Bleecher Snyder <[email protected]>
  • Loading branch information
randall77 committed Sep 19, 2021
1 parent 771b8ea commit 83b36ff
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/cmd/compile/internal/ssa/gen/ARM.rules
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,8 @@
(TST x (MOVWconst [c])) => (TSTconst [c] x)
(TEQ x (MOVWconst [c])) => (TEQconst [c] x)

(SRR x (MOVWconst [c])) => (SRRconst x [c&31])

// Canonicalize the order of arguments to comparisons - helps with CSE.
(CMP x y) && canonLessThan(x,y) => (InvertFlags (CMP y x))

Expand Down Expand Up @@ -1136,7 +1138,6 @@
( ORshiftRL [c] (SLLconst x [32-c]) x) => (SRRconst [ c] x)
(XORshiftRL [c] (SLLconst x [32-c]) x) => (SRRconst [ c] x)

(RotateLeft32 x (MOVWconst [c])) => (SRRconst [-c&31] x)
(RotateLeft16 <t> x (MOVWconst [c])) => (Or16 (Lsh16x32 <t> x (MOVWconst [c&15])) (Rsh16Ux32 <t> x (MOVWconst [-c&15])))
(RotateLeft8 <t> x (MOVWconst [c])) => (Or8 (Lsh8x32 <t> x (MOVWconst [c&7])) (Rsh8Ux32 <t> x (MOVWconst [-c&7])))
(RotateLeft32 x y) => (SRR x (RSBconst [0] <y.Type> y))
Expand Down
3 changes: 3 additions & 0 deletions src/cmd/compile/internal/ssa/gen/ARM64.rules
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,9 @@
(CMPW x (MOVDconst [c])) => (CMPWconst [int32(c)] x)
(CMPW (MOVDconst [c]) x) => (InvertFlags (CMPWconst [int32(c)] x))

(ROR x (MOVDconst [c])) => (RORconst x [c&63])
(RORW x (MOVDconst [c])) => (RORWconst x [c&31])

// Canonicalize the order of arguments to comparisons - helps with CSE.
((CMP|CMPW) x y) && canonLessThan(x,y) => (InvertFlags ((CMP|CMPW) y x))

Expand Down
33 changes: 20 additions & 13 deletions src/cmd/compile/internal/ssa/rewriteARM.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions src/cmd/compile/internal/ssa/rewriteARM64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 17 additions & 2 deletions test/codegen/rotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,15 @@ func rot64(x uint64) uint64 {
// ppc64le:"ROTL\t[$]9"
a += x<<9 ^ x>>55

// s390x:"RISBGZ\t[$]0, [$]63, [$]7, "
// amd64:"ROLQ\t[$]10"
// arm64:"ROR\t[$]54"
// s390x:"RISBGZ\t[$]0, [$]63, [$]10, "
// ppc64:"ROTL\t[$]10"
// ppc64le:"ROTL\t[$]10"
// arm64:"ROR\t[$]57" // TODO this is not great line numbering, but then again, the instruction did appear
// s390x:"RISBGZ\t[$]0, [$]63, [$]7, " // TODO ditto
a += bits.RotateLeft64(x, 10)

return a
}

Expand Down Expand Up @@ -64,8 +71,16 @@ func rot32(x uint32) uint32 {
// ppc64le:"ROTLW\t[$]9"
a += x<<9 ^ x>>23

// s390x:"RLL\t[$]7"
// amd64:"ROLL\t[$]10"
// arm:"MOVW\tR\\d+@>22"
// arm64:"RORW\t[$]22"
// s390x:"RLL\t[$]10"
// ppc64:"ROTLW\t[$]10"
// ppc64le:"ROTLW\t[$]10"
// arm64:"RORW\t[$]25" // TODO this is not great line numbering, but then again, the instruction did appear
// s390x:"RLL\t[$]7" // TODO ditto
a += bits.RotateLeft32(x, 10)

return a
}

Expand Down

0 comments on commit 83b36ff

Please sign in to comment.