From b785daa704fbf5fc9a63451003722082b0928959 Mon Sep 17 00:00:00 2001 From: "chunyang.dai" Date: Wed, 23 Sep 2015 20:43:42 -0700 Subject: [PATCH] X87: [turbofan] Add support for reinterpreting integers as floating point and vice versa. port c610a22231212b12055c294f55b8f3942127580b (r30849). original commit message: BUG= Review URL: https://codereview.chromium.org/1362783003 Cr-Commit-Position: refs/heads/master@{#30898} --- src/compiler/x87/code-generator-x87.cc | 22 ++++++++++++++++++++++ src/compiler/x87/instruction-codes-x87.h | 2 ++ src/compiler/x87/instruction-selector-x87.cc | 7 +++++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/compiler/x87/code-generator-x87.cc b/src/compiler/x87/code-generator-x87.cc index 4f90a80..9ca9a30 100644 --- a/src/compiler/x87/code-generator-x87.cc +++ b/src/compiler/x87/code-generator-x87.cc @@ -1069,6 +1069,28 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) { } break; } + case kX87BitcastFI: { + __ fstp(0); + __ mov(i.OutputRegister(), MemOperand(esp, 0)); + __ lea(esp, Operand(esp, kFloatSize)); + break; + } + case kX87BitcastIF: { + if (instr->InputAt(0)->IsRegister()) { + __ lea(esp, Operand(esp, -kFloatSize)); + __ mov(MemOperand(esp, 0), i.InputRegister(0)); + __ fstp(0); + __ fld_s(MemOperand(esp, 0)); + __ lea(esp, Operand(esp, kFloatSize)); + } else { + __ lea(esp, Operand(esp, -kDoubleSize)); + __ mov(MemOperand(esp, 0), i.InputRegister(0)); + __ fstp(0); + __ fld_d(MemOperand(esp, 0)); + __ lea(esp, Operand(esp, kDoubleSize)); + } + break; + } case kX87Lea: { AddressingMode mode = AddressingModeField::decode(instr->opcode()); // Shorten "leal" to "addl", "subl" or "shll" if the register allocation diff --git a/src/compiler/x87/instruction-codes-x87.h b/src/compiler/x87/instruction-codes-x87.h index d1b759b..9408e41 100644 --- a/src/compiler/x87/instruction-codes-x87.h +++ b/src/compiler/x87/instruction-codes-x87.h @@ -74,6 +74,8 @@ namespace compiler { V(X87Movss) \ V(X87Movsd) \ V(X87Lea) \ + V(X87BitcastFI) \ + V(X87BitcastIF) \ V(X87Push) \ V(X87PushFloat64) \ V(X87PushFloat32) \ diff --git a/src/compiler/x87/instruction-selector-x87.cc b/src/compiler/x87/instruction-selector-x87.cc index 2051b14..ac868fb 100644 --- a/src/compiler/x87/instruction-selector-x87.cc +++ b/src/compiler/x87/instruction-selector-x87.cc @@ -665,12 +665,15 @@ void InstructionSelector::VisitTruncateFloat64ToInt32(Node* node) { void InstructionSelector::VisitBitcastFloat32ToInt32(Node* node) { - UNIMPLEMENTED(); + X87OperandGenerator g(this); + Emit(kX87PushFloat32, g.NoOutput(), g.Use(node->InputAt(0))); + Emit(kX87BitcastFI, g.DefineAsRegister(node), 0, NULL); } void InstructionSelector::VisitBitcastInt32ToFloat32(Node* node) { - UNIMPLEMENTED(); + X87OperandGenerator g(this); + Emit(kX87BitcastIF, g.DefineAsFixed(node, stX_0), g.Use(node->InputAt(0))); } -- 2.7.4