| Index: src/compiler/x64/code-generator-x64.cc
|
| diff --git a/src/compiler/x64/code-generator-x64.cc b/src/compiler/x64/code-generator-x64.cc
|
| index c9ce8d7f193716ebeb676a8315a3927ab3187ddd..c9de5428183a22603c57540b100766ef9276eb6c 100644
|
| --- a/src/compiler/x64/code-generator-x64.cc
|
| +++ b/src/compiler/x64/code-generator-x64.cc
|
| @@ -941,10 +941,53 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) {
|
| ASSEMBLE_SSE_UNOP(Cvtss2sd);
|
| break;
|
| case kSSEFloat32Round: {
|
| - CpuFeatureScope sse_scope(masm(), SSE4_1);
|
| RoundingMode const mode =
|
| static_cast<RoundingMode>(MiscField::decode(instr->opcode()));
|
| - __ Roundss(i.OutputDoubleRegister(), i.InputDoubleRegister(0), mode);
|
| + if (CpuFeatures::IsSupported(SSE4_1)) {
|
| + CpuFeatureScope sse_scope(masm(), SSE4_1);
|
| + __ Roundss(i.OutputDoubleRegister(), i.InputDoubleRegister(0), mode);
|
| + } else {
|
| + // Set the rounding mode.
|
| + // We have to store the original rounding mode in memory.
|
| + __ subq(rsp, Immediate(kPointerSize * 2));
|
| + __ stmxcsr(Operand(rsp, 0));
|
| + __ movl(kScratchRegister, Operand(rsp, 0));
|
| + __ andl(kScratchRegister, Immediate(0xffff9fff));
|
| + __ orl(kScratchRegister, Immediate(mode << 13));
|
| + __ movl(Operand(rsp, kPointerSize), kScratchRegister);
|
| + __ ldmxcsr(Operand(rsp, kPointerSize));
|
| +
|
| + // Start with the conversion.
|
| + if (instr->InputAt(0)->IsDoubleRegister()) {
|
| + __ Cvtss2siq(kScratchRegister, i.InputDoubleRegister(0));
|
| + } else {
|
| + __ Cvtss2siq(kScratchRegister, i.InputOperand(0));
|
| + }
|
| +
|
| + Label out_of_range;
|
| + Label done;
|
| + __ cmpq(kScratchRegister, Immediate(1));
|
| + // If the conversion results in INT64_MIN, then the input is out of
|
| + // int64 range.
|
| + __ j(overflow, &out_of_range);
|
| + // Rounding is done by converting the value back to float.
|
| + __ Cvtqsi2ss(i.OutputDoubleRegister(), kScratchRegister);
|
| + __ jmp(&done);
|
| +
|
| + __ bind(&out_of_range);
|
| + // The input is out of int64 range. Fractions are not possible for
|
| + // inputs out of int64 range, so we don't have to do any rounding.
|
| + if (instr->InputAt(0)->IsDoubleRegister()) {
|
| + __ movss(i.OutputDoubleRegister(), i.InputDoubleRegister(0));
|
| + } else {
|
| + __ movss(i.OutputDoubleRegister(), i.InputOperand(0));
|
| + }
|
| +
|
| + __ bind(&done);
|
| + // Restore the original rounding mode.
|
| + __ ldmxcsr(Operand(rsp, 0));
|
| + __ addq(rsp, Immediate(kPointerSize * 2));
|
| + }
|
| break;
|
| }
|
| case kSSEFloat64Cmp:
|
| @@ -1021,10 +1064,53 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) {
|
| ASSEMBLE_SSE_UNOP(sqrtsd);
|
| break;
|
| case kSSEFloat64Round: {
|
| - CpuFeatureScope sse_scope(masm(), SSE4_1);
|
| RoundingMode const mode =
|
| static_cast<RoundingMode>(MiscField::decode(instr->opcode()));
|
| - __ Roundsd(i.OutputDoubleRegister(), i.InputDoubleRegister(0), mode);
|
| + if (CpuFeatures::IsSupported(SSE4_1)) {
|
| + CpuFeatureScope sse_scope(masm(), SSE4_1);
|
| + __ Roundsd(i.OutputDoubleRegister(), i.InputDoubleRegister(0), mode);
|
| + } else {
|
| + // Set the rounding mode.
|
| + // We have to store the original rounding mode in memory.
|
| + __ subq(rsp, Immediate(kPointerSize * 2));
|
| + __ stmxcsr(Operand(rsp, 0));
|
| + __ movl(kScratchRegister, Operand(rsp, 0));
|
| + __ andl(kScratchRegister, Immediate(0xffff9fff));
|
| + __ orl(kScratchRegister, Immediate(mode << 13));
|
| + __ movl(Operand(rsp, kPointerSize), kScratchRegister);
|
| + __ ldmxcsr(Operand(rsp, kPointerSize));
|
| +
|
| + // Start with the conversion.
|
| + if (instr->InputAt(0)->IsDoubleRegister()) {
|
| + __ Cvtsd2siq(kScratchRegister, i.InputDoubleRegister(0));
|
| + } else {
|
| + __ Cvtsd2siq(kScratchRegister, i.InputOperand(0));
|
| + }
|
| +
|
| + Label out_of_range;
|
| + Label done;
|
| + __ cmpq(kScratchRegister, Immediate(1));
|
| + // If the conversion results in INT64_MIN, but the input was not
|
| + // INT64_MIN, then the conversion fails.
|
| + __ j(overflow, &out_of_range);
|
| + __ Cvtqsi2sd(i.OutputDoubleRegister(), kScratchRegister);
|
| + __ jmp(&done);
|
| +
|
| + __ bind(&out_of_range);
|
| + // The input is out of int64 range. Fractions are not possible for
|
| + // inputs
|
| + // out of int64 range, so we don't have to do any rounding.
|
| + if (instr->InputAt(0)->IsDoubleRegister()) {
|
| + __ movsd(i.OutputDoubleRegister(), i.InputDoubleRegister(0));
|
| + } else {
|
| + __ movsd(i.OutputDoubleRegister(), i.InputOperand(0));
|
| + }
|
| +
|
| + __ bind(&done);
|
| + // Restore the original rounding mode.
|
| + __ ldmxcsr(Operand(rsp, 0));
|
| + __ addq(rsp, Immediate(kPointerSize * 2));
|
| + }
|
| break;
|
| }
|
| case kSSEFloat64ToFloat32:
|
|
|