1
2
3
4
5
6
7 package codegen
8
9 import "math/bits"
10
11
14
15 func bitcheck64_constleft(a uint64) (n int) {
16
17 if a&(1<<63) != 0 {
18 return 1
19 }
20
21 if a&(1<<60) != 0 {
22 return 1
23 }
24
25 if a&(1<<0) != 0 {
26 return 1
27 }
28 return 0
29 }
30
31 func bitcheck64_constright(a [8]uint64) (n int) {
32
33 if (a[0]>>63)&1 != 0 {
34 return 1
35 }
36
37 if a[1]>>63 != 0 {
38 return 1
39 }
40
41 if a[2]>>63 == 0 {
42 return 1
43 }
44
45 if (a[3]>>60)&1 == 0 {
46 return 1
47 }
48
49 if (a[4]>>1)&1 == 0 {
50 return 1
51 }
52
53 if (a[5]>>0)&1 == 0 {
54 return 1
55 }
56
57 if (a[6]>>5)&4 == 0 {
58 return 1
59 }
60 return 0
61 }
62
63 func bitcheck64_var(a, b uint64) (n int) {
64
65 if a&(1<<(b&63)) != 0 {
66 return 1
67 }
68
69 if (b>>(a&63))&1 != 0 {
70 return 1
71 }
72 return 0
73 }
74
75 func bitcheck64_mask(a uint64) (n int) {
76
77 if a&0x8000000000000000 != 0 {
78 return 1
79 }
80
81 if a&0x800000000000000 != 0 {
82 return 1
83 }
84
85 if a&0x1 != 0 {
86 return 1
87 }
88 return 0
89 }
90
91 func biton64(a, b uint64) (n uint64) {
92
93 n += b | (1 << (a & 63))
94
95
96 n += a | (1 << 63)
97
98
99 n += a | (1 << 60)
100
101
102 n += a | (1 << 0)
103
104 return n
105 }
106
107 func bitoff64(a, b uint64) (n uint64) {
108
109 n += b &^ (1 << (a & 63))
110
111
112 n += a &^ (1 << 63)
113
114
115 n += a &^ (1 << 60)
116
117
118 n += a &^ (1 << 0)
119
120 return n
121 }
122
123 func bitcompl64(a, b uint64) (n uint64) {
124
125 n += b ^ (1 << (a & 63))
126
127
128 n += a ^ (1 << 63)
129
130
131 n += a ^ (1 << 60)
132
133
134 n += a ^ (1 << 0)
135
136 return n
137 }
138
139
142
143 func bitcheck32_constleft(a uint32) (n int) {
144
145 if a&(1<<31) != 0 {
146 return 1
147 }
148
149 if a&(1<<28) != 0 {
150 return 1
151 }
152
153 if a&(1<<0) != 0 {
154 return 1
155 }
156 return 0
157 }
158
159 func bitcheck32_constright(a [8]uint32) (n int) {
160
161 if (a[0]>>31)&1 != 0 {
162 return 1
163 }
164
165 if a[1]>>31 != 0 {
166 return 1
167 }
168
169 if a[2]>>31 == 0 {
170 return 1
171 }
172
173 if (a[3]>>28)&1 == 0 {
174 return 1
175 }
176
177 if (a[4]>>1)&1 == 0 {
178 return 1
179 }
180
181 if (a[5]>>0)&1 == 0 {
182 return 1
183 }
184
185 if (a[6]>>5)&4 == 0 {
186 return 1
187 }
188 return 0
189 }
190
191 func bitcheck32_var(a, b uint32) (n int) {
192
193 if a&(1<<(b&31)) != 0 {
194 return 1
195 }
196
197 if (b>>(a&31))&1 != 0 {
198 return 1
199 }
200 return 0
201 }
202
203 func bitcheck32_mask(a uint32) (n int) {
204
205 if a&0x80000000 != 0 {
206 return 1
207 }
208
209 if a&0x8000000 != 0 {
210 return 1
211 }
212
213 if a&0x1 != 0 {
214 return 1
215 }
216 return 0
217 }
218
219 func biton32(a, b uint32) (n uint32) {
220
221 n += b | (1 << (a & 31))
222
223
224 n += a | (1 << 31)
225
226
227 n += a | (1 << 28)
228
229
230 n += a | (1 << 0)
231
232 return n
233 }
234
235 func bitoff32(a, b uint32) (n uint32) {
236
237 n += b &^ (1 << (a & 31))
238
239
240 n += a &^ (1 << 31)
241
242
243 n += a &^ (1 << 28)
244
245
246 n += a &^ (1 << 0)
247
248 return n
249 }
250
251 func bitcompl32(a, b uint32) (n uint32) {
252
253 n += b ^ (1 << (a & 31))
254
255
256 n += a ^ (1 << 31)
257
258
259 n += a ^ (1 << 28)
260
261
262 n += a ^ (1 << 0)
263
264 return n
265 }
266
267
268 func bitOpOnMem(a []uint32, b, c, d uint32) {
269
270 a[0] &= 200
271
272 a[1] |= 220
273
274 a[2] ^= 240
275 }
276
277 func bitcheckMostNegative(b uint8) bool {
278
279 return b&0x80 == 0x80
280 }
281
282
283
284 func and_mask_1(a uint64) uint64 {
285
286 return a & ((1 << 63) - 1)
287 }
288
289 func and_mask_2(a uint64) uint64 {
290
291 return a & (1 << 63)
292 }
293
294 func and_mask_3(a, b uint32) (uint32, uint32) {
295
296 a &= 0xffffaaaa
297
298 b &= 0xffc003ff
299 return a, b
300 }
301
302
303
304 func op_bic(x, y uint32) uint32 {
305
306 return x &^ y
307 }
308
309 func op_eon(x, y, z uint32, a []uint32, n, m uint64) uint64 {
310
311 a[0] = x ^ (y ^ 0xffffffff)
312
313
314 a[1] = ^(y ^ z)
315
316
317 a[2] = x ^ ^z
318
319
320 return n ^ (m ^ 0xffffffffffffffff)
321 }
322
323 func op_orn(x, y uint32) uint32 {
324
325 return x | ^y
326 }
327
328
329 func bitSetPowerOf2Test(x int) bool {
330
331 return x&8 == 8
332 }
333
334 func bitSetTest(x int) bool {
335
336
337 return x&9 == 9
338 }
339
340
341 func cont1Mask64U(x uint64) uint64 {
342
343 return x & 0x0000ffffffff0000
344 }
345
346
347 func cont0Mask64U(x uint64) uint64 {
348
349 return x & 0xffff00000000ffff
350 }
351
352 func issue44228a(a []int64, i int) bool {
353
354 return a[i>>6]&(1<<(i&63)) != 0
355 }
356 func issue44228b(a []int32, i int) bool {
357
358 return a[i>>5]&(1<<(i&31)) != 0
359 }
360
361 func issue48467(x, y uint64) uint64 {
362
363 d, borrow := bits.Sub64(x, y, 0)
364 return x - d&(-borrow)
365 }
366
367 func foldConst(x, y uint64) uint64 {
368
369 d, b := bits.Add64(x, 7, 0)
370 return b & d
371 }
372
373 func foldConstOutOfRange(a uint64) uint64 {
374
375 return a + 0x1234568
376 }
377
378
379 func signextendAndMask8to64(a int8) (s, z uint64) {
380
381 s = uint64(a) & 0x3F7
382
383 z = uint64(uint8(a)) & 0x3F7
384 return
385 }
386
387
388 func zeroextendAndMask8to64(a int8, b int16) (x, y uint64) {
389
390 x = uint64(a) & 0xFF
391
392 y = uint64(b) & 0xFFFF
393 return
394 }
395
396
397 func bitRotateAndMask(io64 [8]uint64, io32 [4]uint32, io16 [4]uint16, io8 [4]uint8) {
398
399 io64[0] = io64[0] & 0xFFFFFFFFFFFF0000
400
401 io64[1] = io64[1] & 0x0000FFFFFFFFFFFF
402
403 io64[2] = (io64[2] >> 4) & 0x0000FFFFFFFFFFFF
404
405 io64[3] = (io64[3] >> 28) & 0x0000FFFFFFFFFFFF
406
407
408 io64[4] = uint64(bits.RotateLeft32(io32[0], 1) & 0xF000000F)
409
410
411 io32[0] = io32[0] & 0x0FFFF000
412
413 io32[1] = io32[1] & 0xF0000FFF
414
415 io32[2] = io32[2] & 0xFFFF0002
416
417 var bigc uint32 = 0x12345678
418
419 io16[0] = io16[0] & uint16(bigc)
420
421
422 io8[0] = io8[0] & uint8(bigc)
423 }
424
View as plain text