Index: src/ia32/macro-assembler-ia32.cc |
diff --git a/src/ia32/macro-assembler-ia32.cc b/src/ia32/macro-assembler-ia32.cc |
index be210aaef1fdd873362c4e8dff9932e98a8017db..ed0a8042493d1ec79922490f02d9b3f1bee0ba7e 100644 |
--- a/src/ia32/macro-assembler-ia32.cc |
+++ b/src/ia32/macro-assembler-ia32.cc |
@@ -581,12 +581,152 @@ void MacroAssembler::DebugBreak() { |
} |
+void MacroAssembler::Cvtsi2ss(XMMRegister dst, const Operand& src) { |
+ xorps(dst, dst); |
+ cvtsi2ss(dst, src); |
+} |
+ |
+ |
void MacroAssembler::Cvtsi2sd(XMMRegister dst, const Operand& src) { |
xorps(dst, dst); |
cvtsi2sd(dst, src); |
} |
+void MacroAssembler::Roundss(XMMRegister dst, XMMRegister src, Register tmp, |
+ XMMRegister xtmp, RoundingMode mode) { |
+ if (CpuFeatures::IsSupported(SSE4_1)) { |
+ CpuFeatureScope sse_scope(this, SSE4_1); |
+ roundss(dst, src, mode); |
+ } else { |
+ // We have to store the original rounding mode to restore it later. |
+ { |
+ sub(esp, Immediate(kPointerSize * 2)); |
+ stmxcsr(Operand(esp, 0)); |
+ mov(tmp, Operand(esp, 0)); |
+ and_(tmp, Immediate(0xffff9fff)); |
+ or_(tmp, Immediate(mode << 13)); |
+ mov(Operand(esp, kPointerSize), tmp); |
+ ldmxcsr(Operand(esp, kPointerSize)); |
+ } |
+ |
+ // Do rounding by conversion to int. |
+ cvtss2si(tmp, src); |
+ |
+ Label out_of_range; |
+ Label done; |
+ // Check whether the input is within int32 range. |
+ cmp(tmp, Immediate(1)); |
+ j(overflow, &out_of_range); |
+ // Saving the sign bit. |
+ // Initialize xtmp with 0x80000000. |
+ pcmpeqd(xtmp, xtmp); |
+ pslld(xtmp, 31); |
+ andps(xtmp, src); |
+ // If the conversion results in INT_MIN, then the input is outside |
+ // int range, and due to the limited precision of float32 this means |
+ // that the input must have been an integer already. We are therefore |
+ // done already. |
+ cvtsi2ss(dst, tmp); |
+ // Restore the sign bit. |
+ orps(dst, xtmp); |
+ |
+ if (!dst.is(src)) { |
+ jmp(&done); |
+ } |
+ |
+ bind(&out_of_range); |
+ if (!dst.is(src)) { |
+ movss(dst, src); |
+ } |
+ |
+ bind(&done); |
+ // Restore the original rounding mode. |
+ ldmxcsr(Operand(esp, 0)); |
+ add(esp, Immediate(kPointerSize * 2)); |
+ } |
+} |
+ |
+ |
+void MacroAssembler::Roundsd(XMMRegister dst, XMMRegister src, Register tmp, |
+ XMMRegister xtmp, RoundingMode mode) { |
+ if (CpuFeatures::IsSupported(SSE4_1)) { |
+ CpuFeatureScope sse_scope(this, SSE4_1); |
+ roundsd(dst, src, mode); |
+ } else { |
+ // We have to store the original rounding mode to restore it later. |
+ { |
+ sub(esp, Immediate(kPointerSize * 2)); |
+ stmxcsr(Operand(esp, 0)); |
+ mov(tmp, Operand(esp, 0)); |
+ and_(tmp, Immediate(0xffff9fff)); |
+ or_(tmp, Immediate(mode << 13)); |
+ mov(Operand(esp, kPointerSize), tmp); |
+ ldmxcsr(Operand(esp, kPointerSize)); |
+ } |
+ |
+ // Convert the input to int32. |
+ cvtsd2si(tmp, src); |
+ |
+ Label out_of_range; |
+ Label done; |
+ // Check whether the input is within int32 range. |
+ cmp(tmp, Immediate(1)); |
+ j(overflow, &out_of_range); |
+ // Saving the sign bit. |
+ // Initialize xtmp with 0x8000000000000000. |
+ pcmpeqd(xtmp, xtmp); |
+ psllq(xtmp, 63); |
+ andpd(xtmp, src); |
+ // The input is within int32 range. We achieve rounding by converting |
+ // back to float. |
+ Cvtsi2sd(dst, tmp); |
+ // Restore the sign bit. |
+ orpd(dst, xtmp); |
+ jmp(&done); |
+ |
+ bind(&out_of_range); |
+ if (!dst.is(src)) { |
+ movsd(dst, src); |
+ } |
+ |
+ // xtmp=abs(src) |
+ pcmpeqd(xtmp, xtmp); |
+ psrlq(xtmp, 1); |
+ andpd(xtmp, src); |
+ |
+ // If abs(src) >= 2^52, then float64 precision guarantees that the input is |
+ // an integer already. |
+ ucomisd(xtmp, Operand::StaticVariable( |
+ ExternalReference::address_of_rounding_limit())); |
+ j(above_equal, &done); |
+ |
+ // If abs(src) != src, then src contains a negative number. For negative |
+ // numbers we calculate src - 2^52 + 2^52 instead of src + 2^52 - 2^52. |
+ ucomisd(xtmp, src); |
+ |
+ movsd(xtmp, Operand::StaticVariable( |
+ ExternalReference::address_of_rounding_limit())); |
+ |
+ Label below_zero; |
+ j(not_equal, &below_zero); |
+ |
+ addsd(dst, xtmp); |
+ subsd(dst, xtmp); |
+ jmp(&done); |
+ |
+ bind(&below_zero); |
+ subsd(dst, xtmp); |
+ addsd(dst, xtmp); |
+ |
+ bind(&done); |
+ // Restore the original rounding mode. |
+ ldmxcsr(Operand(esp, 0)); |
+ add(esp, Immediate(kPointerSize * 2)); |
+ } |
+} |
+ |
+ |
bool MacroAssembler::IsUnsafeImmediate(const Immediate& x) { |
static const int kMaxImmediateBits = 17; |
if (!RelocInfo::IsNone(x.rmode_)) return false; |