| 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/bits.h" |
| 9 #include "src/wasm/wasm-macro-gen.h" | 10 #include "src/wasm/wasm-macro-gen.h" |
| 10 | 11 |
| 11 #include "test/cctest/cctest.h" | 12 #include "test/cctest/cctest.h" |
| 12 #include "test/cctest/compiler/value-helper.h" | 13 #include "test/cctest/compiler/value-helper.h" |
| 13 #include "test/cctest/wasm/test-signatures.h" | 14 #include "test/cctest/wasm/test-signatures.h" |
| 14 #include "test/cctest/wasm/wasm-run-utils.h" | 15 #include "test/cctest/wasm/wasm-run-utils.h" |
| 15 | 16 |
| 16 #define CHECK_TRAP32(x) \ | 17 #define CHECK_TRAP32(x) \ |
| 17 CHECK_EQ(0xdeadbeef, (bit_cast<uint32_t>(x)) & 0xFFFFFFFF) | 18 CHECK_EQ(0xdeadbeef, (bit_cast<uint32_t>(x)) & 0xFFFFFFFF) |
| 18 #define CHECK_TRAP64(x) \ | 19 #define CHECK_TRAP64(x) \ |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 V(I64UConvertF32, true) \ | 79 V(I64UConvertF32, true) \ |
| 79 V(I64UConvertF64, true) \ | 80 V(I64UConvertF64, true) \ |
| 80 V(I64SConvertI32, true) \ | 81 V(I64SConvertI32, true) \ |
| 81 V(I64UConvertI32, true) \ | 82 V(I64UConvertI32, true) \ |
| 82 V(F32SConvertI64, true) \ | 83 V(F32SConvertI64, true) \ |
| 83 V(F32UConvertI64, true) \ | 84 V(F32UConvertI64, true) \ |
| 84 V(F64SConvertI64, true) \ | 85 V(F64SConvertI64, true) \ |
| 85 V(F64UConvertI64, true) \ | 86 V(F64UConvertI64, true) \ |
| 86 V(F64ReinterpretI64, true) \ | 87 V(F64ReinterpretI64, true) \ |
| 87 V(I64ReinterpretF64, true) \ | 88 V(I64ReinterpretF64, true) \ |
| 88 V(I64Ror, false) \ | 89 V(I64Ror, true) \ |
| 89 V(I64Rol, false) | 90 V(I64Rol, true) |
| 90 | 91 |
| 91 #define DECLARE_CONST(name, cond) static const bool kSupported_##name = cond; | 92 #define DECLARE_CONST(name, cond) static const bool kSupported_##name = cond; |
| 92 FOREACH_I64_OPERATOR(DECLARE_CONST) | 93 FOREACH_I64_OPERATOR(DECLARE_CONST) |
| 93 #undef DECLARE_CONST | 94 #undef DECLARE_CONST |
| 94 | 95 |
| 95 #define REQUIRE(name) \ | 96 #define REQUIRE(name) \ |
| 96 if (!WASM_64 && !kSupported_##name) return | 97 if (!WASM_64 && !kSupported_##name) return |
| 97 | 98 |
| 98 TEST(Run_Wasm_I64Const) { | 99 TEST(Run_Wasm_I64Const) { |
| 99 REQUIRE(I64Const); | 100 REQUIRE(I64Const); |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64()); | 311 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64()); |
| 311 BUILD(r, WASM_I64_XOR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 312 BUILD(r, WASM_I64_XOR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
| 312 FOR_INT64_INPUTS(i) { | 313 FOR_INT64_INPUTS(i) { |
| 313 FOR_INT64_INPUTS(j) { CHECK_EQ((*i) ^ (*j), r.Call(*i, *j)); } | 314 FOR_INT64_INPUTS(j) { CHECK_EQ((*i) ^ (*j), r.Call(*i, *j)); } |
| 314 } | 315 } |
| 315 } | 316 } |
| 316 // kExprI64Shl: | 317 // kExprI64Shl: |
| 317 TEST(Run_Wasm_I64Shl) { | 318 TEST(Run_Wasm_I64Shl) { |
| 318 REQUIRE(I64Shl); | 319 REQUIRE(I64Shl); |
| 319 { | 320 { |
| 320 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64()); | 321 WasmRunner<uint64_t> r(MachineType::Uint64(), MachineType::Uint64()); |
| 321 BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 322 BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
| 323 |
| 322 FOR_UINT64_INPUTS(i) { | 324 FOR_UINT64_INPUTS(i) { |
| 323 for (int64_t j = 1; j < 64; j++) { | 325 FOR_UINT64_INPUTS(j) { |
| 324 CHECK_EQ(*i << j, r.Call(*i, j)); | 326 uint64_t expected = (*i) << (*j & 0x3f); |
| 327 CHECK_EQ(expected, r.Call(*i, *j)); |
| 325 } | 328 } |
| 326 } | 329 } |
| 327 } | 330 } |
| 328 { | 331 { |
| 329 WasmRunner<int64_t> r(MachineType::Int64()); | 332 WasmRunner<int64_t> r(MachineType::Int64()); |
| 330 BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(0))); | 333 BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(0))); |
| 331 FOR_UINT64_INPUTS(i) { CHECK_EQ(*i << 0, r.Call(*i)); } | 334 FOR_UINT64_INPUTS(i) { CHECK_EQ(*i << 0, r.Call(*i)); } |
| 332 } | 335 } |
| 333 { | 336 { |
| 334 WasmRunner<int64_t> r(MachineType::Int64()); | 337 WasmRunner<int64_t> r(MachineType::Int64()); |
| 335 BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(32))); | 338 BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(32))); |
| 336 FOR_UINT64_INPUTS(i) { CHECK_EQ(*i << 32, r.Call(*i)); } | 339 FOR_UINT64_INPUTS(i) { CHECK_EQ(*i << 32, r.Call(*i)); } |
| 337 } | 340 } |
| 338 { | 341 { |
| 339 WasmRunner<int64_t> r(MachineType::Int64()); | 342 WasmRunner<int64_t> r(MachineType::Int64()); |
| 340 BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(20))); | 343 BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(20))); |
| 341 FOR_UINT64_INPUTS(i) { CHECK_EQ(*i << 20, r.Call(*i)); } | 344 FOR_UINT64_INPUTS(i) { CHECK_EQ(*i << 20, r.Call(*i)); } |
| 342 } | 345 } |
| 343 { | 346 { |
| 344 WasmRunner<int64_t> r(MachineType::Int64()); | 347 WasmRunner<int64_t> r(MachineType::Int64()); |
| 345 BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(40))); | 348 BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(40))); |
| 346 FOR_UINT64_INPUTS(i) { CHECK_EQ(*i << 40, r.Call(*i)); } | 349 FOR_UINT64_INPUTS(i) { CHECK_EQ(*i << 40, r.Call(*i)); } |
| 347 } | 350 } |
| 348 } | 351 } |
| 349 // kExprI64ShrU: | 352 // kExprI64ShrU: |
| 350 TEST(Run_Wasm_I64ShrU) { | 353 TEST(Run_Wasm_I64ShrU) { |
| 351 REQUIRE(I64ShrU); | 354 REQUIRE(I64ShrU); |
| 352 { | 355 { |
| 353 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64()); | 356 WasmRunner<uint64_t> r(MachineType::Uint64(), MachineType::Uint64()); |
| 354 BUILD(r, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 357 BUILD(r, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
| 358 |
| 355 FOR_UINT64_INPUTS(i) { | 359 FOR_UINT64_INPUTS(i) { |
| 356 for (int64_t j = 1; j < 64; j++) { | 360 FOR_UINT64_INPUTS(j) { |
| 357 CHECK_EQ(*i >> j, r.Call(*i, j)); | 361 uint64_t expected = (*i) >> (*j & 0x3f); |
| 362 CHECK_EQ(expected, r.Call(*i, *j)); |
| 358 } | 363 } |
| 359 } | 364 } |
| 360 } | 365 } |
| 361 { | 366 { |
| 362 WasmRunner<int64_t> r(MachineType::Int64()); | 367 WasmRunner<int64_t> r(MachineType::Int64()); |
| 363 BUILD(r, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(0))); | 368 BUILD(r, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(0))); |
| 364 FOR_UINT64_INPUTS(i) { CHECK_EQ(*i >> 0, r.Call(*i)); } | 369 FOR_UINT64_INPUTS(i) { CHECK_EQ(*i >> 0, r.Call(*i)); } |
| 365 } | 370 } |
| 366 { | 371 { |
| 367 WasmRunner<int64_t> r(MachineType::Int64()); | 372 WasmRunner<int64_t> r(MachineType::Int64()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 378 BUILD(r, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(40))); | 383 BUILD(r, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(40))); |
| 379 FOR_UINT64_INPUTS(i) { CHECK_EQ(*i >> 40, r.Call(*i)); } | 384 FOR_UINT64_INPUTS(i) { CHECK_EQ(*i >> 40, r.Call(*i)); } |
| 380 } | 385 } |
| 381 } | 386 } |
| 382 // kExprI64ShrS: | 387 // kExprI64ShrS: |
| 383 TEST(Run_Wasm_I64ShrS) { | 388 TEST(Run_Wasm_I64ShrS) { |
| 384 REQUIRE(I64ShrS); | 389 REQUIRE(I64ShrS); |
| 385 { | 390 { |
| 386 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64()); | 391 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64()); |
| 387 BUILD(r, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 392 BUILD(r, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
| 393 |
| 388 FOR_INT64_INPUTS(i) { | 394 FOR_INT64_INPUTS(i) { |
| 389 for (int64_t j = 1; j < 64; j++) { | 395 FOR_INT64_INPUTS(j) { |
| 390 CHECK_EQ(*i >> j, r.Call(*i, j)); | 396 int64_t expected = (*i) >> (*j & 0x3f); |
| 397 CHECK_EQ(expected, r.Call(*i, *j)); |
| 391 } | 398 } |
| 392 } | 399 } |
| 393 } | 400 } |
| 394 { | 401 { |
| 395 WasmRunner<int64_t> r(MachineType::Int64()); | 402 WasmRunner<int64_t> r(MachineType::Int64()); |
| 396 BUILD(r, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64V_1(0))); | 403 BUILD(r, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64V_1(0))); |
| 397 FOR_INT64_INPUTS(i) { CHECK_EQ(*i >> 0, r.Call(*i)); } | 404 FOR_INT64_INPUTS(i) { CHECK_EQ(*i >> 0, r.Call(*i)); } |
| 398 } | 405 } |
| 399 { | 406 { |
| 400 WasmRunner<int64_t> r(MachineType::Int64()); | 407 WasmRunner<int64_t> r(MachineType::Int64()); |
| (...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1299 WASM_ZERO)); | 1306 WASM_ZERO)); |
| 1300 | 1307 |
| 1301 *global = 0xFFFFFFFFFFFFFFFFLL; | 1308 *global = 0xFFFFFFFFFFFFFFFFLL; |
| 1302 for (int i = 9; i < 444444; i += 111111) { | 1309 for (int i = 9; i < 444444; i += 111111) { |
| 1303 int64_t expected = *global & i; | 1310 int64_t expected = *global & i; |
| 1304 r.Call(i); | 1311 r.Call(i); |
| 1305 CHECK_EQ(expected, *global); | 1312 CHECK_EQ(expected, *global); |
| 1306 } | 1313 } |
| 1307 } | 1314 } |
| 1308 | 1315 |
| 1309 TEST(Run_WasmI64Eqz) { | 1316 TEST(Run_Wasm_I64Eqz) { |
| 1310 REQUIRE(I64Eq); | 1317 REQUIRE(I64Eq); |
| 1311 | 1318 |
| 1312 WasmRunner<int32_t> r(MachineType::Int64()); | 1319 WasmRunner<int32_t> r(MachineType::Int64()); |
| 1313 BUILD(r, WASM_I64_EQZ(WASM_GET_LOCAL(0))); | 1320 BUILD(r, WASM_I64_EQZ(WASM_GET_LOCAL(0))); |
| 1314 | 1321 |
| 1315 FOR_INT64_INPUTS(i) { | 1322 FOR_INT64_INPUTS(i) { |
| 1316 int32_t result = *i == 0 ? 1 : 0; | 1323 int32_t result = *i == 0 ? 1 : 0; |
| 1317 CHECK_EQ(result, r.Call(*i)); | 1324 CHECK_EQ(result, r.Call(*i)); |
| 1318 } | 1325 } |
| 1319 } | 1326 } |
| 1320 | 1327 |
| 1321 TEST(Run_WasmI64Shl) { | 1328 TEST(Run_Wasm_I64Ror) { |
| 1322 REQUIRE(I64Shl); | 1329 REQUIRE(I64Ror); |
| 1323 WasmRunner<uint64_t> r(MachineType::Uint64(), MachineType::Uint64()); | 1330 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64()); |
| 1324 BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 1331 BUILD(r, WASM_I64_ROR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
| 1325 | 1332 |
| 1326 FOR_UINT64_INPUTS(i) { | 1333 FOR_UINT64_INPUTS(i) { |
| 1327 FOR_UINT64_INPUTS(j) { | 1334 FOR_UINT64_INPUTS(j) { |
| 1328 uint64_t expected = (*i) << (*j & 0x3f); | 1335 int64_t expected = bits::RotateRight64(*i, *j & 0x3f); |
| 1329 CHECK_EQ(expected, r.Call(*i, *j)); | 1336 CHECK_EQ(expected, r.Call(*i, *j)); |
| 1330 } | 1337 } |
| 1331 } | 1338 } |
| 1332 } | 1339 } |
| 1333 | 1340 |
| 1334 TEST(Run_WasmI64Shr) { | 1341 TEST(Run_Wasm_I64Rol) { |
| 1335 REQUIRE(I64ShrU); | 1342 REQUIRE(I64Rol); |
| 1336 WasmRunner<uint64_t> r(MachineType::Uint64(), MachineType::Uint64()); | 1343 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64()); |
| 1337 BUILD(r, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 1344 BUILD(r, WASM_I64_ROL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
| 1338 | 1345 |
| 1339 FOR_UINT64_INPUTS(i) { | 1346 FOR_UINT64_INPUTS(i) { |
| 1340 FOR_UINT64_INPUTS(j) { | 1347 FOR_UINT64_INPUTS(j) { |
| 1341 uint64_t expected = (*i) >> (*j & 0x3f); | 1348 int64_t expected = bits::RotateLeft64(*i, *j & 0x3f); |
| 1342 CHECK_EQ(expected, r.Call(*i, *j)); | 1349 CHECK_EQ(expected, r.Call(*i, *j)); |
| 1343 } | 1350 } |
| 1344 } | 1351 } |
| 1345 } | |
| 1346 | |
| 1347 TEST(Run_WasmI64Sar) { | |
| 1348 REQUIRE(I64ShrS); | |
| 1349 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64()); | |
| 1350 BUILD(r, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | |
| 1351 | |
| 1352 FOR_INT64_INPUTS(i) { | |
| 1353 FOR_INT64_INPUTS(j) { | |
| 1354 int64_t expected = (*i) >> (*j & 0x3f); | |
| 1355 CHECK_EQ(expected, r.Call(*i, *j)); | |
| 1356 } | |
| 1357 } | |
| 1358 } | 1352 } |
| OLD | NEW |