| 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 <cmath> | 5 #include <cmath> |
| 6 #include <functional> | 6 #include <functional> |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
| 10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 default: | 54 default: |
| 55 return NULL; | 55 return NULL; |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 | 59 |
| 60 TEST(CodeGenInt32Binop) { | 60 TEST(CodeGenInt32Binop) { |
| 61 RawMachineAssemblerTester<void> m; | 61 RawMachineAssemblerTester<void> m; |
| 62 | 62 |
| 63 const Operator* kOps[] = { | 63 const Operator* kOps[] = { |
| 64 m.machine()->Word32And(), m.machine()->Word32Or(), | 64 m.machine()->Word32And(), m.machine()->Word32Or(), |
| 65 m.machine()->Word32Xor(), m.machine()->Word32Shl(), | 65 m.machine()->Word32Xor(), m.machine()->Word32Shl(), |
| 66 m.machine()->Word32Shr(), m.machine()->Word32Sar(), | 66 m.machine()->Word32Shr(), m.machine()->Word32Sar(), |
| 67 m.machine()->Word32Equal(), m.machine()->Int32Add(), | 67 m.machine()->Word32Equal(), m.machine()->Int32Add(), |
| 68 m.machine()->Int32Sub(), m.machine()->Int32Mul(), | 68 m.machine()->Int32Sub(), m.machine()->Int32Mul(), |
| 69 m.machine()->Int32MulHigh(), m.machine()->Int32Div(), | 69 m.machine()->Int32MulHigh(), m.machine()->Int32Div(), |
| 70 m.machine()->Uint32Div(), m.machine()->Int32Mod(), | 70 m.machine()->Uint32Div(), m.machine()->Int32Mod(), |
| 71 m.machine()->Uint32Mod(), m.machine()->Int32LessThan(), | 71 m.machine()->Uint32Mod(), m.machine()->Uint32MulHigh(), |
| 72 m.machine()->Int32LessThanOrEqual(), m.machine()->Uint32LessThan(), | 72 m.machine()->Int32LessThan(), m.machine()->Int32LessThanOrEqual(), |
| 73 m.machine()->Uint32LessThanOrEqual()}; | 73 m.machine()->Uint32LessThan(), m.machine()->Uint32LessThanOrEqual()}; |
| 74 | 74 |
| 75 for (size_t i = 0; i < arraysize(kOps); ++i) { | 75 for (size_t i = 0; i < arraysize(kOps); ++i) { |
| 76 for (int j = 0; j < 8; j++) { | 76 for (int j = 0; j < 8; j++) { |
| 77 for (int k = 0; k < 8; k++) { | 77 for (int k = 0; k < 8; k++) { |
| 78 RawMachineAssemblerTester<int32_t> m(kMachInt32, kMachInt32); | 78 RawMachineAssemblerTester<int32_t> m(kMachInt32, kMachInt32); |
| 79 Node* a = Int32Input(&m, j); | 79 Node* a = Int32Input(&m, j); |
| 80 Node* b = Int32Input(&m, k); | 80 Node* b = Int32Input(&m, k); |
| 81 m.Return(m.NewNode(kOps[i], a, b)); | 81 m.Return(m.NewNode(kOps[i], a, b)); |
| 82 m.GenerateCode(); | 82 m.GenerateCode(); |
| 83 } | 83 } |
| (...skipping 1409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1493 // Use uint32_t because signed overflow is UB in C. | 1493 // Use uint32_t because signed overflow is UB in C. |
| 1494 int expected = *i - static_cast<uint32_t>(p0 * p1); | 1494 int expected = *i - static_cast<uint32_t>(p0 * p1); |
| 1495 CHECK_EQ(expected, bt.call(p0, p1)); | 1495 CHECK_EQ(expected, bt.call(p0, p1)); |
| 1496 } | 1496 } |
| 1497 } | 1497 } |
| 1498 } | 1498 } |
| 1499 } | 1499 } |
| 1500 } | 1500 } |
| 1501 | 1501 |
| 1502 | 1502 |
| 1503 TEST(RunUint32MulHighP) { |
| 1504 RawMachineAssemblerTester<int32_t> m; |
| 1505 Int32BinopTester bt(&m); |
| 1506 bt.AddReturn(m.Uint32MulHigh(bt.param0, bt.param1)); |
| 1507 FOR_UINT32_INPUTS(i) { |
| 1508 FOR_UINT32_INPUTS(j) { |
| 1509 int32_t expected = bit_cast<int32_t>(static_cast<uint32_t>( |
| 1510 (static_cast<uint64_t>(*i) * static_cast<uint64_t>(*j)) >> 32)); |
| 1511 CHECK_EQ(expected, bt.call(bit_cast<int32_t>(*i), bit_cast<int32_t>(*j))); |
| 1512 } |
| 1513 } |
| 1514 } |
| 1515 |
| 1516 |
| 1503 TEST(RunInt32DivP) { | 1517 TEST(RunInt32DivP) { |
| 1504 { | 1518 { |
| 1505 RawMachineAssemblerTester<int32_t> m; | 1519 RawMachineAssemblerTester<int32_t> m; |
| 1506 Int32BinopTester bt(&m); | 1520 Int32BinopTester bt(&m); |
| 1507 bt.AddReturn(m.Int32Div(bt.param0, bt.param1)); | 1521 bt.AddReturn(m.Int32Div(bt.param0, bt.param1)); |
| 1508 FOR_INT32_INPUTS(i) { | 1522 FOR_INT32_INPUTS(i) { |
| 1509 FOR_INT32_INPUTS(j) { | 1523 FOR_INT32_INPUTS(j) { |
| 1510 int p0 = *i; | 1524 int p0 = *i; |
| 1511 int p1 = *j; | 1525 int p1 = *j; |
| 1512 if (p1 != 0 && (static_cast<uint32_t>(p0) != 0x80000000 || p1 != -1)) { | 1526 if (p1 != 0 && (static_cast<uint32_t>(p0) != 0x80000000 || p1 != -1)) { |
| (...skipping 1292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2805 CHECK_EQ(constant, m.Call(0)); | 2819 CHECK_EQ(constant, m.Call(0)); |
| 2806 } | 2820 } |
| 2807 } | 2821 } |
| 2808 } | 2822 } |
| 2809 | 2823 |
| 2810 | 2824 |
| 2811 TEST(RunDeadInt32Binops) { | 2825 TEST(RunDeadInt32Binops) { |
| 2812 RawMachineAssemblerTester<int32_t> m; | 2826 RawMachineAssemblerTester<int32_t> m; |
| 2813 | 2827 |
| 2814 const Operator* kOps[] = { | 2828 const Operator* kOps[] = { |
| 2815 m.machine()->Word32And(), m.machine()->Word32Or(), | 2829 m.machine()->Word32And(), m.machine()->Word32Or(), |
| 2816 m.machine()->Word32Xor(), m.machine()->Word32Shl(), | 2830 m.machine()->Word32Xor(), m.machine()->Word32Shl(), |
| 2817 m.machine()->Word32Shr(), m.machine()->Word32Sar(), | 2831 m.machine()->Word32Shr(), m.machine()->Word32Sar(), |
| 2818 m.machine()->Word32Ror(), m.machine()->Word32Equal(), | 2832 m.machine()->Word32Ror(), m.machine()->Word32Equal(), |
| 2819 m.machine()->Int32Add(), m.machine()->Int32Sub(), | 2833 m.machine()->Int32Add(), m.machine()->Int32Sub(), |
| 2820 m.machine()->Int32Mul(), m.machine()->Int32MulHigh(), | 2834 m.machine()->Int32Mul(), m.machine()->Int32MulHigh(), |
| 2821 m.machine()->Int32Div(), m.machine()->Uint32Div(), | 2835 m.machine()->Int32Div(), m.machine()->Uint32Div(), |
| 2822 m.machine()->Int32Mod(), m.machine()->Uint32Mod(), | 2836 m.machine()->Int32Mod(), m.machine()->Uint32Mod(), |
| 2823 m.machine()->Int32LessThan(), m.machine()->Int32LessThanOrEqual(), | 2837 m.machine()->Uint32MulHigh(), m.machine()->Int32LessThan(), |
| 2824 m.machine()->Uint32LessThan(), m.machine()->Uint32LessThanOrEqual()}; | 2838 m.machine()->Int32LessThanOrEqual(), m.machine()->Uint32LessThan(), |
| 2839 m.machine()->Uint32LessThanOrEqual()}; |
| 2825 | 2840 |
| 2826 for (size_t i = 0; i < arraysize(kOps); ++i) { | 2841 for (size_t i = 0; i < arraysize(kOps); ++i) { |
| 2827 RawMachineAssemblerTester<int32_t> m(kMachInt32, kMachInt32); | 2842 RawMachineAssemblerTester<int32_t> m(kMachInt32, kMachInt32); |
| 2828 int32_t constant = static_cast<int32_t>(0x55555 + i); | 2843 int32_t constant = static_cast<int32_t>(0x55555 + i); |
| 2829 m.NewNode(kOps[i], m.Parameter(0), m.Parameter(1)); | 2844 m.NewNode(kOps[i], m.Parameter(0), m.Parameter(1)); |
| 2830 m.Return(m.Int32Constant(constant)); | 2845 m.Return(m.Int32Constant(constant)); |
| 2831 | 2846 |
| 2832 CHECK_EQ(constant, m.Call(1, 1)); | 2847 CHECK_EQ(constant, m.Call(1, 1)); |
| 2833 } | 2848 } |
| 2834 } | 2849 } |
| (...skipping 1863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4698 m.Float64RoundTiesAway(m.LoadFromPointer(&input, kMachFloat64))); | 4713 m.Float64RoundTiesAway(m.LoadFromPointer(&input, kMachFloat64))); |
| 4699 m.Return(m.Int32Constant(0)); | 4714 m.Return(m.Int32Constant(0)); |
| 4700 for (size_t i = 0; i < arraysize(kValues); ++i) { | 4715 for (size_t i = 0; i < arraysize(kValues); ++i) { |
| 4701 input = kValues[i]; | 4716 input = kValues[i]; |
| 4702 CHECK_EQ(0, m.Call()); | 4717 CHECK_EQ(0, m.Call()); |
| 4703 double expected = round(kValues[i]); | 4718 double expected = round(kValues[i]); |
| 4704 CHECK_EQ(expected, result); | 4719 CHECK_EQ(expected, result); |
| 4705 } | 4720 } |
| 4706 } | 4721 } |
| 4707 #endif // V8_TURBOFAN_TARGET | 4722 #endif // V8_TURBOFAN_TARGET |
| OLD | NEW |