OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. Use of this | 1 // Copyright 2014 the V8 project authors. All rights reserved. Use of this |
2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
3 // LICENSE file. | 3 // 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/base/utils/random-number-generator.h" | 10 #include "src/base/utils/random-number-generator.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 namespace compiler { | 21 namespace compiler { |
22 | 22 |
23 | 23 |
24 TEST(RunInt32Add) { | 24 TEST(RunInt32Add) { |
25 RawMachineAssemblerTester<int32_t> m; | 25 RawMachineAssemblerTester<int32_t> m; |
26 Node* add = m.Int32Add(m.Int32Constant(0), m.Int32Constant(1)); | 26 Node* add = m.Int32Add(m.Int32Constant(0), m.Int32Constant(1)); |
27 m.Return(add); | 27 m.Return(add); |
28 CHECK_EQ(1, m.Call()); | 28 CHECK_EQ(1, m.Call()); |
29 } | 29 } |
30 | 30 |
| 31 static int RunInt32AddShift(bool is_left, int32_t add_left, int32_t add_right, |
| 32 int32_t shift_left, int32_t shit_right) { |
| 33 RawMachineAssemblerTester<int32_t> m; |
| 34 Node* shift = |
| 35 m.Word32Shl(m.Int32Constant(shift_left), m.Int32Constant(shit_right)); |
| 36 Node* add = m.Int32Add(m.Int32Constant(add_left), m.Int32Constant(add_right)); |
| 37 Node* lsa = is_left ? m.Int32Add(shift, add) : m.Int32Add(add, shift); |
| 38 m.Return(lsa); |
| 39 return m.Call(); |
| 40 } |
| 41 |
| 42 TEST(RunInt32AddShift) { |
| 43 struct Test_case { |
| 44 int32_t add_left, add_right, shift_left, shit_right, expected; |
| 45 }; |
| 46 |
| 47 Test_case tc[] = { |
| 48 {20, 22, 4, 2, 58}, |
| 49 {20, 22, 4, 1, 50}, |
| 50 {20, 22, 1, 6, 106}, |
| 51 {INT_MAX - 2, 1, 1, 1, INT_MIN}, // INT_MAX - 2 + 1 + (1 << 1), overflow. |
| 52 }; |
| 53 const size_t tc_size = sizeof(tc) / sizeof(Test_case); |
| 54 |
| 55 for (size_t i = 0; i < tc_size; ++i) { |
| 56 CHECK_EQ(tc[i].expected, |
| 57 RunInt32AddShift(false, tc[i].add_left, tc[i].add_right, |
| 58 tc[i].shift_left, tc[i].shit_right)); |
| 59 CHECK_EQ(tc[i].expected, |
| 60 RunInt32AddShift(true, tc[i].add_left, tc[i].add_right, |
| 61 tc[i].shift_left, tc[i].shit_right)); |
| 62 } |
| 63 } |
31 | 64 |
32 TEST(RunWord32ReverseBits) { | 65 TEST(RunWord32ReverseBits) { |
33 BufferedRawMachineAssemblerTester<uint32_t> m(MachineType::Uint32()); | 66 BufferedRawMachineAssemblerTester<uint32_t> m(MachineType::Uint32()); |
34 if (!m.machine()->Word32ReverseBits().IsSupported()) { | 67 if (!m.machine()->Word32ReverseBits().IsSupported()) { |
35 // We can only test the operator if it exists on the testing platform. | 68 // We can only test the operator if it exists on the testing platform. |
36 return; | 69 return; |
37 } | 70 } |
38 m.Return(m.AddNode(m.machine()->Word32ReverseBits().op(), m.Parameter(0))); | 71 m.Return(m.AddNode(m.machine()->Word32ReverseBits().op(), m.Parameter(0))); |
39 | 72 |
40 CHECK_EQ(uint32_t(0x00000000), m.Call(uint32_t(0x00000000))); | 73 CHECK_EQ(uint32_t(0x00000000), m.Call(uint32_t(0x00000000))); |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 int32_t expected = constant; | 662 int32_t expected = constant; |
630 int64_t result; | 663 int64_t result; |
631 if (!bits::SignedSubOverflow64(*i, *j, &result)) { | 664 if (!bits::SignedSubOverflow64(*i, *j, &result)) { |
632 expected = static_cast<int32_t>(result); | 665 expected = static_cast<int32_t>(result); |
633 } | 666 } |
634 CHECK_EQ(expected, static_cast<int32_t>(bt.call(*i, *j))); | 667 CHECK_EQ(expected, static_cast<int32_t>(bt.call(*i, *j))); |
635 } | 668 } |
636 } | 669 } |
637 } | 670 } |
638 | 671 |
| 672 static int64_t RunInt64AddShift(bool is_left, int64_t add_left, |
| 673 int64_t add_right, int64_t shift_left, |
| 674 int64_t shit_right) { |
| 675 RawMachineAssemblerTester<int64_t> m; |
| 676 Node* shift = m.Word64Shl(m.Int64Constant(4), m.Int64Constant(2)); |
| 677 Node* add = m.Int64Add(m.Int64Constant(20), m.Int64Constant(22)); |
| 678 Node* dlsa = is_left ? m.Int64Add(shift, add) : m.Int64Add(add, shift); |
| 679 m.Return(dlsa); |
| 680 return m.Call(); |
| 681 } |
| 682 |
| 683 TEST(RunInt64AddShift) { |
| 684 struct Test_case { |
| 685 int64_t add_left, add_right, shift_left, shit_right, expected; |
| 686 }; |
| 687 |
| 688 Test_case tc[] = { |
| 689 {20, 22, 4, 2, 58}, |
| 690 {20, 22, 4, 1, 50}, |
| 691 {20, 22, 1, 6, 106}, |
| 692 {INT64_MAX - 2, 1, 1, 1, |
| 693 INT64_MIN}, // INT64_MAX - 2 + 1 + (1 << 1), overflow. |
| 694 }; |
| 695 const size_t tc_size = sizeof(tc) / sizeof(Test_case); |
| 696 |
| 697 for (size_t i = 0; i < tc_size; ++i) { |
| 698 CHECK_EQ(58, RunInt64AddShift(false, tc[i].add_left, tc[i].add_right, |
| 699 tc[i].shift_left, tc[i].shit_right)); |
| 700 CHECK_EQ(58, RunInt64AddShift(true, tc[i].add_left, tc[i].add_right, |
| 701 tc[i].shift_left, tc[i].shit_right)); |
| 702 } |
| 703 } |
639 | 704 |
640 // TODO(titzer): add tests that run 64-bit integer operations. | 705 // TODO(titzer): add tests that run 64-bit integer operations. |
641 #endif // V8_TARGET_ARCH_64_BIT | 706 #endif // V8_TARGET_ARCH_64_BIT |
642 | 707 |
643 | 708 |
644 TEST(RunGoto) { | 709 TEST(RunGoto) { |
645 RawMachineAssemblerTester<int32_t> m; | 710 RawMachineAssemblerTester<int32_t> m; |
646 int constant = 99999; | 711 int constant = 99999; |
647 | 712 |
648 RawMachineLabel next; | 713 RawMachineLabel next; |
(...skipping 5781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6430 r.Goto(&merge); | 6495 r.Goto(&merge); |
6431 r.Bind(&merge); | 6496 r.Bind(&merge); |
6432 Node* phi = r.Phi(MachineRepresentation::kWord32, fa, fb); | 6497 Node* phi = r.Phi(MachineRepresentation::kWord32, fa, fb); |
6433 r.Return(phi); | 6498 r.Return(phi); |
6434 CHECK_EQ(1, r.Call(1)); | 6499 CHECK_EQ(1, r.Call(1)); |
6435 } | 6500 } |
6436 | 6501 |
6437 } // namespace compiler | 6502 } // namespace compiler |
6438 } // namespace internal | 6503 } // namespace internal |
6439 } // namespace v8 | 6504 } // namespace v8 |
OLD | NEW |