Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(578)

Side by Side Diff: runtime/vm/intermediate_language_test.cc

Issue 333643004: Add range analysis for left-shift smi operations. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
55 RangeBoundary::FromConstant(100)); 55 RangeBoundary::FromConstant(100));
56 EXPECT(negative->IsNegative()); 56 EXPECT(negative->IsNegative());
57 EXPECT(positive->IsPositive()); 57 EXPECT(positive->IsPositive());
58 EXPECT(zero->Overlaps(0, 0)); 58 EXPECT(zero->Overlaps(0, 0));
59 EXPECT(positive->Overlaps(0, 0)); 59 EXPECT(positive->Overlaps(0, 0));
60 EXPECT(!negative->Overlaps(0, 0)); 60 EXPECT(!negative->Overlaps(0, 0));
61 EXPECT(range_x->Overlaps(0, 0)); 61 EXPECT(range_x->Overlaps(0, 0));
62 EXPECT(range_x->IsWithin(-15, 100)); 62 EXPECT(range_x->IsWithin(-15, 100));
63 EXPECT(!range_x->IsWithin(-15, 99)); 63 EXPECT(!range_x->IsWithin(-15, 99));
64 EXPECT(!range_x->IsWithin(-14, 100)); 64 EXPECT(!range_x->IsWithin(-14, 100));
65
66 #define TEST_RANGE_SHL(Op, l_min, l_max, r_min, r_max, result_min, result_max) \
67 { \
68 RangeBoundary min, max; \
69 Range* left_range = new Range( \
70 RangeBoundary::FromConstant(l_min), \
71 RangeBoundary::FromConstant(l_max)); \
72 Range* shift_range = new Range( \
73 RangeBoundary::FromConstant(r_min), \
74 RangeBoundary::FromConstant(r_max)); \
75 Op(left_range, shift_range, &min, &max); \
76 EXPECT(min.Equals(result_min)); \
77 if (!min.Equals(result_min)) OS::Print("%s\n", min.ToCString()); \
78 EXPECT(max.Equals(result_max)); \
79 if (!max.Equals(result_max)) OS::Print("%s\n", max.ToCString()); \
80 }
81
82 TEST_RANGE_SHL(Range::Shl, -15, 100, 0, 2,
83 RangeBoundary(-60), RangeBoundary(400));
84 TEST_RANGE_SHL(Range::Shl, -15, 100, -2, 2,
85 RangeBoundary(-60), RangeBoundary(400));
86 TEST_RANGE_SHL(Range::Shl, -15, -10, 1, 2,
87 RangeBoundary(-60), RangeBoundary(-20));
88 TEST_RANGE_SHL(Range::Shl, 5, 10, -2, 2,
89 RangeBoundary(5), RangeBoundary(40));
90 TEST_RANGE_SHL(Range::Shl, -15, 100, 0, 64,
91 RangeBoundary::NegativeInfinity(),
92 RangeBoundary::PositiveInfinity());
93 TEST_RANGE_SHL(Range::Shl, -1, 1, 0, 63,
94 RangeBoundary::NegativeInfinity(),
95 RangeBoundary::PositiveInfinity());
96 TEST_RANGE_SHL(Range::Shl, 0, 100, 0, 64,
97 RangeBoundary(0), RangeBoundary::PositiveInfinity());
98 TEST_RANGE_SHL(Range::Shl, -100, 0, 0, 64,
99 RangeBoundary::NegativeInfinity(), RangeBoundary(0));
100
101 #undef TEST_RANGE_SHL
65 } 102 }
66 103
67 104
68 TEST_CASE(RangeTestsInfinity) { 105 TEST_CASE(RangeTestsInfinity) {
69 // +/- inf overflowed. 106 // +/- inf overflowed.
70 EXPECT(RangeBoundary::NegativeInfinity().Overflowed()); 107 EXPECT(RangeBoundary::NegativeInfinity().Overflowed());
71 EXPECT(RangeBoundary::PositiveInfinity().Overflowed()); 108 EXPECT(RangeBoundary::PositiveInfinity().Overflowed());
72 109
73 Range* all = new Range(RangeBoundary::NegativeInfinity(), 110 Range* all = new Range(RangeBoundary::NegativeInfinity(),
74 RangeBoundary::PositiveInfinity()); 111 RangeBoundary::PositiveInfinity());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 Range* unsatisfiable_right = new Range(RangeBoundary::PositiveInfinity(), 153 Range* unsatisfiable_right = new Range(RangeBoundary::PositiveInfinity(),
117 RangeBoundary::FromConstant(0)); 154 RangeBoundary::FromConstant(0));
118 EXPECT(unsatisfiable_right->IsUnsatisfiable()); 155 EXPECT(unsatisfiable_right->IsUnsatisfiable());
119 156
120 Range* unsatisfiable_left = new Range(RangeBoundary::FromConstant(0), 157 Range* unsatisfiable_left = new Range(RangeBoundary::FromConstant(0),
121 RangeBoundary::NegativeInfinity()); 158 RangeBoundary::NegativeInfinity());
122 EXPECT(unsatisfiable_left->IsUnsatisfiable()); 159 EXPECT(unsatisfiable_left->IsUnsatisfiable());
123 } 160 }
124 161
125 } // namespace dart 162 } // namespace dart
OLDNEW
« runtime/vm/intermediate_language.cc ('K') | « runtime/vm/intermediate_language.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698