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

Side by Side Diff: test/cctest/wasm/test-run-wasm.cc

Issue 2077623002: [wasm] memory size is an uint32_t, not a size_t. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fixes Created 4 years, 6 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 | « src/wasm/wasm-module.h ('k') | test/cctest/wasm/wasm-run-utils.h » ('j') | 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 #include <stdint.h> 5 #include <stdint.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "src/base/platform/elapsed-timer.h" 9 #include "src/base/platform/elapsed-timer.h"
10 10
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 WASM_EXEC_TEST(Int8Const_fallthru2) { 45 WASM_EXEC_TEST(Int8Const_fallthru2) {
46 WasmRunner<int32_t> r(execution_mode); 46 WasmRunner<int32_t> r(execution_mode);
47 const byte kExpectedValue = 123; 47 const byte kExpectedValue = 123;
48 // -99 kExpectedValue 48 // -99 kExpectedValue
49 BUILD(r, WASM_I8(-99), WASM_I8(kExpectedValue)); 49 BUILD(r, WASM_I8(-99), WASM_I8(kExpectedValue));
50 CHECK_EQ(kExpectedValue, r.Call()); 50 CHECK_EQ(kExpectedValue, r.Call());
51 } 51 }
52 52
53 WASM_EXEC_TEST(Int8Const_all) { 53 WASM_EXEC_TEST(Int8Const_all) {
54 for (int value = -128; value <= 127; value++) { 54 for (int value = -128; value <= 127; ++value) {
55 WasmRunner<int32_t> r(execution_mode); 55 WasmRunner<int32_t> r(execution_mode);
56 // return(value) 56 // return(value)
57 BUILD(r, WASM_I8(value)); 57 BUILD(r, WASM_I8(value));
58 int32_t result = r.Call(); 58 int32_t result = r.Call();
59 CHECK_EQ(value, result); 59 CHECK_EQ(value, result);
60 } 60 }
61 } 61 }
62 62
63 WASM_EXEC_TEST(Int32Const) { 63 WASM_EXEC_TEST(Int32Const) {
64 WasmRunner<int32_t> r(execution_mode); 64 WasmRunner<int32_t> r(execution_mode);
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 BUILD(r, WASM_I32_REMU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 393 BUILD(r, WASM_I32_REMU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
394 CHECK_EQ(17, r.Call(217, 100)); 394 CHECK_EQ(17, r.Call(217, 100));
395 const int32_t kMin = std::numeric_limits<int32_t>::min(); 395 const int32_t kMin = std::numeric_limits<int32_t>::min();
396 CHECK_TRAP(r.Call(100, 0)); 396 CHECK_TRAP(r.Call(100, 0));
397 CHECK_TRAP(r.Call(-1001, 0)); 397 CHECK_TRAP(r.Call(-1001, 0));
398 CHECK_TRAP(r.Call(kMin, 0)); 398 CHECK_TRAP(r.Call(kMin, 0));
399 CHECK_EQ(kMin, r.Call(kMin, -1)); 399 CHECK_EQ(kMin, r.Call(kMin, -1));
400 } 400 }
401 401
402 WASM_EXEC_TEST(Int32DivS_byzero_const) { 402 WASM_EXEC_TEST(Int32DivS_byzero_const) {
403 for (int8_t denom = -2; denom < 8; denom++) { 403 for (int8_t denom = -2; denom < 8; ++denom) {
404 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 404 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
405 BUILD(r, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I8(denom))); 405 BUILD(r, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I8(denom)));
406 for (int32_t val = -7; val < 8; val++) { 406 for (int32_t val = -7; val < 8; ++val) {
407 if (denom == 0) { 407 if (denom == 0) {
408 CHECK_TRAP(r.Call(val)); 408 CHECK_TRAP(r.Call(val));
409 } else { 409 } else {
410 CHECK_EQ(val / denom, r.Call(val)); 410 CHECK_EQ(val / denom, r.Call(val));
411 } 411 }
412 } 412 }
413 } 413 }
414 } 414 }
415 415
416 WASM_EXEC_TEST(Int32DivU_byzero_const) { 416 WASM_EXEC_TEST(Int32DivU_byzero_const) {
417 for (uint32_t denom = 0xfffffffe; denom < 8; denom++) { 417 for (uint32_t denom = 0xfffffffe; denom < 8; ++denom) {
418 WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32()); 418 WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32());
419 BUILD(r, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I32V_1(denom))); 419 BUILD(r, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I32V_1(denom)));
420 420
421 for (uint32_t val = 0xfffffff0; val < 8; val++) { 421 for (uint32_t val = 0xfffffff0; val < 8; ++val) {
422 if (denom == 0) { 422 if (denom == 0) {
423 CHECK_TRAP(r.Call(val)); 423 CHECK_TRAP(r.Call(val));
424 } else { 424 } else {
425 CHECK_EQ(val / denom, r.Call(val)); 425 CHECK_EQ(val / denom, r.Call(val));
426 } 426 }
427 } 427 }
428 } 428 }
429 } 429 }
430 430
431 WASM_EXEC_TEST(Int32DivS_trap_effect) { 431 WASM_EXEC_TEST(Int32DivS_trap_effect) {
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 WASM_I8(88)); 884 WASM_I8(88));
885 CHECK_EQ(86, r.Call(0)); 885 CHECK_EQ(86, r.Call(0));
886 CHECK_EQ(87, r.Call(1)); 886 CHECK_EQ(87, r.Call(1));
887 CHECK_EQ(88, r.Call(2)); 887 CHECK_EQ(88, r.Call(2));
888 CHECK_EQ(85, r.Call(3)); 888 CHECK_EQ(85, r.Call(3));
889 CHECK_EQ(85, r.Call(4)); 889 CHECK_EQ(85, r.Call(4));
890 CHECK_EQ(85, r.Call(5)); 890 CHECK_EQ(85, r.Call(5));
891 } 891 }
892 892
893 WASM_EXEC_TEST(BrTable4) { 893 WASM_EXEC_TEST(BrTable4) {
894 for (int i = 0; i < 4; i++) { 894 for (int i = 0; i < 4; ++i) {
895 for (int t = 0; t < 4; t++) { 895 for (int t = 0; t < 4; ++t) {
896 uint32_t cases[] = {0, 1, 2, 3}; 896 uint32_t cases[] = {0, 1, 2, 3};
897 cases[i] = t; 897 cases[i] = t;
898 byte code[] = {B2(B2(B2(B2(B1(WASM_BR_TABLE( 898 byte code[] = {B2(B2(B2(B2(B1(WASM_BR_TABLE(
899 WASM_GET_LOCAL(0), 3, BR_TARGET(cases[0]), 899 WASM_GET_LOCAL(0), 3, BR_TARGET(cases[0]),
900 BR_TARGET(cases[1]), BR_TARGET(cases[2]), 900 BR_TARGET(cases[1]), BR_TARGET(cases[2]),
901 BR_TARGET(cases[3]))), 901 BR_TARGET(cases[3]))),
902 RET_I8(70)), 902 RET_I8(70)),
903 RET_I8(71)), 903 RET_I8(71)),
904 RET_I8(72)), 904 RET_I8(72)),
905 RET_I8(73)), 905 RET_I8(73)),
906 WASM_I8(75)}; 906 WASM_I8(75)};
907 907
908 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 908 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
909 r.Build(code, code + arraysize(code)); 909 r.Build(code, code + arraysize(code));
910 910
911 for (int x = -3; x < 50; x++) { 911 for (int x = -3; x < 50; ++x) {
912 int index = (x > 3 || x < 0) ? 3 : x; 912 int index = (x > 3 || x < 0) ? 3 : x;
913 int32_t expected = 70 + cases[index]; 913 int32_t expected = 70 + cases[index];
914 CHECK_EQ(expected, r.Call(x)); 914 CHECK_EQ(expected, r.Call(x));
915 } 915 }
916 } 916 }
917 } 917 }
918 } 918 }
919 919
920 WASM_EXEC_TEST(BrTable4x4) { 920 WASM_EXEC_TEST(BrTable4x4) {
921 for (byte a = 0; a < 4; a++) { 921 for (byte a = 0; a < 4; ++a) {
922 for (byte b = 0; b < 4; b++) { 922 for (byte b = 0; b < 4; ++b) {
923 for (byte c = 0; c < 4; c++) { 923 for (byte c = 0; c < 4; ++c) {
924 for (byte d = 0; d < 4; d++) { 924 for (byte d = 0; d < 4; ++d) {
925 for (int i = 0; i < 4; i++) { 925 for (int i = 0; i < 4; ++i) {
926 uint32_t cases[] = {a, b, c, d}; 926 uint32_t cases[] = {a, b, c, d};
927 byte code[] = { 927 byte code[] = {
928 B2(B2(B2(B2(B1(WASM_BR_TABLE( 928 B2(B2(B2(B2(B1(WASM_BR_TABLE(
929 WASM_GET_LOCAL(0), 3, BR_TARGET(cases[0]), 929 WASM_GET_LOCAL(0), 3, BR_TARGET(cases[0]),
930 BR_TARGET(cases[1]), BR_TARGET(cases[2]), 930 BR_TARGET(cases[1]), BR_TARGET(cases[2]),
931 BR_TARGET(cases[3]))), 931 BR_TARGET(cases[3]))),
932 RET_I8(50)), 932 RET_I8(50)),
933 RET_I8(51)), 933 RET_I8(51)),
934 RET_I8(52)), 934 RET_I8(52)),
935 RET_I8(53)), 935 RET_I8(53)),
936 WASM_I8(55)}; 936 WASM_I8(55)};
937 937
938 WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); 938 WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
939 r.Build(code, code + arraysize(code)); 939 r.Build(code, code + arraysize(code));
940 940
941 for (int x = -6; x < 47; x++) { 941 for (int x = -6; x < 47; ++x) {
942 int index = (x > 3 || x < 0) ? 3 : x; 942 int index = (x > 3 || x < 0) ? 3 : x;
943 int32_t expected = 50 + cases[index]; 943 int32_t expected = 50 + cases[index];
944 CHECK_EQ(expected, r.Call(x)); 944 CHECK_EQ(expected, r.Call(x));
945 } 945 }
946 } 946 }
947 } 947 }
948 } 948 }
949 } 949 }
950 } 950 }
951 } 951 }
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1315 memory[0] = 88888888; 1315 memory[0] = 88888888;
1316 CHECK_EQ(88888888, r.Call(0)); 1316 CHECK_EQ(88888888, r.Call(0));
1317 1317
1318 memory[0] = 77777777; 1318 memory[0] = 77777777;
1319 CHECK_EQ(77777777, r.Call(0)); 1319 CHECK_EQ(77777777, r.Call(0));
1320 } 1320 }
1321 1321
1322 WASM_EXEC_TEST(LoadMemI32_alignment) { 1322 WASM_EXEC_TEST(LoadMemI32_alignment) {
1323 TestingModule module(execution_mode); 1323 TestingModule module(execution_mode);
1324 int32_t* memory = module.AddMemoryElems<int32_t>(8); 1324 int32_t* memory = module.AddMemoryElems<int32_t>(8);
1325 for (byte alignment = 0; alignment <= 2; alignment++) { 1325 for (byte alignment = 0; alignment <= 2; ++alignment) {
1326 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1326 WasmRunner<int32_t> r(&module, MachineType::Int32());
1327 module.RandomizeMemory(1111); 1327 module.RandomizeMemory(1111);
1328 1328
1329 BUILD(r, 1329 BUILD(r,
1330 WASM_LOAD_MEM_ALIGNMENT(MachineType::Int32(), WASM_I8(0), alignment)); 1330 WASM_LOAD_MEM_ALIGNMENT(MachineType::Int32(), WASM_I8(0), alignment));
1331 1331
1332 memory[0] = 0x1a2b3c4d; 1332 memory[0] = 0x1a2b3c4d;
1333 CHECK_EQ(0x1a2b3c4d, r.Call(0)); 1333 CHECK_EQ(0x1a2b3c4d, r.Call(0));
1334 1334
1335 memory[0] = 0x5e6f7a8b; 1335 memory[0] = 0x5e6f7a8b;
1336 CHECK_EQ(0x5e6f7a8b, r.Call(0)); 1336 CHECK_EQ(0x5e6f7a8b, r.Call(0));
1337 1337
1338 memory[0] = 0x9ca0b1c2; 1338 memory[0] = 0x9ca0b1c2;
1339 CHECK_EQ(0x9ca0b1c2, r.Call(0)); 1339 CHECK_EQ(0x9ca0b1c2, r.Call(0));
1340 } 1340 }
1341 } 1341 }
1342 1342
1343 WASM_EXEC_TEST(LoadMemI32_oob) { 1343 WASM_EXEC_TEST(LoadMemI32_oob) {
1344 TestingModule module(execution_mode); 1344 TestingModule module(execution_mode);
1345 int32_t* memory = module.AddMemoryElems<int32_t>(8); 1345 int32_t* memory = module.AddMemoryElems<int32_t>(8);
1346 WasmRunner<int32_t> r(&module, MachineType::Uint32()); 1346 WasmRunner<int32_t> r(&module, MachineType::Uint32());
1347 module.RandomizeMemory(1111); 1347 module.RandomizeMemory(1111);
1348 1348
1349 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))); 1349 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0)));
1350 1350
1351 memory[0] = 88888888; 1351 memory[0] = 88888888;
1352 CHECK_EQ(88888888, r.Call(0u)); 1352 CHECK_EQ(88888888, r.Call(0u));
1353 for (uint32_t offset = 29; offset < 40; offset++) { 1353 for (uint32_t offset = 29; offset < 40; ++offset) {
1354 CHECK_TRAP(r.Call(offset)); 1354 CHECK_TRAP(r.Call(offset));
1355 } 1355 }
1356 1356
1357 for (uint32_t offset = 0x80000000; offset < 0x80000010; offset++) { 1357 for (uint32_t offset = 0x80000000; offset < 0x80000010; ++offset) {
1358 CHECK_TRAP(r.Call(offset)); 1358 CHECK_TRAP(r.Call(offset));
1359 } 1359 }
1360 } 1360 }
1361 1361
1362 WASM_EXEC_TEST(LoadMem_offset_oob) { 1362 WASM_EXEC_TEST(LoadMem_offset_oob) {
1363 TestingModule module(execution_mode); 1363 TestingModule module(execution_mode);
1364 module.AddMemoryElems<int32_t>(8); 1364 module.AddMemoryElems<int32_t>(8);
1365 1365
1366 static const MachineType machineTypes[] = { 1366 static const MachineType machineTypes[] = {
1367 MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), 1367 MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(),
1368 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(), 1368 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(),
1369 MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(), 1369 MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(),
1370 MachineType::Float64()}; 1370 MachineType::Float64()};
1371 1371
1372 for (size_t m = 0; m < arraysize(machineTypes); m++) { 1372 for (size_t m = 0; m < arraysize(machineTypes); ++m) {
1373 module.RandomizeMemory(1116 + static_cast<int>(m)); 1373 module.RandomizeMemory(1116 + static_cast<int>(m));
1374 WasmRunner<int32_t> r(&module, MachineType::Uint32()); 1374 WasmRunner<int32_t> r(&module, MachineType::Uint32());
1375 uint32_t boundary = 24 - WasmOpcodes::MemSize(machineTypes[m]); 1375 uint32_t boundary = 24 - WasmOpcodes::MemSize(machineTypes[m]);
1376 1376
1377 BUILD(r, WASM_LOAD_MEM_OFFSET(machineTypes[m], 8, WASM_GET_LOCAL(0)), 1377 BUILD(r, WASM_LOAD_MEM_OFFSET(machineTypes[m], 8, WASM_GET_LOCAL(0)),
1378 WASM_ZERO); 1378 WASM_ZERO);
1379 1379
1380 CHECK_EQ(0, r.Call(boundary)); // in bounds. 1380 CHECK_EQ(0, r.Call(boundary)); // in bounds.
1381 1381
1382 for (uint32_t offset = boundary + 1; offset < boundary + 19; offset++) { 1382 for (uint32_t offset = boundary + 1; offset < boundary + 19; ++offset) {
1383 CHECK_TRAP(r.Call(offset)); // out of bounds. 1383 CHECK_TRAP(r.Call(offset)); // out of bounds.
1384 } 1384 }
1385 } 1385 }
1386 } 1386 }
1387 1387
1388 WASM_EXEC_TEST(LoadMemI32_offset) { 1388 WASM_EXEC_TEST(LoadMemI32_offset) {
1389 TestingModule module(execution_mode); 1389 TestingModule module(execution_mode);
1390 int32_t* memory = module.AddMemoryElems<int32_t>(4); 1390 int32_t* memory = module.AddMemoryElems<int32_t>(4);
1391 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1391 WasmRunner<int32_t> r(&module, MachineType::Int32());
1392 module.RandomizeMemory(1111); 1392 module.RandomizeMemory(1111);
(...skipping 13 matching lines...) Expand all
1406 memory[2] = 33333333; 1406 memory[2] = 33333333;
1407 memory[3] = 44444444; 1407 memory[3] = 44444444;
1408 CHECK_EQ(22222222, r.Call(0)); 1408 CHECK_EQ(22222222, r.Call(0));
1409 CHECK_EQ(33333333, r.Call(4)); 1409 CHECK_EQ(33333333, r.Call(4));
1410 CHECK_EQ(44444444, r.Call(8)); 1410 CHECK_EQ(44444444, r.Call(8));
1411 } 1411 }
1412 1412
1413 WASM_EXEC_TEST(LoadMemI32_const_oob_misaligned) { 1413 WASM_EXEC_TEST(LoadMemI32_const_oob_misaligned) {
1414 const int kMemSize = 12; 1414 const int kMemSize = 12;
1415 // TODO(titzer): Fix misaligned accesses on MIPS and re-enable. 1415 // TODO(titzer): Fix misaligned accesses on MIPS and re-enable.
1416 for (int offset = 0; offset < kMemSize + 5; offset++) { 1416 for (int offset = 0; offset < kMemSize + 5; ++offset) {
1417 for (int index = 0; index < kMemSize + 5; index++) { 1417 for (int index = 0; index < kMemSize + 5; ++index) {
1418 TestingModule module(execution_mode); 1418 TestingModule module(execution_mode);
1419 module.AddMemoryElems<byte>(kMemSize); 1419 module.AddMemoryElems<byte>(kMemSize);
1420 1420
1421 WasmRunner<int32_t> r(&module); 1421 WasmRunner<int32_t> r(&module);
1422 module.RandomizeMemory(); 1422 module.RandomizeMemory();
1423 1423
1424 BUILD(r, 1424 BUILD(r,
1425 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index))); 1425 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index)));
1426 1426
1427 if ((offset + index) <= (kMemSize - sizeof(int32_t))) { 1427 if ((offset + index) <= (kMemSize - sizeof(int32_t))) {
(...skipping 25 matching lines...) Expand all
1453 } 1453 }
1454 } 1454 }
1455 } 1455 }
1456 } 1456 }
1457 1457
1458 WASM_EXEC_TEST(StoreMemI32_alignment) { 1458 WASM_EXEC_TEST(StoreMemI32_alignment) {
1459 TestingModule module(execution_mode); 1459 TestingModule module(execution_mode);
1460 int32_t* memory = module.AddMemoryElems<int32_t>(4); 1460 int32_t* memory = module.AddMemoryElems<int32_t>(4);
1461 const int32_t kWritten = 0x12345678; 1461 const int32_t kWritten = 0x12345678;
1462 1462
1463 for (byte i = 0; i <= 2; i++) { 1463 for (byte i = 0; i <= 2; ++i) {
1464 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1464 WasmRunner<int32_t> r(&module, MachineType::Int32());
1465 BUILD(r, WASM_STORE_MEM_ALIGNMENT(MachineType::Int32(), WASM_ZERO, i, 1465 BUILD(r, WASM_STORE_MEM_ALIGNMENT(MachineType::Int32(), WASM_ZERO, i,
1466 WASM_GET_LOCAL(0))); 1466 WASM_GET_LOCAL(0)));
1467 module.RandomizeMemory(1111); 1467 module.RandomizeMemory(1111);
1468 memory[0] = 0; 1468 memory[0] = 0;
1469 1469
1470 CHECK_EQ(kWritten, r.Call(kWritten)); 1470 CHECK_EQ(kWritten, r.Call(kWritten));
1471 CHECK_EQ(kWritten, memory[0]); 1471 CHECK_EQ(kWritten, memory[0]);
1472 } 1472 }
1473 } 1473 }
1474 1474
1475 WASM_EXEC_TEST(StoreMemI32_offset) { 1475 WASM_EXEC_TEST(StoreMemI32_offset) {
1476 TestingModule module(execution_mode); 1476 TestingModule module(execution_mode);
1477 int32_t* memory = module.AddMemoryElems<int32_t>(4); 1477 int32_t* memory = module.AddMemoryElems<int32_t>(4);
1478 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1478 WasmRunner<int32_t> r(&module, MachineType::Int32());
1479 const int32_t kWritten = 0xaabbccdd; 1479 const int32_t kWritten = 0xaabbccdd;
1480 1480
1481 BUILD(r, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0), 1481 BUILD(r, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0),
1482 WASM_I32V_5(kWritten))); 1482 WASM_I32V_5(kWritten)));
1483 1483
1484 for (int i = 0; i < 2; i++) { 1484 for (int i = 0; i < 2; ++i) {
1485 module.RandomizeMemory(1111); 1485 module.RandomizeMemory(1111);
1486 memory[0] = 66666666; 1486 memory[0] = 66666666;
1487 memory[1] = 77777777; 1487 memory[1] = 77777777;
1488 memory[2] = 88888888; 1488 memory[2] = 88888888;
1489 memory[3] = 99999999; 1489 memory[3] = 99999999;
1490 CHECK_EQ(kWritten, r.Call(i * 4)); 1490 CHECK_EQ(kWritten, r.Call(i * 4));
1491 CHECK_EQ(66666666, memory[0]); 1491 CHECK_EQ(66666666, memory[0]);
1492 CHECK_EQ(i == 0 ? kWritten : 77777777, memory[1]); 1492 CHECK_EQ(i == 0 ? kWritten : 77777777, memory[1]);
1493 CHECK_EQ(i == 1 ? kWritten : 88888888, memory[2]); 1493 CHECK_EQ(i == 1 ? kWritten : 88888888, memory[2]);
1494 CHECK_EQ(i == 2 ? kWritten : 99999999, memory[3]); 1494 CHECK_EQ(i == 2 ? kWritten : 99999999, memory[3]);
1495 } 1495 }
1496 } 1496 }
1497 1497
1498 WASM_EXEC_TEST(StoreMem_offset_oob) { 1498 WASM_EXEC_TEST(StoreMem_offset_oob) {
1499 TestingModule module(execution_mode); 1499 TestingModule module(execution_mode);
1500 byte* memory = module.AddMemoryElems<byte>(32); 1500 byte* memory = module.AddMemoryElems<byte>(32);
1501 1501
1502 // 64-bit cases are handled in test-run-wasm-64.cc 1502 // 64-bit cases are handled in test-run-wasm-64.cc
1503 static const MachineType machineTypes[] = { 1503 static const MachineType machineTypes[] = {
1504 MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), 1504 MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(),
1505 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(), 1505 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(),
1506 MachineType::Float32(), MachineType::Float64()}; 1506 MachineType::Float32(), MachineType::Float64()};
1507 1507
1508 for (size_t m = 0; m < arraysize(machineTypes); m++) { 1508 for (size_t m = 0; m < arraysize(machineTypes); ++m) {
1509 module.RandomizeMemory(1119 + static_cast<int>(m)); 1509 module.RandomizeMemory(1119 + static_cast<int>(m));
1510 WasmRunner<int32_t> r(&module, MachineType::Uint32()); 1510 WasmRunner<int32_t> r(&module, MachineType::Uint32());
1511 1511
1512 BUILD(r, WASM_STORE_MEM_OFFSET(machineTypes[m], 8, WASM_GET_LOCAL(0), 1512 BUILD(r, WASM_STORE_MEM_OFFSET(machineTypes[m], 8, WASM_GET_LOCAL(0),
1513 WASM_LOAD_MEM(machineTypes[m], WASM_ZERO)), 1513 WASM_LOAD_MEM(machineTypes[m], WASM_ZERO)),
1514 WASM_ZERO); 1514 WASM_ZERO);
1515 1515
1516 byte memsize = WasmOpcodes::MemSize(machineTypes[m]); 1516 byte memsize = WasmOpcodes::MemSize(machineTypes[m]);
1517 uint32_t boundary = 24 - memsize; 1517 uint32_t boundary = 24 - memsize;
1518 CHECK_EQ(0, r.Call(boundary)); // in bounds. 1518 CHECK_EQ(0, r.Call(boundary)); // in bounds.
1519 CHECK_EQ(0, memcmp(&memory[0], &memory[8 + boundary], memsize)); 1519 CHECK_EQ(0, memcmp(&memory[0], &memory[8 + boundary], memsize));
1520 1520
1521 for (uint32_t offset = boundary + 1; offset < boundary + 19; offset++) { 1521 for (uint32_t offset = boundary + 1; offset < boundary + 19; ++offset) {
1522 CHECK_TRAP(r.Call(offset)); // out of bounds. 1522 CHECK_TRAP(r.Call(offset)); // out of bounds.
1523 } 1523 }
1524 } 1524 }
1525 } 1525 }
1526 1526
1527 WASM_EXEC_TEST(LoadMemI32_P) { 1527 WASM_EXEC_TEST(LoadMemI32_P) {
1528 const int kNumElems = 8; 1528 const int kNumElems = 8;
1529 TestingModule module(execution_mode); 1529 TestingModule module(execution_mode);
1530 int32_t* memory = module.AddMemoryElems<int32_t>(kNumElems); 1530 int32_t* memory = module.AddMemoryElems<int32_t>(kNumElems);
1531 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1531 WasmRunner<int32_t> r(&module, MachineType::Int32());
1532 module.RandomizeMemory(2222); 1532 module.RandomizeMemory(2222);
1533 1533
1534 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))); 1534 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0)));
1535 1535
1536 for (int i = 0; i < kNumElems; i++) { 1536 for (int i = 0; i < kNumElems; ++i) {
1537 CHECK_EQ(memory[i], r.Call(i * 4)); 1537 CHECK_EQ(memory[i], r.Call(i * 4));
1538 } 1538 }
1539 } 1539 }
1540 1540
1541 WASM_EXEC_TEST(MemI32_Sum) { 1541 WASM_EXEC_TEST(MemI32_Sum) {
1542 const int kNumElems = 20; 1542 const int kNumElems = 20;
1543 TestingModule module(execution_mode); 1543 TestingModule module(execution_mode);
1544 uint32_t* memory = module.AddMemoryElems<uint32_t>(kNumElems); 1544 uint32_t* memory = module.AddMemoryElems<uint32_t>(kNumElems);
1545 WasmRunner<uint32_t> r(&module, MachineType::Int32()); 1545 WasmRunner<uint32_t> r(&module, MachineType::Int32());
1546 const byte kSum = r.AllocateLocal(kAstI32); 1546 const byte kSum = r.AllocateLocal(kAstI32);
1547 1547
1548 BUILD(r, WASM_BLOCK( 1548 BUILD(r, WASM_BLOCK(
1549 2, WASM_WHILE( 1549 2, WASM_WHILE(
1550 WASM_GET_LOCAL(0), 1550 WASM_GET_LOCAL(0),
1551 WASM_BLOCK( 1551 WASM_BLOCK(
1552 2, WASM_SET_LOCAL( 1552 2, WASM_SET_LOCAL(
1553 kSum, WASM_I32_ADD( 1553 kSum, WASM_I32_ADD(
1554 WASM_GET_LOCAL(kSum), 1554 WASM_GET_LOCAL(kSum),
1555 WASM_LOAD_MEM(MachineType::Int32(), 1555 WASM_LOAD_MEM(MachineType::Int32(),
1556 WASM_GET_LOCAL(0)))), 1556 WASM_GET_LOCAL(0)))),
1557 WASM_SET_LOCAL( 1557 WASM_SET_LOCAL(
1558 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(4))))), 1558 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(4))))),
1559 WASM_GET_LOCAL(1))); 1559 WASM_GET_LOCAL(1)));
1560 1560
1561 // Run 4 trials. 1561 // Run 4 trials.
1562 for (int i = 0; i < 3; i++) { 1562 for (int i = 0; i < 3; ++i) {
1563 module.RandomizeMemory(i * 33); 1563 module.RandomizeMemory(i * 33);
1564 uint32_t expected = 0; 1564 uint32_t expected = 0;
1565 for (size_t j = kNumElems - 1; j > 0; j--) { 1565 for (size_t j = kNumElems - 1; j > 0; --j) {
1566 expected += memory[j]; 1566 expected += memory[j];
1567 } 1567 }
1568 uint32_t result = r.Call(static_cast<int>(4 * (kNumElems - 1))); 1568 uint32_t result = r.Call(4 * (kNumElems - 1));
1569 CHECK_EQ(expected, result); 1569 CHECK_EQ(expected, result);
1570 } 1570 }
1571 } 1571 }
1572 1572
1573 WASM_EXEC_TEST(CheckMachIntsZero) { 1573 WASM_EXEC_TEST(CheckMachIntsZero) {
1574 const int kNumElems = 55; 1574 const int kNumElems = 55;
1575 TestingModule module(execution_mode); 1575 TestingModule module(execution_mode);
1576 module.AddMemoryElems<uint32_t>(kNumElems); 1576 module.AddMemoryElems<uint32_t>(kNumElems);
1577 WasmRunner<uint32_t> r(&module, MachineType::Int32()); 1577 WasmRunner<uint32_t> r(&module, MachineType::Int32());
1578 1578
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1613 WASM_GET_LOCAL(kSum)), 1613 WASM_GET_LOCAL(kSum)),
1614 WASM_GET_LOCAL(0))); 1614 WASM_GET_LOCAL(0)));
1615 1615
1616 CHECK_EQ(0, r.Call(4 * (kSize - 1))); 1616 CHECK_EQ(0, r.Call(4 * (kSize - 1)));
1617 CHECK_NE(-99.25, buffer[0]); 1617 CHECK_NE(-99.25, buffer[0]);
1618 CHECK_EQ(71256.0f, buffer[0]); 1618 CHECK_EQ(71256.0f, buffer[0]);
1619 } 1619 }
1620 1620
1621 template <typename T> 1621 template <typename T>
1622 T GenerateAndRunFold(WasmExecutionMode execution_mode, WasmOpcode binop, 1622 T GenerateAndRunFold(WasmExecutionMode execution_mode, WasmOpcode binop,
1623 T* buffer, size_t size, LocalType astType, 1623 T* buffer, uint32_t size, LocalType astType,
1624 MachineType memType) { 1624 MachineType memType) {
1625 TestingModule module(execution_mode); 1625 TestingModule module(execution_mode);
1626 module.AddMemoryElems<T>(size); 1626 module.AddMemoryElems<T>(size);
1627 for (size_t i = 0; i < size; i++) { 1627 for (uint32_t i = 0; i < size; ++i) {
1628 module.raw_mem_start<T>()[i] = buffer[i]; 1628 module.raw_mem_start<T>()[i] = buffer[i];
1629 } 1629 }
1630 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1630 WasmRunner<int32_t> r(&module, MachineType::Int32());
1631 const byte kAccum = r.AllocateLocal(astType); 1631 const byte kAccum = r.AllocateLocal(astType);
1632 1632
1633 BUILD( 1633 BUILD(
1634 r, 1634 r,
1635 WASM_BLOCK( 1635 WASM_BLOCK(
1636 4, WASM_SET_LOCAL(kAccum, WASM_LOAD_MEM(memType, WASM_ZERO)), 1636 4, WASM_SET_LOCAL(kAccum, WASM_LOAD_MEM(memType, WASM_ZERO)),
1637 WASM_WHILE( 1637 WASM_WHILE(
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1781 1781
1782 WASM_EXEC_TEST(Int32LoadInt8_signext) { 1782 WASM_EXEC_TEST(Int32LoadInt8_signext) {
1783 TestingModule module(execution_mode); 1783 TestingModule module(execution_mode);
1784 const int kNumElems = 16; 1784 const int kNumElems = 16;
1785 int8_t* memory = module.AddMemoryElems<int8_t>(kNumElems); 1785 int8_t* memory = module.AddMemoryElems<int8_t>(kNumElems);
1786 module.RandomizeMemory(); 1786 module.RandomizeMemory();
1787 memory[0] = -1; 1787 memory[0] = -1;
1788 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1788 WasmRunner<int32_t> r(&module, MachineType::Int32());
1789 BUILD(r, WASM_LOAD_MEM(MachineType::Int8(), WASM_GET_LOCAL(0))); 1789 BUILD(r, WASM_LOAD_MEM(MachineType::Int8(), WASM_GET_LOCAL(0)));
1790 1790
1791 for (size_t i = 0; i < kNumElems; i++) { 1791 for (int i = 0; i < kNumElems; ++i) {
1792 CHECK_EQ(memory[i], r.Call(static_cast<int>(i))); 1792 CHECK_EQ(memory[i], r.Call(i));
1793 } 1793 }
1794 } 1794 }
1795 1795
1796 WASM_EXEC_TEST(Int32LoadInt8_zeroext) { 1796 WASM_EXEC_TEST(Int32LoadInt8_zeroext) {
1797 TestingModule module(execution_mode); 1797 TestingModule module(execution_mode);
1798 const int kNumElems = 16; 1798 const int kNumElems = 16;
1799 byte* memory = module.AddMemory(kNumElems); 1799 byte* memory = module.AddMemory(kNumElems);
1800 module.RandomizeMemory(77); 1800 module.RandomizeMemory(77);
1801 memory[0] = 255; 1801 memory[0] = 255;
1802 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1802 WasmRunner<int32_t> r(&module, MachineType::Int32());
1803 BUILD(r, WASM_LOAD_MEM(MachineType::Uint8(), WASM_GET_LOCAL(0))); 1803 BUILD(r, WASM_LOAD_MEM(MachineType::Uint8(), WASM_GET_LOCAL(0)));
1804 1804
1805 for (size_t i = 0; i < kNumElems; i++) { 1805 for (int i = 0; i < kNumElems; ++i) {
1806 CHECK_EQ(memory[i], r.Call(static_cast<int>(i))); 1806 CHECK_EQ(memory[i], r.Call(i));
1807 } 1807 }
1808 } 1808 }
1809 1809
1810 WASM_EXEC_TEST(Int32LoadInt16_signext) { 1810 WASM_EXEC_TEST(Int32LoadInt16_signext) {
1811 TestingModule module(execution_mode); 1811 TestingModule module(execution_mode);
1812 const int kNumBytes = 16; 1812 const int kNumBytes = 16;
1813 byte* memory = module.AddMemory(kNumBytes); 1813 byte* memory = module.AddMemory(kNumBytes);
1814 module.RandomizeMemory(888); 1814 module.RandomizeMemory(888);
1815 memory[1] = 200; 1815 memory[1] = 200;
1816 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1816 WasmRunner<int32_t> r(&module, MachineType::Int32());
1817 BUILD(r, WASM_LOAD_MEM(MachineType::Int16(), WASM_GET_LOCAL(0))); 1817 BUILD(r, WASM_LOAD_MEM(MachineType::Int16(), WASM_GET_LOCAL(0)));
1818 1818
1819 for (size_t i = 0; i < kNumBytes; i += 2) { 1819 for (int i = 0; i < kNumBytes; i += 2) {
1820 int32_t expected = memory[i] | (static_cast<int8_t>(memory[i + 1]) << 8); 1820 int32_t expected = memory[i] | (static_cast<int8_t>(memory[i + 1]) << 8);
1821 CHECK_EQ(expected, r.Call(static_cast<int>(i))); 1821 CHECK_EQ(expected, r.Call(i));
1822 } 1822 }
1823 } 1823 }
1824 1824
1825 WASM_EXEC_TEST(Int32LoadInt16_zeroext) { 1825 WASM_EXEC_TEST(Int32LoadInt16_zeroext) {
1826 TestingModule module(execution_mode); 1826 TestingModule module(execution_mode);
1827 const int kNumBytes = 16; 1827 const int kNumBytes = 16;
1828 byte* memory = module.AddMemory(kNumBytes); 1828 byte* memory = module.AddMemory(kNumBytes);
1829 module.RandomizeMemory(9999); 1829 module.RandomizeMemory(9999);
1830 memory[1] = 204; 1830 memory[1] = 204;
1831 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1831 WasmRunner<int32_t> r(&module, MachineType::Int32());
1832 BUILD(r, WASM_LOAD_MEM(MachineType::Uint16(), WASM_GET_LOCAL(0))); 1832 BUILD(r, WASM_LOAD_MEM(MachineType::Uint16(), WASM_GET_LOCAL(0)));
1833 1833
1834 for (size_t i = 0; i < kNumBytes; i += 2) { 1834 for (int i = 0; i < kNumBytes; i += 2) {
1835 int32_t expected = memory[i] | (memory[i + 1] << 8); 1835 int32_t expected = memory[i] | (memory[i + 1] << 8);
1836 CHECK_EQ(expected, r.Call(static_cast<int>(i))); 1836 CHECK_EQ(expected, r.Call(i));
1837 } 1837 }
1838 } 1838 }
1839 1839
1840 WASM_EXEC_TEST(Int32Global) { 1840 WASM_EXEC_TEST(Int32Global) {
1841 TestingModule module(execution_mode); 1841 TestingModule module(execution_mode);
1842 int32_t* global = module.AddGlobal<int32_t>(MachineType::Int32()); 1842 int32_t* global = module.AddGlobal<int32_t>(MachineType::Int32());
1843 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1843 WasmRunner<int32_t> r(&module, MachineType::Int32());
1844 // global = global + p0 1844 // global = global + p0
1845 BUILD(r, WASM_STORE_GLOBAL( 1845 BUILD(r, WASM_STORE_GLOBAL(
1846 0, WASM_I32_ADD(WASM_LOAD_GLOBAL(0), WASM_GET_LOCAL(0)))); 1846 0, WASM_I32_ADD(WASM_LOAD_GLOBAL(0), WASM_GET_LOCAL(0))));
1847 1847
1848 *global = 116; 1848 *global = 116;
1849 for (int i = 9; i < 444444; i += 111111) { 1849 for (int i = 9; i < 444444; i += 111111) {
1850 int32_t expected = *global + i; 1850 int32_t expected = *global + i;
1851 r.Call(i); 1851 r.Call(i);
1852 CHECK_EQ(expected, *global); 1852 CHECK_EQ(expected, *global);
1853 } 1853 }
1854 } 1854 }
1855 1855
1856 WASM_EXEC_TEST(Int32Globals_DontAlias) { 1856 WASM_EXEC_TEST(Int32Globals_DontAlias) {
1857 const int kNumGlobals = 3; 1857 const int kNumGlobals = 3;
1858 TestingModule module(execution_mode); 1858 TestingModule module(execution_mode);
1859 int32_t* globals[] = {module.AddGlobal<int32_t>(MachineType::Int32()), 1859 int32_t* globals[] = {module.AddGlobal<int32_t>(MachineType::Int32()),
1860 module.AddGlobal<int32_t>(MachineType::Int32()), 1860 module.AddGlobal<int32_t>(MachineType::Int32()),
1861 module.AddGlobal<int32_t>(MachineType::Int32())}; 1861 module.AddGlobal<int32_t>(MachineType::Int32())};
1862 1862
1863 for (int g = 0; g < kNumGlobals; g++) { 1863 for (int g = 0; g < kNumGlobals; ++g) {
1864 // global = global + p0 1864 // global = global + p0
1865 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1865 WasmRunner<int32_t> r(&module, MachineType::Int32());
1866 BUILD(r, WASM_STORE_GLOBAL( 1866 BUILD(r, WASM_STORE_GLOBAL(
1867 g, WASM_I32_ADD(WASM_LOAD_GLOBAL(g), WASM_GET_LOCAL(0)))); 1867 g, WASM_I32_ADD(WASM_LOAD_GLOBAL(g), WASM_GET_LOCAL(0))));
1868 1868
1869 // Check that reading/writing global number {g} doesn't alter the others. 1869 // Check that reading/writing global number {g} doesn't alter the others.
1870 *globals[g] = 116 * g; 1870 *globals[g] = 116 * g;
1871 int32_t before[kNumGlobals]; 1871 int32_t before[kNumGlobals];
1872 for (int i = 9; i < 444444; i += 111113) { 1872 for (int i = 9; i < 444444; i += 111113) {
1873 int32_t sum = *globals[g] + i; 1873 int32_t sum = *globals[g] + i;
1874 for (int j = 0; j < kNumGlobals; j++) before[j] = *globals[j]; 1874 for (int j = 0; j < kNumGlobals; ++j) before[j] = *globals[j];
1875 r.Call(i); 1875 r.Call(i);
1876 for (int j = 0; j < kNumGlobals; j++) { 1876 for (int j = 0; j < kNumGlobals; ++j) {
1877 int32_t expected = j == g ? sum : before[j]; 1877 int32_t expected = j == g ? sum : before[j];
1878 CHECK_EQ(expected, *globals[j]); 1878 CHECK_EQ(expected, *globals[j]);
1879 } 1879 }
1880 } 1880 }
1881 } 1881 }
1882 } 1882 }
1883 1883
1884 WASM_EXEC_TEST(Float32Global) { 1884 WASM_EXEC_TEST(Float32Global) {
1885 TestingModule module(execution_mode); 1885 TestingModule module(execution_mode);
1886 float* global = module.AddGlobal<float>(MachineType::Float32()); 1886 float* global = module.AddGlobal<float>(MachineType::Float32());
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1984 WasmRunner<int32_t> r(&module); 1984 WasmRunner<int32_t> r(&module);
1985 BUILD(r, WASM_CALL_FUNCTION0(index)); 1985 BUILD(r, WASM_CALL_FUNCTION0(index));
1986 1986
1987 int32_t result = r.Call(); 1987 int32_t result = r.Call();
1988 CHECK_EQ(kExpected, result); 1988 CHECK_EQ(kExpected, result);
1989 } 1989 }
1990 1990
1991 WASM_EXEC_TEST(CallF32StackParameter) { 1991 WASM_EXEC_TEST(CallF32StackParameter) {
1992 // Build the target function. 1992 // Build the target function.
1993 LocalType param_types[20]; 1993 LocalType param_types[20];
1994 for (int i = 0; i < 20; i++) param_types[i] = kAstF32; 1994 for (int i = 0; i < 20; ++i) param_types[i] = kAstF32;
1995 FunctionSig sig(1, 19, param_types); 1995 FunctionSig sig(1, 19, param_types);
1996 TestingModule module(execution_mode); 1996 TestingModule module(execution_mode);
1997 WasmFunctionCompiler t(&sig, &module); 1997 WasmFunctionCompiler t(&sig, &module);
1998 BUILD(t, WASM_GET_LOCAL(17)); 1998 BUILD(t, WASM_GET_LOCAL(17));
1999 uint32_t index = t.CompileAndAdd(); 1999 uint32_t index = t.CompileAndAdd();
2000 2000
2001 // Build the calling function. 2001 // Build the calling function.
2002 WasmRunner<float> r(&module); 2002 WasmRunner<float> r(&module);
2003 BUILD(r, WASM_CALL_FUNCTIONN( 2003 BUILD(r, WASM_CALL_FUNCTIONN(
2004 19, index, WASM_F32(1.0f), WASM_F32(2.0f), WASM_F32(4.0f), 2004 19, index, WASM_F32(1.0f), WASM_F32(2.0f), WASM_F32(4.0f),
2005 WASM_F32(8.0f), WASM_F32(16.0f), WASM_F32(32.0f), 2005 WASM_F32(8.0f), WASM_F32(16.0f), WASM_F32(32.0f),
2006 WASM_F32(64.0f), WASM_F32(128.0f), WASM_F32(256.0f), 2006 WASM_F32(64.0f), WASM_F32(128.0f), WASM_F32(256.0f),
2007 WASM_F32(1.5f), WASM_F32(2.5f), WASM_F32(4.5f), WASM_F32(8.5f), 2007 WASM_F32(1.5f), WASM_F32(2.5f), WASM_F32(4.5f), WASM_F32(8.5f),
2008 WASM_F32(16.5f), WASM_F32(32.5f), WASM_F32(64.5f), 2008 WASM_F32(16.5f), WASM_F32(32.5f), WASM_F32(64.5f),
2009 WASM_F32(128.5f), WASM_F32(256.5f), WASM_F32(512.5f))); 2009 WASM_F32(128.5f), WASM_F32(256.5f), WASM_F32(512.5f)));
2010 2010
2011 float result = r.Call(); 2011 float result = r.Call();
2012 CHECK_EQ(256.5f, result); 2012 CHECK_EQ(256.5f, result);
2013 } 2013 }
2014 2014
2015 WASM_EXEC_TEST(CallF64StackParameter) { 2015 WASM_EXEC_TEST(CallF64StackParameter) {
2016 // Build the target function. 2016 // Build the target function.
2017 LocalType param_types[20]; 2017 LocalType param_types[20];
2018 for (int i = 0; i < 20; i++) param_types[i] = kAstF64; 2018 for (int i = 0; i < 20; ++i) param_types[i] = kAstF64;
2019 FunctionSig sig(1, 19, param_types); 2019 FunctionSig sig(1, 19, param_types);
2020 TestingModule module(execution_mode); 2020 TestingModule module(execution_mode);
2021 WasmFunctionCompiler t(&sig, &module); 2021 WasmFunctionCompiler t(&sig, &module);
2022 BUILD(t, WASM_GET_LOCAL(17)); 2022 BUILD(t, WASM_GET_LOCAL(17));
2023 uint32_t index = t.CompileAndAdd(); 2023 uint32_t index = t.CompileAndAdd();
2024 2024
2025 // Build the calling function. 2025 // Build the calling function.
2026 WasmRunner<double> r(&module); 2026 WasmRunner<double> r(&module);
2027 BUILD(r, WASM_CALL_FUNCTIONN(19, index, WASM_F64(1.0), WASM_F64(2.0), 2027 BUILD(r, WASM_CALL_FUNCTIONN(19, index, WASM_F64(1.0), WASM_F64(2.0),
2028 WASM_F64(4.0), WASM_F64(8.0), WASM_F64(16.0), 2028 WASM_F64(4.0), WASM_F64(8.0), WASM_F64(16.0),
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
2123 } else { 2123 } else {
2124 CHECK_EQ(expected, memory[0]); 2124 CHECK_EQ(expected, memory[0]);
2125 } 2125 }
2126 } 2126 }
2127 } 2127 }
2128 } 2128 }
2129 2129
2130 #define ADD_CODE(vec, ...) \ 2130 #define ADD_CODE(vec, ...) \
2131 do { \ 2131 do { \
2132 byte __buf[] = {__VA_ARGS__}; \ 2132 byte __buf[] = {__VA_ARGS__}; \
2133 for (size_t i = 0; i < sizeof(__buf); i++) vec.push_back(__buf[i]); \ 2133 for (size_t i = 0; i < sizeof(__buf); ++i) vec.push_back(__buf[i]); \
2134 } while (false) 2134 } while (false)
2135 2135
2136 static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) { 2136 static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
2137 const int kExpected = 6333; 2137 const int kExpected = 6333;
2138 const int kElemSize = 8; 2138 const int kElemSize = 8;
2139 TestSignatures sigs; 2139 TestSignatures sigs;
2140 2140
2141 // 64-bit cases handled in test-run-wasm-64.cc. 2141 // 64-bit cases handled in test-run-wasm-64.cc.
2142 static MachineType mixed[] = { 2142 static MachineType mixed[] = {
2143 MachineType::Int32(), MachineType::Float32(), MachineType::Float64(), 2143 MachineType::Int32(), MachineType::Float32(), MachineType::Float64(),
2144 MachineType::Float32(), MachineType::Int32(), MachineType::Float64(), 2144 MachineType::Float32(), MachineType::Int32(), MachineType::Float64(),
2145 MachineType::Float32(), MachineType::Float64(), MachineType::Int32(), 2145 MachineType::Float32(), MachineType::Float64(), MachineType::Int32(),
2146 MachineType::Int32(), MachineType::Int32()}; 2146 MachineType::Int32(), MachineType::Int32()};
2147 2147
2148 int num_params = static_cast<int>(arraysize(mixed)) - start; 2148 int num_params = static_cast<int>(arraysize(mixed)) - start;
2149 for (int which = 0; which < num_params; which++) { 2149 for (int which = 0; which < num_params; ++which) {
2150 v8::base::AccountingAllocator allocator; 2150 v8::base::AccountingAllocator allocator;
2151 Zone zone(&allocator); 2151 Zone zone(&allocator);
2152 TestingModule module(execution_mode); 2152 TestingModule module(execution_mode);
2153 module.AddMemory(1024); 2153 module.AddMemory(1024);
2154 MachineType* memtypes = &mixed[start]; 2154 MachineType* memtypes = &mixed[start];
2155 MachineType result = memtypes[which]; 2155 MachineType result = memtypes[which];
2156 2156
2157 // ========================================================================= 2157 // =========================================================================
2158 // Build the selector function. 2158 // Build the selector function.
2159 // ========================================================================= 2159 // =========================================================================
2160 uint32_t index; 2160 uint32_t index;
2161 FunctionSig::Builder b(&zone, 1, num_params); 2161 FunctionSig::Builder b(&zone, 1, num_params);
2162 b.AddReturn(WasmOpcodes::LocalTypeFor(result)); 2162 b.AddReturn(WasmOpcodes::LocalTypeFor(result));
2163 for (int i = 0; i < num_params; i++) { 2163 for (int i = 0; i < num_params; ++i) {
2164 b.AddParam(WasmOpcodes::LocalTypeFor(memtypes[i])); 2164 b.AddParam(WasmOpcodes::LocalTypeFor(memtypes[i]));
2165 } 2165 }
2166 WasmFunctionCompiler t(b.Build(), &module); 2166 WasmFunctionCompiler t(b.Build(), &module);
2167 BUILD(t, WASM_GET_LOCAL(which)); 2167 BUILD(t, WASM_GET_LOCAL(which));
2168 index = t.CompileAndAdd(); 2168 index = t.CompileAndAdd();
2169 2169
2170 // ========================================================================= 2170 // =========================================================================
2171 // Build the calling function. 2171 // Build the calling function.
2172 // ========================================================================= 2172 // =========================================================================
2173 WasmRunner<int32_t> r(&module); 2173 WasmRunner<int32_t> r(&module);
2174 std::vector<byte> code; 2174 std::vector<byte> code;
2175 2175
2176 // Load the offset for the store. 2176 // Load the offset for the store.
2177 ADD_CODE(code, WASM_ZERO); 2177 ADD_CODE(code, WASM_ZERO);
2178 2178
2179 // Load the arguments. 2179 // Load the arguments.
2180 for (int i = 0; i < num_params; i++) { 2180 for (int i = 0; i < num_params; ++i) {
2181 int offset = (i + 1) * kElemSize; 2181 int offset = (i + 1) * kElemSize;
2182 ADD_CODE(code, WASM_LOAD_MEM(memtypes[i], WASM_I8(offset))); 2182 ADD_CODE(code, WASM_LOAD_MEM(memtypes[i], WASM_I8(offset)));
2183 } 2183 }
2184 2184
2185 // Call the selector function. 2185 // Call the selector function.
2186 ADD_CODE(code, kExprCallFunction, static_cast<byte>(num_params), 2186 ADD_CODE(code, kExprCallFunction, static_cast<byte>(num_params),
2187 static_cast<byte>(index)); 2187 static_cast<byte>(index));
2188 2188
2189 // Store the result in memory. 2189 // Store the result in memory.
2190 ADD_CODE(code, 2190 ADD_CODE(code,
2191 static_cast<byte>(WasmOpcodes::LoadStoreOpcodeOf(result, true)), 2191 static_cast<byte>(WasmOpcodes::LoadStoreOpcodeOf(result, true)),
2192 ZERO_ALIGNMENT, ZERO_OFFSET); 2192 ZERO_ALIGNMENT, ZERO_OFFSET);
2193 2193
2194 // Return the expected value. 2194 // Return the expected value.
2195 ADD_CODE(code, WASM_I32V_2(kExpected)); 2195 ADD_CODE(code, WASM_I32V_2(kExpected));
2196 2196
2197 r.Build(&code[0], &code[0] + code.size()); 2197 r.Build(&code[0], &code[0] + code.size());
2198 2198
2199 // Run the code. 2199 // Run the code.
2200 for (int t = 0; t < 10; t++) { 2200 for (int t = 0; t < 10; ++t) {
2201 module.RandomizeMemory(); 2201 module.RandomizeMemory();
2202 CHECK_EQ(kExpected, r.Call()); 2202 CHECK_EQ(kExpected, r.Call());
2203 2203
2204 int size = WasmOpcodes::MemSize(result); 2204 int size = WasmOpcodes::MemSize(result);
2205 for (int i = 0; i < size; i++) { 2205 for (int i = 0; i < size; ++i) {
2206 int base = (which + 1) * kElemSize; 2206 int base = (which + 1) * kElemSize;
2207 byte expected = module.raw_mem_at<byte>(base + i); 2207 byte expected = module.raw_mem_at<byte>(base + i);
2208 byte result = module.raw_mem_at<byte>(i); 2208 byte result = module.raw_mem_at<byte>(i);
2209 CHECK_EQ(expected, result); 2209 CHECK_EQ(expected, result);
2210 } 2210 }
2211 } 2211 }
2212 } 2212 }
2213 } 2213 }
2214 2214
2215 WASM_EXEC_TEST(MixedCall_0) { Run_WasmMixedCall_N(execution_mode, 0); } 2215 WASM_EXEC_TEST(MixedCall_0) { Run_WasmMixedCall_N(execution_mode, 0); }
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
2771 2771
2772 FOR_FLOAT32_INPUTS(i) { 2772 FOR_FLOAT32_INPUTS(i) {
2773 FOR_FLOAT32_INPUTS(j) { CHECK_FLOAT_EQ(copysignf(*i, *j), r.Call(*i, *j)); } 2773 FOR_FLOAT32_INPUTS(j) { CHECK_FLOAT_EQ(copysignf(*i, *j), r.Call(*i, *j)); }
2774 } 2774 }
2775 } 2775 }
2776 2776
2777 static void CompileCallIndirectMany(LocalType param) { 2777 static void CompileCallIndirectMany(LocalType param) {
2778 // Make sure we don't run out of registers when compiling indirect calls 2778 // Make sure we don't run out of registers when compiling indirect calls
2779 // with many many parameters. 2779 // with many many parameters.
2780 TestSignatures sigs; 2780 TestSignatures sigs;
2781 for (byte num_params = 0; num_params < 40; num_params++) { 2781 for (byte num_params = 0; num_params < 40; ++num_params) {
2782 v8::base::AccountingAllocator allocator; 2782 v8::base::AccountingAllocator allocator;
2783 Zone zone(&allocator); 2783 Zone zone(&allocator);
2784 HandleScope scope(CcTest::InitIsolateOnce()); 2784 HandleScope scope(CcTest::InitIsolateOnce());
2785 TestingModule module(kExecuteCompiled); 2785 TestingModule module(kExecuteCompiled);
2786 FunctionSig* sig = sigs.many(&zone, kAstStmt, param, num_params); 2786 FunctionSig* sig = sigs.many(&zone, kAstStmt, param, num_params);
2787 2787
2788 module.AddSignature(sig); 2788 module.AddSignature(sig);
2789 module.AddSignature(sig); 2789 module.AddSignature(sig);
2790 module.AddIndirectFunctionTable(nullptr, 0); 2790 module.AddIndirectFunctionTable(nullptr, 0);
2791 2791
2792 WasmFunctionCompiler t(sig, &module); 2792 WasmFunctionCompiler t(sig, &module);
2793 2793
2794 std::vector<byte> code; 2794 std::vector<byte> code;
2795 ADD_CODE(code, kExprI8Const, 0); 2795 ADD_CODE(code, kExprI8Const, 0);
2796 for (byte p = 0; p < num_params; p++) { 2796 for (byte p = 0; p < num_params; ++p) {
2797 ADD_CODE(code, kExprGetLocal, p); 2797 ADD_CODE(code, kExprGetLocal, p);
2798 } 2798 }
2799 ADD_CODE(code, kExprCallIndirect, static_cast<byte>(num_params), 1); 2799 ADD_CODE(code, kExprCallIndirect, static_cast<byte>(num_params), 1);
2800 2800
2801 t.Build(&code[0], &code[0] + code.size()); 2801 t.Build(&code[0], &code[0] + code.size());
2802 t.Compile(); 2802 t.Compile();
2803 } 2803 }
2804 } 2804 }
2805 2805
2806 TEST(Compile_Wasm_CallIndirect_Many_i32) { CompileCallIndirectMany(kAstI32); } 2806 TEST(Compile_Wasm_CallIndirect_Many_i32) { CompileCallIndirectMany(kAstI32); }
2807 2807
2808 TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kAstF32); } 2808 TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kAstF32); }
2809 2809
2810 TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kAstF64); } 2810 TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kAstF64); }
2811 2811
2812 WASM_EXEC_TEST(Int32RemS_dead) { 2812 WASM_EXEC_TEST(Int32RemS_dead) {
2813 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), 2813 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
2814 MachineType::Int32()); 2814 MachineType::Int32());
2815 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_ZERO); 2815 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_ZERO);
2816 const int32_t kMin = std::numeric_limits<int32_t>::min(); 2816 const int32_t kMin = std::numeric_limits<int32_t>::min();
2817 CHECK_EQ(0, r.Call(133, 100)); 2817 CHECK_EQ(0, r.Call(133, 100));
2818 CHECK_EQ(0, r.Call(kMin, -1)); 2818 CHECK_EQ(0, r.Call(kMin, -1));
2819 CHECK_EQ(0, r.Call(0, 1)); 2819 CHECK_EQ(0, r.Call(0, 1));
2820 CHECK_TRAP(r.Call(100, 0)); 2820 CHECK_TRAP(r.Call(100, 0));
2821 CHECK_TRAP(r.Call(-1001, 0)); 2821 CHECK_TRAP(r.Call(-1001, 0));
2822 CHECK_TRAP(r.Call(kMin, 0)); 2822 CHECK_TRAP(r.Call(kMin, 0));
2823 } 2823 }
OLDNEW
« no previous file with comments | « src/wasm/wasm-module.h ('k') | test/cctest/wasm/wasm-run-utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698