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

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

Issue 12082063: Enable correct optimized double modulo operation. (TODO: enable remainder optimization). (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 2533 matching lines...) Expand 10 before | Expand all | Expand 10 after
2544 __ DoubleRound(result, value, temp); 2544 __ DoubleRound(result, value, temp);
2545 break; 2545 break;
2546 } 2546 }
2547 default: 2547 default:
2548 UNREACHABLE(); 2548 UNREACHABLE();
2549 } 2549 }
2550 } 2550 }
2551 2551
2552 2552
2553 LocationSummary* InvokeMathCFunctionInstr::MakeLocationSummary() const { 2553 LocationSummary* InvokeMathCFunctionInstr::MakeLocationSummary() const {
2554 if (recognized_kind() == MethodRecognizer::kDoubleMod) {
2555 ASSERT(InputCount() == 2);
2556 const intptr_t kNumTemps = 2;
2557 LocationSummary* result =
2558 new LocationSummary(InputCount(), kNumTemps, LocationSummary::kCall);
2559 result->set_in(0, Location::FpuRegisterLocation(XMM1, Location::kDouble));
2560 result->set_in(1, Location::FpuRegisterLocation(XMM2, Location::kDouble));
2561 result->set_out(Location::FpuRegisterLocation(XMM1, Location::kDouble));
2562 result->set_temp(0, Location::FpuRegisterLocation(XMM2, Location::kDouble));
2563 result->set_temp(1, Location::FpuRegisterLocation(XMM3, Location::kDouble));
2564 return result;
2565 }
2554 ASSERT((InputCount() == 1) || (InputCount() == 2)); 2566 ASSERT((InputCount() == 1) || (InputCount() == 2));
2555 const intptr_t kNumTemps = 0; 2567 const intptr_t kNumTemps = 0;
2556 LocationSummary* result = 2568 LocationSummary* result =
2557 new LocationSummary(InputCount(), kNumTemps, LocationSummary::kCall); 2569 new LocationSummary(InputCount(), kNumTemps, LocationSummary::kCall);
2558 result->set_in(0, Location::FpuRegisterLocation(XMM1, Location::kDouble)); 2570 result->set_in(0, Location::FpuRegisterLocation(XMM1, Location::kDouble));
2559 if (InputCount() == 2) { 2571 if (InputCount() == 2) {
2560 result->set_in(1, Location::FpuRegisterLocation(XMM2, Location::kDouble)); 2572 result->set_in(1, Location::FpuRegisterLocation(XMM2, Location::kDouble));
2561 } 2573 }
2562 result->set_out(Location::FpuRegisterLocation(XMM1, Location::kDouble)); 2574 result->set_out(Location::FpuRegisterLocation(XMM1, Location::kDouble));
2563 return result; 2575 return result;
2564 } 2576 }
2565 2577
2566 2578
2567 void InvokeMathCFunctionInstr::EmitNativeCode(FlowGraphCompiler* compiler) { 2579 void InvokeMathCFunctionInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
2580 if (recognized_kind() == MethodRecognizer::kDoubleMod) {
2581 // Preserve right argument.
2582 __ pushl(EAX);
2583 __ pushl(EAX);
2584 __ movsd(Address(ESP, 0), locs()->in(1).fpu_reg());
2585 }
2586
2568 __ EnterFrame(0); 2587 __ EnterFrame(0);
2569 __ ReserveAlignedFrameSpace(kDoubleSize * InputCount()); 2588 __ ReserveAlignedFrameSpace(kDoubleSize * InputCount());
2570 for (intptr_t i = 0; i < InputCount(); i++) { 2589 for (intptr_t i = 0; i < InputCount(); i++) {
2571 __ movsd(Address(ESP, kDoubleSize * i), locs()->in(i).fpu_reg()); 2590 __ movsd(Address(ESP, kDoubleSize * i), locs()->in(i).fpu_reg());
2572 } 2591 }
2573 __ CallRuntime(TargetFunction()); 2592 __ CallRuntime(TargetFunction());
2574 __ fstpl(Address(ESP, 0)); 2593 __ fstpl(Address(ESP, 0));
2575 __ movsd(locs()->out().fpu_reg(), Address(ESP, 0)); 2594 __ movsd(locs()->out().fpu_reg(), Address(ESP, 0));
2576 __ leave(); 2595 __ leave();
2596
2597 if (recognized_kind() == MethodRecognizer::kDoubleMod) {
2598 // Result of C call is remainder, convert it to modulo.
2599 Label done, equal_zero, right_greater_equal_zero;
2600 XmmRegister remainder = locs()->out().fpu_reg();
2601 XmmRegister zero_temp = locs()->temp(0).fpu_reg();
2602 XmmRegister right_temp = locs()->temp(1).fpu_reg();
2603
2604 __ xorpd(zero_temp, zero_temp); // 0.0 -> 'temp'.
2605 __ comisd(remainder, zero_temp);
2606 __ j(PARITY_EVEN, &done, Assembler::kNearJump); // NaN -> false;
2607 __ j(EQUAL, &equal_zero, Assembler::kNearJump);
2608 __ j(ABOVE, &done, Assembler::kNearJump); // (remainder) > 0 -> done.
2609 // remainder < 0.
2610 // Load preserved right argument.
2611 __ movsd(right_temp, Address(ESP, 0));
2612 __ comisd(right_temp, zero_temp);
2613 __ j(ABOVE_EQUAL, &right_greater_equal_zero, Assembler::kNearJump);
2614 // right < 0.
2615 __ subsd(remainder, right_temp);
2616 __ jmp(&done, Assembler::kNearJump);
2617
2618 __ Bind(&right_greater_equal_zero);
2619 __ addsd(remainder, right_temp);
2620 __ jmp(&done);
2621
2622 __ Bind(&equal_zero);
2623 // Switch to the positive 0.0 (just in case it was negative).
2624 __ movsd(remainder, zero_temp);
2625
2626 __ Bind(&done);
2627 __ Drop(2); // Remove preserved right argument.
2628 }
2577 } 2629 }
2578 2630
2579 2631
2580 LocationSummary* PolymorphicInstanceCallInstr::MakeLocationSummary() const { 2632 LocationSummary* PolymorphicInstanceCallInstr::MakeLocationSummary() const {
2581 return MakeCallSummary(); 2633 return MakeCallSummary();
2582 } 2634 }
2583 2635
2584 2636
2585 void PolymorphicInstanceCallInstr::EmitNativeCode(FlowGraphCompiler* compiler) { 2637 void PolymorphicInstanceCallInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
2586 Label* deopt = compiler->AddDeoptStub(instance_call()->deopt_id(), 2638 Label* deopt = compiler->AddDeoptStub(instance_call()->deopt_id(),
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after
3368 PcDescriptors::kOther, 3420 PcDescriptors::kOther,
3369 locs()); 3421 locs());
3370 __ Drop(2); // Discard type arguments and receiver. 3422 __ Drop(2); // Discard type arguments and receiver.
3371 } 3423 }
3372 3424
3373 } // namespace dart 3425 } // namespace dart
3374 3426
3375 #undef __ 3427 #undef __
3376 3428
3377 #endif // defined TARGET_ARCH_IA32 3429 #endif // defined TARGET_ARCH_IA32
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698