]> Cypherpunks.ru repositories - gostls13.git/blob - test/codegen/mathbits.go
cmd/compile: implement non-constant rotates using ROR on arm64
[gostls13.git] / test / codegen / mathbits.go
1 // asmcheck
2
3 // Copyright 2018 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
6
7 package codegen
8
9 import "math/bits"
10
11 // ----------------------- //
12 //    bits.LeadingZeros    //
13 // ----------------------- //
14
15 func LeadingZeros(n uint) int {
16         // amd64:"BSRQ"
17         // s390x:"FLOGR"
18         // arm:"CLZ" arm64:"CLZ"
19         // mips:"CLZ"
20         return bits.LeadingZeros(n)
21 }
22
23 func LeadingZeros64(n uint64) int {
24         // amd64:"BSRQ"
25         // s390x:"FLOGR"
26         // arm:"CLZ" arm64:"CLZ"
27         // mips:"CLZ"
28         return bits.LeadingZeros64(n)
29 }
30
31 func LeadingZeros32(n uint32) int {
32         // amd64:"BSRQ","LEAQ",-"CMOVQEQ"
33         // s390x:"FLOGR"
34         // arm:"CLZ" arm64:"CLZ"
35         // mips:"CLZ"
36         return bits.LeadingZeros32(n)
37 }
38
39 func LeadingZeros16(n uint16) int {
40         // amd64:"BSRL","LEAL",-"CMOVQEQ"
41         // s390x:"FLOGR"
42         // arm:"CLZ" arm64:"CLZ"
43         // mips:"CLZ"
44         return bits.LeadingZeros16(n)
45 }
46
47 func LeadingZeros8(n uint8) int {
48         // amd64:"BSRL","LEAL",-"CMOVQEQ"
49         // s390x:"FLOGR"
50         // arm:"CLZ" arm64:"CLZ"
51         // mips:"CLZ"
52         return bits.LeadingZeros8(n)
53 }
54
55 // --------------- //
56 //    bits.Len*    //
57 // --------------- //
58
59 func Len(n uint) int {
60         // amd64:"BSRQ"
61         // s390x:"FLOGR"
62         // arm:"CLZ" arm64:"CLZ"
63         // mips:"CLZ"
64         return bits.Len(n)
65 }
66
67 func Len64(n uint64) int {
68         // amd64:"BSRQ"
69         // s390x:"FLOGR"
70         // arm:"CLZ" arm64:"CLZ"
71         // mips:"CLZ"
72         return bits.Len64(n)
73 }
74
75 func Len32(n uint32) int {
76         // amd64:"BSRQ","LEAQ",-"CMOVQEQ"
77         // s390x:"FLOGR"
78         // arm:"CLZ" arm64:"CLZ"
79         // mips:"CLZ"
80         return bits.Len32(n)
81 }
82
83 func Len16(n uint16) int {
84         // amd64:"BSRL","LEAL",-"CMOVQEQ"
85         // s390x:"FLOGR"
86         // arm:"CLZ" arm64:"CLZ"
87         // mips:"CLZ"
88         return bits.Len16(n)
89 }
90
91 func Len8(n uint8) int {
92         // amd64:"BSRL","LEAL",-"CMOVQEQ"
93         // s390x:"FLOGR"
94         // arm:"CLZ" arm64:"CLZ"
95         // mips:"CLZ"
96         return bits.Len8(n)
97 }
98
99 // -------------------- //
100 //    bits.OnesCount    //
101 // -------------------- //
102
103 func OnesCount(n uint) int {
104         // amd64:"POPCNTQ",".*support_popcnt"
105         // arm64:"VCNT","VUADDLV"
106         // s390x:"POPCNT"
107         return bits.OnesCount(n)
108 }
109
110 func OnesCount64(n uint64) int {
111         // amd64:"POPCNTQ",".*support_popcnt"
112         // arm64:"VCNT","VUADDLV"
113         // s390x:"POPCNT"
114         return bits.OnesCount64(n)
115 }
116
117 func OnesCount32(n uint32) int {
118         // amd64:"POPCNTL",".*support_popcnt"
119         // arm64:"VCNT","VUADDLV"
120         // s390x:"POPCNT"
121         return bits.OnesCount32(n)
122 }
123
124 func OnesCount16(n uint16) int {
125         // amd64:"POPCNTL",".*support_popcnt"
126         // arm64:"VCNT","VUADDLV"
127         // s390x:"POPCNT"
128         return bits.OnesCount16(n)
129 }
130
131 func OnesCount8(n uint8) int {
132         // s390x:"POPCNT"
133         return bits.OnesCount8(n)
134 }
135
136 // ----------------------- //
137 //    bits.ReverseBytes    //
138 // ----------------------- //
139
140 func ReverseBytes(n uint) uint {
141         // amd64:"BSWAPQ"
142         // s390x:"MOVDBR"
143         // arm64:"REV"
144         return bits.ReverseBytes(n)
145 }
146
147 func ReverseBytes64(n uint64) uint64 {
148         // amd64:"BSWAPQ"
149         // s390x:"MOVDBR"
150         // arm64:"REV"
151         return bits.ReverseBytes64(n)
152 }
153
154 func ReverseBytes32(n uint32) uint32 {
155         // amd64:"BSWAPL"
156         // s390x:"MOVWBR"
157         // arm64:"REVW"
158         return bits.ReverseBytes32(n)
159 }
160
161 func ReverseBytes16(n uint16) uint16 {
162         // amd64:"ROLW"
163         return bits.ReverseBytes16(n)
164 }
165
166 // --------------------- //
167 //    bits.RotateLeft    //
168 // --------------------- //
169
170 func RotateLeft64(n uint64) uint64 {
171         // amd64:"ROLQ"
172         // arm64:"ROR"
173         // ppc64:"ROTL"
174         // s390x:"RLLG"
175         return bits.RotateLeft64(n, 37)
176 }
177
178 func RotateLeft32(n uint32) uint32 {
179         // amd64:"ROLL" 386:"ROLL"
180         // arm64:"RORW"
181         // ppc64:"ROTLW"
182         // s390x:"RLL"
183         return bits.RotateLeft32(n, 9)
184 }
185
186 func RotateLeft16(n uint16) uint16 {
187         // amd64:"ROLW" 386:"ROLW"
188         return bits.RotateLeft16(n, 5)
189 }
190
191 func RotateLeft8(n uint8) uint8 {
192         // amd64:"ROLB" 386:"ROLB"
193         return bits.RotateLeft8(n, 5)
194 }
195
196 func RotateLeftVariable(n uint, m int) uint {
197         // amd64:"ROLQ"
198         // arm64:"ROR"
199         // ppc64:"ROTL"
200         // s390x:"RLLG"
201         return bits.RotateLeft(n, m)
202 }
203
204 func RotateLeftVariable64(n uint64, m int) uint64 {
205         // amd64:"ROLQ"
206         // arm64:"ROR"
207         // ppc64:"ROTL"
208         // s390x:"RLLG"
209         return bits.RotateLeft64(n, m)
210 }
211
212 func RotateLeftVariable32(n uint32, m int) uint32 {
213         // amd64:"ROLL"
214         // arm64:"RORW"
215         // ppc64:"ROTLW"
216         // s390x:"RLL"
217         return bits.RotateLeft32(n, m)
218 }
219
220 // ------------------------ //
221 //    bits.TrailingZeros    //
222 // ------------------------ //
223
224 func TrailingZeros(n uint) int {
225         // amd64:"BSFQ","MOVL\t\\$64","CMOVQEQ"
226         // s390x:"FLOGR"
227         return bits.TrailingZeros(n)
228 }
229
230 func TrailingZeros64(n uint64) int {
231         // amd64:"BSFQ","MOVL\t\\$64","CMOVQEQ"
232         // s390x:"FLOGR"
233         return bits.TrailingZeros64(n)
234 }
235
236 func TrailingZeros32(n uint32) int {
237         // amd64:"BTSQ\\t\\$32","BSFQ"
238         // s390x:"FLOGR","MOVWZ"
239         return bits.TrailingZeros32(n)
240 }
241
242 func TrailingZeros16(n uint16) int {
243         // amd64:"BSFL","BTSL\\t\\$16"
244         // s390x:"FLOGR","OR\t\\$65536"
245         return bits.TrailingZeros16(n)
246 }
247
248 func TrailingZeros8(n uint8) int {
249         // amd64:"BSFL","BTSL\\t\\$8"
250         // s390x:"FLOGR","OR\t\\$256"
251         return bits.TrailingZeros8(n)
252 }
253
254 // IterateBitsNN checks special handling of TrailingZerosNN when the input is known to be non-zero.
255
256 func IterateBits(n uint) int {
257         i := 0
258         for n != 0 {
259                 // amd64:"BSFQ",-"CMOVEQ"
260                 i += bits.TrailingZeros(n)
261                 n &= n - 1
262         }
263         return i
264 }
265
266 func IterateBits64(n uint64) int {
267         i := 0
268         for n != 0 {
269                 // amd64:"BSFQ",-"CMOVEQ"
270                 i += bits.TrailingZeros64(n)
271                 n &= n - 1
272         }
273         return i
274 }
275
276 func IterateBits32(n uint32) int {
277         i := 0
278         for n != 0 {
279                 // amd64:"BSFL",-"BTSQ"
280                 i += bits.TrailingZeros32(n)
281                 n &= n - 1
282         }
283         return i
284 }
285
286 func IterateBits16(n uint16) int {
287         i := 0
288         for n != 0 {
289                 // amd64:"BSFL",-"BTSL"
290                 i += bits.TrailingZeros16(n)
291                 n &= n - 1
292         }
293         return i
294 }
295
296 func IterateBits8(n uint8) int {
297         i := 0
298         for n != 0 {
299                 // amd64:"BSFL",-"BTSL"
300                 i += bits.TrailingZeros8(n)
301                 n &= n - 1
302         }
303         return i
304 }