Source file
test/codegen/bitfield.go
1
2
3
4
5
6
7 package codegen
8
9
10
11
12 func extr1(x, x2 uint64) uint64 {
13 return x<<7 + x2>>57
14 }
15
16 func extr2(x, x2 uint64) uint64 {
17 return x<<7 | x2>>57
18 }
19
20 func extr3(x, x2 uint64) uint64 {
21 return x<<7 ^ x2>>57
22 }
23
24 func extr4(x, x2 uint32) uint32 {
25 return x<<7 + x2>>25
26 }
27
28 func extr5(x, x2 uint32) uint32 {
29 return x<<7 | x2>>25
30 }
31
32 func extr6(x, x2 uint32) uint32 {
33 return x<<7 ^ x2>>25
34 }
35
36
37 func mask32(x uint32) uint32 {
38 return (x << 29) >> 29
39 }
40
41
42 func mask16(x uint16) uint16 {
43 return (x << 14) >> 14
44 }
45
46
47 func mask8(x uint8) uint8 {
48 return (x << 7) >> 7
49 }
50
51 func maskshift(x uint64) uint64 {
52
53 return ((x << 5) & (0xfff << 5)) >> 5
54 }
55
56
57
58 func bfi1(x, y uint64) uint64 {
59
60 return ((x & 0xfff) << 4) | (y & 0xffffffffffff000f)
61 }
62
63 func bfi2(x, y uint64) uint64 {
64
65 return (x << 24 >> 12) | (y & 0xfff0000000000fff)
66 }
67
68
69 func bfxil1(x, y uint64) uint64 {
70
71 return ((x >> 5) & 0xfff) | (y & 0xfffffffffffff000)
72 }
73
74 func bfxil2(x, y uint64) uint64 {
75
76 return (x << 12 >> 24) | (y & 0xffffff0000000000)
77 }
78
79
80
81 func sbfiz1(x int64) int64 {
82
83 return (x << 4) >> 3
84 }
85
86
87 func sbfiz2(x int32) int64 {
88 return int64(x << 3)
89 }
90
91 func sbfiz3(x int16) int64 {
92 return int64(x << 3)
93 }
94
95 func sbfiz4(x int8) int64 {
96 return int64(x << 3)
97 }
98
99
100
101 func sbfiz5(x int32) int32 {
102
103 return (x << 4) >> 3
104 }
105
106 func sbfiz6(x int16) int64 {
107 return int64(x+1) << 3
108 }
109
110 func sbfiz7(x int8) int64 {
111 return int64(x+1) << 62
112 }
113
114 func sbfiz8(x int32) int64 {
115 return int64(x+1) << 40
116 }
117
118
119
120 func sbfx1(x int64) int64 {
121 return (x << 3) >> 4
122 }
123
124 func sbfx2(x int64) int64 {
125 return (x << 60) >> 60
126 }
127
128
129 func sbfx3(x int32) int64 {
130 return int64(x) >> 3
131 }
132
133 func sbfx4(x int16) int64 {
134 return int64(x) >> 3
135 }
136
137 func sbfx5(x int8) int64 {
138 return int64(x) >> 3
139 }
140
141 func sbfx6(x int32) int64 {
142 return int64(x >> 30)
143 }
144
145 func sbfx7(x int16) int64 {
146 return int64(x >> 10)
147 }
148
149 func sbfx8(x int8) int64 {
150 return int64(x >> 5)
151 }
152
153
154
155 func sbfx9(x int32) int32 {
156 return (x << 3) >> 4
157 }
158
159
160 func sbfx10(x int32) int64 {
161 c := x + 5
162 return int64(c >> 20)
163 }
164
165
166
167 func ubfiz1(x uint64) uint64 {
168
169
170 return (x << 4) >> 3
171 }
172
173
174 func ubfiz2(x uint32) uint64 {
175 return uint64(x+1) << 3
176 }
177
178 func ubfiz3(x uint16) uint64 {
179 return uint64(x+1) << 3
180 }
181
182 func ubfiz4(x uint8) uint64 {
183 return uint64(x+1) << 3
184 }
185
186 func ubfiz5(x uint8) uint64 {
187 return uint64(x) << 60
188 }
189
190 func ubfiz6(x uint32) uint64 {
191 return uint64(x << 30)
192 }
193
194 func ubfiz7(x uint16) uint64 {
195 return uint64(x << 10)
196 }
197
198 func ubfiz8(x uint8) uint64 {
199 return uint64(x << 7)
200 }
201
202
203 func ubfiz9(x uint64) uint64 {
204
205
206 return (x & 0xfff) << 3
207 }
208
209 func ubfiz10(x uint64) uint64 {
210
211
212 return (x << 4) & 0xfff0
213 }
214
215
216 func ubfiz11(x uint32) uint32 {
217
218 return (x << 4) >> 3
219 }
220
221 func ubfiz12(x uint64) uint64 {
222
223
224 return ((x & 0xfffff) << 4) >> 3
225 }
226
227 func ubfiz13(x uint64) uint64 {
228
229 return ((x << 3) & 0xffff) << 2
230 }
231
232 func ubfiz14(x uint64) uint64 {
233
234
235 return ((x << 5) & (0xfff << 5)) << 2
236 }
237
238
239
240 func ubfx1(x uint64) uint64 {
241
242
243 return (x << 1) >> 2
244 }
245
246
247 func ubfx2(x uint32) uint64 {
248 return uint64(x >> 15)
249 }
250
251 func ubfx3(x uint16) uint64 {
252 return uint64(x >> 9)
253 }
254
255 func ubfx4(x uint8) uint64 {
256 return uint64(x >> 3)
257 }
258
259 func ubfx5(x uint32) uint64 {
260 return uint64(x) >> 30
261 }
262
263 func ubfx6(x uint16) uint64 {
264 return uint64(x) >> 10
265 }
266
267 func ubfx7(x uint8) uint64 {
268 return uint64(x) >> 3
269 }
270
271
272 func ubfx8(x uint64) uint64 {
273
274
275 return (x >> 25) & 1023
276 }
277
278 func ubfx9(x uint64) uint64 {
279
280
281 return (x & 0x0ff0) >> 4
282 }
283
284
285 func ubfx10(x uint32) uint32 {
286
287 return (x << 1) >> 2
288 }
289
290 func ubfx11(x uint64) uint64 {
291
292
293 return ((x << 1) >> 2) & 0xfff
294 }
295
296 func ubfx12(x uint64) uint64 {
297
298
299 return ((x >> 3) & 0xfff) >> 1
300 }
301
302 func ubfx13(x uint64) uint64 {
303
304
305 return ((x >> 2) << 5) >> 8
306 }
307
308 func ubfx14(x uint64) uint64 {
309
310
311 return ((x & 0xfffff) << 3) >> 4
312 }
313
314
315 func ubfx15(x uint64) bool {
316 midr := x + 10
317 part_num := uint16((midr >> 4) & 0xfff)
318 if part_num == 0xd0c {
319 return true
320 }
321 return false
322 }
323
324
325 func ubfx16(x uint64) uint64 {
326
327 return ((x >> 3) & 0xfff) >> 1 & 0x3f
328 }
329
330
331
332
333 func shift_no_cmp(x int) int {
334
335
336 return x << 17
337 }
338
339 func rev16(c uint64) (uint64, uint64, uint64) {
340
341 b1 := ((c & 0xff00ff00ff00ff00) >> 8) | ((c & 0x00ff00ff00ff00ff) << 8)
342
343 b2 := ((c & 0xff00ff00ff00ff00) >> 8) + ((c & 0x00ff00ff00ff00ff) << 8)
344
345 b3 := ((c & 0xff00ff00ff00ff00) >> 8) ^ ((c & 0x00ff00ff00ff00ff) << 8)
346 return b1, b2, b3
347 }
348
349 func rev16w(c uint32) (uint32, uint32, uint32) {
350
351 b1 := ((c & 0xff00ff00) >> 8) | ((c & 0x00ff00ff) << 8)
352
353 b2 := ((c & 0xff00ff00) >> 8) + ((c & 0x00ff00ff) << 8)
354
355 b3 := ((c & 0xff00ff00) >> 8) ^ ((c & 0x00ff00ff) << 8)
356 return b1, b2, b3
357 }
358
359 func shift(x uint32, y uint16, z uint8) uint64 {
360
361 a := uint64(x) >> 32
362
363 b := uint64(y) >> 16
364
365 c := uint64(z) >> 8
366
367 return a + b + c
368 }
369
View as plain text