]> git.proxmox.com Git - rustc.git/blame - src/binaryen/test/unit.asm.js
New upstream version 1.25.0+dfsg1
[rustc.git] / src / binaryen / test / unit.asm.js
CommitLineData
abe05a73
XL
1function asm(global, env, buffer) {
2 "use asm";
3
4 var t = global.NaN, u = global.Infinity;
5 var Int = 0;
6 var Double = 0.0;
7 var Math_fround = global.Math.fround;
8 var Math_abs = global.Math.abs;
9 var Math_ceil = global.Math.ceil;
10 var Math_max = global.Math.max;
11 var Math_min = global.Math.min;
12 var Math_sqrt = global.Math.sqrt;
13 var tempDoublePtr = env.tempDoublePtr | 0;
14 var n = env.gb | 0;
15 var STACKTOP = env.STACKTOP | 0;
16 var setTempRet0=env.setTempRet0;
17
18 var abort = env.abort;
19 var print = env.print;
20 var h = env.h;
21 var return_int = env.return_int;
22 var emscripten_log = env.emscripten_log;
23
24 var HEAP8 = new global.Int8Array(buffer);
25 var HEAP16 = new global.Int16Array(buffer);
26 var HEAP32 = new global.Int32Array(buffer);
27 var HEAPU8 = new global.Uint8Array(buffer);
28 var HEAPU16 = new global.Uint16Array(buffer);
29 var HEAPU32 = new global.Uint32Array(buffer);
30 var HEAPF32 = new global.Float32Array(buffer);
31 var HEAPF64 = new global.Float64Array(buffer);
32
33 function big_negative() {
34 var temp = 0.0;
35 temp = +-2147483648;
36 temp = -2147483648.0;
37 temp = -21474836480.0;
38 temp = 0.039625;
39 temp = -0.039625;
40 }
41 function importedDoubles() {
42 var temp = 0.0;
43 temp = t + u + (-u) + (-t);
44 if ((Int | 0) > 0) return -3.4;
45 if (Double > 0.0) return 5.6;
46 return 1.2;
47 }
48 function doubleCompares(x, y) {
49 x = +x;
50 y = +y;
51 var t = 0.0;
52 var Int = 0.0, Double = 0; // confusing with globals
53 if (x > 0.0) return 1.2;
54 Int = x;
55 Double = n;
56 if (Int > 0.0) return -3.4;
57 if ((Double|0) > 0) return 5.6;
58 if (x < y) return +x;
59 return +y;
60 }
61 function intOps(x) {
62 x = x | 0;
63 return (!x) | 0;
64 }
65 function hexLiterals() {
66 var i = 0;
67 i = 0x0 + 0x12ABCdef + 0xFEDcba90 | 0;
68 }
69 function conversions(i, d, f) {
70 i = i | 0;
71 d = +d;
72 f = Math_fround(f);
73 i = ~~d;
74 i = ~~f;
75 d = +(i | 0);
76 d = +(i >>> 0);
77 }
78 function seq() {
79 var J = 0.0;
80 J = (0.1, 5.1) - (3.2, 4.2);
81 }
82 function switcher(x) {
83 x = x | 0;
84 var waka = 0;
85 switch (x | 0) {
86 case 1: return 1;
87 case 2: return 2;
88 }
89 switch (x | 0) {
90 case 12: return 121;
91 case 5: return 51;
92 }
93 Lout: switch (x | 0) {
94 case 12: break;
95 case 10: break Lout;
96 case 5: {
97 while (1) {
98 break;
99 }
100 break;
101 }
102 case 2: {
103 while (1) {
104 break Lout;
105 }
106 break;
107 }
108 }
109
110 L1 : while (1) {
111 L3 : while (1) switch (x | 0) {
112 case -1:
113 {
114 break L1;
115 break;
116 }
117 case 116:
118 {
119 waka = 1;
120 break;
121 }
122 case 110:
123 {
124 break L3;
125 break;
126 }
127 default:
128 {
129 break L1;
130 }
131 }
132 h(120);
133 }
134
135 return 0;
136 }
137 function blocker() {
138 L: {
139 break L;
140 }
141 }
142 function frem() {
143 return +(5.5 % 1.2);
144 }
145 function frem_float() {
146 return Math_fround(Math_fround(5.5) % Math_fround(1.2));
147 }
148 function big_uint_div_u() {
149 var x = 0;
150 x = (4294967295 / 2)&-1;
151 return x | 0;
152 }
153 function trapping_sint_div_s() {
154 var x = 0;
155 x = (-2147483648 / -1);
156 return x | 0;
157 }
158 function fr(x) {
159 x = Math_fround(x);
160 var y = Math_fround(0), z = 0.0;
161 Math_fround(z);
162 Math_fround(y);
163 Math_fround(5);
164 Math_fround(0);
165 Math_fround(5.0);
166 Math_fround(0.0);
167 }
168 function negZero() {
169 return +-0;
170 }
171 function abs() {
172 var x = 0, y = 0.0, z = Math_fround(0);
173 x = Math_abs(0) | 0;
174 y = +Math_abs(0.0);
175 z = Math_fround(Math_abs(Math_fround(0)));
176 }
177 function minmax() {
178 var x = 0.0, y = 0.0, z = Math_fround(0), w = Math_fround(0);
179 x = +Math_min(+x, +y);
180 y = +Math_max(+x, +y);
181 z = Math_fround(Math_min(Math_fround(z), Math_fround(w)));
182 w = Math_fround(Math_max(Math_fround(z), Math_fround(w)));
183 }
184 function neg() {
185 var x = Math_fround(0);
186 x = Math_fround(-x);
187 FUNCTION_TABLE_c[1 & 7](x);
188 }
189 function cneg(x) {
190 x = Math_fround(x);
191 FUNCTION_TABLE_c[1 & 7](x);
192 }
193 function ___syscall_ret() {
194 var $0 = 0;
195 ($0>>>0) > 4294963200; // -4096
196 }
197 function smallCompare(i, j) {
198 i = i | 0;
199 j = j | 0;
200 if ((i | 0) < (j | 0)) i = i + 1 | 0;
201 if ((i >>> 0) < (j >>> 0)) i = i + 1 | 0;
202 return i | 0;
203 }
204 function cneg_nosemicolon() {
205 FUNCTION_TABLE_vi[1 & 7](1) // no semicolon
206 }
207 function forLoop() {
208 var i = 0;
209 for (i = 1; (i | 0) < 200; i = i + 1 | 0) {
210 h(i | 0);
211 }
212 }
213 function ceiling_32_64(u, B) {
214 u = Math_fround(u);
215 B = +B;
216 var temp = Math_fround(0);
217 temp = Math_fround(Math_ceil(B));
218 temp = Math_fround(u * Math_fround(Math_ceil(Math_fround(B))));
219 }
220 function aborts() {
221 abort();
222 abort(55);
223 abort();
224 abort(12.34);
225 abort(+Math_fround(56.78));
226 }
227 function continues() {
228 while (1) {
229 print(1);
230 do {
231 print(5);
232 if (return_int() | 0) continue;
233 } while (0);
234 print(2);
235 }
236 }
237 function bitcasts(i, f) {
238 i = i | 0;
239 f = Math_fround(f);
240 var d = 0.0;
241 (HEAP32[tempDoublePtr >> 2] = i, Math_fround(HEAPF32[tempDoublePtr >> 2])); // i32->f32
242 (HEAP32[tempDoublePtr >> 2] = i, +HEAPF32[tempDoublePtr >> 2]); // i32->f32, no fround
243 (HEAPF32[tempDoublePtr >> 2] = f, HEAP32[tempDoublePtr >> 2] | 0); // f32->i32
244 (HEAPF32[tempDoublePtr >> 2] = d, HEAP32[tempDoublePtr >> 2] | 0); // f64 with implict f32 conversion, ->i32
245 }
246 function recursiveBlockMerging(x) {
247 x = x | 0;
248 lb((1, x) + (2, 3) + (((4, 5), 6), 7) + (8, (9, (10, (11, 12)))) | 0) | 0;
249 x = (lb(1) | 0, x) + (lb(2) | 0, lb(3) | 0) + (((lb(4) | 0, lb(5) | 0), lb(6) | 0), lb(7) | 0) + (lb(8) | 0, (lb(9) | 0, (lb(10) | 0, (lb(11) | 0, lb(12) | 0)))) | 0;
250 return x | 0;
251 }
252
253 function lb(a) {
254 a = a | 0;
255 HEAP32[a >> 2] = n + 136 + 8;
256 return 0;
257 }
258
259 function forgetMe() {
260 123.456;
261 }
262 function exportMe() {
263 -3.14159;
264 }
265
266 function zeroInit(x) {
267 x = x | 0;
268 var y = 0; // reusing this with x is dangerous - x has a value, and y needs to start at 0!
269 if (lb(0) | 0) {
270 if (lb(1) | 0) y = 3;
271 } else {
272 y = 3;
273 }
274 if ((y | 0) == 3) {
275 lb(2) | 0;
276 }
277 }
278
279 function phi() {
280 var x = 0;
281 do {
282 if (lb(1) | 0) {
283 x = 0;
284 break;
285 }
286 x = 1;
287 } while (0);
288 return x | 0;
289 }
290
291 function smallIf() {
292 do {
293 if (return_int() | 0) {
294 lb(3) | 0;
295 } else {
296 break;
297 }
298 } while (0);
299 }
300
301 function dropCall() {
302 if (return_int() | 0) {
303 phi() | 0; // drop this
304 setTempRet0(10); // this too
305 zeroInit(setTempRet0(10) | 0);
306 }
307 return phi() | 0;
308 }
309
310 function useSetGlobal() {
311 var x = 0;
312 x = (Int = 10);
313 Int = 20;
314 return (Int = 30) | 0;
315 }
316
317 function usesSetGlobal2() {
318 return (Int = 40, 50) | 0;
319 }
320
321 function breakThroughMany($s) {
322 $s = $s|0;
323 L1: do {
324 if ($s) {
325 while(1) {
326 if (!($s)) {
327 break L1;
328 }
329 zeroInit(0);
330 }
331 } else {
332 1337;
333 }
334 } while(0);
335 }
336
337 function ifChainEmpty(label) {
338 label = label | 0;
339 if ((label|0) == 4) {
340 return 0;
341 }
342 else if ((label|0) == 7) {
343 // unreachable;
344 }
345 return 0;
346 }
347
348 function heap8NoShift(x) {
349 x = x | 0;
350 return HEAP8[x | 0] | 0;
351 }
352
353 function conditionalTypeFun() {
354 var x = 0, y = 0.0;
355 x = return_int() | 0 ? abort(5) | 0 : 2;
356 y = return_int() | 0 ? +abort(7) : 4.5;
357 }
358
359 function loadSigned(x) {
360 x = x | 0;
361 loadSigned(HEAP8[x >> 0] << 24 >> 24);
362 loadSigned(HEAPU8[x >> 0] << 24 >> 24);
363 loadSigned(HEAP16[x >> 1] << 16 >> 16);
364 loadSigned(HEAPU16[x >> 1] << 16 >> 16);
365 loadSigned(HEAP8[x >> 0] << 24 >> 16);
366 loadSigned(HEAPU8[x >> 0] << 16 >> 24);
367 loadSigned(HEAP16[x >> 1] << 16 >> 24);
368 loadSigned(HEAPU16[x >> 1] << 24 >> 16);
369 }
370
371 function z(x) {
372 x = Math_fround(x);
373 }
374 function w() {
375 return 0.0;
376 }
377
378 function globalOpts() {
379 var x = 0, y = 0.0;
380 x = Int;
381 y = Double;
382 HEAP8[13] = HEAP32[3]; // access memory, should not confuse the global writes
383 Double = y;
384 Int = x;
385 globalOpts();
386 x = Int;
387 if (return_int() | 0) Int = 20; // but this does interfere
388 Int = x;
389 globalOpts();
390 x = Int;
391 globalOpts(); // this too
392 Int = x;
393 }
394
395 function dropCallImport() {
396 if (return_int() | 0) return_int() | 0;
397 }
398
399 function loophi(x, y) {
400 x = x | 0;
401 y = y | 0;
402 var temp = 0, inc = 0, loopvar = 0; // this order matters
403 loopvar = x;
404 while(1) {
405 loophi(loopvar | 0, 0);
406 temp = loopvar;
407 if (temp) {
408 if (temp) {
409 break;
410 }
411 }
412 inc = loopvar + 1 | 0;
413 if ((inc|0) == (y|0)) {
414 loopvar = inc;
415 } else {
416 break;
417 }
418 }
419 }
420
421 function loophi2() {
422 var jnc = 0, i = 0, i$lcssa = 0, temp = 0, j = 0;
423 i = 0;
424 L7: while(1) {
425 j = 0;
426 while(1) {
427 temp = j;
428 if (return_int() | 0) {
429 if (temp) {
430 i$lcssa = i;
431 break L7;
432 }
433 }
434 jnc = j + 1 | 0;
435 if (jnc) {
436 j = jnc;
437 } else {
438 break;
439 }
440 }
441 }
442 return i$lcssa | 0
443 }
444
445 function loophi2b() {
446 var jnc = 0, i = 0, i$lcssa = 0, temp = 0, j = 0;
447 i = 0;
448 L7: while(1) {
449 j = 0;
450 while(1) {
451 temp = j;
452 if (return_int() | 0) {
453 if (temp) {
454 i$lcssa = j;
455 break L7;
456 }
457 }
458 jnc = j + 1 | 0;
459 if (jnc) {
460 j = jnc;
461 } else {
462 break;
463 }
464 }
465 }
466 return i$lcssa | 0
467 }
468
469 function relooperJumpThreading(x) {
470 x = x | 0;
471 var label = 0;
472 // from if
473 if (x) {
474 h(0);
475 label = 1;
476 }
477 if ((label|0) == 1) {
478 h(1);
479 }
480 h(-1);
481 // from loop
482 while (1) {
483 x = x + 1 | 0;
484 if (x) {
485 h(2);
486 label = 2;
487 break;
488 }
489 }
490 if ((label|0) == 2) {
491 h(3);
492 }
493 h(-2);
494 // if-else afterward
495 if (x) {
496 h(4);
497 if ((x|0) == 3) {
498 label = 3;
499 } else {
500 label = 4;
501 }
502 }
503 if ((label|0) == 3) {
504 h(5);
505 } else if ((label|0) == 4) {
506 h(6);
507 }
508 h(-3);
509 // two ifs afterward
510 if (x) {
511 h(7);
512 if ((x|0) == 5) {
513 label = 5;
514 } else {
515 label = 6;
516 }
517 }
518 if ((label|0) == 5) {
519 h(8);
520 if ((x|0) == 6) {
521 label = 6;
522 }
523 }
524 if ((label|0) == 6) {
525 h(9);
526 }
527 h(-4);
528 // labeled if after
529 if (x) {
530 h(10);
531 label = 7;
532 }
533 L1: do {
534 if ((label|0) == 7) {
535 h(11);
536 break L1;
537 }
538 } while (0);
539 h(-5);
540 // labeled if after normal if
541 if (x) {
542 h(12);
543 if ((x|0) == 8) {
544 label = 8;
545 } else {
546 label = 9;
547 }
548 }
549 if ((label|0) == 8) {
550 h(13);
551 if (x) label = 9;
552 }
553 L1: do {
554 if ((label|0) == 9) {
555 h(14);
556 break L1;
557 }
558 } while (0);
559 h(-6);
560 // TODO
561 // labeled if after a first if
562 // do-enclosed if after (?)
563 // test multiple labels, some should be ignored initially by JumpUpdater
564 return x | 0;
565 }
566
567 function relooperJumpThreading__ZN4game14preloadweaponsEv($12, $14, $or$cond8, $or$cond6, $vararg_ptr5, $11, $exitcond) {
568 $12 = $12 | 0;
569 $14 = $14 | 0;
570 $or$cond8 = $or$cond8 | 0;
571 $or$cond6 = $or$cond6 | 0;
572 $vararg_ptr5 = $vararg_ptr5 | 0;
573 $11 = $11 | 0;
574 $exitcond = $exitcond | 0;
575 var label = 0;
576 while(1) {
577 if ($14) {
578 if ($or$cond8) {
579 label = 7;
580 } else {
581 label = 8;
582 }
583 } else {
584 if ($or$cond6) {
585 label = 7;
586 } else {
587 label = 8;
588 }
589 }
590 if ((label|0) == 7) {
591 label = 0;
592 }
593 else if ((label|0) == 8) {
594 label = 0;
595 HEAP32[$vararg_ptr5>>2] = $11;
596 }
597 }
598 }
599
600 function relooperJumpThreading_irreducible(x) {
601 x = x | 0;
602 var label = 0;
603 if ((x|0) == 100) {
604 label = 1;
605 } else {
606 label = 10;
607 }
608 if ((label|0) == 1) {
609 while (1) {
610 relooperJumpThreading_irreducible(1337);
611 label = 1; // this is ok - the if means the body of the if begins with the block for 1. so a setting inside the body of the if must return to the top of the if
612 }
613 }
614 // too many settings, we just look one back, so this one will not be optimized
615 if ((x|0) == 200) {
616 label = 2;
617 } else {
618 label = 10;
619 }
620 if ((x|0) == 300) {
621 label = 2;
622 }
623 if ((label|0) == 2) {
624 relooperJumpThreading_irreducible(1448);
625 }
626 if ((label|0) == 10) {
627 relooperJumpThreading_irreducible(2000);
628 }
629 }
630
631 function __Z12multi_varargiz($0, $$06$i4, $exitcond$i6, $2) {
632 $0 = $0|0;
633 $$06$i4 = $$06$i4 | 0;
634 $exitcond$i6 = $exitcond$i6 | 0;
635 $2 = $2 | 0;
636 var $12 = 0, $20 = 0;
637 if ($2) {
638 while(1) {
639 $12 = $$06$i4;
640 if ($exitcond$i6) {
641 break;
642 } else {
643 $$06$i4 = $20;
644 }
645 }
646 } else {
647 lb(1) | 0; // returns a value, and the while is unreachable
648 }
649 }
650
651 function jumpThreadDrop() {
652 var label = 0, temp = 0;
653 temp = return_int() | 0;
654 while (1) {
655 label = 14;
656 break;
657 }
658 if ((label | 0) == 10) {
659 } else if ((label | 0) == 12) {
660 return_int() | 0; // drop in the middle of an if-else chain for threading
661 } else if ((label | 0) == 14) {
662 }
663 return temp | 0;
664 }
665
666 function dropIgnoredImportInIf($0,$1,$2) {
667 $0 = $0|0;
668 $1 = $1|0;
669 $2 = $2|0;
670 do {
671 if ($0) {
672 $0 = 1;
673 lb($2 | 0) | 0;
674 } else {
675 break;
676 }
677 } while(0);
678 return;
679 }
680
681 function big_fround() {
682 return Math_fround(4294967295);
683 }
684
685 function dropIgnoredImportsInIf($0,$1,$2) {
686 $0 = $0|0;
687 $1 = $1|0;
688 $2 = $2|0;
689 do {
690 if ($0) {
691 lb($1 | 0) | 0;
692 } else {
693 lb($2 | 0) | 0;
694 }
695 } while(0);
696 return;
697 }
698
699 function f32_ucast(x) {
700 x = x | 0;
701 return Math_fround(x>>>0);
702 }
703 function f32_scast(x) {
704 x = x | 0;
705 return Math_fround(x|0);
706 }
707
708 function store_fround(x) {
709 x = x | 0;
710 HEAPF64[10] = Math_fround(x|0);
711 }
712
713 function relocatableAndModules() {
714 ftCall_v(10); // function table call
715 mftCall_v(20); // possible inter-module function table call
716 return ftCall_idi(30, 1.5, 200) | 0; // with args
717 }
718
719 function exported_f32_user(x, y, z) {
720 x = x | 0;
721 y = Math_fround(y);
722 z = +z;
723 return Math_fround(y);
724 }
725
726 function sqrts(x) {
727 x = +x;
728 return +(+Math_sqrt(x) + +Math_fround(Math_sqrt(Math_fround(x))));
729 }
730
731 function f2u(x) {
732 x = +x;
733 return (~~x>>>0) | 0;
734 }
735 function f2s(x) {
736 x = +x;
737 return (~~x) | 0;
738 }
739
740 function autoDrop(x) {
741 x = x | 0;
742 while (1) {
743 if ((x | 0) == 17) {
744 return 5;
745 autoDrop(1) | 0;
746 } else {
747 break;
748 x = autoDrop(2) | 0;
749 }
750 }
751 return x | 0;
752 }
753
754 function indirectInSequence() {
755 var i1 = 0;
756 // this indirect call should have the right type, vi
757 i1 = (FUNCTION_TABLE_vi[1 & 7](0), 1);
758 }
759
760 function emterpretify_assertions_safeHeap() {
761 var i1 = 0;
762 // assignment into the function table param, optimizer can do things there
763 FUNCTION_TABLE_vi[(Int = 1) & 7](i1 | 0);
764 }
765
766 function call_emscripten_log() {
767 // emscripten_log has no return value, don't let the conditional after the comma confuse you
768 emscripten_log(), 2 ? abort() | 0 : 3;
769 }
770
771 function keepAlive() {
772 sqrts(3.14159);
773 sqrts(2.18281); // don't inline it either
774 f2u(100.0);
775 f2s(100.0);
776 autoDrop(52) | 0;
777 indirectInSequence();
778 emterpretify_assertions_safeHeap();
779 call_emscripten_log();
780 }
781
782 function v() {
783 }
784 function vi(x) {
785 x = x | 0;
786 }
787 function ii(x) {
788 x = x | 0;
789 return x | 0;
790 }
791
792 var FUNCTION_TABLE_a = [ v, big_negative, v, v ];
793 var FUNCTION_TABLE_b = [ w, w, importedDoubles, w ];
794 var FUNCTION_TABLE_c = [ z, cneg, z, z, z, z, z, z ];
795 var FUNCTION_TABLE_vi = [ vi, vi, vi, vi, vi, vi, vi, vi ];
796 var FUNCTION_TABLE_ii = [ ii ];
797
798 return { big_negative: big_negative, pick: forgetMe, pick: exportMe, doubleCompares: doubleCompares, intOps: intOps, conversions: conversions, switcher: switcher, frem: frem, frem_float: frem_float, big_uint_div_u: big_uint_div_u, trapping_sint_div_s: trapping_sint_div_s, fr: fr, negZero: negZero, neg: neg, smallCompare: smallCompare, cneg_nosemicolon: cneg_nosemicolon, forLoop: forLoop, ceiling_32_64: ceiling_32_64, aborts: aborts, continues: continues, bitcasts: bitcasts, recursiveBlockMerging: recursiveBlockMerging, lb: lb, zeroInit: zeroInit, phi: phi, smallIf: smallIf, dropCall: dropCall, useSetGlobal: useSetGlobal, usesSetGlobal2: usesSetGlobal2, breakThroughMany: breakThroughMany, ifChainEmpty: ifChainEmpty, heap8NoShift: heap8NoShift, conditionalTypeFun: conditionalTypeFun, loadSigned: loadSigned, globalOpts: globalOpts, dropCallImport: dropCallImport, loophi: loophi, loophi2: loophi2, loophi2b: loophi2b, relooperJumpThreading: relooperJumpThreading, relooperJumpThreading__ZN4game14preloadweaponsEv: relooperJumpThreading__ZN4game14preloadweaponsEv, __Z12multi_varargiz: __Z12multi_varargiz, jumpThreadDrop: jumpThreadDrop, dropIgnoredImportInIf: dropIgnoredImportInIf, dropIgnoredImportsInIf: dropIgnoredImportsInIf, relooperJumpThreading_irreducible: relooperJumpThreading_irreducible, store_fround: store_fround, exportedNumber: 42, relocatableAndModules: relocatableAndModules, exported_f32_user: exported_f32_user, keepAlive: keepAlive };
799}
800