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/wasm/wasm-macro-gen.h" | 9 #include "src/wasm/wasm-macro-gen.h" |
10 | 10 |
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
862 } | 862 } |
863 } | 863 } |
864 | 864 |
865 #define TEST_I64_BINOP(name, expected, a, b) \ | 865 #define TEST_I64_BINOP(name, expected, a, b) \ |
866 do { \ | 866 do { \ |
867 if (WASM_64 || kSupported_##name) \ | 867 if (WASM_64 || kSupported_##name) \ |
868 TestI64Binop(kExpr##name, expected, a, b); \ | 868 TestI64Binop(kExpr##name, expected, a, b); \ |
869 } while (false) | 869 } while (false) |
870 | 870 |
871 TEST(Run_Wasm_I64Binops) { | 871 TEST(Run_Wasm_I64Binops) { |
872 // TODO(titzer): real 64-bit numbers | 872 TEST_I64_BINOP(I64Add, -5586332274295447011, 0x501b72ebabc26847, |
873 TEST_I64_BINOP(I64Add, 8888888888888LL, 3333333333333LL, 5555555555555LL); | 873 0x625de9793d8f79d6); |
874 TEST_I64_BINOP(I64Sub, -111111111111LL, 777777777777LL, 888888888888LL); | 874 TEST_I64_BINOP(I64Sub, 9001903251710731490, 0xf24fe6474640002e, |
875 TEST_I64_BINOP(I64Mul, 65130756, 88734, 734); | 875 0x7562b6f711991b4c); |
876 TEST_I64_BINOP(I64Mul, 65130756, -88734, -734); | 876 TEST_I64_BINOP(I64Mul, -4569547818546064176, 0x231a263c2cbc6451, |
877 TEST_I64_BINOP(I64Mul, -65130756, -88734, 734); | 877 0xead44de6bd3e23d0); |
878 TEST_I64_BINOP(I64DivS, -66, -4777344, 72384); | 878 TEST_I64_BINOP(I64Mul, -25963122347507043, 0x4da1fa47c9352b73, |
879 TEST_I64_BINOP(I64DivU, 805306368, 0xF0000000, 5); | 879 0x91fe82317aa035af); |
880 TEST_I64_BINOP(I64RemS, -3, -3003, 1000); | 880 TEST_I64_BINOP(I64Mul, 7640290486138131960, 0x185731abe8eea47c, |
881 TEST_I64_BINOP(I64RemU, 4, 4004, 1000); | 881 0x714ec59f1380d4c2); |
882 TEST_I64_BINOP(I64And, 0xEE, 0xFFEE, 0xFF0000FF); | 882 TEST_I64_BINOP(I64DivS, -91517, 0x93b1190a34de56a0, 0x00004d8f68863948); |
883 TEST_I64_BINOP(I64Ior, 0xF0FF00FF, 0xF0F000EE, 0x000F0011); | 883 TEST_I64_BINOP(I64DivU, 149016, 0xe15b3727e8a2080a, 0x0000631bfa72db8b); |
884 TEST_I64_BINOP(I64Xor, 0xABCDEF01, 0xABCDEFFF, 0xFE); | 884 TEST_I64_BINOP(I64RemS, -664128064149968, 0x9a78b4e4fe708692, |
885 TEST_I64_BINOP(I64Shl, 0xA0000000, 0xA, 28); | 885 0x0003e0b6b3be7609); |
886 TEST_I64_BINOP(I64ShrU, 0x0700001000123456LL, 0x7000010001234567LL, 4); | 886 TEST_I64_BINOP(I64RemU, 1742040017332765, 0x0ce84708c6258c81, |
887 TEST_I64_BINOP(I64ShrS, 0xFF00000000000000LL, 0x8000000000000000LL, 7); | 887 0x000a6fde82016697); |
888 TEST_I64_BINOP(I64Ror, 0x0100000000000000LL, 0x8000000000000000LL, 7); | 888 TEST_I64_BINOP(I64And, 2531040582801836054, 0xaf257d1602644a16, |
889 TEST_I64_BINOP(I64Ror, 0x0100000000000000LL, 0x8000000000000000LL, 71); | 889 0x33b290a91a10d997); |
890 TEST_I64_BINOP(I64Rol, 0x0000000000000040LL, 0x8000000000000000LL, 7); | 890 TEST_I64_BINOP(I64Ior, 8556201506536114940, 0x169d9be7bd3f0a5c, |
891 TEST_I64_BINOP(I64Rol, 0x0000000000000040LL, 0x8000000000000000LL, 71); | 891 0x66bca28d77af40e8); |
892 TEST_I64_BINOP(I64Xor, -4605655183785456377, 0xb6ea20a5d48e85b8, | |
893 0x76ff4da6c80688bf); | |
894 TEST_I64_BINOP(I64Shl, -7240704056088331264, 0xef4dc1ed030e8ffe, 9); | |
ahaas
2016/03/31 09:14:54
Some instructions (e.g. shifts) have their own tes
| |
895 TEST_I64_BINOP(I64ShrU, 12500673744059159, 0xb1a52fa7deec5d14, 10); | |
896 TEST_I64_BINOP(I64ShrS, 1725103446999874, 0x3107c791461a112b, 11); | |
897 TEST_I64_BINOP(I64Ror, -8960135652432576946, 0x73418d1717e4e83a, 12); | |
898 TEST_I64_BINOP(I64Ror, 7617662827409989779, 0xebff67cf0c126d36, 13); | |
899 TEST_I64_BINOP(I64Rol, -2097714064174346012, 0x43938b8db0b0f230, 14); | |
900 TEST_I64_BINOP(I64Rol, 8728493013947314237, 0xe07af243ac4d219d, 15); | |
892 } | 901 } |
893 | 902 |
894 #define TEST_I64_CMP(name, expected, a, b) \ | 903 #define TEST_I64_CMP(name, expected, a, b) \ |
895 do { \ | 904 do { \ |
896 if (WASM_64 || kSupported_##name) TestI64Cmp(kExpr##name, expected, a, b); \ | 905 if (WASM_64 || kSupported_##name) TestI64Cmp(kExpr##name, expected, a, b); \ |
897 } while (false) | 906 } while (false) |
898 | 907 |
899 TEST(Run_Wasm_I64Compare) { | 908 TEST(Run_Wasm_I64Compare) { |
900 // TODO(titzer): real 64-bit numbers | 909 TEST_I64_CMP(I64Eq, 0, 0xB915D8FA494064F0, 0x04D700B2536019A3); |
901 TEST_I64_CMP(I64Eq, 1, -9999, -9999); | 910 TEST_I64_CMP(I64Ne, 1, 0xC2FAFAAAB0446CDC, 0x52A3328F780C97A3); |
902 TEST_I64_CMP(I64Ne, 1, -9199, -9999); | 911 TEST_I64_CMP(I64LtS, 0, 0x673636E6306B0578, 0x028EC9ECA78F7227); |
903 TEST_I64_CMP(I64LtS, 1, -4, 4); | 912 TEST_I64_CMP(I64LeS, 1, 0xAE5214114B86A0FA, 0x7C1D21DA3DFD0CCF); |
904 TEST_I64_CMP(I64LeS, 0, -2, -3); | 913 TEST_I64_CMP(I64LtU, 0, 0x7D52166381EC1CE0, 0x59F4A6A9E78CD3D8); |
905 TEST_I64_CMP(I64LtU, 1, 0, -6); | 914 TEST_I64_CMP(I64LeU, 1, 0xE4169A385C7EA0E0, 0xFBDBED2C8781E5BC); |
906 TEST_I64_CMP(I64LeU, 1, 98978, 0xF0000000); | 915 TEST_I64_CMP(I64GtS, 0, 0x9D08FF8FB5F42E81, 0xD4E5C9D7FE09F621); |
907 TEST_I64_CMP(I64GtS, 1, 4, -4); | 916 TEST_I64_CMP(I64GeS, 1, 0x78DA3B2F73264E0F, 0x6FE5E2A67C501CBE); |
908 TEST_I64_CMP(I64GeS, 0, -3, -2); | 917 TEST_I64_CMP(I64GtU, 0, 0x8F691284E44F7DA9, 0xD5EA9BC1EE149192); |
909 TEST_I64_CMP(I64GtU, 1, -6, 0); | 918 TEST_I64_CMP(I64GeU, 0, 0x0886A0C58C7AA224, 0x5DDBE5A81FD7EE47); |
910 TEST_I64_CMP(I64GeU, 1, 0xF0000000, 98978); | |
911 } | 919 } |
912 | 920 |
913 TEST(Run_Wasm_I64Clz) { | 921 TEST(Run_Wasm_I64Clz) { |
914 REQUIRE(I64Clz); | 922 REQUIRE(I64Clz); |
915 struct { | 923 struct { |
916 int64_t expected; | 924 int64_t expected; |
917 uint64_t input; | 925 uint64_t input; |
918 } values[] = {{0, 0x8000100000000000}, {1, 0x4000050000000000}, | 926 } values[] = {{0, 0x8000100000000000}, {1, 0x4000050000000000}, |
919 {2, 0x2000030000000000}, {3, 0x1000000300000000}, | 927 {2, 0x2000030000000000}, {3, 0x1000000300000000}, |
920 {4, 0x0805000000000000}, {5, 0x0400600000000000}, | 928 {4, 0x0805000000000000}, {5, 0x0400600000000000}, |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1095 | 1103 |
1096 int64_t expected = static_cast<int64_t>(static_cast<uint64_t>(a) - | 1104 int64_t expected = static_cast<int64_t>(static_cast<uint64_t>(a) - |
1097 static_cast<uint64_t>(b)); | 1105 static_cast<uint64_t>(b)); |
1098 CHECK_EQ(expected, r.Call(a, b)); | 1106 CHECK_EQ(expected, r.Call(a, b)); |
1099 } | 1107 } |
1100 } | 1108 } |
1101 } | 1109 } |
1102 | 1110 |
1103 TEST(Run_Wasm_LoadStoreI64_sx) { | 1111 TEST(Run_Wasm_LoadStoreI64_sx) { |
1104 REQUIRE(I64LoadStore); | 1112 REQUIRE(I64LoadStore); |
1105 REQUIRE(DepthFirst); // TODO(titzer): temporary hack | 1113 REQUIRE(DepthFirst); |
1106 byte loads[] = {kExprI64LoadMem8S, kExprI64LoadMem16S, kExprI64LoadMem32S, | 1114 byte loads[] = {kExprI64LoadMem8S, kExprI64LoadMem16S, kExprI64LoadMem32S, |
1107 kExprI64LoadMem}; | 1115 kExprI64LoadMem}; |
1108 | 1116 |
1109 for (size_t m = 0; m < arraysize(loads); m++) { | 1117 for (size_t m = 0; m < arraysize(loads); m++) { |
1110 TestingModule module; | 1118 TestingModule module; |
1111 byte* memory = module.AddMemoryElems<byte>(16); | 1119 byte* memory = module.AddMemoryElems<byte>(16); |
1112 WasmRunner<int64_t> r(&module); | 1120 WasmRunner<int64_t> r(&module); |
1113 | 1121 |
1114 byte code[] = {kExprI64StoreMem, ZERO_ALIGNMENT, | 1122 byte code[] = {kExprI64StoreMem, ZERO_ALIGNMENT, |
1115 ZERO_OFFSET, // -- | 1123 ZERO_OFFSET, // -- |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1281 } | 1289 } |
1282 uint64_t result = r.Call(8 * (kNumElems - 1)); | 1290 uint64_t result = r.Call(8 * (kNumElems - 1)); |
1283 CHECK_EQ(expected, result); | 1291 CHECK_EQ(expected, result); |
1284 } | 1292 } |
1285 } | 1293 } |
1286 | 1294 |
1287 TEST(Run_Wasm_I64Global) { | 1295 TEST(Run_Wasm_I64Global) { |
1288 REQUIRE(I64LoadStore); | 1296 REQUIRE(I64LoadStore); |
1289 REQUIRE(I64SConvertI32); | 1297 REQUIRE(I64SConvertI32); |
1290 REQUIRE(I64And); | 1298 REQUIRE(I64And); |
1291 REQUIRE(DepthFirst); // TODO(titzer): temporary hack | 1299 REQUIRE(DepthFirst); |
1292 TestingModule module; | 1300 TestingModule module; |
1293 int64_t* global = module.AddGlobal<int64_t>(MachineType::Int64()); | 1301 int64_t* global = module.AddGlobal<int64_t>(MachineType::Int64()); |
1294 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 1302 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
1295 // global = global + p0 | 1303 // global = global + p0 |
1296 BUILD(r, B2(WASM_STORE_GLOBAL( | 1304 BUILD(r, B2(WASM_STORE_GLOBAL( |
1297 0, WASM_I64_AND(WASM_LOAD_GLOBAL(0), | 1305 0, WASM_I64_AND(WASM_LOAD_GLOBAL(0), |
1298 WASM_I64_SCONVERT_I32(WASM_GET_LOCAL(0)))), | 1306 WASM_I64_SCONVERT_I32(WASM_GET_LOCAL(0)))), |
1299 WASM_ZERO)); | 1307 WASM_ZERO)); |
1300 | 1308 |
1301 *global = 0xFFFFFFFFFFFFFFFFLL; | 1309 *global = 0xFFFFFFFFFFFFFFFFLL; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1349 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64()); | 1357 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64()); |
1350 BUILD(r, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 1358 BUILD(r, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
1351 | 1359 |
1352 FOR_INT64_INPUTS(i) { | 1360 FOR_INT64_INPUTS(i) { |
1353 FOR_INT64_INPUTS(j) { | 1361 FOR_INT64_INPUTS(j) { |
1354 int64_t expected = (*i) >> (*j & 0x3f); | 1362 int64_t expected = (*i) >> (*j & 0x3f); |
1355 CHECK_EQ(expected, r.Call(*i, *j)); | 1363 CHECK_EQ(expected, r.Call(*i, *j)); |
1356 } | 1364 } |
1357 } | 1365 } |
1358 } | 1366 } |
OLD | NEW |