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