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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/vm/intermediate_language_x64.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/intermediate_language_ia32.cc
===================================================================
--- runtime/vm/intermediate_language_ia32.cc (revision 18523)
+++ runtime/vm/intermediate_language_ia32.cc (working copy)
@@ -2239,10 +2239,38 @@
break;
}
case Token::kSHL: {
+ Range* right_range = this->right()->definition()->range();
+ if (this->left()->BindsToConstant()) {
+ // If left is constant, we know the maximal allowed size for right.
+ const Object& obj = this->left()->BoundConstant();
+ if (obj.IsSmi()) {
+ const intptr_t left_int = Smi::Cast(obj).Value();
+ if (left_int == 0) {
+ __ cmpl(right, Immediate(0));
+ __ j(NEGATIVE, deopt);
+ break;
+ }
+ intptr_t tmp = (left_int > 0) ? left_int : ~left_int;
+ intptr_t max_right = kSmiBits;
+ while ((tmp >>= 1) != 0) {
+ max_right--;
+ }
+ const bool right_needs_check =
+ (right_range == NULL) ||
+ !right_range->IsWithin(0, max_right - 1);
+ if (right_needs_check) {
+ __ cmpl(right,
+ Immediate(reinterpret_cast<int32_t>(Smi::New(max_right))));
+ __ j(ABOVE_EQUAL, deopt);
+ }
+ __ SmiUntag(right);
+ __ shll(left, right);
+ break;
+ }
+ }
Register temp = locs()->temp(0).reg();
// Check if count too large for handling it inlined.
__ movl(temp, left);
- Range* right_range = this->right()->definition()->range();
const bool right_needs_check =
(right_range == NULL) || !right_range->IsWithin(0, (Smi::kBits - 1));
if (right_needs_check) {
« 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