]> Cypherpunks.ru repositories - gostls13.git/blob - test/codegen/mathbits.go
test/codegen: port math/bits.ReverseBytes tests to codegen
[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"
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:"BSRQ"
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 LeadingZeros8 not intrinsified (see ssa.go)
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"
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:"BSRQ"
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 Len8 not intrisified (see ssa.go)
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.TrailingZeros    //
159 // ------------------------ //
160
161 func TrailingZeros(n uint) int {
162         //amd64:"BSFQ","MOVL\t\\$64","CMOVQEQ"
163         //s390x:"FLOGR"
164         return bits.TrailingZeros(n)
165 }
166
167 func TrailingZeros64(n uint64) int {
168         //amd64:"BSFQ","MOVL\t\\$64","CMOVQEQ"
169         //s390x:"FLOGR"
170         return bits.TrailingZeros64(n)
171 }
172
173 func TrailingZeros32(n uint32) int {
174         //amd64:"MOVQ\t\\$4294967296","ORQ\t[^$]","BSFQ"
175         //s390x:"FLOGR","MOVWZ"
176         return bits.TrailingZeros32(n)
177 }
178
179 func TrailingZeros16(n uint16) int {
180         //amd64:"BSFQ","ORQ\t\\$65536"
181         //s390x:"FLOGR","OR\t\\$65536"
182         return bits.TrailingZeros16(n)
183 }
184
185 func TrailingZeros8(n uint8) int {
186         //amd64:"BSFQ","ORQ\t\\$256"
187         //s390x:"FLOGR","OR\t\\$256"
188         return bits.TrailingZeros8(n)
189 }