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

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

Issue 11098009: Implement SmiToInt and DoubleToInt. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 2 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 1967 matching lines...) Expand 10 before | Expand all | Expand 10 after
1978 1978
1979 1979
1980 void SmiToDoubleInstr::EmitNativeCode(FlowGraphCompiler* compiler) { 1980 void SmiToDoubleInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
1981 Register result = locs()->out().reg(); 1981 Register result = locs()->out().reg();
1982 1982
1983 Label* deopt = compiler->AddDeoptStub(instance_call()->deopt_id(), 1983 Label* deopt = compiler->AddDeoptStub(instance_call()->deopt_id(),
1984 kDeoptIntegerToDouble); 1984 kDeoptIntegerToDouble);
1985 1985
1986 const Class& double_class = compiler->double_class(); 1986 const Class& double_class = compiler->double_class();
1987 const Code& stub = 1987 const Code& stub =
1988 Code::Handle(StubCode::GetAllocationStubForClass(double_class)); 1988 Code::Handle(StubCode::GetAllocationStubForClass(double_class));
1989 const ExternalLabel label(double_class.ToCString(), stub.EntryPoint()); 1989 const ExternalLabel label(double_class.ToCString(), stub.EntryPoint());
1990 1990
1991 // TODO(vegorov): allocate box in the driver loop to avoid spilling. 1991 // TODO(vegorov): allocate box in the driver loop to avoid spilling.
1992 compiler->GenerateCall(instance_call()->token_pos(), 1992 compiler->GenerateCall(instance_call()->token_pos(),
1993 &label, 1993 &label,
1994 PcDescriptors::kOther, 1994 PcDescriptors::kOther,
1995 locs()); 1995 locs());
1996 ASSERT(result == EAX); 1996 ASSERT(result == EAX);
1997 Register value = EBX; 1997 Register value = EBX;
1998 // Preserve argument on the stack until after the deoptimization point. 1998 // Preserve argument on the stack until after the deoptimization point.
1999 __ movl(value, Address(ESP, 0)); 1999 __ movl(value, Address(ESP, 0));
2000 2000
2001 __ testl(value, Immediate(kSmiTagMask)); 2001 __ testl(value, Immediate(kSmiTagMask));
2002 __ j(NOT_ZERO, deopt); // Deoptimize if not Smi. 2002 __ j(NOT_ZERO, deopt); // Deoptimize if not Smi.
2003 __ SmiUntag(value); 2003 __ SmiUntag(value);
2004 __ cvtsi2sd(XMM0, value); 2004 __ cvtsi2sd(XMM0, value);
2005 __ movsd(FieldAddress(result, Double::value_offset()), XMM0); 2005 __ movsd(FieldAddress(result, Double::value_offset()), XMM0);
2006 __ Drop(1); 2006 __ Drop(1);
2007 } 2007 }
2008 2008
2009 2009
2010 LocationSummary* DoubleToIntegerInstr::MakeLocationSummary() const {
2011 const intptr_t kNumInputs = 1;
2012 const intptr_t kNumTemps = 0;
2013 LocationSummary* result =
2014 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kCall);
2015 result->set_in(0, Location::RegisterLocation(ECX));
2016 result->set_out(Location::RegisterLocation(EAX));
2017 return result;
2018 }
2019
2020
2021 void DoubleToIntegerInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
2022 Register result = locs()->out().reg();
2023 Register value_obj = locs()->in(0).reg();
2024 XmmRegister value_double = XMM0;
2025 ASSERT(result == EAX);
2026 ASSERT(result != value_obj);
2027 __ movsd(value_double, FieldAddress(value_obj, Double::value_offset()));
2028 __ cvttsd2si(result, value_double);
2029 // Overflow is signalled with minint.
2030 Label do_call, done;
2031 // Check for overflow and that it fits into Smi.
2032 __ cmpl(result, Immediate(0xC0000000));
2033 __ j(NEGATIVE, &do_call, Assembler::kNearJump);
2034 __ SmiTag(result);
2035 __ jmp(&done);
2036 __ Bind(&do_call);
2037 __ pushl(value_obj);
2038 ASSERT(instance_call()->HasICData());
2039 const ICData& ic_data = *instance_call()->ic_data();
2040 ASSERT((ic_data.NumberOfChecks() == 1));
2041 const Function& target = Function::ZoneHandle(ic_data.GetTargetAt(0));
2042
2043 const intptr_t kNumberOfArguments = 1;
2044 compiler->GenerateStaticCall(instance_call()->deopt_id(),
2045 instance_call()->token_pos(),
2046 target,
2047 kNumberOfArguments,
2048 Array::Handle(), // No argument names.,
2049 locs());
2050 __ Drop(1);
2051 __ Bind(&done);
2052 }
2053
2054
2010 LocationSummary* PolymorphicInstanceCallInstr::MakeLocationSummary() const { 2055 LocationSummary* PolymorphicInstanceCallInstr::MakeLocationSummary() const {
2011 return MakeCallSummary(); 2056 return MakeCallSummary();
2012 } 2057 }
2013 2058
2014 2059
2015 void PolymorphicInstanceCallInstr::EmitNativeCode(FlowGraphCompiler* compiler) { 2060 void PolymorphicInstanceCallInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
2016 Label* deopt = compiler->AddDeoptStub(instance_call()->deopt_id(), 2061 Label* deopt = compiler->AddDeoptStub(instance_call()->deopt_id(),
2017 kDeoptPolymorphicInstanceCallTestFail); 2062 kDeoptPolymorphicInstanceCallTestFail);
2018 if (ic_data().NumberOfChecks() == 0) { 2063 if (ic_data().NumberOfChecks() == 0) {
2019 __ jmp(deopt); 2064 __ jmp(deopt);
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
2481 __ pcmpeqq(XMM0, XMM0); // Generate all 1's. 2526 __ pcmpeqq(XMM0, XMM0); // Generate all 1's.
2482 __ pxor(value, XMM0); 2527 __ pxor(value, XMM0);
2483 } 2528 }
2484 2529
2485 2530
2486 } // namespace dart 2531 } // namespace dart
2487 2532
2488 #undef __ 2533 #undef __
2489 2534
2490 #endif // defined TARGET_ARCH_X64 2535 #endif // defined TARGET_ARCH_X64
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