Skip to content

Commit 83b36ff

Browse files
committed
cmd/compile: implement constant rotates on arm64
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]>
1 parent 771b8ea commit 83b36ff

File tree

5 files changed

+82
-16
lines changed

5 files changed

+82
-16
lines changed

src/cmd/compile/internal/ssa/gen/ARM.rules

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,8 @@
508508
(TST x (MOVWconst [c])) => (TSTconst [c] x)
509509
(TEQ x (MOVWconst [c])) => (TEQconst [c] x)
510510

511+
(SRR x (MOVWconst [c])) => (SRRconst x [c&31])
512+
511513
// Canonicalize the order of arguments to comparisons - helps with CSE.
512514
(CMP x y) && canonLessThan(x,y) => (InvertFlags (CMP y x))
513515

@@ -1136,7 +1138,6 @@
11361138
( ORshiftRL [c] (SLLconst x [32-c]) x) => (SRRconst [ c] x)
11371139
(XORshiftRL [c] (SLLconst x [32-c]) x) => (SRRconst [ c] x)
11381140

1139-
(RotateLeft32 x (MOVWconst [c])) => (SRRconst [-c&31] x)
11401141
(RotateLeft16 <t> x (MOVWconst [c])) => (Or16 (Lsh16x32 <t> x (MOVWconst [c&15])) (Rsh16Ux32 <t> x (MOVWconst [-c&15])))
11411142
(RotateLeft8 <t> x (MOVWconst [c])) => (Or8 (Lsh8x32 <t> x (MOVWconst [c&7])) (Rsh8Ux32 <t> x (MOVWconst [-c&7])))
11421143
(RotateLeft32 x y) => (SRR x (RSBconst [0] <y.Type> y))

src/cmd/compile/internal/ssa/gen/ARM64.rules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,9 @@
11751175
(CMPW x (MOVDconst [c])) => (CMPWconst [int32(c)] x)
11761176
(CMPW (MOVDconst [c]) x) => (InvertFlags (CMPWconst [int32(c)] x))
11771177

1178+
(ROR x (MOVDconst [c])) => (RORconst x [c&63])
1179+
(RORW x (MOVDconst [c])) => (RORWconst x [c&31])
1180+
11781181
// Canonicalize the order of arguments to comparisons - helps with CSE.
11791182
((CMP|CMPW) x y) && canonLessThan(x,y) => (InvertFlags ((CMP|CMPW) y x))
11801183

src/cmd/compile/internal/ssa/rewriteARM.go

Lines changed: 20 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/compile/internal/ssa/rewriteARM64.go

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/codegen/rotate.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,15 @@ func rot64(x uint64) uint64 {
3434
// ppc64le:"ROTL\t[$]9"
3535
a += x<<9 ^ x>>55
3636

37-
// s390x:"RISBGZ\t[$]0, [$]63, [$]7, "
37+
// amd64:"ROLQ\t[$]10"
38+
// arm64:"ROR\t[$]54"
39+
// s390x:"RISBGZ\t[$]0, [$]63, [$]10, "
40+
// ppc64:"ROTL\t[$]10"
41+
// ppc64le:"ROTL\t[$]10"
3842
// arm64:"ROR\t[$]57" // TODO this is not great line numbering, but then again, the instruction did appear
43+
// s390x:"RISBGZ\t[$]0, [$]63, [$]7, " // TODO ditto
44+
a += bits.RotateLeft64(x, 10)
45+
3946
return a
4047
}
4148

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

67-
// s390x:"RLL\t[$]7"
74+
// amd64:"ROLL\t[$]10"
75+
// arm:"MOVW\tR\\d+@>22"
76+
// arm64:"RORW\t[$]22"
77+
// s390x:"RLL\t[$]10"
78+
// ppc64:"ROTLW\t[$]10"
79+
// ppc64le:"ROTLW\t[$]10"
6880
// arm64:"RORW\t[$]25" // TODO this is not great line numbering, but then again, the instruction did appear
81+
// s390x:"RLL\t[$]7" // TODO ditto
82+
a += bits.RotateLeft32(x, 10)
83+
6984
return a
7085
}
7186

0 commit comments

Comments
 (0)