| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 return m->Load(kMachInt32, m->PointerConstant(NULL)); | 51 return m->Load(kMachInt32, m->PointerConstant(NULL)); |
| 52 default: | 52 default: |
| 53 return NULL; | 53 return NULL; |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 | 56 |
| 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* kOps[] = { |
| 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()->Uint32Div(), | 67 m.machine()->Int32MulHigh(), m.machine()->Int32Div(), |
| 68 m.machine()->Int32Mod(), m.machine()->Uint32Mod(), | 68 m.machine()->Uint32Div(), m.machine()->Int32Mod(), |
| 69 m.machine()->Int32LessThan(), m.machine()->Int32LessThanOrEqual(), | 69 m.machine()->Uint32Mod(), m.machine()->Int32LessThan(), |
| 70 m.machine()->Uint32LessThan(), m.machine()->Uint32LessThanOrEqual(), | 70 m.machine()->Int32LessThanOrEqual(), m.machine()->Uint32LessThan(), |
| 71 NULL}; | 71 m.machine()->Uint32LessThanOrEqual()}; |
| 72 | 72 |
| 73 for (int i = 0; ops[i] != NULL; i++) { | 73 for (size_t i = 0; i < arraysize(kOps); ++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); |
| 79 m.Return(m.NewNode(ops[i], a, b)); | 79 m.Return(m.NewNode(kOps[i], a, b)); |
| 80 m.GenerateCode(); | 80 m.GenerateCode(); |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 | 85 |
| 86 | 86 |
| 87 TEST(RunGoto) { | 87 TEST(RunGoto) { |
| 88 RawMachineAssemblerTester<int32_t> m; | 88 RawMachineAssemblerTester<int32_t> m; |
| 89 int constant = 99999; | 89 int constant = 99999; |
| (...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1226 FOR_UINT32_INPUTS(i) { | 1226 FOR_UINT32_INPUTS(i) { |
| 1227 FOR_UINT32_INPUTS(j) { | 1227 FOR_UINT32_INPUTS(j) { |
| 1228 uint32_t expected = *i * *j; | 1228 uint32_t expected = *i * *j; |
| 1229 CHECK_UINT32_EQ(expected, bt.call(*i, *j)); | 1229 CHECK_UINT32_EQ(expected, bt.call(*i, *j)); |
| 1230 } | 1230 } |
| 1231 } | 1231 } |
| 1232 } | 1232 } |
| 1233 } | 1233 } |
| 1234 | 1234 |
| 1235 | 1235 |
| 1236 TEST(RunInt32MulHighP) { |
| 1237 RawMachineAssemblerTester<int32_t> m; |
| 1238 Int32BinopTester bt(&m); |
| 1239 bt.AddReturn(m.Int32MulHigh(bt.param0, bt.param1)); |
| 1240 FOR_INT32_INPUTS(i) { |
| 1241 FOR_INT32_INPUTS(j) { |
| 1242 int32_t expected = static_cast<int32_t>( |
| 1243 (static_cast<int64_t>(*i) * static_cast<int64_t>(*j)) >> 32); |
| 1244 CHECK_EQ(expected, bt.call(*i, *j)); |
| 1245 } |
| 1246 } |
| 1247 } |
| 1248 |
| 1249 |
| 1236 TEST(RunInt32MulImm) { | 1250 TEST(RunInt32MulImm) { |
| 1237 { | 1251 { |
| 1238 FOR_UINT32_INPUTS(i) { | 1252 FOR_UINT32_INPUTS(i) { |
| 1239 RawMachineAssemblerTester<uint32_t> m(kMachUint32); | 1253 RawMachineAssemblerTester<uint32_t> m(kMachUint32); |
| 1240 m.Return(m.Int32Mul(m.Int32Constant(*i), m.Parameter(0))); | 1254 m.Return(m.Int32Mul(m.Int32Constant(*i), m.Parameter(0))); |
| 1241 FOR_UINT32_INPUTS(j) { | 1255 FOR_UINT32_INPUTS(j) { |
| 1242 uint32_t expected = *i * *j; | 1256 uint32_t expected = *i * *j; |
| 1243 CHECK_UINT32_EQ(expected, m.Call(*j)); | 1257 CHECK_UINT32_EQ(expected, m.Call(*j)); |
| 1244 } | 1258 } |
| 1245 } | 1259 } |
| (...skipping 1421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2667 } else { | 2681 } else { |
| 2668 CHECK_EQ(constant, m.Call(0)); | 2682 CHECK_EQ(constant, m.Call(0)); |
| 2669 } | 2683 } |
| 2670 } | 2684 } |
| 2671 } | 2685 } |
| 2672 | 2686 |
| 2673 | 2687 |
| 2674 TEST(RunDeadInt32Binops) { | 2688 TEST(RunDeadInt32Binops) { |
| 2675 RawMachineAssemblerTester<int32_t> m; | 2689 RawMachineAssemblerTester<int32_t> m; |
| 2676 | 2690 |
| 2677 const Operator* ops[] = { | 2691 const Operator* kOps[] = { |
| 2678 m.machine()->Word32And(), m.machine()->Word32Or(), | 2692 m.machine()->Word32And(), m.machine()->Word32Or(), |
| 2679 m.machine()->Word32Xor(), m.machine()->Word32Shl(), | 2693 m.machine()->Word32Xor(), m.machine()->Word32Shl(), |
| 2680 m.machine()->Word32Shr(), m.machine()->Word32Sar(), | 2694 m.machine()->Word32Shr(), m.machine()->Word32Sar(), |
| 2681 m.machine()->Word32Ror(), m.machine()->Word32Equal(), | 2695 m.machine()->Word32Ror(), m.machine()->Word32Equal(), |
| 2682 m.machine()->Int32Add(), m.machine()->Int32Sub(), | 2696 m.machine()->Int32Add(), m.machine()->Int32Sub(), |
| 2683 m.machine()->Int32Mul(), m.machine()->Int32Div(), | 2697 m.machine()->Int32Mul(), m.machine()->Int32MulHigh(), |
| 2684 m.machine()->Uint32Div(), m.machine()->Int32Mod(), | 2698 m.machine()->Int32Div(), m.machine()->Uint32Div(), |
| 2685 m.machine()->Uint32Mod(), m.machine()->Int32LessThan(), | 2699 m.machine()->Int32Mod(), m.machine()->Uint32Mod(), |
| 2686 m.machine()->Int32LessThanOrEqual(), m.machine()->Uint32LessThan(), | 2700 m.machine()->Int32LessThan(), m.machine()->Int32LessThanOrEqual(), |
| 2687 m.machine()->Uint32LessThanOrEqual(), NULL}; | 2701 m.machine()->Uint32LessThan(), m.machine()->Uint32LessThanOrEqual()}; |
| 2688 | 2702 |
| 2689 for (int i = 0; ops[i] != NULL; i++) { | 2703 for (size_t i = 0; i < arraysize(kOps); ++i) { |
| 2690 RawMachineAssemblerTester<int32_t> m(kMachInt32, kMachInt32); | 2704 RawMachineAssemblerTester<int32_t> m(kMachInt32, kMachInt32); |
| 2691 int constant = 0x55555 + i; | 2705 int32_t constant = static_cast<int32_t>(0x55555 + i); |
| 2692 m.NewNode(ops[i], m.Parameter(0), m.Parameter(1)); | 2706 m.NewNode(kOps[i], m.Parameter(0), m.Parameter(1)); |
| 2693 m.Return(m.Int32Constant(constant)); | 2707 m.Return(m.Int32Constant(constant)); |
| 2694 | 2708 |
| 2695 CHECK_EQ(constant, m.Call(1, 1)); | 2709 CHECK_EQ(constant, m.Call(1, 1)); |
| 2696 } | 2710 } |
| 2697 } | 2711 } |
| 2698 | 2712 |
| 2699 | 2713 |
| 2700 template <typename Type> | 2714 template <typename Type> |
| 2701 static void RunLoadImmIndex(MachineType rep) { | 2715 static void RunLoadImmIndex(MachineType rep) { |
| 2702 const int kNumElems = 3; | 2716 const int kNumElems = 3; |
| (...skipping 1691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4394 float actual = *i; | 4408 float actual = *i; |
| 4395 RawMachineAssemblerTester<int32_t> m; | 4409 RawMachineAssemblerTester<int32_t> m; |
| 4396 m.StoreToPointer(&actual, kMachFloat32, m.Float32Constant(expected)); | 4410 m.StoreToPointer(&actual, kMachFloat32, m.Float32Constant(expected)); |
| 4397 m.Return(m.Int32Constant(0)); | 4411 m.Return(m.Int32Constant(0)); |
| 4398 CHECK_EQ(0, m.Call()); | 4412 CHECK_EQ(0, m.Call()); |
| 4399 CHECK_EQ(expected, actual); | 4413 CHECK_EQ(expected, actual); |
| 4400 } | 4414 } |
| 4401 } | 4415 } |
| 4402 | 4416 |
| 4403 #endif // V8_TURBOFAN_TARGET | 4417 #endif // V8_TURBOFAN_TARGET |
| OLD | NEW |