OLD | NEW |
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 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1280 memory[0] = 99999999; | 1280 memory[0] = 99999999; |
1281 CHECK_EQ(99999999, r.Call(0)); | 1281 CHECK_EQ(99999999, r.Call(0)); |
1282 | 1282 |
1283 memory[0] = 88888888; | 1283 memory[0] = 88888888; |
1284 CHECK_EQ(88888888, r.Call(0)); | 1284 CHECK_EQ(88888888, r.Call(0)); |
1285 | 1285 |
1286 memory[0] = 77777777; | 1286 memory[0] = 77777777; |
1287 CHECK_EQ(77777777, r.Call(0)); | 1287 CHECK_EQ(77777777, r.Call(0)); |
1288 } | 1288 } |
1289 | 1289 |
1290 WASM_EXEC_TEST(LoadMemI32_oob) { | 1290 WASM_EXEC_TEST(Run_Wasm_LoadMemI32_alignment) { |
| 1291 TestingModule module; |
| 1292 int32_t* memory = module.AddMemoryElems<int32_t>(8); |
| 1293 for (byte alignment = 0; alignment <= 2; alignment++) { |
| 1294 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
| 1295 module.RandomizeMemory(1111); |
| 1296 |
| 1297 BUILD(r, |
| 1298 WASM_LOAD_MEM_ALIGNMENT(MachineType::Int32(), WASM_I8(0), alignment)); |
| 1299 |
| 1300 memory[0] = 0x1a2b3c4d; |
| 1301 CHECK_EQ(0x1a2b3c4d, r.Call(0)); |
| 1302 |
| 1303 memory[0] = 0x5e6f7a8b; |
| 1304 CHECK_EQ(0x5e6f7a8b, r.Call(0)); |
| 1305 |
| 1306 memory[0] = 0x9ca0b1c2; |
| 1307 CHECK_EQ(0x9ca0b1c2, r.Call(0)); |
| 1308 } |
| 1309 } |
| 1310 |
| 1311 WASM_EXEC_TEST(Run_Wasm_LoadMemI32_oob) { |
1291 TestingModule module; | 1312 TestingModule module; |
1292 int32_t* memory = module.AddMemoryElems<int32_t>(8); | 1313 int32_t* memory = module.AddMemoryElems<int32_t>(8); |
1293 WasmRunner<int32_t> r(&module, MachineType::Uint32()); | 1314 WasmRunner<int32_t> r(&module, MachineType::Uint32()); |
1294 module.RandomizeMemory(1111); | 1315 module.RandomizeMemory(1111); |
1295 | 1316 |
1296 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))); | 1317 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))); |
1297 | 1318 |
1298 memory[0] = 88888888; | 1319 memory[0] = 88888888; |
1299 CHECK_EQ(88888888, r.Call(0u)); | 1320 CHECK_EQ(88888888, r.Call(0u)); |
1300 for (uint32_t offset = 29; offset < 40; offset++) { | 1321 for (uint32_t offset = 29; offset < 40; offset++) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1350 | 1371 |
1351 memory[0] = 11111111; | 1372 memory[0] = 11111111; |
1352 memory[1] = 22222222; | 1373 memory[1] = 22222222; |
1353 memory[2] = 33333333; | 1374 memory[2] = 33333333; |
1354 memory[3] = 44444444; | 1375 memory[3] = 44444444; |
1355 CHECK_EQ(22222222, r.Call(0)); | 1376 CHECK_EQ(22222222, r.Call(0)); |
1356 CHECK_EQ(33333333, r.Call(4)); | 1377 CHECK_EQ(33333333, r.Call(4)); |
1357 CHECK_EQ(44444444, r.Call(8)); | 1378 CHECK_EQ(44444444, r.Call(8)); |
1358 } | 1379 } |
1359 | 1380 |
1360 #if !V8_TARGET_ARCH_MIPS && !V8_TARGET_ARCH_MIPS64 | 1381 WASM_EXEC_TEST(Run_Wasm_LoadMemI32_const_oob_misaligned) { |
1361 | |
1362 WASM_EXEC_TEST(LoadMemI32_const_oob_misaligned) { | |
1363 const int kMemSize = 12; | 1382 const int kMemSize = 12; |
1364 // TODO(titzer): Fix misaligned accesses on MIPS and re-enable. | 1383 // TODO(titzer): Fix misaligned accesses on MIPS and re-enable. |
1365 for (int offset = 0; offset < kMemSize + 5; offset++) { | 1384 for (int offset = 0; offset < kMemSize + 5; offset++) { |
1366 for (int index = 0; index < kMemSize + 5; index++) { | 1385 for (int index = 0; index < kMemSize + 5; index++) { |
1367 TestingModule module; | 1386 TestingModule module; |
1368 module.AddMemoryElems<byte>(kMemSize); | 1387 module.AddMemoryElems<byte>(kMemSize); |
1369 | 1388 |
1370 WasmRunner<int32_t> r(&module); | 1389 WasmRunner<int32_t> r(&module); |
1371 module.RandomizeMemory(); | 1390 module.RandomizeMemory(); |
1372 | 1391 |
1373 BUILD(r, | 1392 BUILD(r, |
1374 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index))); | 1393 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index))); |
1375 | 1394 |
1376 if ((offset + index) <= (kMemSize - sizeof(int32_t))) { | 1395 if ((offset + index) <= (kMemSize - sizeof(int32_t))) { |
1377 CHECK_EQ(module.raw_val_at<int32_t>(offset + index), r.Call()); | 1396 CHECK_EQ(module.raw_val_at<int32_t>(offset + index), r.Call()); |
1378 } else { | 1397 } else { |
1379 CHECK_TRAP(r.Call()); | 1398 CHECK_TRAP(r.Call()); |
1380 } | 1399 } |
1381 } | 1400 } |
1382 } | 1401 } |
1383 } | 1402 } |
1384 | 1403 |
1385 #endif | 1404 WASM_EXEC_TEST(Run_Wasm_LoadMemI32_const_oob) { |
1386 | |
1387 WASM_EXEC_TEST(LoadMemI32_const_oob) { | |
1388 const int kMemSize = 24; | 1405 const int kMemSize = 24; |
1389 for (int offset = 0; offset < kMemSize + 5; offset += 4) { | 1406 for (int offset = 0; offset < kMemSize + 5; offset += 4) { |
1390 for (int index = 0; index < kMemSize + 5; index += 4) { | 1407 for (int index = 0; index < kMemSize + 5; index += 4) { |
1391 TestingModule module; | 1408 TestingModule module; |
1392 module.AddMemoryElems<byte>(kMemSize); | 1409 module.AddMemoryElems<byte>(kMemSize); |
1393 | 1410 |
1394 WasmRunner<int32_t> r(&module); | 1411 WasmRunner<int32_t> r(&module); |
1395 module.RandomizeMemory(); | 1412 module.RandomizeMemory(); |
1396 | 1413 |
1397 BUILD(r, | 1414 BUILD(r, |
1398 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index))); | 1415 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index))); |
1399 | 1416 |
1400 if ((offset + index) <= (kMemSize - sizeof(int32_t))) { | 1417 if ((offset + index) <= (kMemSize - sizeof(int32_t))) { |
1401 CHECK_EQ(module.raw_val_at<int32_t>(offset + index), r.Call()); | 1418 CHECK_EQ(module.raw_val_at<int32_t>(offset + index), r.Call()); |
1402 } else { | 1419 } else { |
1403 CHECK_TRAP(r.Call()); | 1420 CHECK_TRAP(r.Call()); |
1404 } | 1421 } |
1405 } | 1422 } |
1406 } | 1423 } |
1407 } | 1424 } |
1408 | 1425 |
1409 WASM_EXEC_TEST(StoreMemI32_offset) { | 1426 WASM_EXEC_TEST(Run_Wasm_StoreMemI32_alignment) { |
| 1427 TestingModule module; |
| 1428 int32_t* memory = module.AddMemoryElems<int32_t>(4); |
| 1429 const int32_t kWritten = 0x12345678; |
| 1430 |
| 1431 for (byte i = 0; i <= 2; i++) { |
| 1432 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
| 1433 BUILD(r, WASM_STORE_MEM_ALIGNMENT(MachineType::Int32(), WASM_ZERO, i, |
| 1434 WASM_GET_LOCAL(0))); |
| 1435 module.RandomizeMemory(1111); |
| 1436 memory[0] = 0; |
| 1437 |
| 1438 CHECK_EQ(kWritten, r.Call(kWritten)); |
| 1439 CHECK_EQ(kWritten, memory[0]); |
| 1440 } |
| 1441 } |
| 1442 |
| 1443 WASM_EXEC_TEST(Run_Wasm_StoreMemI32_offset) { |
1410 TestingModule module; | 1444 TestingModule module; |
1411 int32_t* memory = module.AddMemoryElems<int32_t>(4); | 1445 int32_t* memory = module.AddMemoryElems<int32_t>(4); |
1412 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1446 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1413 const int32_t kWritten = 0xaabbccdd; | 1447 const int32_t kWritten = 0xaabbccdd; |
1414 | 1448 |
1415 BUILD(r, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0), | 1449 BUILD(r, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0), |
1416 WASM_I32V_5(kWritten))); | 1450 WASM_I32V_5(kWritten))); |
1417 | 1451 |
1418 for (int i = 0; i < 2; i++) { | 1452 for (int i = 0; i < 2; i++) { |
1419 module.RandomizeMemory(1111); | 1453 module.RandomizeMemory(1111); |
(...skipping 1335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2755 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 2789 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); |
2756 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_ZERO); | 2790 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_ZERO); |
2757 const int32_t kMin = std::numeric_limits<int32_t>::min(); | 2791 const int32_t kMin = std::numeric_limits<int32_t>::min(); |
2758 CHECK_EQ(0, r.Call(133, 100)); | 2792 CHECK_EQ(0, r.Call(133, 100)); |
2759 CHECK_EQ(0, r.Call(kMin, -1)); | 2793 CHECK_EQ(0, r.Call(kMin, -1)); |
2760 CHECK_EQ(0, r.Call(0, 1)); | 2794 CHECK_EQ(0, r.Call(0, 1)); |
2761 CHECK_TRAP(r.Call(100, 0)); | 2795 CHECK_TRAP(r.Call(100, 0)); |
2762 CHECK_TRAP(r.Call(-1001, 0)); | 2796 CHECK_TRAP(r.Call(-1001, 0)); |
2763 CHECK_TRAP(r.Call(kMin, 0)); | 2797 CHECK_TRAP(r.Call(kMin, 0)); |
2764 } | 2798 } |
OLD | NEW |