]> Cypherpunks.ru repositories - gostls13.git/blob - test/codegen/mathbits.go
cmd/compile: use prove pass to detect Ctz of non-zero values
[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         return bits.OnesCount(n)
107 }
108
109 func OnesCount64(n uint64) int {
110         // amd64:"POPCNTQ",".*support_popcnt"
111         // arm64:"VCNT","VUADDLV"
112         return bits.OnesCount64(n)
113 }
114
115 func OnesCount32(n uint32) int {
116         // amd64:"POPCNTL",".*support_popcnt"
117         // arm64:"VCNT","VUADDLV"
118         return bits.OnesCount32(n)
119 }
120
121 func OnesCount16(n uint16) int {
122         // amd64:"POPCNTL",".*support_popcnt"
123         // arm64:"VCNT","VUADDLV"
124         return bits.OnesCount16(n)
125 }
126
127 // ----------------------- //
128 //    bits.ReverseBytes    //
129 // ----------------------- //
130
131 func ReverseBytes(n uint) uint {
132         // amd64:"BSWAPQ"
133         // s390x:"MOVDBR"
134         // arm64:"REV"
135         return bits.ReverseBytes(n)
136 }
137
138 func ReverseBytes64(n uint64) uint64 {
139         // amd64:"BSWAPQ"
140         // s390x:"MOVDBR"
141         // arm64:"REV"
142         return bits.ReverseBytes64(n)
143 }
144
145 func ReverseBytes32(n uint32) uint32 {
146         // amd64:"BSWAPL"
147         // s390x:"MOVWBR"
148         // arm64:"REVW"
149         return bits.ReverseBytes32(n)
150 }
151
152 func ReverseBytes16(n uint16) uint16 {
153         // amd64:"ROLW"
154         return bits.ReverseBytes16(n)
155 }
156
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
185 // ------------------------ //
186 //    bits.TrailingZeros    //
187 // ------------------------ //
188
189 func TrailingZeros(n uint) int {
190         // amd64:"BSFQ","MOVL\t\\$64","CMOVQEQ"
191         // s390x:"FLOGR"
192         return bits.TrailingZeros(n)
193 }
194
195 func TrailingZeros64(n uint64) int {
196         // amd64:"BSFQ","MOVL\t\\$64","CMOVQEQ"
197         // s390x:"FLOGR"
198         return bits.TrailingZeros64(n)
199 }
200
201 func TrailingZeros32(n uint32) int {
202         // amd64:"BTSQ\\t\\$32","BSFQ"
203         // s390x:"FLOGR","MOVWZ"
204         return bits.TrailingZeros32(n)
205 }
206
207 func TrailingZeros16(n uint16) int {
208         // amd64:"BSFL","BTSL\\t\\$16"
209         // s390x:"FLOGR","OR\t\\$65536"
210         return bits.TrailingZeros16(n)
211 }
212
213 func TrailingZeros8(n uint8) int {
214         // amd64:"BSFL","BTSL\\t\\$8"
215         // s390x:"FLOGR","OR\t\\$256"
216         return bits.TrailingZeros8(n)
217 }
218
219 // IterateBitsNN checks special handling of TrailingZerosNN when the input is known to be non-zero.
220
221 func IterateBits(n uint) int {
222         i := 0
223         for n != 0 {
224                 // amd64:"BSFQ",-"CMOVEQ"
225                 i += bits.TrailingZeros(n)
226                 n &= n - 1
227         }
228         return i
229 }
230
231 func IterateBits64(n uint64) int {
232         i := 0
233         for n != 0 {
234                 // amd64:"BSFQ",-"CMOVEQ"
235                 i += bits.TrailingZeros64(n)
236                 n &= n - 1
237         }
238         return i
239 }
240
241 func IterateBits32(n uint32) int {
242         i := 0
243         for n != 0 {
244                 // amd64:"BSFL",-"BTSQ"
245                 i += bits.TrailingZeros32(n)
246                 n &= n - 1
247         }
248         return i
249 }
250
251 func IterateBits16(n uint16) int {
252         i := 0
253         for n != 0 {
254                 // amd64:"BSFL",-"BTSL"
255                 i += bits.TrailingZeros16(n)
256                 n &= n - 1
257         }
258         return i
259 }
260
261 func IterateBits8(n uint8) int {
262         i := 0
263         for n != 0 {
264                 // amd64:"BSFL",-"BTSL"
265                 i += bits.TrailingZeros8(n)
266                 n &= n - 1
267         }
268         return i
269 }