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