Source file
test/codegen/comparisons.go
1
2
3
4
5
6
7 package codegen
8
9 import (
10 "cmp"
11 "unsafe"
12 )
13
14
15
16
17
18
19
20
21
22
23 func CompareString1(s string) bool {
24
25
26
27
28 return s == "xx"
29 }
30
31 func CompareString2(s string) bool {
32
33
34
35
36 return s == "xxxx"
37 }
38
39 func CompareString3(s string) bool {
40
41
42
43
44 return s == "xxxxxxxx"
45 }
46
47
48
49 func CompareArray1(a, b [2]byte) bool {
50
51
52
53
54 return a == b
55 }
56
57 func CompareArray2(a, b [3]uint16) bool {
58
59
60 return a == b
61 }
62
63 func CompareArray3(a, b [3]int16) bool {
64
65
66 return a == b
67 }
68
69 func CompareArray4(a, b [12]int8) bool {
70
71
72 return a == b
73 }
74
75 func CompareArray5(a, b [15]byte) bool {
76
77 return a == b
78 }
79
80
81 func CompareArray6(a, b unsafe.Pointer) bool {
82
83
84
85
86 return *((*[4]byte)(a)) != *((*[4]byte)(b))
87 }
88
89
90
91 type T1 struct {
92 a [8]byte
93 }
94
95 func CompareStruct1(s1, s2 T1) bool {
96
97
98 return s1 == s2
99 }
100
101 type T2 struct {
102 a [16]byte
103 }
104
105 func CompareStruct2(s1, s2 T2) bool {
106
107
108 return s1 == s2
109 }
110
111
112
113
114 type T3 struct {
115 a [24]byte
116 }
117
118 func CompareStruct3(s1, s2 T3) bool {
119
120
121 return s1 == s2
122 }
123
124 type T4 struct {
125 a [32]byte
126 }
127
128 func CompareStruct4(s1, s2 T4) bool {
129
130
131 return s1 == s2
132 }
133
134
135
136
137
138
139
140 var r bool
141
142 func CmpFold(x uint32) {
143
144 r = x > 4
145 }
146
147
148
149
150 func CmpMem1(p int, q *int) bool {
151
152 return p < *q
153 }
154
155 func CmpMem2(p *int, q int) bool {
156
157 return *p < q
158 }
159
160 func CmpMem3(p *int) bool {
161
162 return *p < 7
163 }
164
165 func CmpMem4(p *int) bool {
166
167 return 7 < *p
168 }
169
170 func CmpMem5(p **int) {
171
172 *p = nil
173 }
174
175 func CmpMem6(a []int) int {
176
177
178 if a[1] > a[2] {
179 return 1
180 } else {
181 return 2
182 }
183 }
184
185
186
187 func CmpZero1(a int32, ptr *int) {
188 if a < 0 {
189 *ptr = 0
190 }
191 }
192
193 func CmpZero2(a int64, ptr *int) {
194 if a < 0 {
195 *ptr = 0
196 }
197 }
198
199 func CmpZero3(a int32, ptr *int) {
200 if a >= 0 {
201 *ptr = 0
202 }
203 }
204
205 func CmpZero4(a int64, ptr *int) {
206 if a >= 0 {
207 *ptr = 0
208 }
209 }
210
211 func CmpToZero(a, b, d int32, e, f int64, deOptC0, deOptC1 bool) int32 {
212
213
214
215
216 c0 := a&b < 0
217
218
219 c1 := a+b < 0
220
221 c2 := a^b < 0
222
223
224 c3 := e&f < 0
225
226 c4 := e+f < 0
227
228
229
230 c5 := b+d == 0
231
232
233
234
235 c6 := a&d >= 0
236
237 c7 := e&(f<<3) < 0
238
239 c8 := e+(f<<3) < 0
240
241 c9 := e&(-19) < 0
242 if c0 {
243 return 1
244 } else if c1 {
245 return 2
246 } else if c2 {
247 return 3
248 } else if c3 {
249 return 4
250 } else if c4 {
251 return 5
252 } else if c5 {
253 return 6
254 } else if c6 {
255 return 7
256 } else if c7 {
257 return 9
258 } else if c8 {
259 return 10
260 } else if c9 {
261 return 11
262 } else if deOptC0 {
263 return b + d
264 } else if deOptC1 {
265 return a & d
266 } else {
267 return 0
268 }
269 }
270
271 func CmpLogicalToZero(a, b, c uint32, d, e, f, g uint64) uint64 {
272
273
274
275 if a&63 == 0 {
276 return 1
277 }
278
279
280
281 if d&255 == 0 {
282 return 1
283 }
284
285
286
287 if d&e == 0 {
288 return 1
289 }
290
291
292 if f|g == 0 {
293 return 1
294 }
295
296
297
298 if e^d == 0 {
299 return 1
300 }
301 return 0
302 }
303
304
305
306
307
308
309
310 func CmpToZero_ex1(a int64, e int32) int {
311
312 if a+3 < 0 {
313 return 1
314 }
315
316
317 if a+5 <= 0 {
318 return 1
319 }
320
321
322 if a+13 >= 0 {
323 return 2
324 }
325
326
327 if a-7 < 0 {
328 return 3
329 }
330
331
332 if a-11 >= 0 {
333 return 4
334 }
335
336
337 if a-19 > 0 {
338 return 4
339 }
340
341
342
343 if e+3 < 0 {
344 return 5
345 }
346
347
348
349 if e+13 >= 0 {
350 return 6
351 }
352
353
354
355 if e-7 < 0 {
356 return 7
357 }
358
359
360
361 if e-11 >= 0 {
362 return 8
363 }
364
365 return 0
366 }
367
368
369
370 func CmpToZero_ex2(a, b, c int64, e, f, g int32) int {
371
372 if a+b < 0 {
373 return 1
374 }
375
376
377 if a+c <= 0 {
378 return 1
379 }
380
381
382 if b+c >= 0 {
383 return 2
384 }
385
386
387
388 if e+f < 0 {
389 return 5
390 }
391
392
393
394 if f+g >= 0 {
395 return 6
396 }
397 return 0
398 }
399
400
401 func CmpToZero_ex3(a, b, c, d int64, e, f, g, h int32) int {
402
403 if a+b*c < 0 {
404 return 1
405 }
406
407
408 if b+c*d >= 0 {
409 return 2
410 }
411
412
413
414 if e+f*g > 0 {
415 return 5
416 }
417
418
419
420 if f+g*h <= 0 {
421 return 6
422 }
423 return 0
424 }
425
426
427 func CmpToZero_ex4(a, b, c, d int64, e, f, g, h int32) int {
428
429 if a-b*c > 0 {
430 return 1
431 }
432
433
434 if b-c*d >= 0 {
435 return 2
436 }
437
438
439 if e-f*g < 0 {
440 return 5
441 }
442
443
444 if f-g*h >= 0 {
445 return 6
446 }
447 return 0
448 }
449
450 func CmpToZero_ex5(e, f int32, u uint32) int {
451
452 if e+f<<1 > 0 {
453 return 1
454 }
455
456
457 if f-int32(u>>2) >= 0 {
458 return 2
459 }
460 return 0
461 }
462
463 func UintLtZero(a uint8, b uint16, c uint32, d uint64) int {
464
465
466 if a < 0 || b < 0 || c < 0 || d < 0 {
467 return 1
468 }
469 return 0
470 }
471
472 func UintGeqZero(a uint8, b uint16, c uint32, d uint64) int {
473
474
475 if a >= 0 || b >= 0 || c >= 0 || d >= 0 {
476 return 1
477 }
478 return 0
479 }
480
481 func UintGtZero(a uint8, b uint16, c uint32, d uint64) int {
482
483 if a > 0 || b > 0 || c > 0 || d > 0 {
484 return 1
485 }
486 return 0
487 }
488
489 func UintLeqZero(a uint8, b uint16, c uint32, d uint64) int {
490
491 if a <= 0 || b <= 0 || c <= 0 || d <= 0 {
492 return 1
493 }
494 return 0
495 }
496
497 func UintLtOne(a uint8, b uint16, c uint32, d uint64) int {
498
499 if a < 1 || b < 1 || c < 1 || d < 1 {
500 return 1
501 }
502 return 0
503 }
504
505 func UintGeqOne(a uint8, b uint16, c uint32, d uint64) int {
506
507 if a >= 1 || b >= 1 || c >= 1 || d >= 1 {
508 return 1
509 }
510 return 0
511 }
512
513 func CmpToZeroU_ex1(a uint8, b uint16, c uint32, d uint64) int {
514
515 if 0 < a {
516 return 1
517 }
518
519 if 0 < b {
520 return 1
521 }
522
523 if 0 < c {
524 return 1
525 }
526
527 if 0 < d {
528 return 1
529 }
530 return 0
531 }
532
533 func CmpToZeroU_ex2(a uint8, b uint16, c uint32, d uint64) int {
534
535 if a <= 0 {
536 return 1
537 }
538
539 if b <= 0 {
540 return 1
541 }
542
543 if c <= 0 {
544 return 1
545 }
546
547 if d <= 0 {
548 return 1
549 }
550 return 0
551 }
552
553 func CmpToOneU_ex1(a uint8, b uint16, c uint32, d uint64) int {
554
555 if a < 1 {
556 return 1
557 }
558
559 if b < 1 {
560 return 1
561 }
562
563 if c < 1 {
564 return 1
565 }
566
567 if d < 1 {
568 return 1
569 }
570 return 0
571 }
572
573 func CmpToOneU_ex2(a uint8, b uint16, c uint32, d uint64) int {
574
575 if 1 <= a {
576 return 1
577 }
578
579 if 1 <= b {
580 return 1
581 }
582
583 if 1 <= c {
584 return 1
585 }
586
587 if 1 <= d {
588 return 1
589 }
590 return 0
591 }
592
593
594
595 func equalConstString1() bool {
596 a := string("A")
597 b := string("Z")
598
599
600
601
602 return a == b
603 }
604
605 func equalVarString1(a string) bool {
606 b := string("Z")
607
608
609
610
611 return a[:1] == b
612 }
613
614 func equalConstString2() bool {
615 a := string("AA")
616 b := string("ZZ")
617
618
619
620
621 return a == b
622 }
623
624 func equalVarString2(a string) bool {
625 b := string("ZZ")
626
627
628
629
630 return a[:2] == b
631 }
632
633 func equalConstString4() bool {
634 a := string("AAAA")
635 b := string("ZZZZ")
636
637
638
639
640 return a == b
641 }
642
643 func equalVarString4(a string) bool {
644 b := string("ZZZZ")
645
646
647
648
649 return a[:4] == b
650 }
651
652 func equalConstString8() bool {
653 a := string("AAAAAAAA")
654 b := string("ZZZZZZZZ")
655
656
657
658
659 return a == b
660 }
661
662 func equalVarString8(a string) bool {
663 b := string("ZZZZZZZZ")
664
665
666
667
668 return a[:8] == b
669 }
670
671 func equalVarStringNoSpill(a, b string) bool {
672 s := string("123456789012345678901234567890123")
673
674 memeq1 := a[:33] == s
675
676 memeq2 := s == a[:33]
677
678 memeq3 := s == b[:33]
679 return memeq1 && memeq2 && memeq3
680 }
681
682 func equalVarString17(a string) bool {
683 b := string("12345678901234567")
684
685 return a[:17] == b
686 }
687
688 func cmpToCmn(a, b, c, d int) int {
689 var c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11 int
690
691 if a < -8 {
692 c1 = 1
693 }
694
695 if a+1 == 0 {
696 c2 = 1
697 }
698
699 if a+3 != 0 {
700 c3 = 1
701 }
702
703 if a+b == 0 {
704 c4 = 1
705 }
706
707 if b+c != 0 {
708 c5 = 1
709 }
710
711 if a == -c {
712 c6 = 1
713 }
714
715 if b != -d {
716 c7 = 1
717 }
718
719 if a*b+c == 0 {
720 c8 = 1
721 }
722
723 if a*c+b != 0 {
724 c9 = 1
725 }
726
727 if b*c-a == 0 {
728 c10 = 1
729 }
730
731 if a*d-b != 0 {
732 c11 = 1
733 }
734 return c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 + c9 + c10 + c11
735 }
736
737 func cmpToCmnLessThan(a, b, c, d int) int {
738 var c1, c2, c3, c4 int
739
740 if a+1 < 0 {
741 c1 = 1
742 }
743
744 if a+b < 0 {
745 c2 = 1
746 }
747
748 if a*b+c < 0 {
749 c3 = 1
750 }
751
752 if a-b*c < 0 {
753 c4 = 1
754 }
755 return c1 + c2 + c3 + c4
756 }
757
758 func less128Signed32(x int32) bool {
759
760
761 return x < 128
762 }
763
764 func less128Signed64(x int64) bool {
765
766
767 return x < 128
768 }
769
770 func less128Unsigned32(x uint32) bool {
771
772
773 return x < 128
774 }
775
776 func less128Unsigned64(x uint64) bool {
777
778
779 return x < 128
780 }
781
782 func ge128Unsigned32(x uint32) bool {
783
784
785 return x >= 128
786 }
787
788 func ge128Unsigned64(x uint64) bool {
789
790
791 return x >= 128
792 }
793
794 func ge128Signed32(x int32) bool {
795
796
797 return x >= 128
798 }
799
800 func ge128Signed64(x int64) bool {
801
802
803 return x >= 128
804 }
805
806 func cmpToCmnGreaterThanEqual(a, b, c, d int) int {
807 var c1, c2, c3, c4 int
808
809 if a+1 >= 0 {
810 c1 = 1
811 }
812
813 if a+b >= 0 {
814 c2 = 1
815 }
816
817 if a*b+c >= 0 {
818 c3 = 1
819 }
820
821 if a-b*c >= 0 {
822 c4 = 1
823 }
824 return c1 + c2 + c3 + c4
825 }
826
827 func cmp1(val string) bool {
828 var z string
829
830 return z == val
831 }
832
833 func cmp2(val string) bool {
834 var z string
835
836 return val == z
837 }
838
839 func cmp3(val string) bool {
840 z := "food"
841
842 return z == val
843 }
844
845 func cmp4(val string) bool {
846 z := "food"
847
848 return val == z
849 }
850
851 func cmp5[T comparable](val T) bool {
852 var z T
853
854 return z == val
855 }
856
857 func cmp6[T comparable](val T) bool {
858 var z T
859
860 return val == z
861 }
862
863 func cmp7() {
864 cmp5[string]("")
865 cmp6[string]("")
866 }
867
868 type Point struct {
869 X, Y int
870 }
871
872
873
874
875
876 func invertLessThanNoov(p1, p2, p3 Point) bool {
877
878 return (p1.X-p3.X)*(p2.Y-p3.Y)-(p2.X-p3.X)*(p1.Y-p3.Y) < 0
879 }
880
881 func cmpstring1(x, y string) int {
882
883 if x < y {
884 return -1
885 }
886
887 if x > y {
888 return +1
889 }
890 return 0
891 }
892 func cmpstring2(x, y string) int {
893
894
895
896
897
898
899 return cmp.Compare(x, y)
900 }
901
902 func bijectiveAdd(x uint) bool {
903
904
905 return x+1337 == 42
906 }
907
908 func bijectiveSub1(x uint) bool {
909
910
911 return x-1337 == 42
912 }
913
914 func bijectiveSub2(x uint) bool {
915
916
917 return 1337-x == 42
918 }
919
920 func bijectiveXor(x uint) bool {
921
922
923 return x^1337 == 42
924 }
925
926 func bijectiveCom(x uint) bool {
927
928
929 return ^x == 42
930 }
931
932 func bijectiveNeg(x int) bool {
933
934
935 return -x == 42
936 }
937
938 func bijectiveMul(x uint) bool {
939
940
941 return x*1337 == 42
942 }
943
View as plain text