Bug 1497955: Simplify code generation for wasm truncations to int64 on x86; r=bbouvier
authorDan Gohman <sunfish@mozilla.com>
Thu, 11 Oct 2018 11:30:13 +0200
changeset 496567 d9951c225adde0f0c0daac61bf61c8fb1c9d2780
parent 496566 d699af334ae27f961d06def962b91bb9f1063309
child 496568 ee4f12cc7136126f1d4adec65432a76123f11212
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbbouvier
bugs1497955
milestone64.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 1497955: Simplify code generation for wasm truncations to int64 on x86; r=bbouvier
js/src/jit/x86/MacroAssembler-x86.cpp
--- a/js/src/jit/x86/MacroAssembler-x86.cpp
+++ b/js/src/jit/x86/MacroAssembler-x86.cpp
@@ -982,70 +982,60 @@ MacroAssembler::wasmTruncateFloat32ToUIn
 
     bind(&done);
 }
 
 void
 MacroAssembler::wasmTruncateDoubleToInt64(FloatRegister input, Register64 output, bool isSaturating,
                                           Label* oolEntry, Label* oolRejoin, FloatRegister tempReg)
 {
-    Label fail, convert;
+    Label ok;
     Register temp = output.high;
 
-    // Make sure input fits in (u)int64.
-    reserveStack(2 * sizeof(int32_t));
-    storeDouble(input, Operand(esp, 0));
-    branchDoubleNotInInt64Range(Address(esp, 0), temp, &fail);
-    jump(&convert);
-
-    // Handle failure in ool.
-    bind(&fail);
-    freeStack(2 * sizeof(int32_t));
-    jump(oolEntry);
-    bind(oolRejoin);
     reserveStack(2 * sizeof(int32_t));
     storeDouble(input, Operand(esp, 0));
 
-    // Convert the double/float to int64.
-    bind(&convert);
     truncateDoubleToInt64(Address(esp, 0), Address(esp, 0), temp);
+    load64(Address(esp, 0), output);
 
-    // Load value into int64 register.
-    load64(Address(esp, 0), output);
+    cmpl(Imm32(0), Operand(esp, 0));
+    j(Assembler::NotEqual, &ok);
+
+    cmpl(Imm32(1), Operand(esp, 4));
+    j(Assembler::Overflow, oolEntry);
+
+    bind(&ok);
+    bind(oolRejoin);
+
     freeStack(2 * sizeof(int32_t));
 }
 
 void
 MacroAssembler::wasmTruncateFloat32ToInt64(FloatRegister input, Register64 output,
                                            bool isSaturating,
                                            Label* oolEntry, Label* oolRejoin, FloatRegister tempReg)
 {
-    Label fail, convert;
+    Label ok;
     Register temp = output.high;
 
-    // Make sure input fits in (u)int64.
-    reserveStack(2 * sizeof(int32_t));
-    storeFloat32(input, Operand(esp, 0));
-    branchFloat32NotInInt64Range(Address(esp, 0), temp, &fail);
-    jump(&convert);
-
-    // Handle failure in ool.
-    bind(&fail);
-    freeStack(2 * sizeof(int32_t));
-    jump(oolEntry);
-    bind(oolRejoin);
     reserveStack(2 * sizeof(int32_t));
     storeFloat32(input, Operand(esp, 0));
 
-    // Convert the double/float to int64.
-    bind(&convert);
     truncateFloat32ToInt64(Address(esp, 0), Address(esp, 0), temp);
+    load64(Address(esp, 0), output);
 
-    // Load value into int64 register.
-    load64(Address(esp, 0), output);
+    cmpl(Imm32(0), Operand(esp, 0));
+    j(Assembler::NotEqual, &ok);
+
+    cmpl(Imm32(1), Operand(esp, 4));
+    j(Assembler::Overflow, oolEntry);
+
+    bind(&ok);
+    bind(oolRejoin);
+
     freeStack(2 * sizeof(int32_t));
 }
 
 void
 MacroAssembler::wasmTruncateDoubleToUInt64(FloatRegister input, Register64 output,
                                            bool isSaturating, Label* oolEntry,
                                            Label* oolRejoin, FloatRegister tempReg)
 {