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 dd54431f023527eeb464360794d53228493f4d0c..ffc62107b583ab82f52a15dff565d7a8315f3118 100644 |
--- a/src/compiler/x64/code-generator-x64.cc |
+++ b/src/compiler/x64/code-generator-x64.cc |
@@ -1053,8 +1053,26 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) { |
__ Cvttss2siq(i.OutputRegister(), i.InputOperand(0)); |
} |
if (instr->OutputCount() > 1) { |
- __ Set(i.OutputRegister(1), 0x8000000000000000); |
- __ subq(i.OutputRegister(1), i.OutputRegister(0)); |
+ __ Set(i.OutputRegister(1), 1); |
+ Label done; |
+ Label fail; |
+ __ Move(kScratchDoubleReg, static_cast<float>(INT64_MIN)); |
+ if (instr->InputAt(0)->IsDoubleRegister()) { |
+ __ Ucomiss(kScratchDoubleReg, i.InputDoubleRegister(0)); |
+ } else { |
+ __ Ucomiss(kScratchDoubleReg, i.InputOperand(0)); |
+ } |
+ // If the input is NaN, then the conversion fails. |
+ __ j(parity_even, &fail); |
+ // If the input is INT64_MIN, then the conversion succeeds. |
+ __ j(equal, &done); |
+ __ cmpq(i.OutputRegister(0), Immediate(1)); |
+ // If the conversion results in INT64_MIN, but the input was not |
+ // INT64_MIN, then the conversion fails. |
+ __ j(no_overflow, &done); |
+ __ bind(&fail); |
+ __ Set(i.OutputRegister(1), 0); |
+ __ bind(&done); |
} |
break; |
case kSSEFloat64ToInt64: |
@@ -1064,8 +1082,26 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) { |
__ Cvttsd2siq(i.OutputRegister(0), i.InputOperand(0)); |
} |
if (instr->OutputCount() > 1) { |
- __ Set(i.OutputRegister(1), 0x8000000000000000); |
- __ subq(i.OutputRegister(1), i.OutputRegister(0)); |
+ __ Set(i.OutputRegister(1), 1); |
+ Label done; |
+ Label fail; |
+ __ Move(kScratchDoubleReg, static_cast<double>(INT64_MIN)); |
+ if (instr->InputAt(0)->IsDoubleRegister()) { |
+ __ Ucomisd(kScratchDoubleReg, i.InputDoubleRegister(0)); |
+ } else { |
+ __ Ucomisd(kScratchDoubleReg, i.InputOperand(0)); |
+ } |
+ // If the input is NaN, then the conversion fails. |
+ __ j(parity_even, &fail); |
+ // If the input is INT64_MIN, then the conversion succeeds. |
+ __ j(equal, &done); |
+ __ cmpq(i.OutputRegister(0), Immediate(1)); |
+ // If the conversion results in INT64_MIN, but the input was not |
+ // INT64_MIN, then the conversion fails. |
+ __ j(no_overflow, &done); |
+ __ bind(&fail); |
+ __ Set(i.OutputRegister(1), 0); |
+ __ bind(&done); |
} |
break; |
case kSSEFloat32ToUint64: { |