| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 <functional> | 5 #include <functional> |
| 6 #include <limits> | 6 #include <limits> |
| 7 | 7 |
| 8 #include "src/base/bits.h" | 8 #include "src/base/bits.h" |
| 9 #include "src/compiler/generic-node-inl.h" | 9 #include "src/compiler/generic-node-inl.h" |
| 10 #include "test/cctest/cctest.h" | 10 #include "test/cctest/cctest.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 57 |
| 58 TEST(CodeGenInt32Binop) { | 58 TEST(CodeGenInt32Binop) { |
| 59 RawMachineAssemblerTester<void> m; | 59 RawMachineAssemblerTester<void> m; |
| 60 | 60 |
| 61 const Operator* ops[] = { | 61 const Operator* ops[] = { |
| 62 m.machine()->Word32And(), m.machine()->Word32Or(), | 62 m.machine()->Word32And(), m.machine()->Word32Or(), |
| 63 m.machine()->Word32Xor(), m.machine()->Word32Shl(), | 63 m.machine()->Word32Xor(), m.machine()->Word32Shl(), |
| 64 m.machine()->Word32Shr(), m.machine()->Word32Sar(), | 64 m.machine()->Word32Shr(), m.machine()->Word32Sar(), |
| 65 m.machine()->Word32Equal(), m.machine()->Int32Add(), | 65 m.machine()->Word32Equal(), m.machine()->Int32Add(), |
| 66 m.machine()->Int32Sub(), m.machine()->Int32Mul(), | 66 m.machine()->Int32Sub(), m.machine()->Int32Mul(), |
| 67 m.machine()->Int32Div(), m.machine()->Int32UDiv(), | 67 m.machine()->Int32Div(), m.machine()->Uint32Div(), |
| 68 m.machine()->Int32Mod(), m.machine()->Int32UMod(), | 68 m.machine()->Int32Mod(), m.machine()->Uint32Mod(), |
| 69 m.machine()->Int32LessThan(), m.machine()->Int32LessThanOrEqual(), | 69 m.machine()->Int32LessThan(), m.machine()->Int32LessThanOrEqual(), |
| 70 m.machine()->Uint32LessThan(), m.machine()->Uint32LessThanOrEqual(), | 70 m.machine()->Uint32LessThan(), m.machine()->Uint32LessThanOrEqual(), |
| 71 NULL}; | 71 NULL}; |
| 72 | 72 |
| 73 for (int i = 0; ops[i] != NULL; i++) { | 73 for (int i = 0; ops[i] != NULL; i++) { |
| 74 for (int j = 0; j < 8; j++) { | 74 for (int j = 0; j < 8; j++) { |
| 75 for (int k = 0; k < 8; k++) { | 75 for (int k = 0; k < 8; k++) { |
| 76 RawMachineAssemblerTester<int32_t> m(kMachInt32, kMachInt32); | 76 RawMachineAssemblerTester<int32_t> m(kMachInt32, kMachInt32); |
| 77 Node* a = Int32Input(&m, j); | 77 Node* a = Int32Input(&m, j); |
| 78 Node* b = Int32Input(&m, k); | 78 Node* b = Int32Input(&m, k); |
| (...skipping 1295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1374 if (p1 != 0 && (static_cast<uint32_t>(p0) != 0x80000000 || p1 != -1)) { | 1374 if (p1 != 0 && (static_cast<uint32_t>(p0) != 0x80000000 || p1 != -1)) { |
| 1375 int expected = static_cast<int32_t>(p0 + (p0 / p1)); | 1375 int expected = static_cast<int32_t>(p0 + (p0 / p1)); |
| 1376 CHECK_EQ(expected, bt.call(p0, p1)); | 1376 CHECK_EQ(expected, bt.call(p0, p1)); |
| 1377 } | 1377 } |
| 1378 } | 1378 } |
| 1379 } | 1379 } |
| 1380 } | 1380 } |
| 1381 } | 1381 } |
| 1382 | 1382 |
| 1383 | 1383 |
| 1384 TEST(RunInt32UDivP) { | 1384 TEST(RunUint32DivP) { |
| 1385 { | 1385 { |
| 1386 RawMachineAssemblerTester<int32_t> m; | 1386 RawMachineAssemblerTester<int32_t> m; |
| 1387 Int32BinopTester bt(&m); | 1387 Int32BinopTester bt(&m); |
| 1388 bt.AddReturn(m.Int32UDiv(bt.param0, bt.param1)); | 1388 bt.AddReturn(m.Uint32Div(bt.param0, bt.param1)); |
| 1389 FOR_UINT32_INPUTS(i) { | 1389 FOR_UINT32_INPUTS(i) { |
| 1390 FOR_UINT32_INPUTS(j) { | 1390 FOR_UINT32_INPUTS(j) { |
| 1391 uint32_t p0 = *i; | 1391 uint32_t p0 = *i; |
| 1392 uint32_t p1 = *j; | 1392 uint32_t p1 = *j; |
| 1393 if (p1 != 0) { | 1393 if (p1 != 0) { |
| 1394 uint32_t expected = static_cast<uint32_t>(p0 / p1); | 1394 uint32_t expected = static_cast<uint32_t>(p0 / p1); |
| 1395 CHECK_EQ(expected, bt.call(p0, p1)); | 1395 CHECK_EQ(expected, bt.call(p0, p1)); |
| 1396 } | 1396 } |
| 1397 } | 1397 } |
| 1398 } | 1398 } |
| 1399 } | 1399 } |
| 1400 { | 1400 { |
| 1401 RawMachineAssemblerTester<int32_t> m; | 1401 RawMachineAssemblerTester<int32_t> m; |
| 1402 Int32BinopTester bt(&m); | 1402 Int32BinopTester bt(&m); |
| 1403 bt.AddReturn(m.Int32Add(bt.param0, m.Int32UDiv(bt.param0, bt.param1))); | 1403 bt.AddReturn(m.Int32Add(bt.param0, m.Uint32Div(bt.param0, bt.param1))); |
| 1404 FOR_UINT32_INPUTS(i) { | 1404 FOR_UINT32_INPUTS(i) { |
| 1405 FOR_UINT32_INPUTS(j) { | 1405 FOR_UINT32_INPUTS(j) { |
| 1406 uint32_t p0 = *i; | 1406 uint32_t p0 = *i; |
| 1407 uint32_t p1 = *j; | 1407 uint32_t p1 = *j; |
| 1408 if (p1 != 0) { | 1408 if (p1 != 0) { |
| 1409 uint32_t expected = static_cast<uint32_t>(p0 + (p0 / p1)); | 1409 uint32_t expected = static_cast<uint32_t>(p0 + (p0 / p1)); |
| 1410 CHECK_EQ(expected, bt.call(p0, p1)); | 1410 CHECK_EQ(expected, bt.call(p0, p1)); |
| 1411 } | 1411 } |
| 1412 } | 1412 } |
| 1413 } | 1413 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1442 if (p1 != 0 && (static_cast<uint32_t>(p0) != 0x80000000 || p1 != -1)) { | 1442 if (p1 != 0 && (static_cast<uint32_t>(p0) != 0x80000000 || p1 != -1)) { |
| 1443 int expected = static_cast<int32_t>(p0 + (p0 % p1)); | 1443 int expected = static_cast<int32_t>(p0 + (p0 % p1)); |
| 1444 CHECK_EQ(expected, bt.call(p0, p1)); | 1444 CHECK_EQ(expected, bt.call(p0, p1)); |
| 1445 } | 1445 } |
| 1446 } | 1446 } |
| 1447 } | 1447 } |
| 1448 } | 1448 } |
| 1449 } | 1449 } |
| 1450 | 1450 |
| 1451 | 1451 |
| 1452 TEST(RunInt32UModP) { | 1452 TEST(RunUint32ModP) { |
| 1453 { | 1453 { |
| 1454 RawMachineAssemblerTester<int32_t> m; | 1454 RawMachineAssemblerTester<int32_t> m; |
| 1455 Int32BinopTester bt(&m); | 1455 Int32BinopTester bt(&m); |
| 1456 bt.AddReturn(m.Int32UMod(bt.param0, bt.param1)); | 1456 bt.AddReturn(m.Uint32Mod(bt.param0, bt.param1)); |
| 1457 FOR_UINT32_INPUTS(i) { | 1457 FOR_UINT32_INPUTS(i) { |
| 1458 FOR_UINT32_INPUTS(j) { | 1458 FOR_UINT32_INPUTS(j) { |
| 1459 uint32_t p0 = *i; | 1459 uint32_t p0 = *i; |
| 1460 uint32_t p1 = *j; | 1460 uint32_t p1 = *j; |
| 1461 if (p1 != 0) { | 1461 if (p1 != 0) { |
| 1462 uint32_t expected = static_cast<uint32_t>(p0 % p1); | 1462 uint32_t expected = static_cast<uint32_t>(p0 % p1); |
| 1463 CHECK_EQ(expected, bt.call(p0, p1)); | 1463 CHECK_EQ(expected, bt.call(p0, p1)); |
| 1464 } | 1464 } |
| 1465 } | 1465 } |
| 1466 } | 1466 } |
| 1467 } | 1467 } |
| 1468 { | 1468 { |
| 1469 RawMachineAssemblerTester<int32_t> m; | 1469 RawMachineAssemblerTester<int32_t> m; |
| 1470 Int32BinopTester bt(&m); | 1470 Int32BinopTester bt(&m); |
| 1471 bt.AddReturn(m.Int32Add(bt.param0, m.Int32UMod(bt.param0, bt.param1))); | 1471 bt.AddReturn(m.Int32Add(bt.param0, m.Uint32Mod(bt.param0, bt.param1))); |
| 1472 FOR_UINT32_INPUTS(i) { | 1472 FOR_UINT32_INPUTS(i) { |
| 1473 FOR_UINT32_INPUTS(j) { | 1473 FOR_UINT32_INPUTS(j) { |
| 1474 uint32_t p0 = *i; | 1474 uint32_t p0 = *i; |
| 1475 uint32_t p1 = *j; | 1475 uint32_t p1 = *j; |
| 1476 if (p1 != 0) { | 1476 if (p1 != 0) { |
| 1477 uint32_t expected = static_cast<uint32_t>(p0 + (p0 % p1)); | 1477 uint32_t expected = static_cast<uint32_t>(p0 + (p0 % p1)); |
| 1478 CHECK_EQ(expected, bt.call(p0, p1)); | 1478 CHECK_EQ(expected, bt.call(p0, p1)); |
| 1479 } | 1479 } |
| 1480 } | 1480 } |
| 1481 } | 1481 } |
| (...skipping 1176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2658 TEST(RunDeadInt32Binops) { | 2658 TEST(RunDeadInt32Binops) { |
| 2659 RawMachineAssemblerTester<int32_t> m; | 2659 RawMachineAssemblerTester<int32_t> m; |
| 2660 | 2660 |
| 2661 const Operator* ops[] = { | 2661 const Operator* ops[] = { |
| 2662 m.machine()->Word32And(), m.machine()->Word32Or(), | 2662 m.machine()->Word32And(), m.machine()->Word32Or(), |
| 2663 m.machine()->Word32Xor(), m.machine()->Word32Shl(), | 2663 m.machine()->Word32Xor(), m.machine()->Word32Shl(), |
| 2664 m.machine()->Word32Shr(), m.machine()->Word32Sar(), | 2664 m.machine()->Word32Shr(), m.machine()->Word32Sar(), |
| 2665 m.machine()->Word32Ror(), m.machine()->Word32Equal(), | 2665 m.machine()->Word32Ror(), m.machine()->Word32Equal(), |
| 2666 m.machine()->Int32Add(), m.machine()->Int32Sub(), | 2666 m.machine()->Int32Add(), m.machine()->Int32Sub(), |
| 2667 m.machine()->Int32Mul(), m.machine()->Int32Div(), | 2667 m.machine()->Int32Mul(), m.machine()->Int32Div(), |
| 2668 m.machine()->Int32UDiv(), m.machine()->Int32Mod(), | 2668 m.machine()->Uint32Div(), m.machine()->Int32Mod(), |
| 2669 m.machine()->Int32UMod(), m.machine()->Int32LessThan(), | 2669 m.machine()->Uint32Mod(), m.machine()->Int32LessThan(), |
| 2670 m.machine()->Int32LessThanOrEqual(), m.machine()->Uint32LessThan(), | 2670 m.machine()->Int32LessThanOrEqual(), m.machine()->Uint32LessThan(), |
| 2671 m.machine()->Uint32LessThanOrEqual(), NULL}; | 2671 m.machine()->Uint32LessThanOrEqual(), NULL}; |
| 2672 | 2672 |
| 2673 for (int i = 0; ops[i] != NULL; i++) { | 2673 for (int i = 0; ops[i] != NULL; i++) { |
| 2674 RawMachineAssemblerTester<int32_t> m(kMachInt32, kMachInt32); | 2674 RawMachineAssemblerTester<int32_t> m(kMachInt32, kMachInt32); |
| 2675 int constant = 0x55555 + i; | 2675 int constant = 0x55555 + i; |
| 2676 m.NewNode(ops[i], m.Parameter(0), m.Parameter(1)); | 2676 m.NewNode(ops[i], m.Parameter(0), m.Parameter(1)); |
| 2677 m.Return(m.Int32Constant(constant)); | 2677 m.Return(m.Int32Constant(constant)); |
| 2678 | 2678 |
| 2679 CHECK_EQ(constant, m.Call(1, 1)); | 2679 CHECK_EQ(constant, m.Call(1, 1)); |
| (...skipping 1634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4314 float actual = *i; | 4314 float actual = *i; |
| 4315 RawMachineAssemblerTester<int32_t> m; | 4315 RawMachineAssemblerTester<int32_t> m; |
| 4316 m.StoreToPointer(&actual, kMachFloat32, m.Float32Constant(expected)); | 4316 m.StoreToPointer(&actual, kMachFloat32, m.Float32Constant(expected)); |
| 4317 m.Return(m.Int32Constant(0)); | 4317 m.Return(m.Int32Constant(0)); |
| 4318 CHECK_EQ(0, m.Call()); | 4318 CHECK_EQ(0, m.Call()); |
| 4319 CHECK_EQ(expected, actual); | 4319 CHECK_EQ(expected, actual); |
| 4320 } | 4320 } |
| 4321 } | 4321 } |
| 4322 | 4322 |
| 4323 #endif // V8_TURBOFAN_TARGET | 4323 #endif // V8_TURBOFAN_TARGET |
| OLD | NEW |