Skip to content

Commit cde3478

Browse files
committed
test/codegen: port math/bits.RotateLeft tests to codegen
Only RotateLeft{64,32} were tested, and just for ppc64. This CL adds tests for RotateLeft{64,32,16,8} on arm64 and amd64/386, for the cases where the calls are actually instrinsified. RotateLeft tests (the last ones for math/bits functions) are deleted from asm_test. This CL also adds a space between the "//" and the arch name in the comments, to uniform this file to the style used in all the other files. Change-Id: Ifc2a27261d70bcc294b4ec64490d8367f62d2b89 Reviewed-on: https://go-review.googlesource.com/99596 Reviewed-by: Giovanni Bajo <[email protected]>
1 parent 6b5a0b5 commit cde3478

File tree

2 files changed

+99
-89
lines changed

2 files changed

+99
-89
lines changed

src/cmd/compile/internal/gc/asm_test.go

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,9 @@ var allAsmTests = []*asmTests{
259259
tests: linuxMIPS64Tests,
260260
},
261261
{
262-
arch: "ppc64le",
263-
os: "linux",
264-
imports: []string{"math/bits"},
265-
tests: linuxPPC64LETests,
262+
arch: "ppc64le",
263+
os: "linux",
264+
tests: linuxPPC64LETests,
266265
},
267266
{
268267
arch: "amd64",
@@ -1701,23 +1700,6 @@ var linuxPPC64LETests = []*asmTest{
17011700
`,
17021701
pos: []string{"\tROTL\t"},
17031702
},
1704-
{
1705-
fn: `
1706-
func f10(a uint32) uint32 {
1707-
return bits.RotateLeft32(a, 9)
1708-
}
1709-
`,
1710-
pos: []string{"\tROTLW\t"},
1711-
},
1712-
{
1713-
fn: `
1714-
func f11(a uint64) uint64 {
1715-
return bits.RotateLeft64(a, 37)
1716-
}
1717-
`,
1718-
pos: []string{"\tROTL\t"},
1719-
},
1720-
17211703
{
17221704
// check that stack store is optimized away
17231705
fn: `

test/codegen/mathbits.go

Lines changed: 96 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -13,42 +13,42 @@ import "math/bits"
1313
// ----------------------- //
1414

1515
func LeadingZeros(n uint) int {
16-
//amd64:"BSRQ"
17-
//s390x:"FLOGR"
18-
//arm:"CLZ" arm64:"CLZ"
19-
//mips:"CLZ"
16+
// amd64:"BSRQ"
17+
// s390x:"FLOGR"
18+
// arm:"CLZ" arm64:"CLZ"
19+
// mips:"CLZ"
2020
return bits.LeadingZeros(n)
2121
}
2222

2323
func LeadingZeros64(n uint64) int {
24-
//amd64:"BSRQ"
25-
//s390x:"FLOGR"
26-
//arm:"CLZ" arm64:"CLZ"
27-
//mips:"CLZ"
24+
// amd64:"BSRQ"
25+
// s390x:"FLOGR"
26+
// arm:"CLZ" arm64:"CLZ"
27+
// mips:"CLZ"
2828
return bits.LeadingZeros64(n)
2929
}
3030

3131
func LeadingZeros32(n uint32) int {
32-
//amd64:"BSRQ"
33-
//s390x:"FLOGR"
34-
//arm:"CLZ" arm64:"CLZ"
35-
//mips:"CLZ"
32+
// amd64:"BSRQ"
33+
// s390x:"FLOGR"
34+
// arm:"CLZ" arm64:"CLZ"
35+
// mips:"CLZ"
3636
return bits.LeadingZeros32(n)
3737
}
3838

3939
func LeadingZeros16(n uint16) int {
40-
//amd64:"BSRQ"
41-
//s390x:"FLOGR"
42-
//arm:"CLZ" arm64:"CLZ"
43-
//mips:"CLZ"
40+
// amd64:"BSRQ"
41+
// s390x:"FLOGR"
42+
// arm:"CLZ" arm64:"CLZ"
43+
// mips:"CLZ"
4444
return bits.LeadingZeros16(n)
4545
}
4646

4747
func LeadingZeros8(n uint8) int {
48-
//amd64 LeadingZeros8 not intrinsified (see ssa.go)
49-
//s390x:"FLOGR"
50-
//arm:"CLZ" arm64:"CLZ"
51-
//mips:"CLZ"
48+
// amd64 LeadingZeros8 not intrinsified (see ssa.go)
49+
// s390x:"FLOGR"
50+
// arm:"CLZ" arm64:"CLZ"
51+
// mips:"CLZ"
5252
return bits.LeadingZeros8(n)
5353
}
5454

@@ -57,42 +57,42 @@ func LeadingZeros8(n uint8) int {
5757
// --------------- //
5858

5959
func Len(n uint) int {
60-
//amd64:"BSRQ"
61-
//s390x:"FLOGR"
62-
//arm:"CLZ" arm64:"CLZ"
63-
//mips:"CLZ"
60+
// amd64:"BSRQ"
61+
// s390x:"FLOGR"
62+
// arm:"CLZ" arm64:"CLZ"
63+
// mips:"CLZ"
6464
return bits.Len(n)
6565
}
6666

6767
func Len64(n uint64) int {
68-
//amd64:"BSRQ"
69-
//s390x:"FLOGR"
70-
//arm:"CLZ" arm64:"CLZ"
71-
//mips:"CLZ"
68+
// amd64:"BSRQ"
69+
// s390x:"FLOGR"
70+
// arm:"CLZ" arm64:"CLZ"
71+
// mips:"CLZ"
7272
return bits.Len64(n)
7373
}
7474

7575
func Len32(n uint32) int {
76-
//amd64:"BSRQ"
77-
//s390x:"FLOGR"
78-
//arm:"CLZ" arm64:"CLZ"
79-
//mips:"CLZ"
76+
// amd64:"BSRQ"
77+
// s390x:"FLOGR"
78+
// arm:"CLZ" arm64:"CLZ"
79+
// mips:"CLZ"
8080
return bits.Len32(n)
8181
}
8282

8383
func Len16(n uint16) int {
84-
//amd64:"BSRQ"
85-
//s390x:"FLOGR"
86-
//arm:"CLZ" arm64:"CLZ"
87-
//mips:"CLZ"
84+
// amd64:"BSRQ"
85+
// s390x:"FLOGR"
86+
// arm:"CLZ" arm64:"CLZ"
87+
// mips:"CLZ"
8888
return bits.Len16(n)
8989
}
9090

9191
func Len8(n uint8) int {
92-
//amd64 Len8 not intrisified (see ssa.go)
93-
//s390x:"FLOGR"
94-
//arm:"CLZ" arm64:"CLZ"
95-
//mips:"CLZ"
92+
// amd64 Len8 not intrisified (see ssa.go)
93+
// s390x:"FLOGR"
94+
// arm:"CLZ" arm64:"CLZ"
95+
// mips:"CLZ"
9696
return bits.Len8(n)
9797
}
9898

@@ -101,26 +101,26 @@ func Len8(n uint8) int {
101101
// -------------------- //
102102

103103
func OnesCount(n uint) int {
104-
//amd64:"POPCNTQ",".*support_popcnt"
105-
//arm64:"VCNT","VUADDLV"
104+
// amd64:"POPCNTQ",".*support_popcnt"
105+
// arm64:"VCNT","VUADDLV"
106106
return bits.OnesCount(n)
107107
}
108108

109109
func OnesCount64(n uint64) int {
110-
//amd64:"POPCNTQ",".*support_popcnt"
111-
//arm64:"VCNT","VUADDLV"
110+
// amd64:"POPCNTQ",".*support_popcnt"
111+
// arm64:"VCNT","VUADDLV"
112112
return bits.OnesCount64(n)
113113
}
114114

115115
func OnesCount32(n uint32) int {
116-
//amd64:"POPCNTL",".*support_popcnt"
117-
//arm64:"VCNT","VUADDLV"
116+
// amd64:"POPCNTL",".*support_popcnt"
117+
// arm64:"VCNT","VUADDLV"
118118
return bits.OnesCount32(n)
119119
}
120120

121121
func OnesCount16(n uint16) int {
122-
//amd64:"POPCNTL",".*support_popcnt"
123-
//arm64:"VCNT","VUADDLV"
122+
// amd64:"POPCNTL",".*support_popcnt"
123+
// arm64:"VCNT","VUADDLV"
124124
return bits.OnesCount16(n)
125125
}
126126

@@ -129,61 +129,89 @@ func OnesCount16(n uint16) int {
129129
// ----------------------- //
130130

131131
func ReverseBytes(n uint) uint {
132-
//amd64:"BSWAPQ"
133-
//s390x:"MOVDBR"
134-
//arm64:"REV"
132+
// amd64:"BSWAPQ"
133+
// s390x:"MOVDBR"
134+
// arm64:"REV"
135135
return bits.ReverseBytes(n)
136136
}
137137

138138
func ReverseBytes64(n uint64) uint64 {
139-
//amd64:"BSWAPQ"
140-
//s390x:"MOVDBR"
141-
//arm64:"REV"
139+
// amd64:"BSWAPQ"
140+
// s390x:"MOVDBR"
141+
// arm64:"REV"
142142
return bits.ReverseBytes64(n)
143143
}
144144

145145
func ReverseBytes32(n uint32) uint32 {
146-
//amd64:"BSWAPL"
147-
//s390x:"MOVWBR"
148-
//arm64:"REVW"
146+
// amd64:"BSWAPL"
147+
// s390x:"MOVWBR"
148+
// arm64:"REVW"
149149
return bits.ReverseBytes32(n)
150150
}
151151

152152
func ReverseBytes16(n uint16) uint16 {
153-
//amd64:"ROLW"
153+
// amd64:"ROLW"
154154
return bits.ReverseBytes16(n)
155155
}
156156

157+
// --------------------- //
158+
// bits.RotateLeft //
159+
// --------------------- //
160+
161+
func RotateLeft64(n uint64) uint64 {
162+
// amd64:"ROLQ"
163+
// arm64:"ROR"
164+
// ppc64:"ROTL"
165+
return bits.RotateLeft64(n, 37)
166+
}
167+
168+
func RotateLeft32(n uint32) uint32 {
169+
// amd64:"ROLL" 386:"ROLL"
170+
// arm64:"RORW"
171+
// ppc64:"ROTLW"
172+
return bits.RotateLeft32(n, 9)
173+
}
174+
175+
func RotateLeft16(n uint16) uint16 {
176+
// amd64:"ROLW" 386:"ROLW"
177+
return bits.RotateLeft16(n, 5)
178+
}
179+
180+
func RotateLeft8(n uint8) uint8 {
181+
// amd64:"ROLB" 386:"ROLB"
182+
return bits.RotateLeft8(n, 5)
183+
}
184+
157185
// ------------------------ //
158186
// bits.TrailingZeros //
159187
// ------------------------ //
160188

161189
func TrailingZeros(n uint) int {
162-
//amd64:"BSFQ","MOVL\t\\$64","CMOVQEQ"
163-
//s390x:"FLOGR"
190+
// amd64:"BSFQ","MOVL\t\\$64","CMOVQEQ"
191+
// s390x:"FLOGR"
164192
return bits.TrailingZeros(n)
165193
}
166194

167195
func TrailingZeros64(n uint64) int {
168-
//amd64:"BSFQ","MOVL\t\\$64","CMOVQEQ"
169-
//s390x:"FLOGR"
196+
// amd64:"BSFQ","MOVL\t\\$64","CMOVQEQ"
197+
// s390x:"FLOGR"
170198
return bits.TrailingZeros64(n)
171199
}
172200

173201
func TrailingZeros32(n uint32) int {
174-
//amd64:"MOVQ\t\\$4294967296","ORQ\t[^$]","BSFQ"
175-
//s390x:"FLOGR","MOVWZ"
202+
// amd64:"MOVQ\t\\$4294967296","ORQ\t[^$]","BSFQ"
203+
// s390x:"FLOGR","MOVWZ"
176204
return bits.TrailingZeros32(n)
177205
}
178206

179207
func TrailingZeros16(n uint16) int {
180-
//amd64:"BSFQ","ORQ\t\\$65536"
181-
//s390x:"FLOGR","OR\t\\$65536"
208+
// amd64:"BSFQ","ORQ\t\\$65536"
209+
// s390x:"FLOGR","OR\t\\$65536"
182210
return bits.TrailingZeros16(n)
183211
}
184212

185213
func TrailingZeros8(n uint8) int {
186-
//amd64:"BSFQ","ORQ\t\\$256"
187-
//s390x:"FLOGR","OR\t\\$256"
214+
// amd64:"BSFQ","ORQ\t\\$256"
215+
// s390x:"FLOGR","OR\t\\$256"
188216
return bits.TrailingZeros8(n)
189217
}

0 commit comments

Comments
 (0)