Source file
test/codegen/memcombine.go
1
2
3
4
5
6
7 package codegen
8
9 import (
10 "encoding/binary"
11 "runtime"
12 )
13
14
15
16
17
18 func load_le64(b []byte) uint64 {
19
20
21
22
23 return binary.LittleEndian.Uint64(b)
24 }
25
26 func load_le64_idx(b []byte, idx int) uint64 {
27
28
29
30
31 return binary.LittleEndian.Uint64(b[idx:])
32 }
33
34 func load_le32(b []byte) uint32 {
35
36
37
38
39
40 return binary.LittleEndian.Uint32(b)
41 }
42
43 func load_le32_idx(b []byte, idx int) uint32 {
44
45
46
47
48
49 return binary.LittleEndian.Uint32(b[idx:])
50 }
51
52 func load_le16(b []byte) uint16 {
53
54
55
56
57 return binary.LittleEndian.Uint16(b)
58 }
59
60 func load_le16_idx(b []byte, idx int) uint16 {
61
62
63
64
65 return binary.LittleEndian.Uint16(b[idx:])
66 }
67
68 func load_be64(b []byte) uint64 {
69
70
71
72
73
74 return binary.BigEndian.Uint64(b)
75 }
76
77 func load_be64_idx(b []byte, idx int) uint64 {
78
79
80
81
82
83 return binary.BigEndian.Uint64(b[idx:])
84 }
85
86 func load_be32(b []byte) uint32 {
87
88
89
90
91
92 return binary.BigEndian.Uint32(b)
93 }
94
95 func load_be32_idx(b []byte, idx int) uint32 {
96
97
98
99
100
101 return binary.BigEndian.Uint32(b[idx:])
102 }
103
104 func load_be16(b []byte) uint16 {
105
106
107
108
109 return binary.BigEndian.Uint16(b)
110 }
111
112 func load_be16_idx(b []byte, idx int) uint16 {
113
114
115
116
117 return binary.BigEndian.Uint16(b[idx:])
118 }
119
120 func load_le_byte2_uint16(s []byte) uint16 {
121
122
123
124
125 return uint16(s[0]) | uint16(s[1])<<8
126 }
127
128 func load_le_byte2_uint16_inv(s []byte) uint16 {
129
130
131
132
133 return uint16(s[1])<<8 | uint16(s[0])
134 }
135
136 func load_le_byte4_uint32(s []byte) uint32 {
137
138
139
140
141 return uint32(s[0]) | uint32(s[1])<<8 | uint32(s[2])<<16 | uint32(s[3])<<24
142 }
143
144 func load_le_byte4_uint32_inv(s []byte) uint32 {
145
146 return uint32(s[3])<<24 | uint32(s[2])<<16 | uint32(s[1])<<8 | uint32(s[0])
147 }
148
149 func load_le_byte8_uint64(s []byte) uint64 {
150
151
152
153 return uint64(s[0]) | uint64(s[1])<<8 | uint64(s[2])<<16 | uint64(s[3])<<24 | uint64(s[4])<<32 | uint64(s[5])<<40 | uint64(s[6])<<48 | uint64(s[7])<<56
154 }
155
156 func load_le_byte8_uint64_inv(s []byte) uint64 {
157
158 return uint64(s[7])<<56 | uint64(s[6])<<48 | uint64(s[5])<<40 | uint64(s[4])<<32 | uint64(s[3])<<24 | uint64(s[2])<<16 | uint64(s[1])<<8 | uint64(s[0])
159 }
160
161 func load_be_byte2_uint16(s []byte) uint16 {
162
163
164
165 return uint16(s[0])<<8 | uint16(s[1])
166 }
167
168 func load_be_byte2_uint16_inv(s []byte) uint16 {
169
170
171
172 return uint16(s[1]) | uint16(s[0])<<8
173 }
174
175 func load_be_byte4_uint32(s []byte) uint32 {
176
177 return uint32(s[0])<<24 | uint32(s[1])<<16 | uint32(s[2])<<8 | uint32(s[3])
178 }
179
180 func load_be_byte4_uint32_inv(s []byte) uint32 {
181
182
183
184 return uint32(s[3]) | uint32(s[2])<<8 | uint32(s[1])<<16 | uint32(s[0])<<24
185 }
186
187 func load_be_byte8_uint64(s []byte) uint64 {
188
189
190 return uint64(s[0])<<56 | uint64(s[1])<<48 | uint64(s[2])<<40 | uint64(s[3])<<32 | uint64(s[4])<<24 | uint64(s[5])<<16 | uint64(s[6])<<8 | uint64(s[7])
191 }
192
193 func load_be_byte8_uint64_inv(s []byte) uint64 {
194
195
196
197
198 return uint64(s[7]) | uint64(s[6])<<8 | uint64(s[5])<<16 | uint64(s[4])<<24 | uint64(s[3])<<32 | uint64(s[2])<<40 | uint64(s[1])<<48 | uint64(s[0])<<56
199 }
200
201 func load_le_byte2_uint16_idx(s []byte, idx int) uint16 {
202
203
204
205 return uint16(s[idx]) | uint16(s[idx+1])<<8
206 }
207
208 func load_le_byte2_uint16_idx_inv(s []byte, idx int) uint16 {
209
210
211
212 return uint16(s[idx+1])<<8 | uint16(s[idx])
213 }
214
215 func load_le_byte4_uint32_idx(s []byte, idx int) uint32 {
216
217
218 return uint32(s[idx]) | uint32(s[idx+1])<<8 | uint32(s[idx+2])<<16 | uint32(s[idx+3])<<24
219 }
220
221 func load_le_byte4_uint32_idx_inv(s []byte, idx int) uint32 {
222
223 return uint32(s[idx+3])<<24 | uint32(s[idx+2])<<16 | uint32(s[idx+1])<<8 | uint32(s[idx])
224 }
225
226 func load_le_byte8_uint64_idx(s []byte, idx int) uint64 {
227
228
229 return uint64(s[idx]) | uint64(s[idx+1])<<8 | uint64(s[idx+2])<<16 | uint64(s[idx+3])<<24 | uint64(s[idx+4])<<32 | uint64(s[idx+5])<<40 | uint64(s[idx+6])<<48 | uint64(s[idx+7])<<56
230 }
231
232 func load_le_byte8_uint64_idx_inv(s []byte, idx int) uint64 {
233
234 return uint64(s[idx+7])<<56 | uint64(s[idx+6])<<48 | uint64(s[idx+5])<<40 | uint64(s[idx+4])<<32 | uint64(s[idx+3])<<24 | uint64(s[idx+2])<<16 | uint64(s[idx+1])<<8 | uint64(s[idx])
235 }
236
237 func load_be_byte2_uint16_idx(s []byte, idx int) uint16 {
238
239
240 return uint16(s[idx])<<8 | uint16(s[idx+1])
241 }
242
243 func load_be_byte2_uint16_idx_inv(s []byte, idx int) uint16 {
244
245
246 return uint16(s[idx+1]) | uint16(s[idx])<<8
247 }
248
249 func load_be_byte4_uint32_idx(s []byte, idx int) uint32 {
250
251 return uint32(s[idx])<<24 | uint32(s[idx+1])<<16 | uint32(s[idx+2])<<8 | uint32(s[idx+3])
252 }
253
254 func load_be_byte8_uint64_idx(s []byte, idx int) uint64 {
255
256 return uint64(s[idx])<<56 | uint64(s[idx+1])<<48 | uint64(s[idx+2])<<40 | uint64(s[idx+3])<<32 | uint64(s[idx+4])<<24 | uint64(s[idx+5])<<16 | uint64(s[idx+6])<<8 | uint64(s[idx+7])
257 }
258
259 func load_le_byte2_uint16_idx2(s []byte, idx int) uint16 {
260
261 return uint16(s[idx<<1]) | uint16(s[(idx<<1)+1])<<8
262 }
263
264 func load_le_byte2_uint16_idx2_inv(s []byte, idx int) uint16 {
265
266 return uint16(s[(idx<<1)+1])<<8 | uint16(s[idx<<1])
267 }
268
269 func load_le_byte4_uint32_idx4(s []byte, idx int) uint32 {
270
271 return uint32(s[idx<<2]) | uint32(s[(idx<<2)+1])<<8 | uint32(s[(idx<<2)+2])<<16 | uint32(s[(idx<<2)+3])<<24
272 }
273
274 func load_le_byte4_uint32_idx4_inv(s []byte, idx int) uint32 {
275
276 return uint32(s[(idx<<2)+3])<<24 | uint32(s[(idx<<2)+2])<<16 | uint32(s[(idx<<2)+1])<<8 | uint32(s[idx<<2])
277 }
278
279 func load_le_byte8_uint64_idx8(s []byte, idx int) uint64 {
280
281 return uint64(s[idx<<3]) | uint64(s[(idx<<3)+1])<<8 | uint64(s[(idx<<3)+2])<<16 | uint64(s[(idx<<3)+3])<<24 | uint64(s[(idx<<3)+4])<<32 | uint64(s[(idx<<3)+5])<<40 | uint64(s[(idx<<3)+6])<<48 | uint64(s[(idx<<3)+7])<<56
282 }
283
284 func load_le_byte8_uint64_idx8_inv(s []byte, idx int) uint64 {
285
286 return uint64(s[(idx<<3)+7])<<56 | uint64(s[(idx<<3)+6])<<48 | uint64(s[(idx<<3)+5])<<40 | uint64(s[(idx<<3)+4])<<32 | uint64(s[(idx<<3)+3])<<24 | uint64(s[(idx<<3)+2])<<16 | uint64(s[(idx<<3)+1])<<8 | uint64(s[idx<<3])
287 }
288
289 func load_be_byte2_uint16_idx2(s []byte, idx int) uint16 {
290
291 return uint16(s[idx<<1])<<8 | uint16(s[(idx<<1)+1])
292 }
293
294 func load_be_byte2_uint16_idx2_inv(s []byte, idx int) uint16 {
295
296 return uint16(s[(idx<<1)+1]) | uint16(s[idx<<1])<<8
297 }
298
299 func load_be_byte4_uint32_idx4(s []byte, idx int) uint32 {
300
301 return uint32(s[idx<<2])<<24 | uint32(s[(idx<<2)+1])<<16 | uint32(s[(idx<<2)+2])<<8 | uint32(s[(idx<<2)+3])
302 }
303
304 func load_be_byte8_uint64_idx8(s []byte, idx int) uint64 {
305
306 return uint64(s[idx<<3])<<56 | uint64(s[(idx<<3)+1])<<48 | uint64(s[(idx<<3)+2])<<40 | uint64(s[(idx<<3)+3])<<32 | uint64(s[(idx<<3)+4])<<24 | uint64(s[(idx<<3)+5])<<16 | uint64(s[(idx<<3)+6])<<8 | uint64(s[(idx<<3)+7])
307 }
308
309
310
311 func fcall_byte(a [2]byte) [2]byte {
312 return fcall_byte(fcall_byte(a))
313 }
314
315 func fcall_uint16(a [2]uint16) [2]uint16 {
316 return fcall_uint16(fcall_uint16(a))
317 }
318
319 func fcall_uint32(a [2]uint32) [2]uint32 {
320 return fcall_uint32(fcall_uint32(a))
321 }
322
323
324
325 func load_op_merge(p, q *int) {
326 x := *p
327 *q += x
328 }
329 func load_op_no_merge(p, q *int) {
330 x := *p
331 for i := 0; i < 10; i++ {
332 *q += x
333 }
334 }
335
336
337 func offsets_fold(_, a [20]byte) (b [20]byte) {
338
339 b = a
340 return
341 }
342
343
344
345
346 func safe_point(p, q *[2]*int) {
347 a, b := p[0], p[1]
348 runtime.GC()
349 q[0], q[1] = a, b
350 }
351
352
353
354
355
356 func store_le64(b []byte, x uint64) {
357
358
359
360
361 binary.LittleEndian.PutUint64(b, x)
362 }
363
364 func store_le64_idx(b []byte, x uint64, idx int) {
365
366
367
368
369 binary.LittleEndian.PutUint64(b[idx:], x)
370 }
371
372 func store_le64_idx2(dst []byte, d, length, offset int) []byte {
373 a := dst[d : d+length]
374 b := dst[d-offset:]
375
376 binary.LittleEndian.PutUint64(a, binary.LittleEndian.Uint64(b))
377 return dst
378 }
379
380 func store_le64_idx_const(b []byte, idx int) {
381
382 binary.LittleEndian.PutUint64(b[idx:], 123)
383 }
384
385 func store_le64_load(b []byte, x *[8]byte) {
386 _ = b[8]
387
388
389
390
391 binary.LittleEndian.PutUint64(b, binary.LittleEndian.Uint64(x[:]))
392 }
393
394 func store_le32(b []byte, x uint32) {
395
396
397
398
399 binary.LittleEndian.PutUint32(b, x)
400 }
401
402 func store_le32_idx(b []byte, x uint32, idx int) {
403
404
405
406
407 binary.LittleEndian.PutUint32(b[idx:], x)
408 }
409
410 func store_le32_idx_const(b []byte, idx int) {
411
412 binary.LittleEndian.PutUint32(b[idx:], 123)
413 }
414
415 func store_le16(b []byte, x uint16) {
416
417
418
419
420 binary.LittleEndian.PutUint16(b, x)
421 }
422
423 func store_le16_idx(b []byte, x uint16, idx int) {
424
425
426
427
428 binary.LittleEndian.PutUint16(b[idx:], x)
429 }
430
431 func store_le16_idx_const(b []byte, idx int) {
432
433 binary.LittleEndian.PutUint16(b[idx:], 123)
434 }
435
436 func store_be64(b []byte, x uint64) {
437
438
439
440
441
442 binary.BigEndian.PutUint64(b, x)
443 }
444
445 func store_be64_idx(b []byte, x uint64, idx int) {
446
447
448
449
450
451 binary.BigEndian.PutUint64(b[idx:], x)
452 }
453
454 func store_be32(b []byte, x uint32) {
455
456
457
458
459
460 binary.BigEndian.PutUint32(b, x)
461 }
462
463 func store_be64_load(b, x *[8]byte) {
464
465
466 binary.BigEndian.PutUint64(b[:], binary.BigEndian.Uint64(x[:]))
467 }
468
469 func store_be32_load(b, x *[8]byte) {
470
471
472 binary.BigEndian.PutUint32(b[:], binary.BigEndian.Uint32(x[:]))
473 }
474
475 func store_be32_idx(b []byte, x uint32, idx int) {
476
477
478
479
480
481 binary.BigEndian.PutUint32(b[idx:], x)
482 }
483
484 func store_be16(b []byte, x uint16) {
485
486
487
488
489
490 binary.BigEndian.PutUint16(b, x)
491 }
492
493 func store_be16_idx(b []byte, x uint16, idx int) {
494
495
496
497
498
499 binary.BigEndian.PutUint16(b[idx:], x)
500 }
501
502 func store_le_byte_2(b []byte, val uint16) {
503 _ = b[2]
504
505
506
507 b[1], b[2] = byte(val), byte(val>>8)
508 }
509
510 func store_le_byte_2_inv(b []byte, val uint16) {
511 _ = b[2]
512
513
514 b[2], b[1] = byte(val>>8), byte(val)
515 }
516
517 func store_le_byte_4(b []byte, val uint32) {
518 _ = b[4]
519
520
521
522 b[1], b[2], b[3], b[4] = byte(val), byte(val>>8), byte(val>>16), byte(val>>24)
523 }
524
525 func store_le_byte_8(b []byte, val uint64) {
526 _ = b[8]
527
528
529 b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8] = byte(val), byte(val>>8), byte(val>>16), byte(val>>24), byte(val>>32), byte(val>>40), byte(val>>48), byte(val>>56)
530 }
531
532 func store_be_byte_2(b []byte, val uint16) {
533 _ = b[2]
534
535
536
537 b[1], b[2] = byte(val>>8), byte(val)
538 }
539
540 func store_be_byte_4(b []byte, val uint32) {
541 _ = b[4]
542
543
544
545 b[1], b[2], b[3], b[4] = byte(val>>24), byte(val>>16), byte(val>>8), byte(val)
546 }
547
548 func store_be_byte_8(b []byte, val uint64) {
549 _ = b[8]
550
551
552
553 b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8] = byte(val>>56), byte(val>>48), byte(val>>40), byte(val>>32), byte(val>>24), byte(val>>16), byte(val>>8), byte(val)
554 }
555
556 func store_le_byte_2_idx(b []byte, idx int, val uint16) {
557 _, _ = b[idx+0], b[idx+1]
558
559
560 b[idx+1], b[idx+0] = byte(val>>8), byte(val)
561 }
562
563 func store_le_byte_2_idx_inv(b []byte, idx int, val uint16) {
564 _, _ = b[idx+0], b[idx+1]
565
566 b[idx+0], b[idx+1] = byte(val), byte(val>>8)
567 }
568
569 func store_le_byte_4_idx(b []byte, idx int, val uint32) {
570 _, _, _, _ = b[idx+0], b[idx+1], b[idx+2], b[idx+3]
571
572 b[idx+3], b[idx+2], b[idx+1], b[idx+0] = byte(val>>24), byte(val>>16), byte(val>>8), byte(val)
573 }
574
575 func store_be_byte_2_idx(b []byte, idx int, val uint16) {
576 _, _ = b[idx+0], b[idx+1]
577
578 b[idx+0], b[idx+1] = byte(val>>8), byte(val)
579 }
580
581 func store_be_byte_4_idx(b []byte, idx int, val uint32) {
582 _, _, _, _ = b[idx+0], b[idx+1], b[idx+2], b[idx+3]
583
584 b[idx+0], b[idx+1], b[idx+2], b[idx+3] = byte(val>>24), byte(val>>16), byte(val>>8), byte(val)
585 }
586
587 func store_be_byte_2_idx2(b []byte, idx int, val uint16) {
588 _, _ = b[(idx<<1)+0], b[(idx<<1)+1]
589
590 b[(idx<<1)+0], b[(idx<<1)+1] = byte(val>>8), byte(val)
591 }
592
593 func store_le_byte_2_idx2(b []byte, idx int, val uint16) {
594 _, _ = b[(idx<<1)+0], b[(idx<<1)+1]
595
596 b[(idx<<1)+1], b[(idx<<1)+0] = byte(val>>8), byte(val)
597 }
598
599 func store_be_byte_4_idx4(b []byte, idx int, val uint32) {
600 _, _, _, _ = b[(idx<<2)+0], b[(idx<<2)+1], b[(idx<<2)+2], b[(idx<<2)+3]
601
602 b[(idx<<2)+0], b[(idx<<2)+1], b[(idx<<2)+2], b[(idx<<2)+3] = byte(val>>24), byte(val>>16), byte(val>>8), byte(val)
603 }
604
605 func store_le_byte_4_idx4_inv(b []byte, idx int, val uint32) {
606 _, _, _, _ = b[(idx<<2)+0], b[(idx<<2)+1], b[(idx<<2)+2], b[(idx<<2)+3]
607
608 b[(idx<<2)+3], b[(idx<<2)+2], b[(idx<<2)+1], b[(idx<<2)+0] = byte(val>>24), byte(val>>16), byte(val>>8), byte(val)
609 }
610
611
612
613
614
615
616
617 func zero_byte_2(b1, b2 []byte) {
618
619 _, _ = b1[1], b2[1]
620
621
622
623 b1[0], b1[1] = 0, 0
624
625
626
627 b2[1], b2[0] = 0, 0
628 }
629
630 func zero_byte_4(b1, b2 []byte) {
631 _, _ = b1[3], b2[3]
632
633
634
635 b1[0], b1[1], b1[2], b1[3] = 0, 0, 0, 0
636
637 b2[2], b2[3], b2[1], b2[0] = 0, 0, 0, 0
638 }
639
640 func zero_byte_8(b []byte) {
641 _ = b[7]
642 b[0], b[1], b[2], b[3] = 0, 0, 0, 0
643 b[4], b[5], b[6], b[7] = 0, 0, 0, 0
644 }
645
646 func zero_byte_16(b []byte) {
647 _ = b[15]
648 b[0], b[1], b[2], b[3] = 0, 0, 0, 0
649 b[4], b[5], b[6], b[7] = 0, 0, 0, 0
650 b[8], b[9], b[10], b[11] = 0, 0, 0, 0
651 b[12], b[13], b[14], b[15] = 0, 0, 0, 0
652 }
653
654 func zero_byte_30(a *[30]byte) {
655 *a = [30]byte{}
656 }
657
658 func zero_byte_39(a *[39]byte) {
659 *a = [39]byte{}
660 }
661
662 func zero_byte_2_idx(b []byte, idx int) {
663 _, _ = b[idx+0], b[idx+1]
664
665 b[idx+0], b[idx+1] = 0, 0
666 }
667
668 func zero_byte_2_idx2(b []byte, idx int) {
669 _, _ = b[(idx<<1)+0], b[(idx<<1)+1]
670
671 b[(idx<<1)+0], b[(idx<<1)+1] = 0, 0
672 }
673
674 func zero_uint16_2(h1, h2 []uint16) {
675 _, _ = h1[1], h2[1]
676
677
678
679 h1[0], h1[1] = 0, 0
680
681
682
683 h2[1], h2[0] = 0, 0
684 }
685
686 func zero_uint16_4(h1, h2 []uint16) {
687 _, _ = h1[3], h2[3]
688
689
690 h1[0], h1[1], h1[2], h1[3] = 0, 0, 0, 0
691
692 h2[2], h2[3], h2[1], h2[0] = 0, 0, 0, 0
693 }
694
695 func zero_uint16_8(h []uint16) {
696 _ = h[7]
697 h[0], h[1], h[2], h[3] = 0, 0, 0, 0
698 h[4], h[5], h[6], h[7] = 0, 0, 0, 0
699 }
700
701 func zero_uint32_2(w1, w2 []uint32) {
702 _, _ = w1[1], w2[1]
703
704
705 w1[0], w1[1] = 0, 0
706
707
708 w2[1], w2[0] = 0, 0
709 }
710
711 func zero_uint32_4(w1, w2 []uint32) {
712 _, _ = w1[3], w2[3]
713 w1[0], w1[1], w1[2], w1[3] = 0, 0, 0, 0
714 w2[2], w2[3], w2[1], w2[0] = 0, 0, 0, 0
715 }
716
717 func zero_uint64_2(d1, d2 []uint64) {
718 _, _ = d1[1], d2[1]
719 d1[0], d1[1] = 0, 0
720 d2[1], d2[0] = 0, 0
721 }
722
View as plain text