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

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: addressed comments, added tests 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
« no previous file with comments | « runtime/vm/intermediate_language.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_OP(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_OP(Range::Shl, -15, 100, 0, 2,
83 RangeBoundary(-60), RangeBoundary(400));
84 TEST_RANGE_OP(Range::Shl, -15, 100, -2, 2,
85 RangeBoundary(-60), RangeBoundary(400));
86 TEST_RANGE_OP(Range::Shl, -15, -10, 1, 2,
87 RangeBoundary(-60), RangeBoundary(-20));
88 TEST_RANGE_OP(Range::Shl, 5, 10, -2, 2,
89 RangeBoundary(5), RangeBoundary(40));
90 TEST_RANGE_OP(Range::Shl, -15, 100, 0, 64,
91 RangeBoundary::NegativeInfinity(),
92 RangeBoundary::PositiveInfinity());
93 TEST_RANGE_OP(Range::Shl, -1, 1, 63, 63,
94 RangeBoundary::NegativeInfinity(),
95 RangeBoundary::PositiveInfinity());
96 if (kBitsPerWord == 64) {
97 TEST_RANGE_OP(Range::Shl, -1, 1, 62, 62,
98 RangeBoundary(kSmiMin),
99 RangeBoundary::PositiveInfinity());
100 TEST_RANGE_OP(Range::Shl, -1, 1, 30, 30,
101 RangeBoundary(-1 << 30),
102 RangeBoundary(1 << 30));
103 } else {
104 TEST_RANGE_OP(Range::Shl, -1, 1, 30, 30,
105 RangeBoundary(kSmiMin),
106 RangeBoundary::PositiveInfinity());
107 TEST_RANGE_OP(Range::Shl, -1, 1, 62, 62,
108 RangeBoundary::NegativeInfinity(),
109 RangeBoundary::PositiveInfinity());
110 }
111 TEST_RANGE_OP(Range::Shl, 0, 100, 0, 64,
112 RangeBoundary(0), RangeBoundary::PositiveInfinity());
113 TEST_RANGE_OP(Range::Shl, -100, 0, 0, 64,
114 RangeBoundary::NegativeInfinity(), RangeBoundary(0));
115
116 #undef TEST_RANGE_SHL
Vyacheslav Egorov (Google) 2014/06/12 15:46:17 TEST_RANGE_OP
Florian Schneider 2014/06/13 07:12:21 Done.
65 } 117 }
66 118
67 119
68 TEST_CASE(RangeTestsInfinity) { 120 TEST_CASE(RangeTestsInfinity) {
69 // +/- inf overflowed. 121 // +/- inf overflowed.
70 EXPECT(RangeBoundary::NegativeInfinity().Overflowed()); 122 EXPECT(RangeBoundary::NegativeInfinity().Overflowed());
71 EXPECT(RangeBoundary::PositiveInfinity().Overflowed()); 123 EXPECT(RangeBoundary::PositiveInfinity().Overflowed());
72 124
73 Range* all = new Range(RangeBoundary::NegativeInfinity(), 125 Range* all = new Range(RangeBoundary::NegativeInfinity(),
74 RangeBoundary::PositiveInfinity()); 126 RangeBoundary::PositiveInfinity());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 Range* unsatisfiable_right = new Range(RangeBoundary::PositiveInfinity(), 168 Range* unsatisfiable_right = new Range(RangeBoundary::PositiveInfinity(),
117 RangeBoundary::FromConstant(0)); 169 RangeBoundary::FromConstant(0));
118 EXPECT(unsatisfiable_right->IsUnsatisfiable()); 170 EXPECT(unsatisfiable_right->IsUnsatisfiable());
119 171
120 Range* unsatisfiable_left = new Range(RangeBoundary::FromConstant(0), 172 Range* unsatisfiable_left = new Range(RangeBoundary::FromConstant(0),
121 RangeBoundary::NegativeInfinity()); 173 RangeBoundary::NegativeInfinity());
122 EXPECT(unsatisfiable_left->IsUnsatisfiable()); 174 EXPECT(unsatisfiable_left->IsUnsatisfiable());
123 } 175 }
124 176
125 } // namespace dart 177 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/intermediate_language.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698