aboutsummaryrefslogtreecommitdiff
path: root/tools/test-js-optimizer-asm-regs-harder.js
blob: 0231a2151768c99d6a254f2b2e8edafc06f4f889 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
function asm(x, y) {
 x = +x;
 y = y | 0;
 var int1 = 0, int2 = 0; // do not mix the types!
 var double1 = +0, double2 = +0;
 int1 = (x+x)|0;
 double1 = d(Math_max(10, Math_min(5, f())));
 int2 = (int1+2)|0;
 print(int2);
 double2 = double1*5;
 return double2;
}
function _doit($x, $y$0, $y$1) {
 $x = $x | 0;
 $y$0 = $y$0 | 0;
 $y$1 = $y$1 | 0;
 var __stackBase__ = 0;
 __stackBase__ = STACKTOP;
 _printf(__str | 0, (tempInt = STACKTOP, STACKTOP = STACKTOP + 8 | 0, HEAP32[(tempInt & 16777215) >> 2] = $y$0, HEAP32[(tempInt + 4 & 16777215) >> 2] = $y$1, tempInt));
 STACKTOP = __stackBase__;
 return 0 | 0;
}
function stackRestore(top) {
 top = top|0;
 STACKTOP = top;
}
function switchey(x, y) {
 x = +x;
 y = y | 0;
 var int1 = 0, int2 = 0; // do not mix the types!
 var double1 = +0, double2 = +0;
 switch(x|0) {
  case 0:
   int1 = (x+x)|0;
   double1 = d(Math_max(10, Math_min(5, f())));
   int2 = (int1+2)|0;
   print(int2);
   double2 = double1*5;
   return double2;
  case 1:
   return 20;
 }
}
function switchey2() {
 var $rng2 = 0, $count_06 = 0, $i_05 = 0, $2 = +0, $3 = +0, $count_1 = 0, $9 = 0, label = 0, __stackBase__ = 0;
 __stackBase__ = STACKTOP;
 STACKTOP = STACKTOP + 8 | 0;
 label = 1;
 while (1) switch (label | 0) {
  case 1:
  $rng2 = __stackBase__ | 0;
  __ZN6RandomC1Ev($rng2);
  $i_05 = 0;
  $count_06 = 0;
  label = 2;
  break;
  case 2:
  $2 = +__ZN6Random3getEf(8, +1);
  $3 = +__ZN6Random3getEf($rng2, +1);
  _printf(24, (tempInt = STACKTOP, STACKTOP = STACKTOP + 16 | 0, HEAPF64[CHECK_ALIGN_8(tempInt | 0) >> 3] = $2, HEAPF64[CHECK_ALIGN_8(tempInt + 8 | 0) >> 3] = $3, tempInt) | 0);
  $count_1 = ($2 != $3 & 1) + $count_06 | 0;
  $9 = $i_05 + 1 | 0;
  if (($9 | 0) < 100) {
   $i_05 = $9;
   $count_06 = $count_1;
   label = 2;
   break;
  } else {
   label = 3;
   break;
  }
  case 3:
  _printf(16, (tempInt = STACKTOP, STACKTOP = STACKTOP + 8 | 0, HEAP32[CHECK_ALIGN_4(tempInt | 0) >> 2] = $count_1, tempInt) | 0);
  STACKTOP = __stackBase__;
  return 0;
 }
 return 0;
}
function iffey() {
 var $rng2 = 0, $count_06 = 0, $i_05 = 0, $2 = +0, $3 = +0, $count_1 = 0, $9 = 0, label = 0, __stackBase__ = 0;
 __stackBase__ = STACKTOP;
 STACKTOP = STACKTOP + 8 | 0;
 label = 1;
 while (1) {
  if (label | 0) {
   $rng2 = __stackBase__ | 0;
   __ZN6RandomC1Ev($rng2);
   $i_05 = 0;
   $count_06 = 0;
   label = 2;
  } else {
   $2 = +__ZN6Random3getEf(8, +1);
   $3 = +__ZN6Random3getEf($rng2, +1);
   _printf(24, (tempInt = STACKTOP, STACKTOP = STACKTOP + 16 | 0, HEAPF64[CHECK_ALIGN_8(tempInt | 0) >> 3] = $2, HEAPF64[CHECK_ALIGN_8(tempInt + 8 | 0) >> 3] = $3, tempInt) | 0);
   $count_1 = ($2 != $3 & 1) + $count_06 | 0;
   $9 = $i_05 + 1 | 0;
   if (($9 | 0) < 100) {
    $i_05 = $9;
    $count_06 = $count_1;
    label = 2;
   } else {
    label = 3;
    return 10;
   }
  }
 }
 return 0;
}
function labelledJump(x) {
 x = x | 0;
 var label = 0
 // y and z don't conflict, but only if you know about labelled jumps.
 var y = 0, z = 0;
 y = 2;
 if (x) {
   z = 17;
   label = 1;
 }
 if (label == 1) {
  x = z + 1;
 } else {
  x = y + 1;
 }
 return x;
}
function linkedVars() {
 var outer1 = 0, outer2 = 0;
 var inner1_0 = 0, inner1_1 = 0, inner2_0 = 0, inner2_1 = 0;
 while (1) {
  outer1 = 9;
  outer2 = 5;
  while (outer1 > 0 || outer2 > 0) {
   // All these copy assignment should be eliminated by var sharing.
   inner1_0 = outer1;
   inner2_0 = outer2;
   if (inner1_0 < inner2_0) {
    inner1_1 = inner1_0 - 1;
    inner2_1 = inner2_0;
   } else {
    inner1_1 = inner1_0;
    inner2_1 = inner2_0 - 1;
   }
   outer1 = inner1_1;
   outer2 = inner2_1;
  }
  if (outer1 < outer2) {
    break;
  }
 }
 return outer1 + outer2;
}
// EMSCRIPTEN_GENERATED_FUNCTIONS: ["asm", "_doit", "stackRestore", "switchey", "switchey2", "iffey", "labelledJump", "linkedVars']