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

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

Issue 2034093002: Implement WASM big-endian support (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add byte swapping TODO mark 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
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/bits.h" 9 #include "src/base/bits.h"
10 #include "src/wasm/wasm-macro-gen.h" 10 #include "src/wasm/wasm-macro-gen.h"
(...skipping 1220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 REQUIRE(I64ReinterpretF64); 1231 REQUIRE(I64ReinterpretF64);
1232 TestingModule module(execution_mode); 1232 TestingModule module(execution_mode);
1233 int64_t* memory = module.AddMemoryElems<int64_t>(8); 1233 int64_t* memory = module.AddMemoryElems<int64_t>(8);
1234 WasmRunner<int64_t> r(&module); 1234 WasmRunner<int64_t> r(&module);
1235 1235
1236 BUILD(r, WASM_I64_REINTERPRET_F64( 1236 BUILD(r, WASM_I64_REINTERPRET_F64(
1237 WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO))); 1237 WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO)));
1238 1238
1239 FOR_INT32_INPUTS(i) { 1239 FOR_INT32_INPUTS(i) {
1240 int64_t expected = static_cast<int64_t>(*i) * 0x300010001; 1240 int64_t expected = static_cast<int64_t>(*i) * 0x300010001;
1241 memory[0] = expected; 1241 module.WriteMemory(&memory[0], expected);
1242 CHECK_EQ(expected, r.Call()); 1242 CHECK_EQ(expected, r.Call());
1243 } 1243 }
1244 } 1244 }
1245 1245
1246 WASM_EXEC_TEST(F64ReinterpretI64) { 1246 WASM_EXEC_TEST(F64ReinterpretI64) {
1247 REQUIRE(F64ReinterpretI64); 1247 REQUIRE(F64ReinterpretI64);
1248 TestingModule module(execution_mode); 1248 TestingModule module(execution_mode);
1249 int64_t* memory = module.AddMemoryElems<int64_t>(8); 1249 int64_t* memory = module.AddMemoryElems<int64_t>(8);
1250 WasmRunner<int64_t> r(&module, MachineType::Int64()); 1250 WasmRunner<int64_t> r(&module, MachineType::Int64());
1251 1251
1252 BUILD(r, WASM_BLOCK( 1252 BUILD(r, WASM_BLOCK(
1253 2, WASM_STORE_MEM(MachineType::Float64(), WASM_ZERO, 1253 2, WASM_STORE_MEM(MachineType::Float64(), WASM_ZERO,
1254 WASM_F64_REINTERPRET_I64(WASM_GET_LOCAL(0))), 1254 WASM_F64_REINTERPRET_I64(WASM_GET_LOCAL(0))),
1255 WASM_GET_LOCAL(0))); 1255 WASM_GET_LOCAL(0)));
1256 1256
1257 FOR_INT32_INPUTS(i) { 1257 FOR_INT32_INPUTS(i) {
1258 int64_t expected = static_cast<int64_t>(*i) * 0x300010001; 1258 int64_t expected = static_cast<int64_t>(*i) * 0x300010001;
1259 CHECK_EQ(expected, r.Call(expected)); 1259 CHECK_EQ(expected, r.Call(expected));
1260 CHECK_EQ(expected, memory[0]); 1260 CHECK_EQ(expected, module.ReadMemory<int64_t>(&memory[0]));
1261 } 1261 }
1262 } 1262 }
1263 1263
1264 WASM_EXEC_TEST(LoadMemI64) { 1264 WASM_EXEC_TEST(LoadMemI64) {
1265 REQUIRE(I64LoadStore); 1265 REQUIRE(I64LoadStore);
1266 TestingModule module(execution_mode); 1266 TestingModule module(execution_mode);
1267 int64_t* memory = module.AddMemoryElems<int64_t>(8); 1267 int64_t* memory = module.AddMemoryElems<int64_t>(8);
1268 module.RandomizeMemory(1111); 1268 module.RandomizeMemory(1111);
1269 WasmRunner<int64_t> r(&module); 1269 WasmRunner<int64_t> r(&module);
1270 1270
1271 BUILD(r, WASM_LOAD_MEM(MachineType::Int64(), WASM_I8(0))); 1271 BUILD(r, WASM_LOAD_MEM(MachineType::Int64(), WASM_I8(0)));
1272 1272
1273 memory[0] = 0xaabbccdd00112233LL; 1273 module.WriteMemory<int64_t>(&memory[0], 0xaabbccdd00112233LL);
1274 CHECK_EQ(0xaabbccdd00112233LL, r.Call()); 1274 CHECK_EQ(0xaabbccdd00112233LL, r.Call());
1275 1275
1276 memory[0] = 0x33aabbccdd001122LL; 1276 module.WriteMemory<int64_t>(&memory[0], 0x33aabbccdd001122LL);
1277 CHECK_EQ(0x33aabbccdd001122LL, r.Call()); 1277 CHECK_EQ(0x33aabbccdd001122LL, r.Call());
1278 1278
1279 memory[0] = 77777777; 1279 module.WriteMemory<int64_t>(&memory[0], 77777777);
1280 CHECK_EQ(77777777, r.Call()); 1280 CHECK_EQ(77777777, r.Call());
1281 } 1281 }
1282 1282
1283 WASM_EXEC_TEST(LoadMemI64_alignment) { 1283 WASM_EXEC_TEST(LoadMemI64_alignment) {
1284 REQUIRE(I64LoadStore); 1284 REQUIRE(I64LoadStore);
1285 TestingModule module(execution_mode); 1285 TestingModule module(execution_mode);
1286 int64_t* memory = module.AddMemoryElems<int64_t>(8); 1286 int64_t* memory = module.AddMemoryElems<int64_t>(8);
1287 for (byte alignment = 0; alignment <= 3; alignment++) { 1287 for (byte alignment = 0; alignment <= 3; alignment++) {
1288 module.RandomizeMemory(1111); 1288 module.RandomizeMemory(1111);
1289 WasmRunner<int64_t> r(&module); 1289 WasmRunner<int64_t> r(&module);
1290 1290
1291 BUILD(r, 1291 BUILD(r,
1292 WASM_LOAD_MEM_ALIGNMENT(MachineType::Int64(), WASM_I8(0), alignment)); 1292 WASM_LOAD_MEM_ALIGNMENT(MachineType::Int64(), WASM_I8(0), alignment));
1293 1293
1294 memory[0] = 0xaabbccdd00112233LL; 1294 module.WriteMemory<int64_t>(&memory[0], 0xaabbccdd00112233LL);
1295 CHECK_EQ(0xaabbccdd00112233LL, r.Call()); 1295 CHECK_EQ(0xaabbccdd00112233LL, r.Call());
1296 1296
1297 memory[0] = 0x33aabbccdd001122LL; 1297 module.WriteMemory<int64_t>(&memory[0], 0x33aabbccdd001122LL);
1298 CHECK_EQ(0x33aabbccdd001122LL, r.Call()); 1298 CHECK_EQ(0x33aabbccdd001122LL, r.Call());
1299 1299
1300 memory[0] = 77777777; 1300 module.WriteMemory<int64_t>(&memory[0], 77777777);
1301 CHECK_EQ(77777777, r.Call()); 1301 CHECK_EQ(77777777, r.Call());
1302 } 1302 }
1303 } 1303 }
1304 1304
1305 WASM_EXEC_TEST(MemI64_Sum) { 1305 WASM_EXEC_TEST(MemI64_Sum) {
1306 REQUIRE(I64LoadStore); 1306 REQUIRE(I64LoadStore);
1307 REQUIRE(I64Add); 1307 REQUIRE(I64Add);
1308 REQUIRE(I64Sub); 1308 REQUIRE(I64Sub);
1309 REQUIRE(I64Phi); 1309 REQUIRE(I64Phi);
1310 const int kNumElems = 20; 1310 const int kNumElems = 20;
(...skipping 13 matching lines...) Expand all
1324 WASM_GET_LOCAL(0)))), 1324 WASM_GET_LOCAL(0)))),
1325 WASM_SET_LOCAL( 1325 WASM_SET_LOCAL(
1326 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(8))))), 1326 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(8))))),
1327 WASM_GET_LOCAL(1))); 1327 WASM_GET_LOCAL(1)));
1328 1328
1329 // Run 4 trials. 1329 // Run 4 trials.
1330 for (int i = 0; i < 3; i++) { 1330 for (int i = 0; i < 3; i++) {
1331 module.RandomizeMemory(i * 33); 1331 module.RandomizeMemory(i * 33);
1332 uint64_t expected = 0; 1332 uint64_t expected = 0;
1333 for (size_t j = kNumElems - 1; j > 0; j--) { 1333 for (size_t j = kNumElems - 1; j > 0; j--) {
1334 expected += memory[j]; 1334 expected += module.ReadMemory(&memory[j]);
1335 } 1335 }
1336 uint64_t result = r.Call(8 * (kNumElems - 1)); 1336 uint64_t result = r.Call(8 * (kNumElems - 1));
1337 CHECK_EQ(expected, result); 1337 CHECK_EQ(expected, result);
1338 } 1338 }
1339 } 1339 }
1340 1340
1341 WASM_EXEC_TEST(StoreMemI64_alignment) { 1341 WASM_EXEC_TEST(StoreMemI64_alignment) {
1342 TestingModule module(execution_mode); 1342 TestingModule module(execution_mode);
1343 int64_t* memory = module.AddMemoryElems<int64_t>(4); 1343 int64_t* memory = module.AddMemoryElems<int64_t>(4);
1344 const int64_t kWritten = 0x12345678abcd0011ll; 1344 const int64_t kWritten = 0x12345678abcd0011ll;
1345 1345
1346 for (byte i = 0; i <= 3; i++) { 1346 for (byte i = 0; i <= 3; i++) {
1347 WasmRunner<int64_t> r(&module, MachineType::Int64()); 1347 WasmRunner<int64_t> r(&module, MachineType::Int64());
1348 BUILD(r, WASM_STORE_MEM_ALIGNMENT(MachineType::Int64(), WASM_ZERO, i, 1348 BUILD(r, WASM_STORE_MEM_ALIGNMENT(MachineType::Int64(), WASM_ZERO, i,
1349 WASM_GET_LOCAL(0))); 1349 WASM_GET_LOCAL(0)));
1350 module.RandomizeMemory(1111); 1350 module.RandomizeMemory(1111);
1351 memory[0] = 0; 1351 module.WriteMemory<int64_t>(&memory[0], 0);
1352 1352
1353 CHECK_EQ(kWritten, r.Call(kWritten)); 1353 CHECK_EQ(kWritten, r.Call(kWritten));
1354 CHECK_EQ(kWritten, memory[0]); 1354 CHECK_EQ(kWritten, module.ReadMemory(&memory[0]));
1355 } 1355 }
1356 } 1356 }
1357 1357
1358 WASM_EXEC_TEST(I64Global) { 1358 WASM_EXEC_TEST(I64Global) {
1359 REQUIRE(I64LoadStore); 1359 REQUIRE(I64LoadStore);
1360 REQUIRE(I64SConvertI32); 1360 REQUIRE(I64SConvertI32);
1361 REQUIRE(I64And); 1361 REQUIRE(I64And);
1362 REQUIRE(DepthFirst); 1362 REQUIRE(DepthFirst);
1363 TestingModule module(execution_mode); 1363 TestingModule module(execution_mode);
1364 int64_t* global = module.AddGlobal<int64_t>(MachineType::Int64()); 1364 int64_t* global = module.AddGlobal<int64_t>(MachineType::Int64());
1365 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1365 WasmRunner<int32_t> r(&module, MachineType::Int32());
1366 // global = global + p0 1366 // global = global + p0
1367 BUILD(r, B2(WASM_STORE_GLOBAL( 1367 BUILD(r, B2(WASM_STORE_GLOBAL(
1368 0, WASM_I64_AND(WASM_LOAD_GLOBAL(0), 1368 0, WASM_I64_AND(WASM_LOAD_GLOBAL(0),
1369 WASM_I64_SCONVERT_I32(WASM_GET_LOCAL(0)))), 1369 WASM_I64_SCONVERT_I32(WASM_GET_LOCAL(0)))),
1370 WASM_ZERO)); 1370 WASM_ZERO));
1371 1371
1372 *global = 0xFFFFFFFFFFFFFFFFLL; 1372 module.WriteMemory<int64_t>(global, 0xFFFFFFFFFFFFFFFFLL);
1373 for (int i = 9; i < 444444; i += 111111) { 1373 for (int i = 9; i < 444444; i += 111111) {
1374 int64_t expected = *global & i; 1374 int64_t expected = *global & i;
1375 r.Call(i); 1375 r.Call(i);
1376 CHECK_EQ(expected, *global); 1376 CHECK_EQ(expected, *global);
1377 } 1377 }
1378 } 1378 }
1379 1379
1380 WASM_EXEC_TEST(I64Eqz) { 1380 WASM_EXEC_TEST(I64Eqz) {
1381 REQUIRE(I64Eq); 1381 REQUIRE(I64Eq);
1382 1382
(...skipping 26 matching lines...) Expand all
1409 MachineType::Int64()); 1409 MachineType::Int64());
1410 BUILD(r, WASM_I64_ROL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 1410 BUILD(r, WASM_I64_ROL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
1411 1411
1412 FOR_UINT64_INPUTS(i) { 1412 FOR_UINT64_INPUTS(i) {
1413 FOR_UINT64_INPUTS(j) { 1413 FOR_UINT64_INPUTS(j) {
1414 int64_t expected = bits::RotateLeft64(*i, *j & 0x3f); 1414 int64_t expected = bits::RotateLeft64(*i, *j & 0x3f);
1415 CHECK_EQ(expected, r.Call(*i, *j)); 1415 CHECK_EQ(expected, r.Call(*i, *j));
1416 } 1416 }
1417 } 1417 }
1418 } 1418 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698