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

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
« no previous file with comments | « no previous file | runtime/vm/intermediate_language_x64.cc » ('j') | 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) 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 2221 matching lines...) Expand 10 before | Expand all | Expand 10 after
2232 __ movl(right, Immediate(kCountLimit)); 2232 __ movl(right, Immediate(kCountLimit));
2233 __ Bind(&count_ok); 2233 __ Bind(&count_ok);
2234 } 2234 }
2235 ASSERT(right == ECX); // Count must be in ECX 2235 ASSERT(right == ECX); // Count must be in ECX
2236 __ SmiUntag(left); 2236 __ SmiUntag(left);
2237 __ sarl(left, right); 2237 __ sarl(left, right);
2238 __ SmiTag(left); 2238 __ SmiTag(left);
2239 break; 2239 break;
2240 } 2240 }
2241 case Token::kSHL: { 2241 case Token::kSHL: {
2242 Range* right_range = this->right()->definition()->range();
2243 if (this->left()->BindsToConstant()) {
2244 // If left is constant, we know the maximal allowed size for right.
2245 const Object& obj = this->left()->BoundConstant();
2246 if (obj.IsSmi()) {
2247 const intptr_t left_int = Smi::Cast(obj).Value();
2248 if (left_int == 0) {
2249 __ cmpl(right, Immediate(0));
2250 __ j(NEGATIVE, deopt);
2251 break;
2252 }
2253 intptr_t tmp = (left_int > 0) ? left_int : ~left_int;
2254 intptr_t max_right = kSmiBits;
2255 while ((tmp >>= 1) != 0) {
2256 max_right--;
2257 }
2258 const bool right_needs_check =
2259 (right_range == NULL) ||
2260 !right_range->IsWithin(0, max_right - 1);
2261 if (right_needs_check) {
2262 __ cmpl(right,
2263 Immediate(reinterpret_cast<int32_t>(Smi::New(max_right))));
2264 __ j(ABOVE_EQUAL, deopt);
2265 }
2266 __ SmiUntag(right);
2267 __ shll(left, right);
2268 break;
2269 }
2270 }
2242 Register temp = locs()->temp(0).reg(); 2271 Register temp = locs()->temp(0).reg();
2243 // Check if count too large for handling it inlined. 2272 // Check if count too large for handling it inlined.
2244 __ movl(temp, left); 2273 __ movl(temp, left);
2245 Range* right_range = this->right()->definition()->range();
2246 const bool right_needs_check = 2274 const bool right_needs_check =
2247 (right_range == NULL) || !right_range->IsWithin(0, (Smi::kBits - 1)); 2275 (right_range == NULL) || !right_range->IsWithin(0, (Smi::kBits - 1));
2248 if (right_needs_check) { 2276 if (right_needs_check) {
2249 __ cmpl(right, 2277 __ cmpl(right,
2250 Immediate(reinterpret_cast<int32_t>(Smi::New(Smi::kBits)))); 2278 Immediate(reinterpret_cast<int32_t>(Smi::New(Smi::kBits))));
2251 __ j(ABOVE_EQUAL, deopt); 2279 __ j(ABOVE_EQUAL, deopt);
2252 } 2280 }
2253 ASSERT(right == ECX); // Count must be in ECX 2281 ASSERT(right == ECX); // Count must be in ECX
2254 __ SmiUntag(right); 2282 __ SmiUntag(right);
2255 // Overflow test (preserve temp and right); 2283 // Overflow test (preserve temp and right);
(...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after
3452 PcDescriptors::kOther, 3480 PcDescriptors::kOther,
3453 locs()); 3481 locs());
3454 __ Drop(2); // Discard type arguments and receiver. 3482 __ Drop(2); // Discard type arguments and receiver.
3455 } 3483 }
3456 3484
3457 } // namespace dart 3485 } // namespace dart
3458 3486
3459 #undef __ 3487 #undef __
3460 3488
3461 #endif // defined TARGET_ARCH_IA32 3489 #endif // defined TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/intermediate_language_x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698