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

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

Issue 2034093002: Implement WASM big-endian support (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Small fixes. Rebase to master 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 | « test/cctest/cctest.status ('k') | test/cctest/wasm/test-run-wasm-64.cc » ('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 969 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 WASM_EXEC_TEST(F32ReinterpretI32) { 980 WASM_EXEC_TEST(F32ReinterpretI32) {
981 TestingModule module(execution_mode); 981 TestingModule module(execution_mode);
982 int32_t* memory = module.AddMemoryElems<int32_t>(8); 982 int32_t* memory = module.AddMemoryElems<int32_t>(8);
983 WasmRunner<int32_t> r(&module); 983 WasmRunner<int32_t> r(&module);
984 984
985 BUILD(r, WASM_I32_REINTERPRET_F32( 985 BUILD(r, WASM_I32_REINTERPRET_F32(
986 WASM_LOAD_MEM(MachineType::Float32(), WASM_ZERO))); 986 WASM_LOAD_MEM(MachineType::Float32(), WASM_ZERO)));
987 987
988 FOR_INT32_INPUTS(i) { 988 FOR_INT32_INPUTS(i) {
989 int32_t expected = *i; 989 int32_t expected = *i;
990 memory[0] = expected; 990 module.WriteMemory(&memory[0], expected);
991 CHECK_EQ(expected, r.Call()); 991 CHECK_EQ(expected, r.Call());
992 } 992 }
993 } 993 }
994 994
995 WASM_EXEC_TEST(I32ReinterpretF32) { 995 WASM_EXEC_TEST(I32ReinterpretF32) {
996 TestingModule module(execution_mode); 996 TestingModule module(execution_mode);
997 int32_t* memory = module.AddMemoryElems<int32_t>(8); 997 int32_t* memory = module.AddMemoryElems<int32_t>(8);
998 WasmRunner<int32_t> r(&module, MachineType::Int32()); 998 WasmRunner<int32_t> r(&module, MachineType::Int32());
999 999
1000 BUILD(r, WASM_BLOCK( 1000 BUILD(r, WASM_BLOCK(
1001 2, WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, 1001 2, WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO,
1002 WASM_F32_REINTERPRET_I32(WASM_GET_LOCAL(0))), 1002 WASM_F32_REINTERPRET_I32(WASM_GET_LOCAL(0))),
1003 WASM_I8(107))); 1003 WASM_I8(107)));
1004 1004
1005 FOR_INT32_INPUTS(i) { 1005 FOR_INT32_INPUTS(i) {
1006 int32_t expected = *i; 1006 int32_t expected = *i;
1007 CHECK_EQ(107, r.Call(expected)); 1007 CHECK_EQ(107, r.Call(expected));
1008 CHECK_EQ(expected, memory[0]); 1008 CHECK_EQ(expected, module.ReadMemory(&memory[0]));
1009 } 1009 }
1010 } 1010 }
1011 1011
1012 WASM_EXEC_TEST(ReturnStore) { 1012 WASM_EXEC_TEST(ReturnStore) {
1013 TestingModule module(execution_mode); 1013 TestingModule module(execution_mode);
1014 int32_t* memory = module.AddMemoryElems<int32_t>(8); 1014 int32_t* memory = module.AddMemoryElems<int32_t>(8);
1015 WasmRunner<int32_t> r(&module); 1015 WasmRunner<int32_t> r(&module);
1016 1016
1017 BUILD(r, WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO, 1017 BUILD(r, WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO,
1018 WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO))); 1018 WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)));
1019 1019
1020 FOR_INT32_INPUTS(i) { 1020 FOR_INT32_INPUTS(i) {
1021 int32_t expected = *i; 1021 int32_t expected = *i;
1022 memory[0] = expected; 1022 module.WriteMemory(&memory[0], expected);
1023 CHECK_EQ(expected, r.Call()); 1023 CHECK_EQ(expected, r.Call());
1024 } 1024 }
1025 } 1025 }
1026 1026
1027 WASM_EXEC_TEST(VoidReturn1) { 1027 WASM_EXEC_TEST(VoidReturn1) {
1028 // We use a wrapper function because WasmRunner<void> does not exist. 1028 // We use a wrapper function because WasmRunner<void> does not exist.
1029 1029
1030 // Build the test function. 1030 // Build the test function.
1031 TestSignatures sigs; 1031 TestSignatures sigs;
1032 TestingModule module(execution_mode); 1032 TestingModule module(execution_mode);
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1302 } 1302 }
1303 1303
1304 WASM_EXEC_TEST(LoadMemI32) { 1304 WASM_EXEC_TEST(LoadMemI32) {
1305 TestingModule module(execution_mode); 1305 TestingModule module(execution_mode);
1306 int32_t* memory = module.AddMemoryElems<int32_t>(8); 1306 int32_t* memory = module.AddMemoryElems<int32_t>(8);
1307 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1307 WasmRunner<int32_t> r(&module, MachineType::Int32());
1308 module.RandomizeMemory(1111); 1308 module.RandomizeMemory(1111);
1309 1309
1310 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(0))); 1310 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(0)));
1311 1311
1312 memory[0] = 99999999; 1312 module.WriteMemory(&memory[0], 99999999);
1313 CHECK_EQ(99999999, r.Call(0)); 1313 CHECK_EQ(99999999, r.Call(0));
1314 1314
1315 memory[0] = 88888888; 1315 module.WriteMemory(&memory[0], 88888888);
1316 CHECK_EQ(88888888, r.Call(0)); 1316 CHECK_EQ(88888888, r.Call(0));
1317 1317
1318 memory[0] = 77777777; 1318 module.WriteMemory(&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 module.WriteMemory(&memory[0], 0x1a2b3c4d);
1333 CHECK_EQ(0x1a2b3c4d, r.Call(0)); 1333 CHECK_EQ(0x1a2b3c4d, r.Call(0));
1334 1334
1335 memory[0] = 0x5e6f7a8b; 1335 module.WriteMemory(&memory[0], 0x5e6f7a8b);
1336 CHECK_EQ(0x5e6f7a8b, r.Call(0)); 1336 CHECK_EQ(0x5e6f7a8b, r.Call(0));
1337 1337
1338 memory[0] = 0x9ca0b1c2; 1338 module.WriteMemory(&memory[0], 0x7ca0b1c2);
1339 CHECK_EQ(0x9ca0b1c2, r.Call(0)); 1339 CHECK_EQ(0x7ca0b1c2, 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 module.WriteMemory(&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
(...skipping 24 matching lines...) Expand all
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);
1393 1393
1394 BUILD(r, WASM_LOAD_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0))); 1394 BUILD(r, WASM_LOAD_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0)));
1395 1395
1396 memory[0] = 66666666; 1396 module.WriteMemory(&memory[0], 66666666);
1397 memory[1] = 77777777; 1397 module.WriteMemory(&memory[1], 77777777);
1398 memory[2] = 88888888; 1398 module.WriteMemory(&memory[2], 88888888);
1399 memory[3] = 99999999; 1399 module.WriteMemory(&memory[3], 99999999);
1400 CHECK_EQ(77777777, r.Call(0)); 1400 CHECK_EQ(77777777, r.Call(0));
1401 CHECK_EQ(88888888, r.Call(4)); 1401 CHECK_EQ(88888888, r.Call(4));
1402 CHECK_EQ(99999999, r.Call(8)); 1402 CHECK_EQ(99999999, r.Call(8));
1403 1403
1404 memory[0] = 11111111; 1404 module.WriteMemory(&memory[0], 11111111);
1405 memory[1] = 22222222; 1405 module.WriteMemory(&memory[1], 22222222);
1406 memory[2] = 33333333; 1406 module.WriteMemory(&memory[2], 33333333);
1407 memory[3] = 44444444; 1407 module.WriteMemory(&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) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, module.ReadMemory(&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 module.WriteMemory(&memory[0], 66666666);
1487 memory[1] = 77777777; 1487 module.WriteMemory(&memory[1], 77777777);
1488 memory[2] = 88888888; 1488 module.WriteMemory(&memory[2], 88888888);
1489 memory[3] = 99999999; 1489 module.WriteMemory(&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, module.ReadMemory(&memory[0]));
1492 CHECK_EQ(i == 0 ? kWritten : 77777777, memory[1]); 1492 CHECK_EQ(i == 0 ? kWritten : 77777777, module.ReadMemory(&memory[1]));
1493 CHECK_EQ(i == 1 ? kWritten : 88888888, memory[2]); 1493 CHECK_EQ(i == 1 ? kWritten : 88888888, module.ReadMemory(&memory[2]));
1494 CHECK_EQ(i == 2 ? kWritten : 99999999, memory[3]); 1494 CHECK_EQ(i == 2 ? kWritten : 99999999, module.ReadMemory(&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(),
(...skipping 22 matching lines...) Expand all
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(module.ReadMemory(&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 += module.ReadMemory(&memory[j]);
1567 } 1567 }
1568 uint32_t result = r.Call(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
1579 BUILD(r, kExprLoop, kExprGetLocal, 0, kExprIf, kExprGetLocal, 0, 1579 BUILD(r, kExprLoop, kExprGetLocal, 0, kExprIf, kExprGetLocal, 0,
1580 kExprI32LoadMem, 0, 0, kExprIf, kExprI8Const, 255, kExprReturn, ARITY_1, 1580 kExprI32LoadMem, 0, 0, kExprIf, kExprI8Const, 255, kExprReturn, ARITY_1,
1581 kExprEnd, kExprGetLocal, 0, kExprI8Const, 4, kExprI32Sub, kExprSetLocal, 1581 kExprEnd, kExprGetLocal, 0, kExprI8Const, 4, kExprI32Sub, kExprSetLocal,
1582 0, kExprBr, ARITY_1, DEPTH_0, kExprEnd, kExprEnd, kExprI8Const, 0); 1582 0, kExprBr, ARITY_1, DEPTH_0, kExprEnd, kExprEnd, kExprI8Const, 0);
1583 1583
1584 module.BlankMemory(); 1584 module.BlankMemory();
1585 CHECK_EQ(0, r.Call((kNumElems - 1) * 4)); 1585 CHECK_EQ(0, r.Call((kNumElems - 1) * 4));
1586 } 1586 }
1587 1587
1588 WASM_EXEC_TEST(MemF32_Sum) { 1588 WASM_EXEC_TEST(MemF32_Sum) {
1589 const int kSize = 5; 1589 const int kSize = 5;
1590 TestingModule module(execution_mode); 1590 TestingModule module(execution_mode);
1591 module.AddMemoryElems<float>(kSize); 1591 module.AddMemoryElems<float>(kSize);
1592 float* buffer = module.raw_mem_start<float>(); 1592 float* buffer = module.raw_mem_start<float>();
1593 buffer[0] = -99.25; 1593 module.WriteMemory(&buffer[0], -99.25f);
1594 buffer[1] = -888.25; 1594 module.WriteMemory(&buffer[1], -888.25f);
1595 buffer[2] = -77.25; 1595 module.WriteMemory(&buffer[2], -77.25f);
1596 buffer[3] = 66666.25; 1596 module.WriteMemory(&buffer[3], 66666.25f);
1597 buffer[4] = 5555.25; 1597 module.WriteMemory(&buffer[4], 5555.25f);
1598 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1598 WasmRunner<int32_t> r(&module, MachineType::Int32());
1599 const byte kSum = r.AllocateLocal(kAstF32); 1599 const byte kSum = r.AllocateLocal(kAstF32);
1600 1600
1601 BUILD(r, WASM_BLOCK( 1601 BUILD(r, WASM_BLOCK(
1602 3, WASM_WHILE( 1602 3, WASM_WHILE(
1603 WASM_GET_LOCAL(0), 1603 WASM_GET_LOCAL(0),
1604 WASM_BLOCK( 1604 WASM_BLOCK(
1605 2, WASM_SET_LOCAL( 1605 2, WASM_SET_LOCAL(
1606 kSum, WASM_F32_ADD( 1606 kSum, WASM_F32_ADD(
1607 WASM_GET_LOCAL(kSum), 1607 WASM_GET_LOCAL(kSum),
1608 WASM_LOAD_MEM(MachineType::Float32(), 1608 WASM_LOAD_MEM(MachineType::Float32(),
1609 WASM_GET_LOCAL(0)))), 1609 WASM_GET_LOCAL(0)))),
1610 WASM_SET_LOCAL( 1610 WASM_SET_LOCAL(
1611 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(4))))), 1611 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(4))))),
1612 WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, 1612 WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO,
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.25f, module.ReadMemory(&buffer[0]));
1618 CHECK_EQ(71256.0f, buffer[0]); 1618 CHECK_EQ(71256.0f, module.ReadMemory(&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, uint32_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 T* memory = module.AddMemoryElems<T>(size);
1627 for (uint32_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.WriteMemory(&memory[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(
1638 WASM_GET_LOCAL(0), 1638 WASM_GET_LOCAL(0),
1639 WASM_BLOCK( 1639 WASM_BLOCK(
1640 2, WASM_SET_LOCAL( 1640 2, WASM_SET_LOCAL(
1641 kAccum, 1641 kAccum,
1642 WASM_BINOP(binop, WASM_GET_LOCAL(kAccum), 1642 WASM_BINOP(binop, WASM_GET_LOCAL(kAccum),
1643 WASM_LOAD_MEM(memType, WASM_GET_LOCAL(0)))), 1643 WASM_LOAD_MEM(memType, WASM_GET_LOCAL(0)))),
1644 WASM_SET_LOCAL( 1644 WASM_SET_LOCAL(
1645 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(sizeof(T)))))), 1645 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(sizeof(T)))))),
1646 WASM_STORE_MEM(memType, WASM_ZERO, WASM_GET_LOCAL(kAccum)), 1646 WASM_STORE_MEM(memType, WASM_ZERO, WASM_GET_LOCAL(kAccum)),
1647 WASM_GET_LOCAL(0))); 1647 WASM_GET_LOCAL(0)));
1648 r.Call(static_cast<int>(sizeof(T) * (size - 1))); 1648 r.Call(static_cast<int>(sizeof(T) * (size - 1)));
1649 return module.raw_mem_at<double>(0); 1649 return module.ReadMemory(&memory[0]);
1650 } 1650 }
1651 1651
1652 WASM_EXEC_TEST(MemF64_Mul) { 1652 WASM_EXEC_TEST(MemF64_Mul) {
1653 const size_t kSize = 6; 1653 const size_t kSize = 6;
1654 double buffer[kSize] = {1, 2, 2, 2, 2, 2}; 1654 double buffer[kSize] = {1, 2, 2, 2, 2, 2};
1655 double result = 1655 double result =
1656 GenerateAndRunFold<double>(execution_mode, kExprF64Mul, buffer, kSize, 1656 GenerateAndRunFold<double>(execution_mode, kExprF64Mul, buffer, kSize,
1657 kAstF64, MachineType::Float64()); 1657 kAstF64, MachineType::Float64());
1658 CHECK_EQ(32, result); 1658 CHECK_EQ(32, result);
1659 } 1659 }
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
2032 WASM_F64(32.5), WASM_F64(64.5), WASM_F64(128.5), 2032 WASM_F64(32.5), WASM_F64(64.5), WASM_F64(128.5),
2033 WASM_F64(256.5), WASM_F64(512.5))); 2033 WASM_F64(256.5), WASM_F64(512.5)));
2034 2034
2035 float result = r.Call(); 2035 float result = r.Call();
2036 CHECK_EQ(256.5, result); 2036 CHECK_EQ(256.5, result);
2037 } 2037 }
2038 2038
2039 WASM_EXEC_TEST(CallVoid) { 2039 WASM_EXEC_TEST(CallVoid) {
2040 const byte kMemOffset = 8; 2040 const byte kMemOffset = 8;
2041 const int32_t kElemNum = kMemOffset / sizeof(int32_t); 2041 const int32_t kElemNum = kMemOffset / sizeof(int32_t);
2042 const int32_t kExpected = -414444; 2042 const int32_t kExpected = 414444;
2043 // Build the target function. 2043 // Build the target function.
2044 TestSignatures sigs; 2044 TestSignatures sigs;
2045 TestingModule module(execution_mode); 2045 TestingModule module(execution_mode);
2046 module.AddMemory(16); 2046 int32_t* memory = module.AddMemoryElems<int32_t>(16 / sizeof(int32_t));
2047 module.RandomizeMemory(); 2047 module.RandomizeMemory();
2048 WasmFunctionCompiler t(sigs.v_v(), &module); 2048 WasmFunctionCompiler t(sigs.v_v(), &module);
2049 BUILD(t, WASM_STORE_MEM(MachineType::Int32(), WASM_I8(kMemOffset), 2049 BUILD(t, WASM_STORE_MEM(MachineType::Int32(), WASM_I8(kMemOffset),
2050 WASM_I32V_3(kExpected))); 2050 WASM_I32V_3(kExpected)));
2051 uint32_t index = t.CompileAndAdd(); 2051 uint32_t index = t.CompileAndAdd();
2052 2052
2053 // Build the calling function. 2053 // Build the calling function.
2054 WasmRunner<int32_t> r(&module); 2054 WasmRunner<int32_t> r(&module);
2055 BUILD(r, WASM_CALL_FUNCTION0(index), 2055 BUILD(r, WASM_CALL_FUNCTION0(index),
2056 WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(kMemOffset))); 2056 WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(kMemOffset)));
2057 2057
2058 int32_t result = r.Call(); 2058 int32_t result = r.Call();
2059 CHECK_EQ(kExpected, result); 2059 CHECK_EQ(kExpected, result);
2060 CHECK_EQ(kExpected, module.raw_mem_start<int32_t>()[kElemNum]); 2060 CHECK_EQ(static_cast<int64_t>(kExpected),
2061 static_cast<int64_t>(module.ReadMemory(&memory[kElemNum])));
2061 } 2062 }
2062 2063
2063 WASM_EXEC_TEST(Call_Int32Add) { 2064 WASM_EXEC_TEST(Call_Int32Add) {
2064 // Build the target function. 2065 // Build the target function.
2065 TestSignatures sigs; 2066 TestSignatures sigs;
2066 TestingModule module(execution_mode); 2067 TestingModule module(execution_mode);
2067 WasmFunctionCompiler t(sigs.i_ii(), &module); 2068 WasmFunctionCompiler t(sigs.i_ii(), &module);
2068 BUILD(t, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 2069 BUILD(t, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
2069 uint32_t index = t.CompileAndAdd(); 2070 uint32_t index = t.CompileAndAdd();
2070 2071
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2107 BUILD(r, WASM_BLOCK( 2108 BUILD(r, WASM_BLOCK(
2108 2, WASM_STORE_MEM( 2109 2, WASM_STORE_MEM(
2109 MachineType::Float64(), WASM_ZERO, 2110 MachineType::Float64(), WASM_ZERO,
2110 WASM_F64_SUB( 2111 WASM_F64_SUB(
2111 WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO), 2112 WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO),
2112 WASM_LOAD_MEM(MachineType::Float64(), WASM_I8(8)))), 2113 WASM_LOAD_MEM(MachineType::Float64(), WASM_I8(8)))),
2113 WASM_I8(107))); 2114 WASM_I8(107)));
2114 2115
2115 FOR_FLOAT64_INPUTS(i) { 2116 FOR_FLOAT64_INPUTS(i) {
2116 FOR_FLOAT64_INPUTS(j) { 2117 FOR_FLOAT64_INPUTS(j) {
2117 memory[0] = *i; 2118 module.WriteMemory(&memory[0], *i);
2118 memory[1] = *j; 2119 module.WriteMemory(&memory[1], *j);
2119 double expected = *i - *j; 2120 double expected = *i - *j;
2120 CHECK_EQ(107, r.Call()); 2121 CHECK_EQ(107, r.Call());
2122
2121 if (expected != expected) { 2123 if (expected != expected) {
2122 CHECK(memory[0] != memory[0]); 2124 CHECK(module.ReadMemory(&memory[0]) != module.ReadMemory(&memory[0]));
2123 } else { 2125 } else {
2124 CHECK_EQ(expected, memory[0]); 2126 CHECK_EQ(expected, module.ReadMemory(&memory[0]));
2125 } 2127 }
2126 } 2128 }
2127 } 2129 }
2128 } 2130 }
2129 2131
2130 #define ADD_CODE(vec, ...) \ 2132 #define ADD_CODE(vec, ...) \
2131 do { \ 2133 do { \
2132 byte __buf[] = {__VA_ARGS__}; \ 2134 byte __buf[] = {__VA_ARGS__}; \
2133 for (size_t i = 0; i < sizeof(__buf); ++i) vec.push_back(__buf[i]); \ 2135 for (size_t i = 0; i < sizeof(__buf); ++i) vec.push_back(__buf[i]); \
2134 } while (false) 2136 } while (false)
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
2814 MachineType::Int32()); 2816 MachineType::Int32());
2815 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_ZERO); 2817 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(); 2818 const int32_t kMin = std::numeric_limits<int32_t>::min();
2817 CHECK_EQ(0, r.Call(133, 100)); 2819 CHECK_EQ(0, r.Call(133, 100));
2818 CHECK_EQ(0, r.Call(kMin, -1)); 2820 CHECK_EQ(0, r.Call(kMin, -1));
2819 CHECK_EQ(0, r.Call(0, 1)); 2821 CHECK_EQ(0, r.Call(0, 1));
2820 CHECK_TRAP(r.Call(100, 0)); 2822 CHECK_TRAP(r.Call(100, 0));
2821 CHECK_TRAP(r.Call(-1001, 0)); 2823 CHECK_TRAP(r.Call(-1001, 0));
2822 CHECK_TRAP(r.Call(kMin, 0)); 2824 CHECK_TRAP(r.Call(kMin, 0));
2823 } 2825 }
OLDNEW
« no previous file with comments | « test/cctest/cctest.status ('k') | test/cctest/wasm/test-run-wasm-64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698