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

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
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 return MakeCallSummary(); // Slow case calls the method.
2012 }
2013
2014
2015 void DoubleToIntegerInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
2016 Register result = locs()->out().reg();
2017 ASSERT(result == EAX);
2018 Register value_obj = EBX;
2019 XmmRegister value_double = XMM0;
2020 __ movl(value_obj, Address(ESP, 0));
Florian Schneider 2012/10/09 11:13:58 Alternatively, you could make the instruction take
srdjan 2012/10/09 21:23:04 Done.
2021 __ movsd(value_double, FieldAddress(value_obj, Double::value_offset()));
2022 __ cvttsd2si(result, value_double);
Florian Schneider 2012/10/09 11:13:58 Please add this instruction to the disassembler. I
srdjan 2012/10/09 21:23:04 Done.
2023 // Overflow is signalled with minint.
2024 Label do_call, done;
2025 // Check for overflow and that it fits into Smi.
2026 __ cmpl(result, Immediate(0xC0000000));
2027 __ j(NEGATIVE, &do_call, Assembler::kNearJump);
2028 __ SmiTag(result);
2029 __ Drop(1);
2030 __ jmp(&done);
2031 __ Bind(&do_call);
2032 ASSERT(instance_call()->HasICData());
2033 const ICData& ic_data = *instance_call()->ic_data();
2034 ASSERT((ic_data.NumberOfChecks() == 1));
2035 const Function& target = Function::ZoneHandle(ic_data.GetTargetAt(0));
2036
2037 const intptr_t kNumberOfArguments = 1;
2038 compiler->GenerateStaticCall(instance_call()->deopt_id(),
2039 instance_call()->token_pos(),
2040 target,
2041 kNumberOfArguments,
2042 Array::Handle(), // No argument names.,
2043 locs());
2044 __ Bind(&done);
2045 }
2046
2047
2010 LocationSummary* PolymorphicInstanceCallInstr::MakeLocationSummary() const { 2048 LocationSummary* PolymorphicInstanceCallInstr::MakeLocationSummary() const {
2011 return MakeCallSummary(); 2049 return MakeCallSummary();
2012 } 2050 }
2013 2051
2014 2052
2015 void PolymorphicInstanceCallInstr::EmitNativeCode(FlowGraphCompiler* compiler) { 2053 void PolymorphicInstanceCallInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
2016 Label* deopt = compiler->AddDeoptStub(instance_call()->deopt_id(), 2054 Label* deopt = compiler->AddDeoptStub(instance_call()->deopt_id(),
2017 kDeoptPolymorphicInstanceCallTestFail); 2055 kDeoptPolymorphicInstanceCallTestFail);
2018 if (ic_data().NumberOfChecks() == 0) { 2056 if (ic_data().NumberOfChecks() == 0) {
2019 __ jmp(deopt); 2057 __ jmp(deopt);
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
2461 __ pcmpeqq(XMM0, XMM0); // Generate all 1's. 2499 __ pcmpeqq(XMM0, XMM0); // Generate all 1's.
2462 __ pxor(value, XMM0); 2500 __ pxor(value, XMM0);
2463 } 2501 }
2464 2502
2465 2503
2466 } // namespace dart 2504 } // namespace dart
2467 2505
2468 #undef __ 2506 #undef __
2469 2507
2470 #endif // defined TARGET_ARCH_X64 2508 #endif // defined TARGET_ARCH_X64
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698