Bug 1639113 part 1 - Add truncateDoubleToInt32/truncateFloat32ToInt32 to the MacroAssembler. r=evilpie
authorJan de Mooij <jdemooij@mozilla.com>
Tue, 19 May 2020 19:19:57 +0000
changeset 530976 180e48bc3c41023efa4be7773104c1d7699317eb
parent 530975 61141a5f9c11510333692746455a9d0fa0dbfde0
child 530977 bc823c0fd292a2fcf0d67f83dd8e44424309014d
push id37435
push userapavel@mozilla.com
push dateWed, 20 May 2020 15:28:23 +0000
treeherdermozilla-central@5415da14ec9a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersevilpie
bugs1639113
milestone78.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1639113 part 1 - Add truncateDoubleToInt32/truncateFloat32ToInt32 to the MacroAssembler. r=evilpie Differential Revision: https://phabricator.services.mozilla.com/D75955
js/src/jit/x86-shared/CodeGenerator-x86-shared.h
js/src/jit/x86-shared/MacroAssembler-x86-shared.h
--- a/js/src/jit/x86-shared/CodeGenerator-x86-shared.h
+++ b/js/src/jit/x86-shared/CodeGenerator-x86-shared.h
@@ -94,29 +94,24 @@ class CodeGeneratorX86Shared : public Co
     masm.test32(lhs, rhs);
     bailoutIf(c, snapshot);
   }
   void bailoutIfFalseBool(Register reg, LSnapshot* snapshot) {
     masm.test32(reg, Imm32(0xFF));
     bailoutIf(Assembler::Zero, snapshot);
   }
   void bailoutCvttsd2si(FloatRegister src, Register dest, LSnapshot* snapshot) {
-    // vcvttsd2si returns 0x80000000 on failure. Test for it by
-    // subtracting 1 and testing overflow. The other possibility is to test
-    // equality for INT_MIN after a comparison, but 1 costs fewer bytes to
-    // materialize.
-    masm.vcvttsd2si(src, dest);
-    masm.cmp32(dest, Imm32(1));
-    bailoutIf(Assembler::Overflow, snapshot);
+    Label bail;
+    masm.truncateDoubleToInt32(src, dest, &bail);
+    bailoutFrom(&bail, snapshot);
   }
   void bailoutCvttss2si(FloatRegister src, Register dest, LSnapshot* snapshot) {
-    // Same trick as explained in the above comment.
-    masm.vcvttss2si(src, dest);
-    masm.cmp32(dest, Imm32(1));
-    bailoutIf(Assembler::Overflow, snapshot);
+    Label bail;
+    masm.truncateFloat32ToInt32(src, dest, &bail);
+    bailoutFrom(&bail, snapshot);
   }
 
   bool generateOutOfLineCode();
 
   void emitCompare(MCompare::CompareType type, const LAllocation* left,
                    const LAllocation* right);
 
   // Emits a branch that directs control flow to the true block if |cond| is
--- a/js/src/jit/x86-shared/MacroAssembler-x86-shared.h
+++ b/js/src/jit/x86-shared/MacroAssembler-x86-shared.h
@@ -863,16 +863,32 @@ class MacroAssemblerX86Shared : public A
     ScratchFloat32Scope scratch(asMasm());
     vcvttss2si(src, dest);
     convertInt32ToFloat32(dest, scratch);
     vucomiss(scratch, src);
     j(Assembler::Parity, fail);
     j(Assembler::NotEqual, fail);
   }
 
+  void truncateDoubleToInt32(FloatRegister src, Register dest, Label* fail) {
+    // vcvttsd2si returns 0x80000000 on failure. Test for it by
+    // subtracting 1 and testing overflow. The other possibility is to test
+    // equality for INT_MIN after a comparison, but 1 costs fewer bytes to
+    // materialize.
+    vcvttsd2si(src, dest);
+    cmp32(dest, Imm32(1));
+    j(Assembler::Overflow, fail);
+  }
+  void truncateFloat32ToInt32(FloatRegister src, Register dest, Label* fail) {
+    // Same trick as explained in the above comment.
+    vcvttss2si(src, dest);
+    cmp32(dest, Imm32(1));
+    j(Assembler::Overflow, fail);
+  }
+
   inline void clampIntToUint8(Register reg);
 
   bool maybeInlineDouble(double d, FloatRegister dest) {
     // Loading zero with xor is specially optimized in hardware.
     if (mozilla::IsPositiveZero(d)) {
       zeroDouble(dest);
       return true;
     }