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

Side by Side Diff: test/unittests/compiler/typer-unittest.cc

Issue 1112123002: Precise bitwise-xor derived result type for all int32 input types. Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Split the bitwise-xor result type derivation into a separate function. Created 5 years, 7 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
« src/compiler/typer.cc ('K') | « src/compiler/typer.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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <functional> 5 #include <functional>
6 6
7 #include "src/codegen.h" 7 #include "src/codegen.h"
8 #include "src/compiler/js-operator.h" 8 #include "src/compiler/js-operator.h"
9 #include "src/compiler/node-properties.h" 9 #include "src/compiler/node-properties.h"
10 #include "test/cctest/types-fuzz.h" 10 #include "test/cctest/types-fuzz.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 double x1 = RandomInt(r1); 139 double x1 = RandomInt(r1);
140 double x2 = RandomInt(r2); 140 double x2 = RandomInt(r2);
141 double result_value = opfun(x1, x2); 141 double result_value = opfun(x1, x2);
142 Type* result_type = Type::Constant( 142 Type* result_type = Type::Constant(
143 isolate()->factory()->NewNumber(result_value), zone()); 143 isolate()->factory()->NewNumber(result_value), zone());
144 EXPECT_TRUE(result_type->Is(expected_type)); 144 EXPECT_TRUE(result_type->Is(expected_type));
145 } 145 }
146 } 146 }
147 } 147 }
148 148
149 // Careful, this function scales poorly.
150 template <int32_t op(int32_t, int32_t), class DeriveFunction>
151 void TestPreciseBinaryArithOp(DeriveFunction derive,
152 int32_t llow, int32_t lhigh, int32_t linc,
153 int32_t rlow, int32_t rhigh, int32_t rinc) {
154 for (int64_t lmin = llow; lmin <= lhigh; lmin += linc) {
155 for (int64_t lmax = lmin; lmax <= lhigh; lmax += linc) {
156 for (int64_t rmin = rlow; rmin <= rhigh; rmin += rinc) {
157 for (int64_t rmax = rmin; rmax <= rhigh; rmax += rinc) {
158 IntType r1 = IntType(int32_t(lmin), int32_t(lmax));
159 IntType r2 = IntType(int32_t(rmin), int32_t(rmax));
160 IntType derived_type = derive(r1, r2);
161 int32_t min = kMaxInt, max = kMinInt;
162 for (int32_t x1 = int32_t(lmin); x1 <= int32_t(lmax); x1++) {
163 for (int32_t x2 = int32_t(rmin); x2 <= int32_t(rmax); x2++) {
164 int32_t result_value = op(x1, x2);
165 min = std::min(result_value, min);
166 max = std::max(result_value, max);
167 }
168 }
169 EXPECT_TRUE(derived_type.min == min && derived_type.max == max);
170 }
171 }
172 }
173 }
174 }
175
149 template <class BinaryFunction> 176 template <class BinaryFunction>
150 void TestBinaryCompareOp(const Operator* op, BinaryFunction opfun) { 177 void TestBinaryCompareOp(const Operator* op, BinaryFunction opfun) {
151 for (int i = 0; i < 100; ++i) { 178 for (int i = 0; i < 100; ++i) {
152 Type::RangeType* r1 = RandomRange()->AsRange(); 179 Type::RangeType* r1 = RandomRange()->AsRange();
153 Type::RangeType* r2 = RandomRange()->AsRange(); 180 Type::RangeType* r2 = RandomRange()->AsRange();
154 Type* expected_type = TypeBinaryOp(op, r1, r2); 181 Type* expected_type = TypeBinaryOp(op, r1, r2);
155 for (int i = 0; i < 10; i++) { 182 for (int i = 0; i < 10; i++) {
156 double x1 = RandomInt(r1); 183 double x1 = RandomInt(r1);
157 double x2 = RandomInt(r2); 184 double x2 = RandomInt(r2);
158 bool result_value = opfun(x1, x2); 185 bool result_value = opfun(x1, x2);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 295
269 TEST_F(TyperTest, TypeJSBitwiseAnd) { 296 TEST_F(TyperTest, TypeJSBitwiseAnd) {
270 TestBinaryBitOp(javascript_.BitwiseAnd(LanguageMode::SLOPPY), bit_and); 297 TestBinaryBitOp(javascript_.BitwiseAnd(LanguageMode::SLOPPY), bit_and);
271 TestBinaryBitOp(javascript_.BitwiseAnd(LanguageMode::STRONG), bit_and); 298 TestBinaryBitOp(javascript_.BitwiseAnd(LanguageMode::STRONG), bit_and);
272 } 299 }
273 300
274 301
275 TEST_F(TyperTest, TypeJSBitwiseXor) { 302 TEST_F(TyperTest, TypeJSBitwiseXor) {
276 TestBinaryBitOp(javascript_.BitwiseXor(LanguageMode::SLOPPY), bit_xor); 303 TestBinaryBitOp(javascript_.BitwiseXor(LanguageMode::SLOPPY), bit_xor);
277 TestBinaryBitOp(javascript_.BitwiseXor(LanguageMode::STRONG), bit_xor); 304 TestBinaryBitOp(javascript_.BitwiseXor(LanguageMode::STRONG), bit_xor);
305 // The derivation algorithm works one bit at a time and scales to
306 // any bit width so verify on practical bit widths.
307 TestPreciseBinaryArithOp<bit_xor>(JSBitwiseXorIntType,
Sven Panne 2015/05/18 12:16:15 How long do these tests actually run? 6 nested for
308 -16, 15, 1, -16, 15, 1);
309 TestPreciseBinaryArithOp<bit_xor>(JSBitwiseXorIntType,
310 kMaxInt - 32, kMaxInt, 1,
311 kMaxInt - 32, kMaxInt, 1);
312 TestPreciseBinaryArithOp<bit_xor>(JSBitwiseXorIntType,
313 kMinInt, kMinInt + 32, 1,
314 kMinInt, kMinInt + 32, 1);
315 TestPreciseBinaryArithOp<bit_xor>(JSBitwiseXorIntType,
316 kMaxInt - 32 * 2, kMaxInt, 2,
317 kMaxInt - 32 * 2, kMaxInt, 2);
318 TestPreciseBinaryArithOp<bit_xor>(JSBitwiseXorIntType,
319 kMinInt, kMinInt + 32 * 2, 2,
320 kMinInt, kMinInt + 32 * 2, 2);
278 } 321 }
279 322
280 323
281 TEST_F(TyperTest, TypeJSShiftLeft) { 324 TEST_F(TyperTest, TypeJSShiftLeft) {
282 TestBinaryBitOp(javascript_.ShiftLeft(LanguageMode::SLOPPY), shift_left); 325 TestBinaryBitOp(javascript_.ShiftLeft(LanguageMode::SLOPPY), shift_left);
283 TestBinaryBitOp(javascript_.ShiftLeft(LanguageMode::STRONG), shift_left); 326 TestBinaryBitOp(javascript_.ShiftLeft(LanguageMode::STRONG), shift_left);
284 } 327 }
285 328
286 329
287 TEST_F(TyperTest, TypeJSShiftRight) { 330 TEST_F(TyperTest, TypeJSShiftRight) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 439
397 440
398 TEST_F(TyperTest, TypeRegressInt32Constant) { 441 TEST_F(TyperTest, TypeRegressInt32Constant) {
399 int values[] = {-5, 10}; 442 int values[] = {-5, 10};
400 for (auto i : values) { 443 for (auto i : values) {
401 Node* c = graph()->NewNode(common()->Int32Constant(i)); 444 Node* c = graph()->NewNode(common()->Int32Constant(i));
402 Type* type = NodeProperties::GetBounds(c).upper; 445 Type* type = NodeProperties::GetBounds(c).upper;
403 EXPECT_TRUE(type->Is(NewRange(i, i))); 446 EXPECT_TRUE(type->Is(NewRange(i, i)));
404 } 447 }
405 } 448 }
OLDNEW
« src/compiler/typer.cc ('K') | « src/compiler/typer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698