OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/intermediate_language.h" | 5 #include "vm/intermediate_language.h" |
6 #include "vm/unit_test.h" | 6 #include "vm/unit_test.h" |
7 | 7 |
8 namespace dart { | 8 namespace dart { |
9 | 9 |
10 TEST_CASE(InstructionTests) { | 10 TEST_CASE(InstructionTests) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 RangeBoundary::FromConstant(100)); | 55 RangeBoundary::FromConstant(100)); |
56 EXPECT(positive->IsPositive()); | 56 EXPECT(positive->IsPositive()); |
57 EXPECT(zero->Overlaps(0, 0)); | 57 EXPECT(zero->Overlaps(0, 0)); |
58 EXPECT(positive->Overlaps(0, 0)); | 58 EXPECT(positive->Overlaps(0, 0)); |
59 EXPECT(!negative->Overlaps(0, 0)); | 59 EXPECT(!negative->Overlaps(0, 0)); |
60 EXPECT(range_x->Overlaps(0, 0)); | 60 EXPECT(range_x->Overlaps(0, 0)); |
61 EXPECT(range_x->IsWithin(-15, 100)); | 61 EXPECT(range_x->IsWithin(-15, 100)); |
62 EXPECT(!range_x->IsWithin(-15, 99)); | 62 EXPECT(!range_x->IsWithin(-15, 99)); |
63 EXPECT(!range_x->IsWithin(-14, 100)); | 63 EXPECT(!range_x->IsWithin(-14, 100)); |
64 | 64 |
65 #define TEST_RANGE_OP(Op, l_min, l_max, r_min, r_max, result_min, result_max) \ | 65 #define TEST_RANGE_OP_(Op, l_min, l_max, r_min, r_max, Clamp, res_min, res_max)\ |
66 { \ | 66 { \ |
67 RangeBoundary min, max; \ | 67 RangeBoundary min, max; \ |
68 Range* left_range = new Range( \ | 68 Range* left_range = new Range( \ |
69 RangeBoundary::FromConstant(l_min), \ | 69 RangeBoundary::FromConstant(l_min), \ |
70 RangeBoundary::FromConstant(l_max)); \ | 70 RangeBoundary::FromConstant(l_max)); \ |
71 Range* shift_range = new Range( \ | 71 Range* shift_range = new Range( \ |
72 RangeBoundary::FromConstant(r_min), \ | 72 RangeBoundary::FromConstant(r_min), \ |
73 RangeBoundary::FromConstant(r_max)); \ | 73 RangeBoundary::FromConstant(r_max)); \ |
74 Op(left_range, shift_range, &min, &max); \ | 74 Op(left_range, shift_range, &min, &max); \ |
75 EXPECT(min.Equals(result_min)); \ | 75 min = Clamp(min); \ |
76 if (!min.Equals(result_min)) OS::Print("%s\n", min.ToCString()); \ | 76 max = Clamp(max); \ |
77 EXPECT(max.Equals(result_max)); \ | 77 EXPECT(min.Equals(res_min)); \ |
78 if (!max.Equals(result_max)) OS::Print("%s\n", max.ToCString()); \ | 78 if (!min.Equals(res_min)) OS::Print("%s\n", min.ToCString()); \ |
| 79 EXPECT(max.Equals(res_max)); \ |
| 80 if (!max.Equals(res_max)) OS::Print("%s\n", max.ToCString()); \ |
79 } | 81 } |
80 | 82 |
| 83 #define NO_CLAMP(b) (b) |
| 84 #define TEST_RANGE_OP(Op, l_min, l_max, r_min, r_max, result_min, result_max) \ |
| 85 TEST_RANGE_OP_(Op, l_min, l_max, r_min, r_max, \ |
| 86 NO_CLAMP, result_min, result_max) |
| 87 |
| 88 #define CLAMP_TO_SMI(b) (b.Clamp(RangeBoundary::kRangeBoundarySmi)) |
| 89 #define TEST_RANGE_OP_SMI(Op, l_min, l_max, r_min, r_max, res_min, res_max) \ |
| 90 TEST_RANGE_OP_(Op, l_min, l_max, r_min, r_max, \ |
| 91 CLAMP_TO_SMI, res_min, res_max) |
| 92 |
81 TEST_RANGE_OP(Range::Shl, -15, 100, 0, 2, | 93 TEST_RANGE_OP(Range::Shl, -15, 100, 0, 2, |
82 RangeBoundary(-60), RangeBoundary(400)); | 94 RangeBoundary(-60), RangeBoundary(400)); |
83 TEST_RANGE_OP(Range::Shl, -15, 100, -2, 2, | 95 TEST_RANGE_OP(Range::Shl, -15, 100, -2, 2, |
84 RangeBoundary(-60), RangeBoundary(400)); | 96 RangeBoundary(-60), RangeBoundary(400)); |
85 TEST_RANGE_OP(Range::Shl, -15, -10, 1, 2, | 97 TEST_RANGE_OP(Range::Shl, -15, -10, 1, 2, |
86 RangeBoundary(-60), RangeBoundary(-20)); | 98 RangeBoundary(-60), RangeBoundary(-20)); |
87 TEST_RANGE_OP(Range::Shl, 5, 10, -2, 2, | 99 TEST_RANGE_OP(Range::Shl, 5, 10, -2, 2, |
88 RangeBoundary(5), RangeBoundary(40)); | 100 RangeBoundary(5), RangeBoundary(40)); |
89 TEST_RANGE_OP(Range::Shl, -15, 100, 0, 64, | 101 TEST_RANGE_OP(Range::Shl, -15, 100, 0, 64, |
90 RangeBoundary::NegativeInfinity(), | 102 RangeBoundary::NegativeInfinity(), |
91 RangeBoundary::PositiveInfinity()); | 103 RangeBoundary::PositiveInfinity()); |
92 TEST_RANGE_OP(Range::Shl, -1, 1, 63, 63, | 104 TEST_RANGE_OP(Range::Shl, -1, 1, 63, 63, |
93 RangeBoundary::NegativeInfinity(), | 105 RangeBoundary(kMinInt64), |
94 RangeBoundary::PositiveInfinity()); | 106 RangeBoundary::PositiveInfinity()); |
95 if (kBitsPerWord == 64) { | 107 if (kBitsPerWord == 64) { |
96 TEST_RANGE_OP(Range::Shl, -1, 1, 62, 62, | 108 TEST_RANGE_OP_SMI(Range::Shl, -1, 1, 62, 62, |
97 RangeBoundary(kSmiMin), | 109 RangeBoundary(kSmiMin), |
98 RangeBoundary::PositiveInfinity()); | 110 RangeBoundary(kSmiMax)); |
99 TEST_RANGE_OP(Range::Shl, -1, 1, 30, 30, | 111 TEST_RANGE_OP_SMI(Range::Shl, -1, 1, 30, 30, |
100 RangeBoundary(-1 << 30), | 112 RangeBoundary(-1 << 30), |
101 RangeBoundary(1 << 30)); | 113 RangeBoundary(1 << 30)); |
102 } else { | 114 } else { |
103 TEST_RANGE_OP(Range::Shl, -1, 1, 30, 30, | 115 TEST_RANGE_OP_SMI(Range::Shl, -1, 1, 30, 30, |
104 RangeBoundary(kSmiMin), | 116 RangeBoundary(kSmiMin), |
105 RangeBoundary::PositiveInfinity()); | 117 RangeBoundary(kSmiMax)); |
106 TEST_RANGE_OP(Range::Shl, -1, 1, 62, 62, | 118 TEST_RANGE_OP_SMI(Range::Shl, -1, 1, 62, 62, |
107 RangeBoundary::NegativeInfinity(), | 119 RangeBoundary(kSmiMin), |
108 RangeBoundary::PositiveInfinity()); | 120 RangeBoundary(kSmiMax)); |
109 } | 121 } |
110 TEST_RANGE_OP(Range::Shl, 0, 100, 0, 64, | 122 TEST_RANGE_OP(Range::Shl, 0, 100, 0, 64, |
111 RangeBoundary(0), RangeBoundary::PositiveInfinity()); | 123 RangeBoundary(0), RangeBoundary::PositiveInfinity()); |
112 TEST_RANGE_OP(Range::Shl, -100, 0, 0, 64, | 124 TEST_RANGE_OP(Range::Shl, -100, 0, 0, 64, |
113 RangeBoundary::NegativeInfinity(), RangeBoundary(0)); | 125 RangeBoundary::NegativeInfinity(), RangeBoundary(0)); |
114 | 126 |
115 TEST_RANGE_OP(Range::Shr, -8, 8, 1, 2, RangeBoundary(-4), RangeBoundary(4)); | 127 TEST_RANGE_OP(Range::Shr, -8, 8, 1, 2, RangeBoundary(-4), RangeBoundary(4)); |
116 TEST_RANGE_OP(Range::Shr, 1, 8, 1, 2, RangeBoundary(0), RangeBoundary(4)); | 128 TEST_RANGE_OP(Range::Shr, 1, 8, 1, 2, RangeBoundary(0), RangeBoundary(4)); |
117 TEST_RANGE_OP(Range::Shr, -16, -8, 1, 2, | 129 TEST_RANGE_OP(Range::Shr, -16, -8, 1, 2, |
118 RangeBoundary(-8), RangeBoundary(-2)); | 130 RangeBoundary(-8), RangeBoundary(-2)); |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 RangeBoundary(static_cast<int64_t>(kMaxInt32)), | 664 RangeBoundary(static_cast<int64_t>(kMaxInt32)), |
653 RangeBoundary::kRangeBoundaryInt64).ConstantValue() == kMaxInt32); | 665 RangeBoundary::kRangeBoundaryInt64).ConstantValue() == kMaxInt32); |
654 | 666 |
655 EXPECT(RangeBoundary::Max( | 667 EXPECT(RangeBoundary::Max( |
656 RangeBoundary(static_cast<int64_t>(kMaxInt64)), | 668 RangeBoundary(static_cast<int64_t>(kMaxInt64)), |
657 RangeBoundary(static_cast<int64_t>(kMaxInt32)), | 669 RangeBoundary(static_cast<int64_t>(kMaxInt32)), |
658 RangeBoundary::kRangeBoundaryInt64).ConstantValue() == kMaxInt64); | 670 RangeBoundary::kRangeBoundaryInt64).ConstantValue() == kMaxInt64); |
659 } | 671 } |
660 | 672 |
661 } // namespace dart | 673 } // namespace dart |
OLD | NEW |