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

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

Issue 1581913005: Allow asm modules to be instatiated with external heaps. (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
« src/wasm/wasm-js.cc ('K') | « src/wasm/wasm-js.cc ('k') | 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();
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 m[i >> 2] = ((m[0]|0) + 1) | 0; 363 m[i >> 2] = ((m[0]|0) + 1) | 0;
364 m[2] = ((m[i >> 2]|0) + 1) | 0; 364 m[2] = ((m[i >> 2]|0) + 1) | 0;
365 return m[2] | 0; 365 return m[2] | 0;
366 } 366 }
367 367
368 return {caller: caller}; 368 return {caller: caller};
369 } 369 }
370 370
371 assertEquals(7, _WASMEXP_.asmCompileRun(TestInt32HeapAccess.toString())); 371 assertEquals(7, _WASMEXP_.asmCompileRun(TestInt32HeapAccess.toString()));
372 372
373 function TestInt32HeapAccessExternal() {
374 var memory = new ArrayBuffer(1024);
375 var memory_int32 = new Int32Array(memory);
376 var module = _WASMEXP_.instantiateModuleFromAsm(
377 TestInt32HeapAccess.toString(), null, memory);
378 module.__init__();
379 assertEquals(7, module.caller());
380 assertEquals(7, memory_int32[2]);
381 }
382
383 TestInt32HeapAccessExternal();
384
373 function TestHeapAccessIntTypes() { 385 function TestHeapAccessIntTypes() {
374 var types = [ 386 var types = [
375 ['Int8Array', '>> 0'], 387 [Int8Array, 'Int8Array', '>> 0'],
376 ['Uint8Array', '>> 0'], 388 [Uint8Array, 'Uint8Array', '>> 0'],
377 ['Int16Array', '>> 1'], 389 [Int16Array, 'Int16Array', '>> 1'],
378 ['Uint16Array', '>> 1'], 390 [Uint16Array, 'Uint16Array', '>> 1'],
379 ['Int32Array', '>> 2'], 391 [Int32Array, 'Int32Array', '>> 2'],
380 ['Uint32Array', '>> 2'], 392 [Uint32Array, 'Uint32Array', '>> 2'],
381 ]; 393 ];
382 for (var i = 0; i < types.length; i++) { 394 for (var i = 0; i < types.length; i++) {
383 var code = TestInt32HeapAccess.toString(); 395 var code = TestInt32HeapAccess.toString();
384 code = code.replace('Int32Array', types[i][0]); 396 code = code.replace('Int32Array', types[i][1]);
385 code = code.replace(/>> 2/g, types[i][1]); 397 code = code.replace(/>> 2/g, types[i][2]);
398 var memory = new ArrayBuffer(1024);
399 var memory_view = new types[i][0](memory);
400 var module = _WASMEXP_.instantiateModuleFromAsm(code, null, memory);
401 module.__init__();
402 assertEquals(7, module.caller());
403 assertEquals(7, memory_view[2]);
386 assertEquals(7, _WASMEXP_.asmCompileRun(code)); 404 assertEquals(7, _WASMEXP_.asmCompileRun(code));
387 } 405 }
388 } 406 }
389 407
390 TestHeapAccessIntTypes(); 408 TestHeapAccessIntTypes();
391 409
392 function TestFloatHeapAccess(stdlib, foreign, buffer) { 410 function TestFloatHeapAccess(stdlib, foreign, buffer) {
393 "use asm"; 411 "use asm";
394 412
395 var f32 = new stdlib.Float32Array(buffer); 413 var f32 = new stdlib.Float32Array(buffer);
(...skipping 10 matching lines...) Expand all
406 f64[j >> 3] = +f64[j >> 3] + 1.0; 424 f64[j >> 3] = +f64[j >> 3] + 1.0;
407 i = +f64[i >> 3] == 9.0; 425 i = +f64[i >> 3] == 9.0;
408 return i|0; 426 return i|0;
409 } 427 }
410 428
411 return {caller: caller}; 429 return {caller: caller};
412 } 430 }
413 431
414 assertEquals(1, _WASMEXP_.asmCompileRun(TestFloatHeapAccess.toString())); 432 assertEquals(1, _WASMEXP_.asmCompileRun(TestFloatHeapAccess.toString()));
415 433
434 function TestFloatHeapAccessExternal() {
435 var memory = new ArrayBuffer(1024);
436 var memory_float64 = new Float64Array(memory);
437 var module = _WASMEXP_.instantiateModuleFromAsm(
438 TestFloatHeapAccess.toString(), null, memory);
439 module.__init__();
440 assertEquals(1, module.caller());
441 assertEquals(9.0, memory_float64[1]);
442 }
443
444 TestFloatHeapAccessExternal();
445
416 function TestConvertI32() { 446 function TestConvertI32() {
417 "use asm"; 447 "use asm";
418 448
419 function caller() { 449 function caller() {
420 var a = 1.5; 450 var a = 1.5;
421 if ((~~(a + a)) == 3) { 451 if ((~~(a + a)) == 3) {
422 return 24; 452 return 24;
423 } 453 }
424 return 0; 454 return 0;
425 } 455 }
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 function caller() { 806 function caller() {
777 return 55; 807 return 55;
778 } 808 }
779 return {alt_caller:caller}; 809 return {alt_caller:caller};
780 } 810 }
781 811
782 var module = _WASMEXP_.instantiateModuleFromAsm( 812 var module = _WASMEXP_.instantiateModuleFromAsm(
783 TestExportNameDifferentFromFunctionName.toString()); 813 TestExportNameDifferentFromFunctionName.toString());
784 module.__init__(); 814 module.__init__();
785 assertEquals(55, module.alt_caller()); 815 assertEquals(55, module.alt_caller());
OLDNEW
« src/wasm/wasm-js.cc ('K') | « src/wasm/wasm-js.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698