From a02e644c50289e4a141799a4a612a3374eeb26ad Mon Sep 17 00:00:00 2001 From: "chunyang.dai" Date: Mon, 13 Jul 2015 19:29:46 -0700 Subject: [PATCH] X87: [turbofan] Add TruncationMode for TruncateFloat64ToInt32. port 4b38c15817033ccd9a65efbb3d038ae2423293c2 (r29527). original commit message: We actually need round to zero truncation to implement the counterpart of LDoubleToI in TurboFan, which tries to convert a double to an integer as required for keyed load/store optimizations. Drive-by-cleanup: Reduce some code duplication in the InstructionSelector implementations. BUG= Review URL: https://codereview.chromium.org/1227923003 Cr-Commit-Position: refs/heads/master@{#29629} --- src/compiler/x87/code-generator-x87.cc | 12 +++++++----- src/compiler/x87/instruction-selector-x87.cc | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/compiler/x87/code-generator-x87.cc b/src/compiler/x87/code-generator-x87.cc index d337ecc9d8..1335d3f568 100644 --- a/src/compiler/x87/code-generator-x87.cc +++ b/src/compiler/x87/code-generator-x87.cc @@ -422,11 +422,13 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) { __ mov(i.OutputRegister(), esp); break; case kArchTruncateDoubleToI: { - auto input = i.InputDoubleRegister(0); - USE(input); - DCHECK(input.code() == 0); - auto result_reg = i.OutputRegister(); - __ TruncateX87TOSToI(result_reg); + if (!instr->InputAt(0)->IsDoubleRegister()) { + __ fld_d(i.InputOperand(0)); + } + __ TruncateX87TOSToI(i.OutputRegister()); + if (!instr->InputAt(0)->IsDoubleRegister()) { + __ fstp(0); + } break; } case kX87Add: diff --git a/src/compiler/x87/instruction-selector-x87.cc b/src/compiler/x87/instruction-selector-x87.cc index 7dda86efdc..d350738e0b 100644 --- a/src/compiler/x87/instruction-selector-x87.cc +++ b/src/compiler/x87/instruction-selector-x87.cc @@ -647,6 +647,23 @@ void InstructionSelector::VisitTruncateFloat64ToFloat32(Node* node) { } +void InstructionSelector::VisitTruncateFloat64ToInt32(Node* node) { + X87OperandGenerator g(this); + + switch (TruncationModeOf(node->op())) { + case TruncationMode::kJavaScript: + Emit(kArchTruncateDoubleToI, g.DefineAsRegister(node), + g.Use(node->InputAt(0))); + return; + case TruncationMode::kRoundToZero: + Emit(kX87Float64ToInt32, g.DefineAsRegister(node), + g.Use(node->InputAt(0))); + return; + } + UNREACHABLE(); +} + + void InstructionSelector::VisitFloat32Add(Node* node) { X87OperandGenerator g(this); Emit(kX87PushFloat32, g.NoOutput(), g.Use(node->InputAt(0)));