OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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/flow_graph_range_analysis.h" | 5 #include "vm/flow_graph_range_analysis.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(RangeTests) { | 10 TEST_CASE(RangeTests) { |
11 Range* zero = new Range( | 11 Range* zero = |
12 RangeBoundary::FromConstant(0), | 12 new Range(RangeBoundary::FromConstant(0), RangeBoundary::FromConstant(0)); |
13 RangeBoundary::FromConstant(0)); | 13 Range* positive = new Range(RangeBoundary::FromConstant(0), |
14 Range* positive = new Range( | 14 RangeBoundary::FromConstant(100)); |
15 RangeBoundary::FromConstant(0), | 15 Range* negative = new Range(RangeBoundary::FromConstant(-1), |
16 RangeBoundary::FromConstant(100)); | 16 RangeBoundary::FromConstant(-100)); |
17 Range* negative = new Range( | 17 Range* range_x = new Range(RangeBoundary::FromConstant(-15), |
18 RangeBoundary::FromConstant(-1), | 18 RangeBoundary::FromConstant(100)); |
19 RangeBoundary::FromConstant(-100)); | |
20 Range* range_x = new Range( | |
21 RangeBoundary::FromConstant(-15), | |
22 RangeBoundary::FromConstant(100)); | |
23 EXPECT(positive->IsPositive()); | 19 EXPECT(positive->IsPositive()); |
24 EXPECT(zero->Overlaps(0, 0)); | 20 EXPECT(zero->Overlaps(0, 0)); |
25 EXPECT(positive->Overlaps(0, 0)); | 21 EXPECT(positive->Overlaps(0, 0)); |
26 EXPECT(!negative->Overlaps(0, 0)); | 22 EXPECT(!negative->Overlaps(0, 0)); |
27 EXPECT(range_x->Overlaps(0, 0)); | 23 EXPECT(range_x->Overlaps(0, 0)); |
28 EXPECT(range_x->IsWithin(-15, 100)); | 24 EXPECT(range_x->IsWithin(-15, 100)); |
29 EXPECT(!range_x->IsWithin(-15, 99)); | 25 EXPECT(!range_x->IsWithin(-15, 99)); |
30 EXPECT(!range_x->IsWithin(-14, 100)); | 26 EXPECT(!range_x->IsWithin(-14, 100)); |
31 | 27 |
32 #define TEST_RANGE_OP_(Op, l_min, l_max, r_min, r_max, Clamp, res_min, res_max)\ | 28 #define TEST_RANGE_OP_(Op, l_min, l_max, r_min, r_max, Clamp, res_min, \ |
| 29 res_max) \ |
33 { \ | 30 { \ |
34 RangeBoundary min, max; \ | 31 RangeBoundary min, max; \ |
35 Range* left_range = new Range( \ | 32 Range* left_range = new Range(RangeBoundary::FromConstant(l_min), \ |
36 RangeBoundary::FromConstant(l_min), \ | 33 RangeBoundary::FromConstant(l_max)); \ |
37 RangeBoundary::FromConstant(l_max)); \ | 34 Range* shift_range = new Range(RangeBoundary::FromConstant(r_min), \ |
38 Range* shift_range = new Range( \ | 35 RangeBoundary::FromConstant(r_max)); \ |
39 RangeBoundary::FromConstant(r_min), \ | |
40 RangeBoundary::FromConstant(r_max)); \ | |
41 Op(left_range, shift_range, &min, &max); \ | 36 Op(left_range, shift_range, &min, &max); \ |
42 min = Clamp(min); \ | 37 min = Clamp(min); \ |
43 max = Clamp(max); \ | 38 max = Clamp(max); \ |
44 EXPECT(min.Equals(res_min)); \ | 39 EXPECT(min.Equals(res_min)); \ |
45 if (FLAG_support_il_printer && !min.Equals(res_min)) { \ | 40 if (FLAG_support_il_printer && !min.Equals(res_min)) { \ |
46 OS::Print("%s\n", min.ToCString()); \ | 41 OS::Print("%s\n", min.ToCString()); \ |
47 } \ | 42 } \ |
48 EXPECT(max.Equals(res_max)); \ | 43 EXPECT(max.Equals(res_max)); \ |
49 if (FLAG_support_il_printer && !max.Equals(res_max)) { \ | 44 if (FLAG_support_il_printer && !max.Equals(res_max)) { \ |
50 OS::Print("%s\n", max.ToCString()); \ | 45 OS::Print("%s\n", max.ToCString()); \ |
51 } \ | 46 } \ |
52 } | 47 } |
53 | 48 |
54 #define NO_CLAMP(b) (b) | 49 #define NO_CLAMP(b) (b) |
55 #define TEST_RANGE_OP(Op, l_min, l_max, r_min, r_max, result_min, result_max) \ | 50 #define TEST_RANGE_OP(Op, l_min, l_max, r_min, r_max, result_min, result_max) \ |
56 TEST_RANGE_OP_(Op, l_min, l_max, r_min, r_max, \ | 51 TEST_RANGE_OP_(Op, l_min, l_max, r_min, r_max, NO_CLAMP, result_min, \ |
57 NO_CLAMP, result_min, result_max) | 52 result_max) |
58 | 53 |
59 #define CLAMP_TO_SMI(b) (b.Clamp(RangeBoundary::kRangeBoundarySmi)) | 54 #define CLAMP_TO_SMI(b) (b.Clamp(RangeBoundary::kRangeBoundarySmi)) |
60 #define TEST_RANGE_OP_SMI(Op, l_min, l_max, r_min, r_max, res_min, res_max) \ | 55 #define TEST_RANGE_OP_SMI(Op, l_min, l_max, r_min, r_max, res_min, res_max) \ |
61 TEST_RANGE_OP_(Op, l_min, l_max, r_min, r_max, \ | 56 TEST_RANGE_OP_(Op, l_min, l_max, r_min, r_max, CLAMP_TO_SMI, res_min, res_max) |
62 CLAMP_TO_SMI, res_min, res_max) | |
63 | 57 |
64 TEST_RANGE_OP(Range::Shl, -15, 100, 0, 2, | 58 TEST_RANGE_OP(Range::Shl, -15, 100, 0, 2, RangeBoundary(-60), |
65 RangeBoundary(-60), RangeBoundary(400)); | 59 RangeBoundary(400)); |
66 TEST_RANGE_OP(Range::Shl, -15, 100, -2, 2, | 60 TEST_RANGE_OP(Range::Shl, -15, 100, -2, 2, RangeBoundary(-60), |
67 RangeBoundary(-60), RangeBoundary(400)); | 61 RangeBoundary(400)); |
68 TEST_RANGE_OP(Range::Shl, -15, -10, 1, 2, | 62 TEST_RANGE_OP(Range::Shl, -15, -10, 1, 2, RangeBoundary(-60), |
69 RangeBoundary(-60), RangeBoundary(-20)); | 63 RangeBoundary(-20)); |
70 TEST_RANGE_OP(Range::Shl, 5, 10, -2, 2, | 64 TEST_RANGE_OP(Range::Shl, 5, 10, -2, 2, RangeBoundary(5), RangeBoundary(40)); |
71 RangeBoundary(5), RangeBoundary(40)); | 65 TEST_RANGE_OP(Range::Shl, -15, 100, 0, 64, RangeBoundary::NegativeInfinity(), |
72 TEST_RANGE_OP(Range::Shl, -15, 100, 0, 64, | |
73 RangeBoundary::NegativeInfinity(), | |
74 RangeBoundary::PositiveInfinity()); | 66 RangeBoundary::PositiveInfinity()); |
75 TEST_RANGE_OP(Range::Shl, -1, 1, 63, 63, | 67 TEST_RANGE_OP(Range::Shl, -1, 1, 63, 63, RangeBoundary(kMinInt64), |
76 RangeBoundary(kMinInt64), | |
77 RangeBoundary::PositiveInfinity()); | 68 RangeBoundary::PositiveInfinity()); |
78 if (kBitsPerWord == 64) { | 69 if (kBitsPerWord == 64) { |
79 TEST_RANGE_OP_SMI(Range::Shl, -1, 1, 62, 62, | 70 TEST_RANGE_OP_SMI(Range::Shl, -1, 1, 62, 62, RangeBoundary(kSmiMin), |
80 RangeBoundary(kSmiMin), | 71 RangeBoundary(kSmiMax)); |
81 RangeBoundary(kSmiMax)); | 72 TEST_RANGE_OP_SMI(Range::Shl, -1, 1, 30, 30, RangeBoundary(-(1 << 30)), |
82 TEST_RANGE_OP_SMI(Range::Shl, -1, 1, 30, 30, | 73 RangeBoundary(1 << 30)); |
83 RangeBoundary(-(1 << 30)), | |
84 RangeBoundary(1 << 30)); | |
85 } else { | 74 } else { |
86 TEST_RANGE_OP_SMI(Range::Shl, -1, 1, 30, 30, | 75 TEST_RANGE_OP_SMI(Range::Shl, -1, 1, 30, 30, RangeBoundary(kSmiMin), |
87 RangeBoundary(kSmiMin), | 76 RangeBoundary(kSmiMax)); |
88 RangeBoundary(kSmiMax)); | 77 TEST_RANGE_OP_SMI(Range::Shl, -1, 1, 62, 62, RangeBoundary(kSmiMin), |
89 TEST_RANGE_OP_SMI(Range::Shl, -1, 1, 62, 62, | 78 RangeBoundary(kSmiMax)); |
90 RangeBoundary(kSmiMin), | |
91 RangeBoundary(kSmiMax)); | |
92 } | 79 } |
93 TEST_RANGE_OP(Range::Shl, 0, 100, 0, 64, | 80 TEST_RANGE_OP(Range::Shl, 0, 100, 0, 64, RangeBoundary(0), |
94 RangeBoundary(0), RangeBoundary::PositiveInfinity()); | 81 RangeBoundary::PositiveInfinity()); |
95 TEST_RANGE_OP(Range::Shl, -100, 0, 0, 64, | 82 TEST_RANGE_OP(Range::Shl, -100, 0, 0, 64, RangeBoundary::NegativeInfinity(), |
96 RangeBoundary::NegativeInfinity(), RangeBoundary(0)); | 83 RangeBoundary(0)); |
97 | 84 |
98 TEST_RANGE_OP(Range::Shr, -8, 8, 1, 2, RangeBoundary(-4), RangeBoundary(4)); | 85 TEST_RANGE_OP(Range::Shr, -8, 8, 1, 2, RangeBoundary(-4), RangeBoundary(4)); |
99 TEST_RANGE_OP(Range::Shr, 1, 8, 1, 2, RangeBoundary(0), RangeBoundary(4)); | 86 TEST_RANGE_OP(Range::Shr, 1, 8, 1, 2, RangeBoundary(0), RangeBoundary(4)); |
100 TEST_RANGE_OP(Range::Shr, -16, -8, 1, 2, | 87 TEST_RANGE_OP(Range::Shr, -16, -8, 1, 2, RangeBoundary(-8), |
101 RangeBoundary(-8), RangeBoundary(-2)); | 88 RangeBoundary(-2)); |
102 TEST_RANGE_OP(Range::Shr, 2, 4, -1, 1, RangeBoundary(1), RangeBoundary(4)); | 89 TEST_RANGE_OP(Range::Shr, 2, 4, -1, 1, RangeBoundary(1), RangeBoundary(4)); |
103 TEST_RANGE_OP(Range::Shr, kMaxInt64, kMaxInt64, 0, 1, | 90 TEST_RANGE_OP(Range::Shr, kMaxInt64, kMaxInt64, 0, 1, |
104 RangeBoundary(kMaxInt64 >> 1), RangeBoundary(kMaxInt64)); | 91 RangeBoundary(kMaxInt64 >> 1), RangeBoundary(kMaxInt64)); |
105 TEST_RANGE_OP(Range::Shr, kMinInt64, kMinInt64, 0, 1, | 92 TEST_RANGE_OP(Range::Shr, kMinInt64, kMinInt64, 0, 1, |
106 RangeBoundary(kMinInt64), RangeBoundary(kMinInt64 >> 1)); | 93 RangeBoundary(kMinInt64), RangeBoundary(kMinInt64 >> 1)); |
107 #undef TEST_RANGE_OP | 94 #undef TEST_RANGE_OP |
108 } | 95 } |
109 | 96 |
110 | 97 |
111 TEST_CASE(RangeTestsInfinity) { | 98 TEST_CASE(RangeTestsInfinity) { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 | 212 |
226 // [-inf, +inf]. | 213 // [-inf, +inf]. |
227 EXPECT(!Range::OnlyNegativeOrZero(range_0, range_0)); | 214 EXPECT(!Range::OnlyNegativeOrZero(range_0, range_0)); |
228 EXPECT(!Range::OnlyPositiveOrZero(range_0, range_0)); | 215 EXPECT(!Range::OnlyPositiveOrZero(range_0, range_0)); |
229 | 216 |
230 EXPECT(Range::ConstantAbsMax(&range_0) == RangeBoundary::kMax); | 217 EXPECT(Range::ConstantAbsMax(&range_0) == RangeBoundary::kMax); |
231 EXPECT(Range::ConstantAbsMax(&range_h) == 2); | 218 EXPECT(Range::ConstantAbsMax(&range_h) == 2); |
232 EXPECT(Range::ConstantAbsMax(&range_i) == 1); | 219 EXPECT(Range::ConstantAbsMax(&range_i) == 1); |
233 | 220 |
234 // RangeBOundary.Equals. | 221 // RangeBOundary.Equals. |
235 EXPECT(RangeBoundary::FromConstant(1).Equals( | 222 EXPECT(RangeBoundary::FromConstant(1).Equals(RangeBoundary::FromConstant(1))); |
236 RangeBoundary::FromConstant(1))); | 223 EXPECT( |
237 EXPECT(!RangeBoundary::FromConstant(2).Equals( | 224 !RangeBoundary::FromConstant(2).Equals(RangeBoundary::FromConstant(1))); |
238 RangeBoundary::FromConstant(1))); | |
239 EXPECT(RangeBoundary::PositiveInfinity().Equals( | 225 EXPECT(RangeBoundary::PositiveInfinity().Equals( |
240 RangeBoundary::PositiveInfinity())); | 226 RangeBoundary::PositiveInfinity())); |
241 EXPECT(!RangeBoundary::PositiveInfinity().Equals( | 227 EXPECT(!RangeBoundary::PositiveInfinity().Equals( |
242 RangeBoundary::NegativeInfinity())); | 228 RangeBoundary::NegativeInfinity())); |
243 EXPECT(RangeBoundary::NegativeInfinity().Equals( | 229 EXPECT(RangeBoundary::NegativeInfinity().Equals( |
244 RangeBoundary::NegativeInfinity())); | 230 RangeBoundary::NegativeInfinity())); |
245 EXPECT(!RangeBoundary::NegativeInfinity().Equals( | 231 EXPECT(!RangeBoundary::NegativeInfinity().Equals( |
246 RangeBoundary::PositiveInfinity())); | 232 RangeBoundary::PositiveInfinity())); |
247 EXPECT(!RangeBoundary::FromConstant(1).Equals( | 233 EXPECT(!RangeBoundary::FromConstant(1).Equals( |
248 RangeBoundary::NegativeInfinity())); | 234 RangeBoundary::NegativeInfinity())); |
(...skipping 11 matching lines...) Expand all Loading... |
260 EXPECT(range_a->min().ConstantValue() == -1); | 246 EXPECT(range_a->min().ConstantValue() == -1); |
261 EXPECT(range_a->max().ConstantValue() == RangeBoundary::kMax); | 247 EXPECT(range_a->max().ConstantValue() == RangeBoundary::kMax); |
262 Range* range_b = new Range(RangeBoundary::NegativeInfinity(), | 248 Range* range_b = new Range(RangeBoundary::NegativeInfinity(), |
263 RangeBoundary::FromConstant(1)); | 249 RangeBoundary::FromConstant(1)); |
264 range_b->Clamp(RangeBoundary::kRangeBoundaryInt64); | 250 range_b->Clamp(RangeBoundary::kRangeBoundaryInt64); |
265 EXPECT(range_b->min().ConstantValue() == RangeBoundary::kMin); | 251 EXPECT(range_b->min().ConstantValue() == RangeBoundary::kMin); |
266 EXPECT(range_b->max().ConstantValue() == 1); | 252 EXPECT(range_b->max().ConstantValue() == 1); |
267 | 253 |
268 { | 254 { |
269 Range result; | 255 Range result; |
270 Range::BinaryOp(Token::kADD, | 256 Range::BinaryOp(Token::kADD, range_a, range_b, NULL, &result); |
271 range_a, | |
272 range_b, | |
273 NULL, | |
274 &result); | |
275 ASSERT(!Range::IsUnknown(&result)); | 257 ASSERT(!Range::IsUnknown(&result)); |
276 EXPECT(result.min().IsNegativeInfinity()); | 258 EXPECT(result.min().IsNegativeInfinity()); |
277 EXPECT(result.max().IsPositiveInfinity()); | 259 EXPECT(result.max().IsPositiveInfinity()); |
278 } | 260 } |
279 | 261 |
280 // Test that [5, 10] + [0, 5] = [5, 15]. | 262 // Test that [5, 10] + [0, 5] = [5, 15]. |
281 Range* range_c = new Range(RangeBoundary::FromConstant(5), | 263 Range* range_c = new Range(RangeBoundary::FromConstant(5), |
282 RangeBoundary::FromConstant(10)); | 264 RangeBoundary::FromConstant(10)); |
283 Range* range_d = new Range(RangeBoundary::FromConstant(0), | 265 Range* range_d = |
284 RangeBoundary::FromConstant(5)); | 266 new Range(RangeBoundary::FromConstant(0), RangeBoundary::FromConstant(5)); |
285 | 267 |
286 { | 268 { |
287 Range result; | 269 Range result; |
288 Range::BinaryOp(Token::kADD, | 270 Range::BinaryOp(Token::kADD, range_c, range_d, NULL, &result); |
289 range_c, | |
290 range_d, | |
291 NULL, | |
292 &result); | |
293 ASSERT(!Range::IsUnknown(&result)); | 271 ASSERT(!Range::IsUnknown(&result)); |
294 EXPECT(result.min().ConstantValue() == 5); | 272 EXPECT(result.min().ConstantValue() == 5); |
295 EXPECT(result.max().ConstantValue() == 15); | 273 EXPECT(result.max().ConstantValue() == 15); |
296 } | 274 } |
297 | 275 |
298 // Test that [0xff, 0xfff] & [0xf, 0xf] = [0x0, 0xf]. | 276 // Test that [0xff, 0xfff] & [0xf, 0xf] = [0x0, 0xf]. |
299 Range* range_e = new Range(RangeBoundary::FromConstant(0xff), | 277 Range* range_e = new Range(RangeBoundary::FromConstant(0xff), |
300 RangeBoundary::FromConstant(0xfff)); | 278 RangeBoundary::FromConstant(0xfff)); |
301 Range* range_f = new Range(RangeBoundary::FromConstant(0xf), | 279 Range* range_f = new Range(RangeBoundary::FromConstant(0xf), |
302 RangeBoundary::FromConstant(0xf)); | 280 RangeBoundary::FromConstant(0xf)); |
303 { | 281 { |
304 Range result; | 282 Range result; |
305 Range::BinaryOp(Token::kBIT_AND, | 283 Range::BinaryOp(Token::kBIT_AND, range_e, range_f, NULL, &result); |
306 range_e, | |
307 range_f, | |
308 NULL, | |
309 &result); | |
310 ASSERT(!Range::IsUnknown(&result)); | 284 ASSERT(!Range::IsUnknown(&result)); |
311 EXPECT(result.min().ConstantValue() == 0x0); | 285 EXPECT(result.min().ConstantValue() == 0x0); |
312 EXPECT(result.max().ConstantValue() == 0xf); | 286 EXPECT(result.max().ConstantValue() == 0xf); |
313 } | 287 } |
314 } | 288 } |
315 | 289 |
316 | 290 |
317 TEST_CASE(RangeAdd) { | 291 TEST_CASE(RangeAdd) { |
318 #define TEST_RANGE_ADD(l_min, l_max, r_min, r_max, result_min, result_max) \ | 292 #define TEST_RANGE_ADD(l_min, l_max, r_min, r_max, result_min, result_max) \ |
319 { \ | 293 { \ |
320 RangeBoundary min, max; \ | 294 RangeBoundary min, max; \ |
321 Range* left_range = new Range( \ | 295 Range* left_range = new Range(RangeBoundary::FromConstant(l_min), \ |
322 RangeBoundary::FromConstant(l_min), \ | 296 RangeBoundary::FromConstant(l_max)); \ |
323 RangeBoundary::FromConstant(l_max)); \ | 297 Range* right_range = new Range(RangeBoundary::FromConstant(r_min), \ |
324 Range* right_range = new Range( \ | 298 RangeBoundary::FromConstant(r_max)); \ |
325 RangeBoundary::FromConstant(r_min), \ | |
326 RangeBoundary::FromConstant(r_max)); \ | |
327 EXPECT(left_range->min().ConstantValue() == l_min); \ | 299 EXPECT(left_range->min().ConstantValue() == l_min); \ |
328 EXPECT(left_range->max().ConstantValue() == l_max); \ | 300 EXPECT(left_range->max().ConstantValue() == l_max); \ |
329 EXPECT(right_range->min().ConstantValue() == r_min); \ | 301 EXPECT(right_range->min().ConstantValue() == r_min); \ |
330 EXPECT(right_range->max().ConstantValue() == r_max); \ | 302 EXPECT(right_range->max().ConstantValue() == r_max); \ |
331 Range::Add(left_range, right_range, &min, &max, NULL); \ | 303 Range::Add(left_range, right_range, &min, &max, NULL); \ |
332 EXPECT(min.Equals(result_min)); \ | 304 EXPECT(min.Equals(result_min)); \ |
333 if (FLAG_support_il_printer && !min.Equals(result_min)) { \ | 305 if (FLAG_support_il_printer && !min.Equals(result_min)) { \ |
334 OS::Print("%s != %s\n", min.ToCString(), result_min.ToCString()); \ | 306 OS::Print("%s != %s\n", min.ToCString(), result_min.ToCString()); \ |
335 } \ | 307 } \ |
336 EXPECT(max.Equals(result_max)); \ | 308 EXPECT(max.Equals(result_max)); \ |
337 if (FLAG_support_il_printer && !max.Equals(result_max)) { \ | 309 if (FLAG_support_il_printer && !max.Equals(result_max)) { \ |
338 OS::Print("%s != %s\n", max.ToCString(), result_max.ToCString()); \ | 310 OS::Print("%s != %s\n", max.ToCString(), result_max.ToCString()); \ |
339 } \ | 311 } \ |
340 } | 312 } |
341 | 313 |
342 // [kMaxInt32, kMaxInt32 + 15] + [10, 20] = [kMaxInt32 + 10, kMaxInt32 + 35]. | 314 // [kMaxInt32, kMaxInt32 + 15] + [10, 20] = [kMaxInt32 + 10, kMaxInt32 + 35]. |
343 TEST_RANGE_ADD(static_cast<int64_t>(kMaxInt32), | 315 TEST_RANGE_ADD(static_cast<int64_t>(kMaxInt32), |
344 static_cast<int64_t>(kMaxInt32) + 15, | 316 static_cast<int64_t>(kMaxInt32) + 15, static_cast<int64_t>(10), |
345 static_cast<int64_t>(10), | |
346 static_cast<int64_t>(20), | 317 static_cast<int64_t>(20), |
347 RangeBoundary(static_cast<int64_t>(kMaxInt32) + 10), | 318 RangeBoundary(static_cast<int64_t>(kMaxInt32) + 10), |
348 RangeBoundary(static_cast<int64_t>(kMaxInt32) + 35)); | 319 RangeBoundary(static_cast<int64_t>(kMaxInt32) + 35)); |
349 | 320 |
350 // [kMaxInt32 - 15, kMaxInt32 + 15] + [15, -15] = [kMaxInt32, kMaxInt32]. | 321 // [kMaxInt32 - 15, kMaxInt32 + 15] + [15, -15] = [kMaxInt32, kMaxInt32]. |
351 TEST_RANGE_ADD(static_cast<int64_t>(kMaxInt32) - 15, | 322 TEST_RANGE_ADD(static_cast<int64_t>(kMaxInt32) - 15, |
352 static_cast<int64_t>(kMaxInt32) + 15, | 323 static_cast<int64_t>(kMaxInt32) + 15, static_cast<int64_t>(15), |
353 static_cast<int64_t>(15), | |
354 static_cast<int64_t>(-15), | 324 static_cast<int64_t>(-15), |
355 RangeBoundary(static_cast<int64_t>(kMaxInt32)), | 325 RangeBoundary(static_cast<int64_t>(kMaxInt32)), |
356 RangeBoundary(static_cast<int64_t>(kMaxInt32))); | 326 RangeBoundary(static_cast<int64_t>(kMaxInt32))); |
357 | 327 |
358 // [kMaxInt32, kMaxInt32 + 15] + [10, kMaxInt64] = [kMaxInt32 + 10, +inf]. | 328 // [kMaxInt32, kMaxInt32 + 15] + [10, kMaxInt64] = [kMaxInt32 + 10, +inf]. |
359 TEST_RANGE_ADD(static_cast<int64_t>(kMaxInt32), | 329 TEST_RANGE_ADD(static_cast<int64_t>(kMaxInt32), |
360 static_cast<int64_t>(kMaxInt32) + 15, | 330 static_cast<int64_t>(kMaxInt32) + 15, static_cast<int64_t>(10), |
361 static_cast<int64_t>(10), | |
362 static_cast<int64_t>(kMaxInt64), | 331 static_cast<int64_t>(kMaxInt64), |
363 RangeBoundary(static_cast<int64_t>(kMaxInt32) + 10), | 332 RangeBoundary(static_cast<int64_t>(kMaxInt32) + 10), |
364 RangeBoundary::PositiveInfinity()); | 333 RangeBoundary::PositiveInfinity()); |
365 | 334 |
366 // [kMinInt64, kMaxInt32 + 15] + [10, 20] = [kMinInt64 + 10, kMaxInt32 + 35]. | 335 // [kMinInt64, kMaxInt32 + 15] + [10, 20] = [kMinInt64 + 10, kMaxInt32 + 35]. |
367 TEST_RANGE_ADD(static_cast<int64_t>(kMinInt64), | 336 TEST_RANGE_ADD(static_cast<int64_t>(kMinInt64), |
368 static_cast<int64_t>(kMaxInt32) + 15, | 337 static_cast<int64_t>(kMaxInt32) + 15, static_cast<int64_t>(10), |
369 static_cast<int64_t>(10), | |
370 static_cast<int64_t>(20), | 338 static_cast<int64_t>(20), |
371 RangeBoundary(static_cast<int64_t>(kMinInt64) + 10), | 339 RangeBoundary(static_cast<int64_t>(kMinInt64) + 10), |
372 RangeBoundary(static_cast<int64_t>(kMaxInt32) + 35)); | 340 RangeBoundary(static_cast<int64_t>(kMaxInt32) + 35)); |
373 | 341 |
374 // [0, 0] + [kMinInt64, kMaxInt64] = [kMinInt64, kMaxInt64]. | 342 // [0, 0] + [kMinInt64, kMaxInt64] = [kMinInt64, kMaxInt64]. |
375 TEST_RANGE_ADD(static_cast<int64_t>(0), | 343 TEST_RANGE_ADD(static_cast<int64_t>(0), static_cast<int64_t>(0), |
376 static_cast<int64_t>(0), | |
377 static_cast<int64_t>(kMinInt64), | 344 static_cast<int64_t>(kMinInt64), |
378 static_cast<int64_t>(kMaxInt64), | 345 static_cast<int64_t>(kMaxInt64), RangeBoundary(kMinInt64), |
379 RangeBoundary(kMinInt64), | |
380 RangeBoundary(kMaxInt64)); | 346 RangeBoundary(kMaxInt64)); |
381 | 347 |
382 // Overflows. | 348 // Overflows. |
383 | 349 |
384 // [-1, 1] + [kMinInt64, kMaxInt64] = [-inf, +inf]. | 350 // [-1, 1] + [kMinInt64, kMaxInt64] = [-inf, +inf]. |
385 TEST_RANGE_ADD(static_cast<int64_t>(-1), | 351 TEST_RANGE_ADD( |
386 static_cast<int64_t>(1), | 352 static_cast<int64_t>(-1), static_cast<int64_t>(1), |
387 static_cast<int64_t>(kMinInt64), | 353 static_cast<int64_t>(kMinInt64), static_cast<int64_t>(kMaxInt64), |
388 static_cast<int64_t>(kMaxInt64), | 354 RangeBoundary::NegativeInfinity(), RangeBoundary::PositiveInfinity()); |
389 RangeBoundary::NegativeInfinity(), | |
390 RangeBoundary::PositiveInfinity()); | |
391 | 355 |
392 // [kMaxInt64, kMaxInt64] + [kMaxInt64, kMaxInt64] = [-inf, +inf]. | 356 // [kMaxInt64, kMaxInt64] + [kMaxInt64, kMaxInt64] = [-inf, +inf]. |
393 TEST_RANGE_ADD(static_cast<int64_t>(kMaxInt64), | 357 TEST_RANGE_ADD( |
394 static_cast<int64_t>(kMaxInt64), | 358 static_cast<int64_t>(kMaxInt64), static_cast<int64_t>(kMaxInt64), |
395 static_cast<int64_t>(kMaxInt64), | 359 static_cast<int64_t>(kMaxInt64), static_cast<int64_t>(kMaxInt64), |
396 static_cast<int64_t>(kMaxInt64), | 360 RangeBoundary::NegativeInfinity(), RangeBoundary::PositiveInfinity()); |
397 RangeBoundary::NegativeInfinity(), | |
398 RangeBoundary::PositiveInfinity()); | |
399 | 361 |
400 // [kMaxInt64, kMaxInt64] + [1, 1] = [-inf, +inf]. | 362 // [kMaxInt64, kMaxInt64] + [1, 1] = [-inf, +inf]. |
401 TEST_RANGE_ADD(static_cast<int64_t>(kMaxInt64), | 363 TEST_RANGE_ADD(static_cast<int64_t>(kMaxInt64), |
402 static_cast<int64_t>(kMaxInt64), | 364 static_cast<int64_t>(kMaxInt64), static_cast<int64_t>(1), |
403 static_cast<int64_t>(1), | 365 static_cast<int64_t>(1), RangeBoundary::NegativeInfinity(), |
404 static_cast<int64_t>(1), | |
405 RangeBoundary::NegativeInfinity(), | |
406 RangeBoundary::PositiveInfinity()); | 366 RangeBoundary::PositiveInfinity()); |
407 | 367 |
408 #undef TEST_RANGE_ADD | 368 #undef TEST_RANGE_ADD |
409 } | 369 } |
410 | 370 |
411 | 371 |
412 TEST_CASE(RangeSub) { | 372 TEST_CASE(RangeSub) { |
413 #define TEST_RANGE_SUB(l_min, l_max, r_min, r_max, result_min, result_max) \ | 373 #define TEST_RANGE_SUB(l_min, l_max, r_min, r_max, result_min, result_max) \ |
414 { \ | 374 { \ |
415 RangeBoundary min, max; \ | 375 RangeBoundary min, max; \ |
416 Range* left_range = new Range( \ | 376 Range* left_range = new Range(RangeBoundary::FromConstant(l_min), \ |
417 RangeBoundary::FromConstant(l_min), \ | 377 RangeBoundary::FromConstant(l_max)); \ |
418 RangeBoundary::FromConstant(l_max)); \ | 378 Range* right_range = new Range(RangeBoundary::FromConstant(r_min), \ |
419 Range* right_range = new Range( \ | 379 RangeBoundary::FromConstant(r_max)); \ |
420 RangeBoundary::FromConstant(r_min), \ | |
421 RangeBoundary::FromConstant(r_max)); \ | |
422 EXPECT(left_range->min().ConstantValue() == l_min); \ | 380 EXPECT(left_range->min().ConstantValue() == l_min); \ |
423 EXPECT(left_range->max().ConstantValue() == l_max); \ | 381 EXPECT(left_range->max().ConstantValue() == l_max); \ |
424 EXPECT(right_range->min().ConstantValue() == r_min); \ | 382 EXPECT(right_range->min().ConstantValue() == r_min); \ |
425 EXPECT(right_range->max().ConstantValue() == r_max); \ | 383 EXPECT(right_range->max().ConstantValue() == r_max); \ |
426 Range::Sub(left_range, right_range, &min, &max, NULL); \ | 384 Range::Sub(left_range, right_range, &min, &max, NULL); \ |
427 EXPECT(min.Equals(result_min)); \ | 385 EXPECT(min.Equals(result_min)); \ |
428 if (FLAG_support_il_printer && !min.Equals(result_min)) { \ | 386 if (FLAG_support_il_printer && !min.Equals(result_min)) { \ |
429 OS::Print("%s != %s\n", min.ToCString(), result_min.ToCString()); \ | 387 OS::Print("%s != %s\n", min.ToCString(), result_min.ToCString()); \ |
430 } \ | 388 } \ |
431 EXPECT(max.Equals(result_max)); \ | 389 EXPECT(max.Equals(result_max)); \ |
432 if (FLAG_support_il_printer && !max.Equals(result_max)) { \ | 390 if (FLAG_support_il_printer && !max.Equals(result_max)) { \ |
433 OS::Print("%s != %s\n", max.ToCString(), result_max.ToCString()); \ | 391 OS::Print("%s != %s\n", max.ToCString(), result_max.ToCString()); \ |
434 } \ | 392 } \ |
435 } | 393 } |
436 | 394 |
437 // [kMaxInt32, kMaxInt32 + 15] - [10, 20] = [kMaxInt32 - 20, kMaxInt32 + 5]. | 395 // [kMaxInt32, kMaxInt32 + 15] - [10, 20] = [kMaxInt32 - 20, kMaxInt32 + 5]. |
438 TEST_RANGE_SUB(static_cast<int64_t>(kMaxInt32), | 396 TEST_RANGE_SUB(static_cast<int64_t>(kMaxInt32), |
439 static_cast<int64_t>(kMaxInt32) + 15, | 397 static_cast<int64_t>(kMaxInt32) + 15, static_cast<int64_t>(10), |
440 static_cast<int64_t>(10), | |
441 static_cast<int64_t>(20), | 398 static_cast<int64_t>(20), |
442 RangeBoundary(static_cast<int64_t>(kMaxInt32) - 20), | 399 RangeBoundary(static_cast<int64_t>(kMaxInt32) - 20), |
443 RangeBoundary(static_cast<int64_t>(kMaxInt32) + 5)); | 400 RangeBoundary(static_cast<int64_t>(kMaxInt32) + 5)); |
444 | 401 |
445 // [kMintInt64, kMintInt64] - [1, 1] = [-inf, +inf]. | 402 // [kMintInt64, kMintInt64] - [1, 1] = [-inf, +inf]. |
446 TEST_RANGE_SUB(static_cast<int64_t>(kMinInt64), | 403 TEST_RANGE_SUB(static_cast<int64_t>(kMinInt64), |
447 static_cast<int64_t>(kMinInt64), | 404 static_cast<int64_t>(kMinInt64), static_cast<int64_t>(1), |
448 static_cast<int64_t>(1), | 405 static_cast<int64_t>(1), RangeBoundary::NegativeInfinity(), |
449 static_cast<int64_t>(1), | |
450 RangeBoundary::NegativeInfinity(), | |
451 RangeBoundary::PositiveInfinity()); | 406 RangeBoundary::PositiveInfinity()); |
452 | 407 |
453 // [1, 1] - [kMintInt64, kMintInt64] = [-inf, +inf]. | 408 // [1, 1] - [kMintInt64, kMintInt64] = [-inf, +inf]. |
454 TEST_RANGE_SUB(static_cast<int64_t>(1), | 409 TEST_RANGE_SUB( |
455 static_cast<int64_t>(1), | 410 static_cast<int64_t>(1), static_cast<int64_t>(1), |
456 static_cast<int64_t>(kMinInt64), | 411 static_cast<int64_t>(kMinInt64), static_cast<int64_t>(kMinInt64), |
457 static_cast<int64_t>(kMinInt64), | 412 RangeBoundary::NegativeInfinity(), RangeBoundary::PositiveInfinity()); |
458 RangeBoundary::NegativeInfinity(), | |
459 RangeBoundary::PositiveInfinity()); | |
460 | 413 |
461 // [kMaxInt32 + 10, kMaxInt32 + 20] - [-20, -20] = | 414 // [kMaxInt32 + 10, kMaxInt32 + 20] - [-20, -20] = |
462 // [kMaxInt32 + 30, kMaxInt32 + 40]. | 415 // [kMaxInt32 + 30, kMaxInt32 + 40]. |
463 TEST_RANGE_SUB(static_cast<int64_t>(kMaxInt32) + 10, | 416 TEST_RANGE_SUB(static_cast<int64_t>(kMaxInt32) + 10, |
464 static_cast<int64_t>(kMaxInt32) + 20, | 417 static_cast<int64_t>(kMaxInt32) + 20, |
465 static_cast<int64_t>(-20), | 418 static_cast<int64_t>(-20), static_cast<int64_t>(-20), |
466 static_cast<int64_t>(-20), | |
467 RangeBoundary(static_cast<int64_t>(kMaxInt32) + 30), | 419 RangeBoundary(static_cast<int64_t>(kMaxInt32) + 30), |
468 RangeBoundary(static_cast<int64_t>(kMaxInt32) + 40)); | 420 RangeBoundary(static_cast<int64_t>(kMaxInt32) + 40)); |
469 | 421 |
470 | 422 |
471 #undef TEST_RANGE_SUB | 423 #undef TEST_RANGE_SUB |
472 } | 424 } |
473 | 425 |
474 | 426 |
475 TEST_CASE(RangeAnd) { | 427 TEST_CASE(RangeAnd) { |
476 #define TEST_RANGE_AND(l_min, l_max, r_min, r_max, result_min, result_max) \ | 428 #define TEST_RANGE_AND(l_min, l_max, r_min, r_max, result_min, result_max) \ |
477 { \ | 429 { \ |
478 RangeBoundary min, max; \ | 430 RangeBoundary min, max; \ |
479 Range* left_range = new Range( \ | 431 Range* left_range = new Range(RangeBoundary::FromConstant(l_min), \ |
480 RangeBoundary::FromConstant(l_min), \ | 432 RangeBoundary::FromConstant(l_max)); \ |
481 RangeBoundary::FromConstant(l_max)); \ | 433 Range* right_range = new Range(RangeBoundary::FromConstant(r_min), \ |
482 Range* right_range = new Range( \ | 434 RangeBoundary::FromConstant(r_max)); \ |
483 RangeBoundary::FromConstant(r_min), \ | |
484 RangeBoundary::FromConstant(r_max)); \ | |
485 EXPECT(left_range->min().ConstantValue() == l_min); \ | 435 EXPECT(left_range->min().ConstantValue() == l_min); \ |
486 EXPECT(left_range->max().ConstantValue() == l_max); \ | 436 EXPECT(left_range->max().ConstantValue() == l_max); \ |
487 EXPECT(right_range->min().ConstantValue() == r_min); \ | 437 EXPECT(right_range->min().ConstantValue() == r_min); \ |
488 EXPECT(right_range->max().ConstantValue() == r_max); \ | 438 EXPECT(right_range->max().ConstantValue() == r_max); \ |
489 Range::And(left_range, right_range, &min, &max); \ | 439 Range::And(left_range, right_range, &min, &max); \ |
490 EXPECT(min.Equals(result_min)); \ | 440 EXPECT(min.Equals(result_min)); \ |
491 if (FLAG_support_il_printer && !min.Equals(result_min)) { \ | 441 if (FLAG_support_il_printer && !min.Equals(result_min)) { \ |
492 OS::Print("%s != %s\n", min.ToCString(), result_min.ToCString()); \ | 442 OS::Print("%s != %s\n", min.ToCString(), result_min.ToCString()); \ |
493 } \ | 443 } \ |
494 EXPECT(max.Equals(result_max)); \ | 444 EXPECT(max.Equals(result_max)); \ |
495 if (FLAG_support_il_printer && !max.Equals(result_max)) { \ | 445 if (FLAG_support_il_printer && !max.Equals(result_max)) { \ |
496 OS::Print("%s != %s\n", max.ToCString(), result_max.ToCString()); \ | 446 OS::Print("%s != %s\n", max.ToCString(), result_max.ToCString()); \ |
497 } \ | 447 } \ |
498 } | 448 } |
499 | 449 |
500 // [0xff, 0xfff] & [0xf, 0xf] = [0x0, 0xf]. | 450 // [0xff, 0xfff] & [0xf, 0xf] = [0x0, 0xf]. |
501 TEST_RANGE_AND(static_cast<int64_t>(0xff), | 451 TEST_RANGE_AND(static_cast<int64_t>(0xff), static_cast<int64_t>(0xfff), |
502 static_cast<int64_t>(0xfff), | 452 static_cast<int64_t>(0xf), static_cast<int64_t>(0xf), |
503 static_cast<int64_t>(0xf), | 453 RangeBoundary(0), RangeBoundary(0xf)); |
504 static_cast<int64_t>(0xf), | |
505 RangeBoundary(0), | |
506 RangeBoundary(0xf)); | |
507 | 454 |
508 // [0xffffffff, 0xffffffff] & [0xfffffffff, 0xfffffffff] = [0x0, 0xfffffffff]. | 455 // [0xffffffff, 0xffffffff] & [0xfffffffff, 0xfffffffff] = [0x0, 0xfffffffff]. |
509 TEST_RANGE_AND(static_cast<int64_t>(0xffffffff), | 456 TEST_RANGE_AND( |
510 static_cast<int64_t>(0xffffffff), | 457 static_cast<int64_t>(0xffffffff), static_cast<int64_t>(0xffffffff), |
511 static_cast<int64_t>(0xfffffffff), | 458 static_cast<int64_t>(0xfffffffff), static_cast<int64_t>(0xfffffffff), |
512 static_cast<int64_t>(0xfffffffff), | 459 RangeBoundary(0), RangeBoundary(static_cast<int64_t>(0xfffffffff))); |
513 RangeBoundary(0), | |
514 RangeBoundary(static_cast<int64_t>(0xfffffffff))); | |
515 | 460 |
516 // [0xffffffff, 0xffffffff] & [-20, 20] = [0x0, 0xffffffff]. | 461 // [0xffffffff, 0xffffffff] & [-20, 20] = [0x0, 0xffffffff]. |
517 TEST_RANGE_AND(static_cast<int64_t>(0xffffffff), | 462 TEST_RANGE_AND(static_cast<int64_t>(0xffffffff), |
518 static_cast<int64_t>(0xffffffff), | 463 static_cast<int64_t>(0xffffffff), static_cast<int64_t>(-20), |
519 static_cast<int64_t>(-20), | 464 static_cast<int64_t>(20), RangeBoundary(0), |
520 static_cast<int64_t>(20), | |
521 RangeBoundary(0), | |
522 RangeBoundary(static_cast<int64_t>(0xffffffff))); | 465 RangeBoundary(static_cast<int64_t>(0xffffffff))); |
523 | 466 |
524 // [-20, 20] & [0xffffffff, 0xffffffff] = [0x0, 0xffffffff]. | 467 // [-20, 20] & [0xffffffff, 0xffffffff] = [0x0, 0xffffffff]. |
525 TEST_RANGE_AND(static_cast<int64_t>(-20), | 468 TEST_RANGE_AND(static_cast<int64_t>(-20), static_cast<int64_t>(20), |
526 static_cast<int64_t>(20), | |
527 static_cast<int64_t>(0xffffffff), | 469 static_cast<int64_t>(0xffffffff), |
528 static_cast<int64_t>(0xffffffff), | 470 static_cast<int64_t>(0xffffffff), RangeBoundary(0), |
529 RangeBoundary(0), | |
530 RangeBoundary(static_cast<int64_t>(0xffffffff))); | 471 RangeBoundary(static_cast<int64_t>(0xffffffff))); |
531 | 472 |
532 // Test that [-20, 20] & [-20, 20] = [-32, 31]. | 473 // Test that [-20, 20] & [-20, 20] = [-32, 31]. |
533 TEST_RANGE_AND(static_cast<int64_t>(-20), | 474 TEST_RANGE_AND(static_cast<int64_t>(-20), static_cast<int64_t>(20), |
534 static_cast<int64_t>(20), | 475 static_cast<int64_t>(-20), static_cast<int64_t>(20), |
535 static_cast<int64_t>(-20), | 476 RangeBoundary(-32), RangeBoundary(31)); |
536 static_cast<int64_t>(20), | |
537 RangeBoundary(-32), | |
538 RangeBoundary(31)); | |
539 | 477 |
540 #undef TEST_RANGE_AND | 478 #undef TEST_RANGE_AND |
541 } | 479 } |
542 | 480 |
543 | 481 |
544 TEST_CASE(RangeIntersectionMinMax) { | 482 TEST_CASE(RangeIntersectionMinMax) { |
545 // Test IntersectionMin and IntersectionMax methods which for constants are | 483 // Test IntersectionMin and IntersectionMax methods which for constants are |
546 // simply defined as Max/Min respectively. | 484 // simply defined as Max/Min respectively. |
547 | 485 |
548 // Constants. | 486 // Constants. |
549 // MIN(0, 1) == 0 | 487 // MIN(0, 1) == 0 |
550 EXPECT(RangeBoundary::IntersectionMax( | 488 EXPECT(RangeBoundary::IntersectionMax(RangeBoundary::FromConstant(0), |
551 RangeBoundary::FromConstant(0), | 489 RangeBoundary::FromConstant(1)) |
552 RangeBoundary::FromConstant(1)).ConstantValue() == 0); | 490 .ConstantValue() == 0); |
553 // MIN(0, -1) == -1 | 491 // MIN(0, -1) == -1 |
554 EXPECT(RangeBoundary::IntersectionMax( | 492 EXPECT(RangeBoundary::IntersectionMax(RangeBoundary::FromConstant(0), |
555 RangeBoundary::FromConstant(0), | 493 RangeBoundary::FromConstant(-1)) |
556 RangeBoundary::FromConstant(-1)).ConstantValue() == -1); | 494 .ConstantValue() == -1); |
557 | 495 |
558 // MIN(1, 0) == 0 | 496 // MIN(1, 0) == 0 |
559 EXPECT(RangeBoundary::IntersectionMax( | 497 EXPECT(RangeBoundary::IntersectionMax(RangeBoundary::FromConstant(1), |
560 RangeBoundary::FromConstant(1), | 498 RangeBoundary::FromConstant(0)) |
561 RangeBoundary::FromConstant(0)).ConstantValue() == 0); | 499 .ConstantValue() == 0); |
562 // MIN(-1, 0) == -1 | 500 // MIN(-1, 0) == -1 |
563 EXPECT(RangeBoundary::IntersectionMax( | 501 EXPECT(RangeBoundary::IntersectionMax(RangeBoundary::FromConstant(-1), |
564 RangeBoundary::FromConstant(-1), | 502 RangeBoundary::FromConstant(0)) |
565 RangeBoundary::FromConstant(0)).ConstantValue() == -1); | 503 .ConstantValue() == -1); |
566 | 504 |
567 // MAX(0, 1) == 1 | 505 // MAX(0, 1) == 1 |
568 EXPECT(RangeBoundary::IntersectionMin( | 506 EXPECT(RangeBoundary::IntersectionMin(RangeBoundary::FromConstant(0), |
569 RangeBoundary::FromConstant(0), | 507 RangeBoundary::FromConstant(1)) |
570 RangeBoundary::FromConstant(1)).ConstantValue() == 1); | 508 .ConstantValue() == 1); |
571 | 509 |
572 // MAX(0, -1) == 0 | 510 // MAX(0, -1) == 0 |
573 EXPECT(RangeBoundary::IntersectionMin( | 511 EXPECT(RangeBoundary::IntersectionMin(RangeBoundary::FromConstant(0), |
574 RangeBoundary::FromConstant(0), | 512 RangeBoundary::FromConstant(-1)) |
575 RangeBoundary::FromConstant(-1)).ConstantValue() == 0); | 513 .ConstantValue() == 0); |
576 | 514 |
577 // MAX(1, 0) == 1 | 515 // MAX(1, 0) == 1 |
578 EXPECT(RangeBoundary::IntersectionMin( | 516 EXPECT(RangeBoundary::IntersectionMin(RangeBoundary::FromConstant(1), |
579 RangeBoundary::FromConstant(1), | 517 RangeBoundary::FromConstant(0)) |
580 RangeBoundary::FromConstant(0)).ConstantValue() == 1); | 518 .ConstantValue() == 1); |
581 // MAX(-1, 0) == 0 | 519 // MAX(-1, 0) == 0 |
582 EXPECT(RangeBoundary::IntersectionMin( | 520 EXPECT(RangeBoundary::IntersectionMin(RangeBoundary::FromConstant(-1), |
583 RangeBoundary::FromConstant(-1), | 521 RangeBoundary::FromConstant(0)) |
584 RangeBoundary::FromConstant(0)).ConstantValue() == 0); | 522 .ConstantValue() == 0); |
585 | 523 |
586 RangeBoundary n_infinity = RangeBoundary::NegativeInfinity(); | 524 RangeBoundary n_infinity = RangeBoundary::NegativeInfinity(); |
587 RangeBoundary p_infinity = RangeBoundary::PositiveInfinity(); | 525 RangeBoundary p_infinity = RangeBoundary::PositiveInfinity(); |
588 | 526 |
589 // Constants vs. infinity. | 527 // Constants vs. infinity. |
590 EXPECT(RangeBoundary::IntersectionMin( | 528 EXPECT(RangeBoundary::IntersectionMin(n_infinity, |
591 n_infinity, | 529 RangeBoundary::FromConstant(-1)) |
592 RangeBoundary::FromConstant(-1)).ConstantValue() == -1); | 530 .ConstantValue() == -1); |
593 | 531 |
594 EXPECT(RangeBoundary::IntersectionMin( | 532 EXPECT(RangeBoundary::IntersectionMin(RangeBoundary::FromConstant(-1), |
595 RangeBoundary::FromConstant(-1), | 533 n_infinity) |
596 n_infinity).ConstantValue() == -1); | 534 .ConstantValue() == -1); |
597 | 535 |
598 EXPECT(RangeBoundary::IntersectionMin( | 536 EXPECT( |
599 RangeBoundary::FromConstant(1), | 537 RangeBoundary::IntersectionMin(RangeBoundary::FromConstant(1), n_infinity) |
600 n_infinity).ConstantValue() == 1); | 538 .ConstantValue() == 1); |
601 | 539 |
602 EXPECT(RangeBoundary::IntersectionMin( | 540 EXPECT( |
603 n_infinity, | 541 RangeBoundary::IntersectionMin(n_infinity, RangeBoundary::FromConstant(1)) |
604 RangeBoundary::FromConstant(1)).ConstantValue() == 1); | 542 .ConstantValue() == 1); |
605 | 543 |
606 EXPECT(RangeBoundary::IntersectionMax( | 544 EXPECT(RangeBoundary::IntersectionMax(p_infinity, |
607 p_infinity, | 545 RangeBoundary::FromConstant(-1)) |
608 RangeBoundary::FromConstant(-1)).ConstantValue() == -1); | 546 .ConstantValue() == -1); |
609 | 547 |
610 EXPECT(RangeBoundary::IntersectionMax( | 548 EXPECT(RangeBoundary::IntersectionMax(RangeBoundary::FromConstant(-1), |
611 RangeBoundary::FromConstant(-1), | 549 p_infinity) |
612 p_infinity).ConstantValue() == -1); | 550 .ConstantValue() == -1); |
613 | 551 |
614 EXPECT(RangeBoundary::IntersectionMax( | 552 EXPECT( |
615 RangeBoundary::FromConstant(1), | 553 RangeBoundary::IntersectionMax(RangeBoundary::FromConstant(1), p_infinity) |
616 p_infinity).ConstantValue() == 1); | 554 .ConstantValue() == 1); |
617 | 555 |
618 EXPECT(RangeBoundary::IntersectionMax( | 556 EXPECT( |
619 p_infinity, | 557 RangeBoundary::IntersectionMax(p_infinity, RangeBoundary::FromConstant(1)) |
620 RangeBoundary::FromConstant(1)).ConstantValue() == 1); | 558 .ConstantValue() == 1); |
621 } | 559 } |
622 | 560 |
623 | 561 |
624 TEST_CASE(RangeJoinMinMax) { | 562 TEST_CASE(RangeJoinMinMax) { |
625 // Test IntersectionMin and IntersectionMax methods which for constants are | 563 // Test IntersectionMin and IntersectionMax methods which for constants are |
626 // simply defined as Min/Max respectively. | 564 // simply defined as Min/Max respectively. |
627 const RangeBoundary::RangeSize size = RangeBoundary::kRangeBoundarySmi; | 565 const RangeBoundary::RangeSize size = RangeBoundary::kRangeBoundarySmi; |
628 | 566 |
629 // Constants. | 567 // Constants. |
630 EXPECT(RangeBoundary::JoinMax( | 568 EXPECT(RangeBoundary::JoinMax(RangeBoundary::FromConstant(0), |
631 RangeBoundary::FromConstant(0), | 569 RangeBoundary::FromConstant(1), size) |
632 RangeBoundary::FromConstant(1), | 570 .ConstantValue() == 1); |
633 size).ConstantValue() == 1); | 571 EXPECT(RangeBoundary::JoinMax(RangeBoundary::FromConstant(0), |
634 EXPECT(RangeBoundary::JoinMax( | 572 RangeBoundary::FromConstant(-1), size) |
635 RangeBoundary::FromConstant(0), | 573 .ConstantValue() == 0); |
636 RangeBoundary::FromConstant(-1), | 574 EXPECT(RangeBoundary::JoinMax(RangeBoundary::FromConstant(1), |
637 size).ConstantValue() == 0); | 575 RangeBoundary::FromConstant(0), size) |
638 EXPECT(RangeBoundary::JoinMax( | 576 .ConstantValue() == 1); |
639 RangeBoundary::FromConstant(1), | 577 EXPECT(RangeBoundary::JoinMax(RangeBoundary::FromConstant(-1), |
640 RangeBoundary::FromConstant(0), | 578 RangeBoundary::FromConstant(0), size) |
641 size).ConstantValue() == 1); | 579 .ConstantValue() == 0); |
642 EXPECT(RangeBoundary::JoinMax( | 580 EXPECT(RangeBoundary::JoinMin(RangeBoundary::FromConstant(0), |
643 RangeBoundary::FromConstant(-1), | 581 RangeBoundary::FromConstant(1), size) |
644 RangeBoundary::FromConstant(0), | 582 .ConstantValue() == 0); |
645 size).ConstantValue() == 0); | 583 EXPECT(RangeBoundary::JoinMin(RangeBoundary::FromConstant(0), |
646 EXPECT(RangeBoundary::JoinMin( | 584 RangeBoundary::FromConstant(-1), size) |
647 RangeBoundary::FromConstant(0), | 585 .ConstantValue() == -1); |
648 RangeBoundary::FromConstant(1), | 586 EXPECT(RangeBoundary::JoinMin(RangeBoundary::FromConstant(1), |
649 size).ConstantValue() == 0); | 587 RangeBoundary::FromConstant(0), size) |
650 EXPECT(RangeBoundary::JoinMin( | 588 .ConstantValue() == 0); |
651 RangeBoundary::FromConstant(0), | 589 EXPECT(RangeBoundary::JoinMin(RangeBoundary::FromConstant(-1), |
652 RangeBoundary::FromConstant(-1), | 590 RangeBoundary::FromConstant(0), size) |
653 size).ConstantValue() == -1); | 591 .ConstantValue() == -1); |
654 EXPECT(RangeBoundary::JoinMin( | |
655 RangeBoundary::FromConstant(1), | |
656 RangeBoundary::FromConstant(0), | |
657 size).ConstantValue() == 0); | |
658 EXPECT(RangeBoundary::JoinMin( | |
659 RangeBoundary::FromConstant(-1), | |
660 RangeBoundary::FromConstant(0), | |
661 size).ConstantValue() == -1); | |
662 | 592 |
663 RangeBoundary n_infinity = RangeBoundary::NegativeInfinity(); | 593 RangeBoundary n_infinity = RangeBoundary::NegativeInfinity(); |
664 RangeBoundary p_infinity = RangeBoundary::PositiveInfinity(); | 594 RangeBoundary p_infinity = RangeBoundary::PositiveInfinity(); |
665 | 595 |
666 // Constants vs. infinity. | 596 // Constants vs. infinity. |
667 EXPECT(RangeBoundary::JoinMin( | 597 EXPECT( |
668 n_infinity, | 598 RangeBoundary::JoinMin(n_infinity, RangeBoundary::FromConstant(-1), size) |
669 RangeBoundary::FromConstant(-1), | 599 .IsMinimumOrBelow(size)); |
670 size).IsMinimumOrBelow(size)); | |
671 | 600 |
672 EXPECT(RangeBoundary::JoinMin( | 601 EXPECT( |
673 RangeBoundary::FromConstant(-1), | 602 RangeBoundary::JoinMin(RangeBoundary::FromConstant(-1), n_infinity, size) |
674 n_infinity, | 603 .IsMinimumOrBelow(size)); |
675 size).IsMinimumOrBelow(size)); | |
676 | 604 |
677 EXPECT(RangeBoundary::JoinMin( | 605 EXPECT( |
678 RangeBoundary::FromConstant(1), | 606 RangeBoundary::JoinMin(RangeBoundary::FromConstant(1), n_infinity, size) |
679 n_infinity, | 607 .IsMinimumOrBelow(size)); |
680 size).IsMinimumOrBelow(size)); | |
681 | 608 |
682 EXPECT(RangeBoundary::JoinMin( | 609 EXPECT( |
683 n_infinity, | 610 RangeBoundary::JoinMin(n_infinity, RangeBoundary::FromConstant(1), size) |
684 RangeBoundary::FromConstant(1), | 611 .IsMinimumOrBelow(size)); |
685 size).IsMinimumOrBelow(size)); | |
686 | 612 |
687 EXPECT(RangeBoundary::JoinMax( | 613 EXPECT( |
688 p_infinity, | 614 RangeBoundary::JoinMax(p_infinity, RangeBoundary::FromConstant(-1), size) |
689 RangeBoundary::FromConstant(-1), | 615 .IsMaximumOrAbove(size)); |
690 size).IsMaximumOrAbove(size)); | |
691 | 616 |
692 EXPECT(RangeBoundary::JoinMax( | 617 EXPECT( |
693 RangeBoundary::FromConstant(-1), | 618 RangeBoundary::JoinMax(RangeBoundary::FromConstant(-1), p_infinity, size) |
694 p_infinity, | 619 .IsMaximumOrAbove(size)); |
695 size).IsMaximumOrAbove(size)); | |
696 | 620 |
697 EXPECT(RangeBoundary::JoinMax( | 621 EXPECT( |
698 RangeBoundary::FromConstant(1), | 622 RangeBoundary::JoinMax(RangeBoundary::FromConstant(1), p_infinity, size) |
699 p_infinity, | 623 .IsMaximumOrAbove(size)); |
700 size).IsMaximumOrAbove(size)); | |
701 | 624 |
702 EXPECT(RangeBoundary::JoinMax( | 625 EXPECT( |
703 p_infinity, | 626 RangeBoundary::JoinMax(p_infinity, RangeBoundary::FromConstant(1), size) |
704 RangeBoundary::FromConstant(1), | 627 .IsMaximumOrAbove(size)); |
705 size).IsMaximumOrAbove(size)); | |
706 } | 628 } |
707 | 629 |
708 } // namespace dart | 630 } // namespace dart |
OLD | NEW |