Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1167)

Side by Side Diff: test/mjsunit/wasm/asm-wasm.js

Issue 1587213003: Reformat asm-wasm.js for increased readability. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Flags: --expose-wasm 5 // Flags: --expose-wasm
6 6
7 function EmptyTest() { 7 function EmptyTest() {
8 "use asm"; 8 "use asm";
9 function caller() { 9 function caller() {
10 empty(); 10 empty();
11 return 11; 11 return 11;
12 } 12 }
13 function empty() { 13 function empty() {
14 } 14 }
15 return {caller: caller}; 15 return {caller: caller};
16 } 16 }
17 17
18 assertEquals(11, _WASMEXP_.asmCompileRun(EmptyTest.toString())); 18 assertEquals(11, _WASMEXP_.asmCompileRun(EmptyTest.toString()));
19 19
20
20 function IntTest() { 21 function IntTest() {
21 "use asm"; 22 "use asm";
22 function sum(a, b) { 23 function sum(a, b) {
23 a = a|0; 24 a = a|0;
24 b = b|0; 25 b = b|0;
25 var c = (b + 1)|0 26 var c = (b + 1)|0
26 var d = 3.0; 27 var d = 3.0;
27 var e = d | 0; // double conversion 28 var e = d | 0; // double conversion
28 return (a + c + 1)|0; 29 return (a + c + 1)|0;
29 } 30 }
30 31
31 function caller() { 32 function caller() {
32 return sum(77,22) | 0; 33 return sum(77,22) | 0;
33 } 34 }
34 35
35 return {caller: caller}; 36 return {caller: caller};
36 } 37 }
37 38
38 assertEquals(101, _WASMEXP_.asmCompileRun(IntTest.toString())); 39 assertEquals(101, _WASMEXP_.asmCompileRun(IntTest.toString()));
39 40
41
40 function Float64Test() { 42 function Float64Test() {
41 "use asm"; 43 "use asm";
42 function sum(a, b) { 44 function sum(a, b) {
43 a = +a; 45 a = +a;
44 b = +b; 46 b = +b;
45 return +(a + b); 47 return +(a + b);
46 } 48 }
47 49
48 function caller() { 50 function caller() {
49 var a = +sum(70.1,10.2); 51 var a = +sum(70.1,10.2);
50 var ret = 0|0; 52 var ret = 0|0;
51 if (a == 80.3) { 53 if (a == 80.3) {
52 ret = 1|0; 54 ret = 1|0;
53 } else { 55 } else {
54 ret = 0|0; 56 ret = 0|0;
55 } 57 }
56 return ret|0; 58 return ret|0;
57 } 59 }
58 60
59 return {caller: caller}; 61 return {caller: caller};
60 } 62 }
61 63
62 assertEquals(1, _WASMEXP_.asmCompileRun(Float64Test.toString())); 64 assertEquals(1, _WASMEXP_.asmCompileRun(Float64Test.toString()));
63 65
66
64 function BadModule() { 67 function BadModule() {
65 "use asm"; 68 "use asm";
66 function caller(a, b) { 69 function caller(a, b) {
67 a = a|0; 70 a = a|0;
68 b = b+0; 71 b = b+0;
69 var c = (b + 1)|0 72 var c = (b + 1)|0
70 return (a + c + 1)|0; 73 return (a + c + 1)|0;
71 } 74 }
72 75
73 function caller() { 76 function caller() {
74 return call(1, 2)|0; 77 return call(1, 2)|0;
75 } 78 }
76 79
77 return {caller: caller}; 80 return {caller: caller};
78 } 81 }
79 82
80 assertThrows(function() { 83 assertThrows(function() {
81 _WASMEXP_.asmCompileRun(BadModule.toString()) 84 _WASMEXP_.asmCompileRun(BadModule.toString())
82 }); 85 });
83 86
87
84 function TestReturnInBlock() { 88 function TestReturnInBlock() {
85 "use asm"; 89 "use asm";
86 90
87 function caller() { 91 function caller() {
88 if(1) { 92 if(1) {
89 { 93 {
90 { 94 {
91 return 1; 95 return 1;
92 } 96 }
93 } 97 }
94 } 98 }
95 return 0; 99 return 0;
96 } 100 }
97 101
98 return {caller: caller}; 102 return {caller: caller};
99 } 103 }
100 104
101 assertEquals(1, _WASMEXP_.asmCompileRun(TestReturnInBlock.toString())); 105 assertEquals(1, _WASMEXP_.asmCompileRun(TestReturnInBlock.toString()));
102 106
107
103 function TestWhileSimple() { 108 function TestWhileSimple() {
104 "use asm"; 109 "use asm";
105 110
106 function caller() { 111 function caller() {
107 var x = 0; 112 var x = 0;
108 while(x < 5) { 113 while(x < 5) {
109 x = (x + 1)|0; 114 x = (x + 1)|0;
110 } 115 }
111 return x|0; 116 return x|0;
112 } 117 }
113 118
114 return {caller: caller}; 119 return {caller: caller};
115 } 120 }
116 121
117 assertEquals(5, _WASMEXP_.asmCompileRun(TestWhileSimple.toString())); 122 assertEquals(5, _WASMEXP_.asmCompileRun(TestWhileSimple.toString()));
118 123
124
119 function TestWhileWithoutBraces() { 125 function TestWhileWithoutBraces() {
120 "use asm"; 126 "use asm";
121 127
122 function caller() { 128 function caller() {
123 var x = 0; 129 var x = 0;
124 while(x <= 3) 130 while(x <= 3)
125 x = (x + 1)|0; 131 x = (x + 1)|0;
126 return x|0; 132 return x|0;
127 } 133 }
128 134
129 return {caller: caller}; 135 return {caller: caller};
130 } 136 }
131 137
132 assertEquals(4, _WASMEXP_.asmCompileRun(TestWhileWithoutBraces.toString())); 138 assertEquals(4, _WASMEXP_.asmCompileRun(TestWhileWithoutBraces.toString()));
133 139
140
134 function TestReturnInWhile() { 141 function TestReturnInWhile() {
135 "use asm"; 142 "use asm";
136 143
137 function caller() { 144 function caller() {
138 var x = 0; 145 var x = 0;
139 while(x < 10) { 146 while(x < 10) {
140 x = (x + 6)|0; 147 x = (x + 6)|0;
141 return x|0; 148 return x|0;
142 } 149 }
143 return x|0; 150 return x|0;
144 } 151 }
145 152
146 return {caller: caller}; 153 return {caller: caller};
147 } 154 }
148 155
149 assertEquals(6, _WASMEXP_.asmCompileRun(TestReturnInWhile.toString())); 156 assertEquals(6, _WASMEXP_.asmCompileRun(TestReturnInWhile.toString()));
150 157
158
151 function TestReturnInWhileWithoutBraces() { 159 function TestReturnInWhileWithoutBraces() {
152 "use asm"; 160 "use asm";
153 161
154 function caller() { 162 function caller() {
155 var x = 0; 163 var x = 0;
156 while(x < 5) 164 while(x < 5)
157 return 7; 165 return 7;
158 return x|0; 166 return x|0;
159 } 167 }
160 168
161 return {caller: caller}; 169 return {caller: caller};
162 } 170 }
163 171
164 assertEquals(7, _WASMEXP_.asmCompileRun(TestReturnInWhileWithoutBraces.toString( ))); 172 assertEquals(
173 7, _WASMEXP_.asmCompileRun(TestReturnInWhileWithoutBraces.toString()));
174
165 175
166 function TestBreakInWhile() { 176 function TestBreakInWhile() {
167 "use asm"; 177 "use asm";
168 178
169 function caller() { 179 function caller() {
170 while(1) { 180 while(1) {
171 break; 181 break;
172 } 182 }
173 return 8; 183 return 8;
174 } 184 }
175 185
176 return {caller: caller}; 186 return {caller: caller};
177 } 187 }
178 188
179 assertEquals(8, _WASMEXP_.asmCompileRun(TestBreakInWhile.toString())); 189 assertEquals(8, _WASMEXP_.asmCompileRun(TestBreakInWhile.toString()));
180 190
191
181 function TestBreakInNestedWhile() { 192 function TestBreakInNestedWhile() {
182 "use asm"; 193 "use asm";
183 194
184 function caller() { 195 function caller() {
185 var x = 1.0; 196 var x = 1.0;
186 while(x < 1.5) { 197 while(x < 1.5) {
187 while(1) 198 while(1)
188 break; 199 break;
189 x = +(x + 0.25); 200 x = +(x + 0.25);
190 } 201 }
191 var ret = 0; 202 var ret = 0;
192 if (x == 1.5) { 203 if (x == 1.5) {
193 ret = 9; 204 ret = 9;
194 } 205 }
195 return ret|0; 206 return ret|0;
196 } 207 }
197 208
198 return {caller: caller}; 209 return {caller: caller};
199 } 210 }
200 211
201 assertEquals(9, _WASMEXP_.asmCompileRun(TestBreakInNestedWhile.toString())); 212 assertEquals(9, _WASMEXP_.asmCompileRun(TestBreakInNestedWhile.toString()));
202 213
214
203 function TestBreakInBlock() { 215 function TestBreakInBlock() {
204 "use asm"; 216 "use asm";
205 217
206 function caller() { 218 function caller() {
207 var x = 0; 219 var x = 0;
208 abc: { 220 abc: {
209 x = 10; 221 x = 10;
210 if (x == 10) { 222 if (x == 10) {
211 break abc; 223 break abc;
212 } 224 }
213 x = 20; 225 x = 20;
214 } 226 }
215 return x|0; 227 return x|0;
216 } 228 }
217 229
218 return {caller: caller}; 230 return {caller: caller};
219 } 231 }
220 232
221 assertEquals(10, _WASMEXP_.asmCompileRun(TestBreakInBlock.toString())); 233 assertEquals(10, _WASMEXP_.asmCompileRun(TestBreakInBlock.toString()));
222 234
235
223 function TestBreakInNamedWhile() { 236 function TestBreakInNamedWhile() {
224 "use asm"; 237 "use asm";
225 238
226 function caller() { 239 function caller() {
227 var x = 0; 240 var x = 0;
228 outer: while (1) { 241 outer: while (1) {
229 x = (x + 1)|0; 242 x = (x + 1)|0;
230 while (x == 11) { 243 while (x == 11) {
231 break outer; 244 break outer;
232 } 245 }
233 } 246 }
234 return x|0; 247 return x|0;
235 } 248 }
236 249
237 return {caller: caller}; 250 return {caller: caller};
238 } 251 }
239 252
240 assertEquals(11, _WASMEXP_.asmCompileRun(TestBreakInNamedWhile.toString())); 253 assertEquals(11, _WASMEXP_.asmCompileRun(TestBreakInNamedWhile.toString()));
241 254
255
242 function TestContinue() { 256 function TestContinue() {
243 "use asm"; 257 "use asm";
244 258
245 function caller() { 259 function caller() {
246 var x = 5; 260 var x = 5;
247 var ret = 0; 261 var ret = 0;
248 while (x >= 0) { 262 while (x >= 0) {
249 x = (x - 1)|0; 263 x = (x - 1)|0;
250 if (x == 2) { 264 if (x == 2) {
251 continue; 265 continue;
252 } 266 }
253 ret = (ret - 1)|0; 267 ret = (ret - 1)|0;
254 } 268 }
255 return ret|0; 269 return ret|0;
256 } 270 }
257 271
258 return {caller: caller}; 272 return {caller: caller};
259 } 273 }
260 274
261 assertEquals(-5, _WASMEXP_.asmCompileRun(TestContinue.toString())); 275 assertEquals(-5, _WASMEXP_.asmCompileRun(TestContinue.toString()));
262 276
277
263 function TestContinueInNamedWhile() { 278 function TestContinueInNamedWhile() {
264 "use asm"; 279 "use asm";
265 280
266 function caller() { 281 function caller() {
267 var x = 5; 282 var x = 5;
268 var y = 0; 283 var y = 0;
269 var ret = 0; 284 var ret = 0;
270 outer: while (x > 0) { 285 outer: while (x > 0) {
271 x = (x - 1)|0; 286 x = (x - 1)|0;
272 y = 0; 287 y = 0;
273 while (y < 5) { 288 while (y < 5) {
274 if (x == 3) { 289 if (x == 3) {
275 continue outer; 290 continue outer;
276 } 291 }
277 ret = (ret + 1)|0; 292 ret = (ret + 1)|0;
278 y = (y + 1)|0; 293 y = (y + 1)|0;
279 } 294 }
280 } 295 }
281 return ret|0; 296 return ret|0;
282 } 297 }
283 298
284 return {caller: caller}; 299 return {caller: caller};
285 } 300 }
286 301
287 assertEquals(20, _WASMEXP_.asmCompileRun(TestContinueInNamedWhile.toString())); 302 assertEquals(20, _WASMEXP_.asmCompileRun(TestContinueInNamedWhile.toString()));
288 303
304
289 function TestNot() { 305 function TestNot() {
290 "use asm"; 306 "use asm";
291 307
292 function caller() { 308 function caller() {
293 var a = !(2 > 3); 309 var a = !(2 > 3);
294 return a | 0; 310 return a | 0;
295 } 311 }
296 312
297 return {caller:caller}; 313 return {caller:caller};
298 } 314 }
299 315
300 assertEquals(1, _WASMEXP_.asmCompileRun(TestNot.toString())); 316 assertEquals(1, _WASMEXP_.asmCompileRun(TestNot.toString()));
301 317
318
302 function TestNotEquals() { 319 function TestNotEquals() {
303 "use asm"; 320 "use asm";
304 321
305 function caller() { 322 function caller() {
306 var a = 3; 323 var a = 3;
307 if (a != 2) { 324 if (a != 2) {
308 return 21; 325 return 21;
309 } 326 }
310 return 0; 327 return 0;
311 } 328 }
312 329
313 return {caller:caller}; 330 return {caller:caller};
314 } 331 }
315 332
316 assertEquals(21, _WASMEXP_.asmCompileRun(TestNotEquals.toString())); 333 assertEquals(21, _WASMEXP_.asmCompileRun(TestNotEquals.toString()));
317 334
335
318 function TestUnsignedComparison() { 336 function TestUnsignedComparison() {
319 "use asm"; 337 "use asm";
320 338
321 function caller() { 339 function caller() {
322 var a = 0xffffffff; 340 var a = 0xffffffff;
323 if ((a>>>0) > (0>>>0)) { 341 if ((a>>>0) > (0>>>0)) {
324 return 22; 342 return 22;
325 } 343 }
326 return 0; 344 return 0;
327 } 345 }
328 346
329 return {caller:caller}; 347 return {caller:caller};
330 } 348 }
331 349
332 assertEquals(22, _WASMEXP_.asmCompileRun(TestUnsignedComparison.toString())); 350 assertEquals(22, _WASMEXP_.asmCompileRun(TestUnsignedComparison.toString()));
333 351
352
334 function TestMixedAdd() { 353 function TestMixedAdd() {
335 "use asm"; 354 "use asm";
336 355
337 function caller() { 356 function caller() {
338 var a = 0x80000000; 357 var a = 0x80000000;
339 var b = 0x7fffffff; 358 var b = 0x7fffffff;
340 var c = 0; 359 var c = 0;
341 c = ((a>>>0) + b)|0; 360 c = ((a>>>0) + b)|0;
342 if ((c >>> 0) > (0>>>0)) { 361 if ((c >>> 0) > (0>>>0)) {
343 if (c < 0) { 362 if (c < 0) {
344 return 23; 363 return 23;
345 } 364 }
346 } 365 }
347 return 0; 366 return 0;
348 } 367 }
349 368
350 return {caller:caller}; 369 return {caller:caller};
351 } 370 }
352 371
353 assertEquals(23, _WASMEXP_.asmCompileRun(TestMixedAdd.toString())); 372 assertEquals(23, _WASMEXP_.asmCompileRun(TestMixedAdd.toString()));
354 373
374
355 function TestInt32HeapAccess(stdlib, foreign, buffer) { 375 function TestInt32HeapAccess(stdlib, foreign, buffer) {
356 "use asm"; 376 "use asm";
357 377
358 var m = new stdlib.Int32Array(buffer); 378 var m = new stdlib.Int32Array(buffer);
359 function caller() { 379 function caller() {
360 var i = 4; 380 var i = 4;
361 381
362 m[0] = (i + 1) | 0; 382 m[0] = (i + 1) | 0;
363 m[i >> 2] = ((m[0]|0) + 1) | 0; 383 m[i >> 2] = ((m[0]|0) + 1) | 0;
364 m[2] = ((m[i >> 2]|0) + 1) | 0; 384 m[2] = ((m[i >> 2]|0) + 1) | 0;
365 return m[2] | 0; 385 return m[2] | 0;
366 } 386 }
367 387
368 return {caller: caller}; 388 return {caller: caller};
369 } 389 }
370 390
371 assertEquals(7, _WASMEXP_.asmCompileRun(TestInt32HeapAccess.toString())); 391 assertEquals(7, _WASMEXP_.asmCompileRun(TestInt32HeapAccess.toString()));
372 392
393
373 function TestHeapAccessIntTypes() { 394 function TestHeapAccessIntTypes() {
374 var types = [ 395 var types = [
375 ['Int8Array', '>> 0'], 396 ['Int8Array', '>> 0'],
376 ['Uint8Array', '>> 0'], 397 ['Uint8Array', '>> 0'],
377 ['Int16Array', '>> 1'], 398 ['Int16Array', '>> 1'],
378 ['Uint16Array', '>> 1'], 399 ['Uint16Array', '>> 1'],
379 ['Int32Array', '>> 2'], 400 ['Int32Array', '>> 2'],
380 ['Uint32Array', '>> 2'], 401 ['Uint32Array', '>> 2'],
381 ]; 402 ];
382 for (var i = 0; i < types.length; i++) { 403 for (var i = 0; i < types.length; i++) {
383 var code = TestInt32HeapAccess.toString(); 404 var code = TestInt32HeapAccess.toString();
384 code = code.replace('Int32Array', types[i][0]); 405 code = code.replace('Int32Array', types[i][0]);
385 code = code.replace(/>> 2/g, types[i][1]); 406 code = code.replace(/>> 2/g, types[i][1]);
386 assertEquals(7, _WASMEXP_.asmCompileRun(code)); 407 assertEquals(7, _WASMEXP_.asmCompileRun(code));
387 } 408 }
388 } 409 }
389 410
390 TestHeapAccessIntTypes(); 411 TestHeapAccessIntTypes();
391 412
413
392 function TestFloatHeapAccess(stdlib, foreign, buffer) { 414 function TestFloatHeapAccess(stdlib, foreign, buffer) {
393 "use asm"; 415 "use asm";
394 416
395 var f32 = new stdlib.Float32Array(buffer); 417 var f32 = new stdlib.Float32Array(buffer);
396 var f64 = new stdlib.Float64Array(buffer); 418 var f64 = new stdlib.Float64Array(buffer);
397 var fround = stdlib.Math.fround; 419 var fround = stdlib.Math.fround;
398 function caller() { 420 function caller() {
399 var i = 8; 421 var i = 8;
400 var j = 8; 422 var j = 8;
401 var v = 6.0; 423 var v = 6.0;
402 424
403 // TODO(bradnelson): Add float32 when asm-wasm supports it. 425 // TODO(bradnelson): Add float32 when asm-wasm supports it.
404 f64[2] = v + 1.0; 426 f64[2] = v + 1.0;
405 f64[i >> 3] = +f64[2] + 1.0; 427 f64[i >> 3] = +f64[2] + 1.0;
406 f64[j >> 3] = +f64[j >> 3] + 1.0; 428 f64[j >> 3] = +f64[j >> 3] + 1.0;
407 i = +f64[i >> 3] == 9.0; 429 i = +f64[i >> 3] == 9.0;
408 return i|0; 430 return i|0;
409 } 431 }
410 432
411 return {caller: caller}; 433 return {caller: caller};
412 } 434 }
413 435
414 assertEquals(1, _WASMEXP_.asmCompileRun(TestFloatHeapAccess.toString())); 436 assertEquals(1, _WASMEXP_.asmCompileRun(TestFloatHeapAccess.toString()));
415 437
438
416 function TestConvertI32() { 439 function TestConvertI32() {
417 "use asm"; 440 "use asm";
418 441
419 function caller() { 442 function caller() {
420 var a = 1.5; 443 var a = 1.5;
421 if ((~~(a + a)) == 3) { 444 if ((~~(a + a)) == 3) {
422 return 24; 445 return 24;
423 } 446 }
424 return 0; 447 return 0;
425 } 448 }
426 449
427 return {caller:caller}; 450 return {caller:caller};
428 } 451 }
429 452
430 assertEquals(24, _WASMEXP_.asmCompileRun(TestConvertI32.toString())); 453 assertEquals(24, _WASMEXP_.asmCompileRun(TestConvertI32.toString()));
431 454
455
432 function TestConvertF64FromInt() { 456 function TestConvertF64FromInt() {
433 "use asm"; 457 "use asm";
434 458
435 function caller() { 459 function caller() {
436 var a = 1; 460 var a = 1;
437 if ((+(a + a)) > 1.5) { 461 if ((+(a + a)) > 1.5) {
438 return 25; 462 return 25;
439 } 463 }
440 return 0; 464 return 0;
441 } 465 }
442 466
443 return {caller:caller}; 467 return {caller:caller};
444 } 468 }
445 469
446 assertEquals(25, _WASMEXP_.asmCompileRun(TestConvertF64FromInt.toString())); 470 assertEquals(25, _WASMEXP_.asmCompileRun(TestConvertF64FromInt.toString()));
447 471
472
448 function TestConvertF64FromUnsigned() { 473 function TestConvertF64FromUnsigned() {
449 "use asm"; 474 "use asm";
450 475
451 function caller() { 476 function caller() {
452 var a = 0xffffffff; 477 var a = 0xffffffff;
453 if ((+(a>>>0)) > 0.0) { 478 if ((+(a>>>0)) > 0.0) {
454 if((+a) < 0.0) { 479 if((+a) < 0.0) {
455 return 26; 480 return 26;
456 } 481 }
457 } 482 }
458 return 0; 483 return 0;
459 } 484 }
460 485
461 return {caller:caller}; 486 return {caller:caller};
462 } 487 }
463 488
464 assertEquals(26, _WASMEXP_.asmCompileRun(TestConvertF64FromUnsigned.toString())) ; 489 assertEquals(26, _WASMEXP_.asmCompileRun(TestConvertF64FromUnsigned.toString())) ;
465 490
491
466 function TestModInt() { 492 function TestModInt() {
467 "use asm"; 493 "use asm";
468 494
469 function caller() { 495 function caller() {
470 var a = -83; 496 var a = -83;
471 var b = 28; 497 var b = 28;
472 return ((a|0)%(b|0))|0; 498 return ((a|0)%(b|0))|0;
473 } 499 }
474 500
475 return {caller:caller}; 501 return {caller:caller};
476 } 502 }
477 503
478 assertEquals(-27, _WASMEXP_.asmCompileRun(TestModInt.toString())); 504 assertEquals(-27, _WASMEXP_.asmCompileRun(TestModInt.toString()));
479 505
506
480 function TestModUnsignedInt() { 507 function TestModUnsignedInt() {
481 "use asm"; 508 "use asm";
482 509
483 function caller() { 510 function caller() {
484 var a = 0x80000000; //2147483648 511 var a = 0x80000000; //2147483648
485 var b = 10; 512 var b = 10;
486 return ((a>>>0)%(b>>>0))|0; 513 return ((a>>>0)%(b>>>0))|0;
487 } 514 }
488 515
489 return {caller:caller}; 516 return {caller:caller};
490 } 517 }
491 518
492 assertEquals(8, _WASMEXP_.asmCompileRun(TestModUnsignedInt.toString())); 519 assertEquals(8, _WASMEXP_.asmCompileRun(TestModUnsignedInt.toString()));
493 520
521
494 function TestModDouble() { 522 function TestModDouble() {
495 "use asm"; 523 "use asm";
496 524
497 function caller() { 525 function caller() {
498 var a = 5.25; 526 var a = 5.25;
499 var b = 2.5; 527 var b = 2.5;
500 if (a%b == 0.25) { 528 if (a%b == 0.25) {
501 return 28; 529 return 28;
502 } 530 }
503 return 0; 531 return 0;
504 } 532 }
505 533
506 return {caller:caller}; 534 return {caller:caller};
507 } 535 }
508 536
509 assertEquals(28, _WASMEXP_.asmCompileRun(TestModDouble.toString())); 537 assertEquals(28, _WASMEXP_.asmCompileRun(TestModDouble.toString()));
510 538
539
511 /* 540 /*
512 TODO: Fix parsing of negative doubles 541 TODO: Fix parsing of negative doubles
513 Fix code to use trunc instead of casts 542 Fix code to use trunc instead of casts
514 function TestModDoubleNegative() { 543 function TestModDoubleNegative() {
515 "use asm"; 544 "use asm";
516 545
517 function caller() { 546 function caller() {
518 var a = -34359738368.25; 547 var a = -34359738368.25;
519 var b = 2.5; 548 var b = 2.5;
520 if (a%b == -0.75) { 549 if (a%b == -0.75) {
521 return 28; 550 return 28;
522 } 551 }
523 return 0; 552 return 0;
524 } 553 }
525 554
526 return {caller:caller}; 555 return {caller:caller};
527 } 556 }
528 557
529 assertEquals(28, _WASMEXP_.asmCompileRun(TestModDoubleNegative.toString())); 558 assertEquals(28, _WASMEXP_.asmCompileRun(TestModDoubleNegative.toString()));
530 */ 559 */
531 560
561
532 function TestNamedFunctions() { 562 function TestNamedFunctions() {
533 "use asm"; 563 "use asm";
534 564
535 var a = 0.0; 565 var a = 0.0;
536 var b = 0.0; 566 var b = 0.0;
537 567
538 function add() { 568 function add() {
539 return +(a + b); 569 return +(a + b);
540 } 570 }
541 571
542 function init() { 572 function init() {
543 a = 43.25; 573 a = 43.25;
544 b = 34.25; 574 b = 34.25;
545 } 575 }
546 576
547 return {init:init, 577 return {init:init,
548 add:add}; 578 add:add};
549 } 579 }
550 580
551 var module = _WASMEXP_.instantiateModuleFromAsm(TestNamedFunctions.toString()); 581 var module = _WASMEXP_.instantiateModuleFromAsm(TestNamedFunctions.toString());
552 module.init(); 582 module.init();
553 assertEquals(77.5, module.add()); 583 assertEquals(77.5, module.add());
554 584
585
555 function TestGlobalsWithInit() { 586 function TestGlobalsWithInit() {
556 "use asm"; 587 "use asm";
557 588
558 var a = 43.25; 589 var a = 43.25;
559 var b = 34.25; 590 var b = 34.25;
560 591
561 function add() { 592 function add() {
562 return +(a + b); 593 return +(a + b);
563 } 594 }
564 595
565 return {add:add}; 596 return {add:add};
566 } 597 }
567 598
568 var module = _WASMEXP_.instantiateModuleFromAsm(TestGlobalsWithInit.toString()); 599 var module = _WASMEXP_.instantiateModuleFromAsm(TestGlobalsWithInit.toString());
569 module.__init__(); 600 module.__init__();
570 assertEquals(77.5, module.add()); 601 assertEquals(77.5, module.add());
571 602
603
572 function TestForLoop() { 604 function TestForLoop() {
573 "use asm" 605 "use asm"
574 606
575 function caller() { 607 function caller() {
576 var ret = 0; 608 var ret = 0;
577 var i = 0; 609 var i = 0;
578 for (i = 2; i <= 10; i = (i+1)|0) { 610 for (i = 2; i <= 10; i = (i+1)|0) {
579 ret = (ret + i) | 0; 611 ret = (ret + i) | 0;
580 } 612 }
581 return ret|0; 613 return ret|0;
582 } 614 }
583 615
584 return {caller:caller}; 616 return {caller:caller};
585 } 617 }
586 618
587 assertEquals(54, _WASMEXP_.asmCompileRun(TestForLoop.toString())); 619 assertEquals(54, _WASMEXP_.asmCompileRun(TestForLoop.toString()));
588 620
621
589 function TestForLoopWithoutInit() { 622 function TestForLoopWithoutInit() {
590 "use asm" 623 "use asm"
591 624
592 function caller() { 625 function caller() {
593 var ret = 0; 626 var ret = 0;
594 var i = 0; 627 var i = 0;
595 for (; i < 10; i = (i+1)|0) { 628 for (; i < 10; i = (i+1)|0) {
596 ret = (ret + 10) | 0; 629 ret = (ret + 10) | 0;
597 } 630 }
598 return ret|0; 631 return ret|0;
599 } 632 }
600 633
601 return {caller:caller}; 634 return {caller:caller};
602 } 635 }
603 636
604 assertEquals(100, _WASMEXP_.asmCompileRun(TestForLoopWithoutInit.toString())); 637 assertEquals(100, _WASMEXP_.asmCompileRun(TestForLoopWithoutInit.toString()));
605 638
639
606 function TestForLoopWithoutCondition() { 640 function TestForLoopWithoutCondition() {
607 "use asm" 641 "use asm"
608 642
609 function caller() { 643 function caller() {
610 var ret = 0; 644 var ret = 0;
611 var i = 0; 645 var i = 0;
612 for (i=1;; i = (i+1)|0) { 646 for (i=1;; i = (i+1)|0) {
613 ret = (ret + i) | 0; 647 ret = (ret + i) | 0;
614 if (i == 11) { 648 if (i == 11) {
615 break; 649 break;
616 } 650 }
617 } 651 }
618 return ret|0; 652 return ret|0;
619 } 653 }
620 654
621 return {caller:caller}; 655 return {caller:caller};
622 } 656 }
623 657
624 assertEquals(66, _WASMEXP_.asmCompileRun(TestForLoopWithoutCondition.toString()) ); 658 assertEquals(66, _WASMEXP_.asmCompileRun(TestForLoopWithoutCondition.toString()) );
625 659
660
626 function TestForLoopWithoutNext() { 661 function TestForLoopWithoutNext() {
627 "use asm" 662 "use asm"
628 663
629 function caller() { 664 function caller() {
630 var i = 0; 665 var i = 0;
631 for (i=1; i < 41;) { 666 for (i=1; i < 41;) {
632 i = (i + 1) | 0; 667 i = (i + 1) | 0;
633 } 668 }
634 return i|0; 669 return i|0;
635 } 670 }
636 671
637 return {caller:caller}; 672 return {caller:caller};
638 } 673 }
639 674
640 assertEquals(41, _WASMEXP_.asmCompileRun(TestForLoopWithoutNext.toString())); 675 assertEquals(41, _WASMEXP_.asmCompileRun(TestForLoopWithoutNext.toString()));
641 676
677
642 function TestForLoopWithoutBody() { 678 function TestForLoopWithoutBody() {
643 "use asm" 679 "use asm"
644 680
645 function caller() { 681 function caller() {
646 var i = 0; 682 var i = 0;
647 for (i=1; i < 45 ; i = (i+1)|0) { 683 for (i=1; i < 45 ; i = (i+1)|0) {
648 } 684 }
649 return i|0; 685 return i|0;
650 } 686 }
651 687
652 return {caller:caller}; 688 return {caller:caller};
653 } 689 }
654 690
655 assertEquals(45, _WASMEXP_.asmCompileRun(TestForLoopWithoutBody.toString())); 691 assertEquals(45, _WASMEXP_.asmCompileRun(TestForLoopWithoutBody.toString()));
656 692
693
657 function TestDoWhile() { 694 function TestDoWhile() {
658 "use asm" 695 "use asm"
659 696
660 function caller() { 697 function caller() {
661 var i = 0; 698 var i = 0;
662 var ret = 21; 699 var ret = 21;
663 do { 700 do {
664 ret = (ret + ret)|0; 701 ret = (ret + ret)|0;
665 i = (i + 1)|0; 702 i = (i + 1)|0;
666 } while (i < 2); 703 } while (i < 2);
667 return ret|0; 704 return ret|0;
668 } 705 }
669 706
670 return {caller:caller}; 707 return {caller:caller};
671 } 708 }
672 709
673 assertEquals(84, _WASMEXP_.asmCompileRun(TestDoWhile.toString())); 710 assertEquals(84, _WASMEXP_.asmCompileRun(TestDoWhile.toString()));
674 711
712
675 function TestConditional() { 713 function TestConditional() {
676 "use asm" 714 "use asm"
677 715
678 function caller() { 716 function caller() {
679 var x = 1; 717 var x = 1;
680 return ((x > 0) ? 41 : 71)|0; 718 return ((x > 0) ? 41 : 71)|0;
681 } 719 }
682 720
683 return {caller:caller}; 721 return {caller:caller};
684 } 722 }
685 723
686 assertEquals(41, _WASMEXP_.asmCompileRun(TestConditional.toString())); 724 assertEquals(41, _WASMEXP_.asmCompileRun(TestConditional.toString()));
687 725
726
688 function TestSwitch() { 727 function TestSwitch() {
689 "use asm" 728 "use asm"
690 729
691 function caller() { 730 function caller() {
692 var ret = 0; 731 var ret = 0;
693 var x = 7; 732 var x = 7;
694 switch (x) { 733 switch (x) {
695 case 1: return 0; 734 case 1: return 0;
696 case 7: { 735 case 7: {
697 ret = 12; 736 ret = 12;
698 break; 737 break;
699 } 738 }
700 default: return 0; 739 default: return 0;
701 } 740 }
702 switch (x) { 741 switch (x) {
703 case 1: return 0; 742 case 1: return 0;
704 case 8: return 0; 743 case 8: return 0;
705 default: ret = (ret + 11)|0; 744 default: ret = (ret + 11)|0;
706 } 745 }
707 return ret|0; 746 return ret|0;
708 } 747 }
709 748
710 return {caller:caller}; 749 return {caller:caller};
711 } 750 }
712 751
713 assertEquals(23, _WASMEXP_.asmCompileRun(TestSwitch.toString())); 752 assertEquals(23, _WASMEXP_.asmCompileRun(TestSwitch.toString()));
714 753
754
715 function TestSwitchFallthrough() { 755 function TestSwitchFallthrough() {
716 "use asm" 756 "use asm"
717 757
718 function caller() { 758 function caller() {
719 var x = 17; 759 var x = 17;
720 var ret = 0; 760 var ret = 0;
721 switch (x) { 761 switch (x) {
722 case 17: 762 case 17:
723 case 14: ret = 39; 763 case 14: ret = 39;
724 case 1: ret = (ret + 3)|0; 764 case 1: ret = (ret + 3)|0;
725 case 4: break; 765 case 4: break;
726 default: ret = (ret + 1)|0; 766 default: ret = (ret + 1)|0;
727 } 767 }
728 return ret|0; 768 return ret|0;
729 } 769 }
730 770
731 return {caller:caller}; 771 return {caller:caller};
732 } 772 }
733 773
734 assertEquals(42, _WASMEXP_.asmCompileRun(TestSwitchFallthrough.toString())); 774 assertEquals(42, _WASMEXP_.asmCompileRun(TestSwitchFallthrough.toString()));
735 775
776
736 function TestNestedSwitch() { 777 function TestNestedSwitch() {
737 "use asm" 778 "use asm"
738 779
739 function caller() { 780 function caller() {
740 var x = 3; 781 var x = 3;
741 var y = -13; 782 var y = -13;
742 switch (x) { 783 switch (x) {
743 case 1: return 0; 784 case 1: return 0;
744 case 3: { 785 case 3: {
745 switch (y) { 786 switch (y) {
746 case 2: return 0; 787 case 2: return 0;
747 case -13: return 43; 788 case -13: return 43;
748 default: return 0; 789 default: return 0;
749 } 790 }
750 } 791 }
751 default: return 0; 792 default: return 0;
752 } 793 }
753 return 0; 794 return 0;
754 } 795 }
755 796
756 return {caller:caller}; 797 return {caller:caller};
757 } 798 }
758 799
759 assertEquals(43, _WASMEXP_.asmCompileRun(TestNestedSwitch.toString())); 800 assertEquals(43, _WASMEXP_.asmCompileRun(TestNestedSwitch.toString()));
760 801
802
761 function TestInitFunctionWithNoGlobals() { 803 function TestInitFunctionWithNoGlobals() {
762 "use asm"; 804 "use asm";
763 function caller() { 805 function caller() {
764 return 51; 806 return 51;
765 } 807 }
766 return {caller}; 808 return {caller};
767 } 809 }
768 810
769 var module = _WASMEXP_.instantiateModuleFromAsm( 811 var module = _WASMEXP_.instantiateModuleFromAsm(
770 TestInitFunctionWithNoGlobals.toString()); 812 TestInitFunctionWithNoGlobals.toString());
771 module.__init__(); 813 module.__init__();
772 assertEquals(51, module.caller()); 814 assertEquals(51, module.caller());
773 815
816
774 function TestExportNameDifferentFromFunctionName() { 817 function TestExportNameDifferentFromFunctionName() {
775 "use asm"; 818 "use asm";
776 function caller() { 819 function caller() {
777 return 55; 820 return 55;
778 } 821 }
779 return {alt_caller:caller}; 822 return {alt_caller:caller};
780 } 823 }
781 824
782 var module = _WASMEXP_.instantiateModuleFromAsm( 825 var module = _WASMEXP_.instantiateModuleFromAsm(
783 TestExportNameDifferentFromFunctionName.toString()); 826 TestExportNameDifferentFromFunctionName.toString());
784 module.__init__(); 827 module.__init__();
785 assertEquals(55, module.alt_caller()); 828 assertEquals(55, module.alt_caller());
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698