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

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

Issue 1928513002: Implement UnalignedLoad and UnalignedStore in WASM using LoadByte/Shift/Or and StoreByte/Shift/And. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Renamed UnalignedAccessConfig to AlignmentRequirements Created 4 years, 7 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
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 1286 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 memory[0] = 99999999; 1297 memory[0] = 99999999;
1298 CHECK_EQ(99999999, r.Call(0)); 1298 CHECK_EQ(99999999, r.Call(0));
1299 1299
1300 memory[0] = 88888888; 1300 memory[0] = 88888888;
1301 CHECK_EQ(88888888, r.Call(0)); 1301 CHECK_EQ(88888888, r.Call(0));
1302 1302
1303 memory[0] = 77777777; 1303 memory[0] = 77777777;
1304 CHECK_EQ(77777777, r.Call(0)); 1304 CHECK_EQ(77777777, r.Call(0));
1305 } 1305 }
1306 1306
1307 TEST(Run_Wasm_LoadMemI32_alignment) {
titzer 2016/05/11 15:22:35 Can you move this into test-run-load-store.cc?
ivica.bogosavljevic 2016/05/12 12:09:55 This test cannot be moved to test-run-load-store.c
titzer 2016/05/17 11:57:39 Acknowledged.
1308 TestingModule module;
1309 int32_t* memory = module.AddMemoryElems<int32_t>(8);
1310 for (byte alignment = 0; alignment <= 2; alignment++) {
1311 WasmRunner<int32_t> r(&module, MachineType::Int32());
1312 module.RandomizeMemory(1111);
1313
1314 BUILD(r,
1315 WASM_LOAD_MEM_ALIGNMENT(MachineType::Int32(), WASM_I8(0), alignment));
1316
1317 memory[0] = 0x1a2b3c4d;
1318 CHECK_EQ(0x1a2b3c4d, r.Call(0));
1319
1320 memory[0] = 0x5e6f7a8b;
1321 CHECK_EQ(0x5e6f7a8b, r.Call(0));
1322
1323 memory[0] = 0x9ca0b1c2;
1324 CHECK_EQ(0x9ca0b1c2, r.Call(0));
1325 }
1326 }
1307 1327
1308 TEST(Run_Wasm_LoadMemI32_oob) { 1328 TEST(Run_Wasm_LoadMemI32_oob) {
1309 TestingModule module; 1329 TestingModule module;
1310 int32_t* memory = module.AddMemoryElems<int32_t>(8); 1330 int32_t* memory = module.AddMemoryElems<int32_t>(8);
1311 WasmRunner<int32_t> r(&module, MachineType::Uint32()); 1331 WasmRunner<int32_t> r(&module, MachineType::Uint32());
1312 module.RandomizeMemory(1111); 1332 module.RandomizeMemory(1111);
1313 1333
1314 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))); 1334 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0)));
1315 1335
1316 memory[0] = 88888888; 1336 memory[0] = 88888888;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1393 memory[0] = 11111111; 1413 memory[0] = 11111111;
1394 memory[1] = 22222222; 1414 memory[1] = 22222222;
1395 memory[2] = 33333333; 1415 memory[2] = 33333333;
1396 memory[3] = 44444444; 1416 memory[3] = 44444444;
1397 CHECK_EQ(22222222, r.Call(0)); 1417 CHECK_EQ(22222222, r.Call(0));
1398 CHECK_EQ(33333333, r.Call(4)); 1418 CHECK_EQ(33333333, r.Call(4));
1399 CHECK_EQ(44444444, r.Call(8)); 1419 CHECK_EQ(44444444, r.Call(8));
1400 } 1420 }
1401 1421
1402 1422
1403 #if !V8_TARGET_ARCH_MIPS && !V8_TARGET_ARCH_MIPS64
1404
1405 TEST(Run_Wasm_LoadMemI32_const_oob_misaligned) { 1423 TEST(Run_Wasm_LoadMemI32_const_oob_misaligned) {
1406 const int kMemSize = 12; 1424 const int kMemSize = 12;
1407 // TODO(titzer): Fix misaligned accesses on MIPS and re-enable. 1425 // TODO(titzer): Fix misaligned accesses on MIPS and re-enable.
1408 for (int offset = 0; offset < kMemSize + 5; offset++) { 1426 for (int offset = 0; offset < kMemSize + 5; offset++) {
1409 for (int index = 0; index < kMemSize + 5; index++) { 1427 for (int index = 0; index < kMemSize + 5; index++) {
1410 TestingModule module; 1428 TestingModule module;
1411 module.AddMemoryElems<byte>(kMemSize); 1429 module.AddMemoryElems<byte>(kMemSize);
1412 1430
1413 WasmRunner<int32_t> r(&module); 1431 WasmRunner<int32_t> r(&module);
1414 module.RandomizeMemory(); 1432 module.RandomizeMemory();
1415 1433
1416 BUILD(r, 1434 BUILD(r,
1417 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index))); 1435 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index)));
1418 1436
1419 if ((offset + index) <= (kMemSize - sizeof(int32_t))) { 1437 if ((offset + index) <= (kMemSize - sizeof(int32_t))) {
1420 CHECK_EQ(module.raw_val_at<int32_t>(offset + index), r.Call()); 1438 CHECK_EQ(module.raw_val_at<int32_t>(offset + index), r.Call());
1421 } else { 1439 } else {
1422 CHECK_TRAP(r.Call()); 1440 CHECK_TRAP(r.Call());
1423 } 1441 }
1424 } 1442 }
1425 } 1443 }
1426 } 1444 }
1427 1445
1428 #endif
1429
1430 1446
1431 TEST(Run_Wasm_LoadMemI32_const_oob) { 1447 TEST(Run_Wasm_LoadMemI32_const_oob) {
1432 const int kMemSize = 24; 1448 const int kMemSize = 24;
1433 for (int offset = 0; offset < kMemSize + 5; offset += 4) { 1449 for (int offset = 0; offset < kMemSize + 5; offset += 4) {
1434 for (int index = 0; index < kMemSize + 5; index += 4) { 1450 for (int index = 0; index < kMemSize + 5; index += 4) {
1435 TestingModule module; 1451 TestingModule module;
1436 module.AddMemoryElems<byte>(kMemSize); 1452 module.AddMemoryElems<byte>(kMemSize);
1437 1453
1438 WasmRunner<int32_t> r(&module); 1454 WasmRunner<int32_t> r(&module);
1439 module.RandomizeMemory(); 1455 module.RandomizeMemory();
1440 1456
1441 BUILD(r, 1457 BUILD(r,
1442 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index))); 1458 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index)));
1443 1459
1444 if ((offset + index) <= (kMemSize - sizeof(int32_t))) { 1460 if ((offset + index) <= (kMemSize - sizeof(int32_t))) {
1445 CHECK_EQ(module.raw_val_at<int32_t>(offset + index), r.Call()); 1461 CHECK_EQ(module.raw_val_at<int32_t>(offset + index), r.Call());
1446 } else { 1462 } else {
1447 CHECK_TRAP(r.Call()); 1463 CHECK_TRAP(r.Call());
1448 } 1464 }
1449 } 1465 }
1450 } 1466 }
1451 } 1467 }
1452 1468
1469 TEST(Run_Wasm_StoreMemI32_alignment) {
1470 TestingModule module;
1471 int32_t* memory = module.AddMemoryElems<int32_t>(4);
1472 const int32_t kWritten = 0x12345678;
1473
1474 for (byte i = 0; i <= 2; i++) {
1475 WasmRunner<int32_t> r(&module, MachineType::Int32());
1476 BUILD(r, WASM_STORE_MEM_ALIGNMENT(MachineType::Int32(), WASM_ZERO, i,
1477 WASM_GET_LOCAL(0)));
1478 module.RandomizeMemory(1111);
1479 memory[0] = 0;
1480
1481 CHECK_EQ(kWritten, r.Call(kWritten));
1482 CHECK_EQ(kWritten, memory[0]);
1483 }
1484 }
1453 1485
1454 TEST(Run_Wasm_StoreMemI32_offset) { 1486 TEST(Run_Wasm_StoreMemI32_offset) {
1455 TestingModule module; 1487 TestingModule module;
1456 int32_t* memory = module.AddMemoryElems<int32_t>(4); 1488 int32_t* memory = module.AddMemoryElems<int32_t>(4);
1457 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1489 WasmRunner<int32_t> r(&module, MachineType::Int32());
1458 const int32_t kWritten = 0xaabbccdd; 1490 const int32_t kWritten = 0xaabbccdd;
1459 1491
1460 BUILD(r, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0), 1492 BUILD(r, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0),
1461 WASM_I32V_5(kWritten))); 1493 WASM_I32V_5(kWritten)));
1462 1494
(...skipping 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after
2861 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); 2893 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
2862 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_ZERO); 2894 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_ZERO);
2863 const int32_t kMin = std::numeric_limits<int32_t>::min(); 2895 const int32_t kMin = std::numeric_limits<int32_t>::min();
2864 CHECK_EQ(0, r.Call(133, 100)); 2896 CHECK_EQ(0, r.Call(133, 100));
2865 CHECK_EQ(0, r.Call(kMin, -1)); 2897 CHECK_EQ(0, r.Call(kMin, -1));
2866 CHECK_EQ(0, r.Call(0, 1)); 2898 CHECK_EQ(0, r.Call(0, 1));
2867 CHECK_TRAP(r.Call(100, 0)); 2899 CHECK_TRAP(r.Call(100, 0));
2868 CHECK_TRAP(r.Call(-1001, 0)); 2900 CHECK_TRAP(r.Call(-1001, 0));
2869 CHECK_TRAP(r.Call(kMin, 0)); 2901 CHECK_TRAP(r.Call(kMin, 0));
2870 } 2902 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698