summaryrefslogtreecommitdiff
path: root/test/i64.asm.js
blob: 8f9bd862693e14aaa41bf1fb6ae19f5a48f10387 (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
//
// Test i64 support in 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 test() {
    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 = i64_load(120, 0); // load and store
    x = i64_load(120, 2);
    x = i64_load(120, 4);
    x = i64_load(120, 8);
    i64_store(120, x, 0);
    i64_store(120, x, 2);
    i64_store(120, x, 4);
    i64_store(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);
    i64_store(100, x, 0);
    arg(i64(x)); // "coercion"/"cast"
  }
  function illegalParam(a, x, c) {
    a = 0;
    x = i64(x);
    b = +0;
    i64_store(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;
  }

  return { test: test, illegalParam : illegalParam, illegalResult: illegalResult };
}