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

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
« no previous file with comments | « runtime/vm/intermediate_language.cc ('k') | 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 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 ASSERT(kSmiTagSize == 1);
2049 Register temp = locs()->temp(0).reg();
2050 __ movl(temp, left);
2051 __ sarl(temp, Immediate(31));
2052 ASSERT(shift_count > 1); // 1, -1 case handled above.
2053 __ shrl(temp, Immediate(32 - shift_count));
2054 __ addl(left, temp);
2055 ASSERT(shift_count > 0);
2056 __ sarl(left, Immediate(shift_count));
2057 if (value < 0) {
2058 __ negl(left);
2059 }
2060 __ SmiTag(left);
2061 break;
2062 }
2025 case Token::kBIT_AND: { 2063 case Token::kBIT_AND: {
2026 // No overflow check. 2064 // No overflow check.
2027 __ andl(left, Immediate(imm)); 2065 __ andl(left, Immediate(imm));
2028 break; 2066 break;
2029 } 2067 }
2030 case Token::kBIT_OR: { 2068 case Token::kBIT_OR: {
2031 // No overflow check. 2069 // No overflow check.
2032 __ orl(left, Immediate(imm)); 2070 __ orl(left, Immediate(imm));
2033 break; 2071 break;
2034 } 2072 }
(...skipping 1326 matching lines...) Expand 10 before | Expand all | Expand 10 after
3361 PcDescriptors::kOther, 3399 PcDescriptors::kOther,
3362 locs()); 3400 locs());
3363 __ Drop(2); // Discard type arguments and receiver. 3401 __ Drop(2); // Discard type arguments and receiver.
3364 } 3402 }
3365 3403
3366 } // namespace dart 3404 } // namespace dart
3367 3405
3368 #undef __ 3406 #undef __
3369 3407
3370 #endif // defined TARGET_ARCH_IA32 3408 #endif // defined TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « runtime/vm/intermediate_language.cc ('k') | runtime/vm/intermediate_language_x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698