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

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

Issue 12091100: Use SAR for positive divident by a power-of two constant divisor. (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 1936 matching lines...) Expand 10 before | Expand all | Expand 10 after
1947 __ Bind(slow_path->exit_label()); 1947 __ Bind(slow_path->exit_label());
1948 } 1948 }
1949 1949
1950 1950
1951 LocationSummary* BinarySmiOpInstr::MakeLocationSummary() const { 1951 LocationSummary* BinarySmiOpInstr::MakeLocationSummary() const {
1952 const intptr_t kNumInputs = 2; 1952 const intptr_t kNumInputs = 2;
1953 if (op_kind() == Token::kTRUNCDIV) { 1953 if (op_kind() == Token::kTRUNCDIV) {
1954 const intptr_t kNumTemps = 1; 1954 const intptr_t kNumTemps = 1;
1955 LocationSummary* summary = 1955 LocationSummary* summary =
1956 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); 1956 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
1957 // Both inputs must be writable because they will be untagged. 1957 if (RightIsPowerOfTwoConstant()) {
1958 summary->set_in(0, Location::RegisterLocation(EAX)); 1958 summary->set_in(0, Location::RequiresRegister());
1959 summary->set_in(1, Location::WritableRegister()); 1959 ConstantInstr* right_constant = right()->definition()->AsConstant();
1960 summary->set_out(Location::SameAsFirstInput()); 1960 summary->set_in(1, Location::Constant(right_constant->value()));
1961 // Will be used for sign extension and division. 1961 summary->set_temp(0, Location::RequiresRegister());
1962 summary->set_temp(0, Location::RegisterLocation(EDX)); 1962 summary->set_out(Location::SameAsFirstInput());
1963 } else {
1964 // Both inputs must be writable because they will be untagged.
1965 summary->set_in(0, Location::RegisterLocation(EAX));
1966 summary->set_in(1, Location::WritableRegister());
1967 summary->set_out(Location::SameAsFirstInput());
1968 // Will be used for sign extension and division.
1969 summary->set_temp(0, Location::RegisterLocation(EDX));
1970 }
1963 return summary; 1971 return summary;
1964 } else if (op_kind() == Token::kSHR) { 1972 } else if (op_kind() == Token::kSHR) {
1965 const intptr_t kNumTemps = 0; 1973 const intptr_t kNumTemps = 0;
1966 LocationSummary* summary = 1974 LocationSummary* summary =
1967 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); 1975 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
1968 summary->set_in(0, Location::RequiresRegister()); 1976 summary->set_in(0, Location::RequiresRegister());
1969 summary->set_in(1, Location::FixedRegisterOrSmiConstant(right(), ECX)); 1977 summary->set_in(1, Location::FixedRegisterOrSmiConstant(right(), ECX));
1970 summary->set_out(Location::SameAsFirstInput()); 1978 summary->set_out(Location::SameAsFirstInput());
1971 return summary; 1979 return summary;
1972 } else if (op_kind() == Token::kSHL) { 1980 } else if (op_kind() == Token::kSHL) {
(...skipping 16 matching lines...) Expand all
1989 } 1997 }
1990 } 1998 }
1991 1999
1992 2000
1993 void BinarySmiOpInstr::EmitNativeCode(FlowGraphCompiler* compiler) { 2001 void BinarySmiOpInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
1994 Register left = locs()->in(0).reg(); 2002 Register left = locs()->in(0).reg();
1995 Register result = locs()->out().reg(); 2003 Register result = locs()->out().reg();
1996 ASSERT(left == result); 2004 ASSERT(left == result);
1997 Label* deopt = NULL; 2005 Label* deopt = NULL;
1998 if (CanDeoptimize()) { 2006 if (CanDeoptimize()) {
1999 deopt = compiler->AddDeoptStub(deopt_id(), 2007 deopt = compiler->AddDeoptStub(deopt_id(), kDeoptBinarySmiOp);
2000 kDeoptBinarySmiOp);
2001 } 2008 }
2002 2009
2003 if (locs()->in(1).IsConstant()) { 2010 if (locs()->in(1).IsConstant()) {
2004 const Object& constant = locs()->in(1).constant(); 2011 const Object& constant = locs()->in(1).constant();
2005 ASSERT(constant.IsSmi()); 2012 ASSERT(constant.IsSmi());
2006 const int32_t imm = 2013 const int32_t imm =
2007 reinterpret_cast<int32_t>(constant.raw()); 2014 reinterpret_cast<int32_t>(constant.raw());
2008 switch (op_kind()) { 2015 switch (op_kind()) {
2009 case Token::kADD: 2016 case Token::kADD:
2010 __ addl(left, Immediate(imm)); 2017 __ addl(left, Immediate(imm));
2011 if (deopt != NULL) __ j(OVERFLOW, deopt); 2018 if (deopt != NULL) __ j(OVERFLOW, deopt);
2012 break; 2019 break;
2013 case Token::kSUB: { 2020 case Token::kSUB: {
2014 __ subl(left, Immediate(imm)); 2021 __ subl(left, Immediate(imm));
2015 if (deopt != NULL) __ j(OVERFLOW, deopt); 2022 if (deopt != NULL) __ j(OVERFLOW, deopt);
2016 break; 2023 break;
2017 } 2024 }
2018 case Token::kMUL: { 2025 case Token::kMUL: {
2019 // Keep left value tagged and untag right value. 2026 // Keep left value tagged and untag right value.
2020 const intptr_t value = Smi::Cast(constant).Value(); 2027 const intptr_t value = Smi::Cast(constant).Value();
2021 __ imull(left, Immediate(value)); 2028 __ imull(left, Immediate(value));
2022 if (deopt != NULL) __ j(OVERFLOW, deopt); 2029 if (deopt != NULL) __ j(OVERFLOW, deopt);
2023 break; 2030 break;
2024 } 2031 }
2032 case Token::kTRUNCDIV: {
2033 const intptr_t value = Smi::Cast(constant).Value();
2034 if (value == 1) {
2035 // Do nothing.
2036 break;
2037 } else if (value == -1) {
2038 // Check the corner case of dividing the 'MIN_SMI' with -1, in which
2039 // case we cannot negate the result.
2040 __ cmpl(left, Immediate(0x80000000));
2041 __ j(EQUAL, deopt);
2042 __ negl(left);
2043 break;
2044 }
2045 ASSERT((value != 0) && Utils::IsPowerOfTwo(Utils::Abs(value)));
2046 const intptr_t shift_count =
2047 Utils::ShiftForPowerOfTwo(Utils::Abs(value)) + kSmiTagSize;
2048 Register temp = locs()->temp(0).reg();
2049 __ movl(temp, left);
2050 __ sarl(temp, Immediate(31));
2051 if (shift_count > 1) {
Florian Schneider 2013/02/04 13:04:03 Redundant if-statment? shift_count will only be 1
srdjan 2013/02/04 19:02:33 Removed
2052 __ shrl(temp, Immediate(32 - shift_count));
2053 }
2054 __ addl(left, temp);
2055 if (shift_count > 0) {
Florian Schneider 2013/02/04 13:04:03 shift_count will always be > 0 here because kSmiTa
srdjan 2013/02/04 19:02:33 Done.
2056 __ sarl(left, Immediate(shift_count));
2057 }
2058 if (value < 0) {
2059 __ negl(left);
2060 }
2061 __ SmiTag(left);
2062 break;
2063 }
2025 case Token::kBIT_AND: { 2064 case Token::kBIT_AND: {
2026 // No overflow check. 2065 // No overflow check.
2027 __ andl(left, Immediate(imm)); 2066 __ andl(left, Immediate(imm));
2028 break; 2067 break;
2029 } 2068 }
2030 case Token::kBIT_OR: { 2069 case Token::kBIT_OR: {
2031 // No overflow check. 2070 // No overflow check.
2032 __ orl(left, Immediate(imm)); 2071 __ orl(left, Immediate(imm));
2033 break; 2072 break;
2034 } 2073 }
(...skipping 1326 matching lines...) Expand 10 before | Expand all | Expand 10 after
3361 PcDescriptors::kOther, 3400 PcDescriptors::kOther,
3362 locs()); 3401 locs());
3363 __ Drop(2); // Discard type arguments and receiver. 3402 __ Drop(2); // Discard type arguments and receiver.
3364 } 3403 }
3365 3404
3366 } // namespace dart 3405 } // namespace dart
3367 3406
3368 #undef __ 3407 #undef __
3369 3408
3370 #endif // defined TARGET_ARCH_IA32 3409 #endif // defined TARGET_ARCH_IA32
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698