summaryrefslogtreecommitdiff
path: root/test/wasm-only.asm.js
blob: eab63ba2b7aba45b015651a11217ab3595ad8a80 (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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
//
// Test wasm-only builds. In this case, fastcomp emits code that is
// not asm.js, it will only ever run as wasm, and contains special intrinsics for
// asm2wasm that map LLVM IR into i64s.
//

function asm(global, env, buffer) {
  "use asm";

  var HEAP8 = new global.Int8Array(buffer);
  var HEAP16 = new global.Int16Array(buffer);
  var HEAP32 = new global.Int32Array(buffer);
  var HEAPU8 = new global.Uint8Array(buffer);
  var HEAPU16 = new global.Uint16Array(buffer);
  var HEAPU32 = new global.Uint32Array(buffer);
  var HEAPF32 = new global.Float32Array(buffer);
  var HEAPF64 = new global.Float64Array(buffer);

  var fround = global.Math.fround;

  var illegalImport = env.illegalImport;
  var illegalImportResult = env.illegalImportResult;

  function loads() {
    var i = 0, f = fround(0), d = +0;
    i = load1(100);
    i = load1(101, 0);
    i = load2(102);
    i = load2(103, 0);
    i = load2(104, 1);
    i = load2(105, 2);
    i = load4(106);
    i = load4(107, 0);
    i = load4(108, 1);
    i = load4(109, 2);
    i = load4(110, 4);
    f = loadf(111);
    f = loadf(112, 0);
    f = loadf(113, 1);
    f = loadf(114, 2);
    f = loadf(115, 4);
    d = loadd(116);
    d = loadd(117, 0);
    d = loadd(118, 1);
    d = loadd(119, 2);
    d = loadd(120, 4);
    d = loadd(121, 8);
  }

  function stores() {
    var i = 0, f = fround(0), d = +0;
    store1(100, i);
    store1(101, i, 0);
    store2(102, i);
    store2(103, i, 0);
    store2(104, i, 1);
    store2(105, i, 2);
    store4(106, i);
    store4(107, i, 0);
    store4(108, i, 1);
    store4(109, i, 2);
    store4(110, i, 4);
    storef(111, f);
    storef(112, f, 0);
    storef(113, f, 1);
    storef(114, f, 2);
    storef(115, f, 4);
    stored(116, d);
    stored(117, d, 0);
    stored(118, d, 1);
    stored(119, d, 2);
    stored(120, d, 4);
    stored(121, d, 8);
  }

  function test() {
    var i = 0, j = i64(), f = fround(0), f1 = fround(0), f2 = fround(0), d1 = +0, d2 = +0;
    // bitcasts
    i = i32_bc2i(f);
    f = i32_bc2f(i);
    i = i32_cttz(i);
    i = i32_ctpop(i);
    j = i64_ctpop(j);
    f1 = f32_copysign(f1, f2);
    d1 = f64_copysign(d1, d2);
  }

  function test64() {
    var x = i64(), y = i64(), z = 0; // define i64 variables using special intrinsic
    var int32 = 0, float32 = fround(0), float64 = +0;
    x = i64_const(100, 0); // i64 constant
    y = i64_const(17, 30);
    x = i64_add(x, y); // binaries
    x = i64_sub(x, y);
    x = i64_mul(x, y);
    x = i64_udiv(x, y);
    x = i64_sdiv(x, y);
    x = i64_urem(x, y);
    x = i64_srem(x, y);
    x = i64_and(x, y);
    x = i64_or(x, y);
    x = i64_xor(x, y);
    x = i64_shl(x, y);
    x = i64_ashr(x, y);
    x = i64_lshr(x, y);
    x = load8(120, 0); // load and store
    x = load8(120);
    x = load8(120, 2);
    x = load8(120, 4);
    x = load8(120, 8);
    store8(120, x, 0);
    store8(120, x);
    store8(120, x, 2);
    store8(120, x, 4);
    store8(120, x, 8);
    // comps
    z = i64_eq(x, y);
    z = i64_ne(x, y);
    z = i64_ule(x, y);
    z = i64_sle(x, y);
    z = i64_uge(x, y);
    z = i64_sge(x, y);
    z = i64_ult(x, y);
    z = i64_slt(x, y);
    z = i64_ugt(x, y);
    z = i64_sgt(x, y);
    // convs
    int32 = i64_trunc(x);
    x = i64_sext(int32);
    x = i64_zext(int32);
    float32 = i64_s2f(x);
    float64 = i64_s2d(x);
    float32 = i64_u2f(x);
    float64 = i64_u2d(x);
    x = i64_f2s(float32);
    x = i64_d2s(float64);
    x = i64_f2u(float32);
    x = i64_d2u(float64);
    // bitcasts
    x = i64_bc2i(float64);
    float64 = i64_bc2d(x);
    // intrinsics
    x = i64_ctlz(y);
    y = i64_cttz(x);
  }
  function imports() {
    illegalImport(-3.13159, i64_const(11, 22), -33); // this call must be legalized
    return i64(illegalImportResult());
  }
  function arg(x) { // illegal param, but not exported
    x = i64(x);
    store8(100, x, 0);
    arg(i64(x)); // "coercion"/"cast"
  }
  function illegalParam(a, x, c) {
    a = 0;
    x = i64(x);
    b = +0;
    store8(100, x, 0);
    illegalParam(0, i64(x), 12.34); // "coercion"/"cast"
  }
  function result() { // illegal result, but not exported
    return i64_const(1, 2);
  }
  function illegalResult() { // illegal result, exported
    return i64_const(1, 2);
  }
  function call1(x) {
    x = i64(x);
    var y = i64();
    y = i64(call1(x));
    return i64(y); // return i64 with a "cast"
  }
  function call2(x) {
    x = i64(x);
    i64(call2(i64(call2(x))));
    return i64_const(591726473, 57073); // return an i64 const
  }
  function returnCastConst() {
     return i64(0);
  }
  function ifValue64($4, $6) {
   $4 = i64($4);
   $6 = i64($6);
   var $$0 = i64(), $9 = i64(), $10 = i64();
   if ($6) {
     $9 = i64(call2($4));
     $$0 = $9;
   } else {
     $10 = i64(call2($4));
     $$0 = $10;
   }
   return i64($$0);
  }
  function ifValue32($4, $6) {
   $4 = $4 | 0;
   $6 = $6 | 0;
   var $$0 = 0, $9 = 0, $10 = 0;
   if ($6) {
     $9 = ifValue32($4 | 0, $6 | 0) | 0;
     $$0 = $9;
   } else {
     $10 = ifValue32($4 | 0, $6 | 0) | 0;
     $$0 = $10;
   }
   return $$0 | 0;
  }
  function switch64($a444) {
    $a444 = i64($a444);
    var $waka = 0;
    switch (i64($a444)) {
     case i64_const(7,10):  {
      $waka = 11000;
      break;
     }
     case i64_const(5,10):  {
      $waka = 10;
      break;
     }
     default: {
      $waka = 1;
     }
    }
    return $waka | 0;
  }
  function keepAlive() {
    loads();
    stores();
    test();
    i64(imports());
    arg(i64(0));
    i64(call1(i64(0)));
    i64(call2(i64(0)));
    i64(returnCastConst());
    i64(ifValue64(i64(0), i64(0)));
    ifValue32(0, 0) | 0;
    switch64(i64(0)) | 0;
  }

  return { test64: test64, illegalParam : illegalParam, illegalResult: illegalResult, keepAlive: keepAlive };
}