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

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

Issue 12212175: Optimize left shift of a constant: compute max value of right that does not overflow into Mint/Bigi… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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/globals.h" // Needed here to get TARGET_ARCH_IA32. 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32.
6 #if defined(TARGET_ARCH_IA32) 6 #if defined(TARGET_ARCH_IA32)
7 7
8 #include "vm/intermediate_language.h" 8 #include "vm/intermediate_language.h"
9 9
10 #include "lib/error.h" 10 #include "lib/error.h"
(...skipping 2198 matching lines...) Expand 10 before | Expand all | Expand 10 after
2209 __ movl(right, Immediate(kCountLimit)); 2209 __ movl(right, Immediate(kCountLimit));
2210 __ Bind(&count_ok); 2210 __ Bind(&count_ok);
2211 } 2211 }
2212 ASSERT(right == ECX); // Count must be in ECX 2212 ASSERT(right == ECX); // Count must be in ECX
2213 __ SmiUntag(left); 2213 __ SmiUntag(left);
2214 __ sarl(left, right); 2214 __ sarl(left, right);
2215 __ SmiTag(left); 2215 __ SmiTag(left);
2216 break; 2216 break;
2217 } 2217 }
2218 case Token::kSHL: { 2218 case Token::kSHL: {
2219 Range* right_range = this->right()->definition()->range();
2220 if (this->left()->BindsToConstant()) {
2221 // If left is constant, we know the maximal allowed size for right.
2222 const Object& obj = this->left()->BoundConstant();
2223 if (obj.IsSmi()) {
2224 const intptr_t left_int = Smi::Cast(obj).Value();
2225 if (left_int == 0) {
2226 __ cmpl(right, Immediate(0));
2227 __ j(NEGATIVE, deopt);
2228 break;
2229 }
2230 intptr_t tmp = (left_int > 0) ? left_int : ~left_int;
2231 intptr_t max_right = kSmiBits;
2232 while ((tmp >>= 1) != 0) {
2233 max_right--;
2234 }
2235 const bool right_needs_check =
2236 (right_range == NULL) ||
2237 !right_range->IsWithin(0, max_right - 1);
2238 if (right_needs_check) {
2239 __ cmpl(right,
2240 Immediate(reinterpret_cast<int32_t>(Smi::New(max_right))));
2241 __ j(ABOVE_EQUAL, deopt);
2242 }
2243 __ SmiUntag(right);
2244 __ shll(left, right);
2245 break;
2246 }
2247 }
2219 Register temp = locs()->temp(0).reg(); 2248 Register temp = locs()->temp(0).reg();
2220 // Check if count too large for handling it inlined. 2249 // Check if count too large for handling it inlined.
2221 __ movl(temp, left); 2250 __ movl(temp, left);
2222 Range* right_range = this->right()->definition()->range();
2223 const bool right_needs_check = 2251 const bool right_needs_check =
2224 (right_range == NULL) || !right_range->IsWithin(0, (Smi::kBits - 1)); 2252 (right_range == NULL) || !right_range->IsWithin(0, (Smi::kBits - 1));
2225 if (right_needs_check) { 2253 if (right_needs_check) {
2226 __ cmpl(right, 2254 __ cmpl(right,
2227 Immediate(reinterpret_cast<int32_t>(Smi::New(Smi::kBits)))); 2255 Immediate(reinterpret_cast<int32_t>(Smi::New(Smi::kBits))));
2228 __ j(ABOVE_EQUAL, deopt); 2256 __ j(ABOVE_EQUAL, deopt);
2229 } 2257 }
2230 ASSERT(right == ECX); // Count must be in ECX 2258 ASSERT(right == ECX); // Count must be in ECX
2231 __ SmiUntag(right); 2259 __ SmiUntag(right);
2232 // Overflow test (preserve temp and right); 2260 // Overflow test (preserve temp and right);
(...skipping 1179 matching lines...) Expand 10 before | Expand all | Expand 10 after
3412 PcDescriptors::kOther, 3440 PcDescriptors::kOther,
3413 locs()); 3441 locs());
3414 __ Drop(2); // Discard type arguments and receiver. 3442 __ Drop(2); // Discard type arguments and receiver.
3415 } 3443 }
3416 3444
3417 } // namespace dart 3445 } // namespace dart
3418 3446
3419 #undef __ 3447 #undef __
3420 3448
3421 #endif // defined TARGET_ARCH_IA32 3449 #endif // defined TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/intermediate_language_x64.cc » ('j') | tests/standalone/constant_left_shift_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698