Bug 1420104 - rabaldr, remove more ifdefs, simplify more. r?bbouvier draft
authorLars T Hansen <lhansen@mozilla.com>
Tue, 28 Nov 2017 09:13:52 +0100
changeset 704218 82424d76a290f0c54dac09b6c5bab73642233eeb
parent 704217 adc00474bdae6284448accfd1fcfbb1d6ca6c43c
child 742028 e5c5aa349cc8e15bf083a5c20b19e6eb1feba5db
push id91107
push userbmo:lhansen@mozilla.com
push dateTue, 28 Nov 2017 10:55:44 +0000
reviewersbbouvier
bugs1420104
milestone59.0a1
Bug 1420104 - rabaldr, remove more ifdefs, simplify more. r?bbouvier Removing some more porting interfaces here because they are not necessary. This was informed by ongoing ARM64 work (hence there's a generalization here for ARM64) but is really independent of it. MozReview-Commit-ID: 6L8qZaOzUFi
js/src/jit/MacroAssembler.h
js/src/jit/arm64/MacroAssembler-arm64.cpp
js/src/wasm/WasmBaselineCompile.cpp
--- a/js/src/jit/MacroAssembler.h
+++ b/js/src/jit/MacroAssembler.h
@@ -1466,26 +1466,38 @@ class MacroAssembler : public MacroAssem
 
     // `ptr` will always be updated.
     void wasmUnalignedStoreI64(const wasm::MemoryAccessDesc& access, Register64 value,
                                Register memoryBase, Register ptr, Register ptrScratch,
                                Register tmp)
         DEFINED_ON(arm);
 
     // wasm specific methods, used in both the wasm baseline compiler and ion.
-    void wasmTruncateDoubleToUInt32(FloatRegister input, Register output, Label* oolEntry) DEFINED_ON(x86, x64, arm, mips32, mips64);
-    void wasmTruncateDoubleToInt32(FloatRegister input, Register output, Label* oolEntry) DEFINED_ON(x86_shared, arm, mips_shared);
-    void outOfLineWasmTruncateDoubleToInt32(FloatRegister input, bool isUnsigned, wasm::BytecodeOffset off, Label* rejoin) DEFINED_ON(x86_shared);
+    void wasmTruncateDoubleToUInt32(FloatRegister input, Register output, Label* oolEntry)
+        DEFINED_ON(x86, x64, arm, arm64, mips32, mips64);
+    void wasmTruncateDoubleToInt32(FloatRegister input, Register output, Label* oolEntry)
+        DEFINED_ON(x86_shared, arm, arm64, mips_shared);
+    void outOfLineWasmTruncateDoubleToInt32(FloatRegister input, bool isUnsigned,
+                                            wasm::BytecodeOffset off, Label* rejoin)
+        DEFINED_ON(x86_shared);
 
-    void wasmTruncateFloat32ToUInt32(FloatRegister input, Register output, Label* oolEntry) DEFINED_ON(x86, x64, arm, mips32, mips64);
-    void wasmTruncateFloat32ToInt32(FloatRegister input, Register output, Label* oolEntry) DEFINED_ON(x86_shared, arm, mips_shared);
-    void outOfLineWasmTruncateFloat32ToInt32(FloatRegister input, bool isUnsigned, wasm::BytecodeOffset off, Label* rejoin) DEFINED_ON(x86_shared);
+    void wasmTruncateFloat32ToUInt32(FloatRegister input, Register output, Label* oolEntry)
+        DEFINED_ON(x86, x64, arm, arm64, mips32, mips64);
+    void wasmTruncateFloat32ToInt32(FloatRegister input, Register output, Label* oolEntry)
+        DEFINED_ON(x86_shared, arm, arm64, mips_shared);
+    void outOfLineWasmTruncateFloat32ToInt32(FloatRegister input, bool isUnsigned,
+                                             wasm::BytecodeOffset off, Label* rejoin)
+        DEFINED_ON(x86_shared);
 
-    void outOfLineWasmTruncateDoubleToInt64(FloatRegister input, bool isUnsigned, wasm::BytecodeOffset off, Label* rejoin) DEFINED_ON(x86_shared);
-    void outOfLineWasmTruncateFloat32ToInt64(FloatRegister input, bool isUnsigned, wasm::BytecodeOffset off, Label* rejoin) DEFINED_ON(x86_shared);
+    void outOfLineWasmTruncateDoubleToInt64(FloatRegister input, bool isUnsigned,
+                                            wasm::BytecodeOffset off, Label* rejoin)
+        DEFINED_ON(x86_shared);
+    void outOfLineWasmTruncateFloat32ToInt64(FloatRegister input, bool isUnsigned,
+                                             wasm::BytecodeOffset off, Label* rejoin)
+        DEFINED_ON(x86_shared);
 
     // This function takes care of loading the callee's TLS and pinned regs but
     // it is the caller's responsibility to save/restore TLS or pinned regs.
     void wasmCallImport(const wasm::CallSiteDesc& desc, const wasm::CalleeDesc& callee);
 
     // WasmTableCallIndexReg must contain the index of the indirect call.
     void wasmCallIndirect(const wasm::CallSiteDesc& desc, const wasm::CalleeDesc& callee, bool needsBoundsCheck);
 
--- a/js/src/jit/arm64/MacroAssembler-arm64.cpp
+++ b/js/src/jit/arm64/MacroAssembler-arm64.cpp
@@ -927,12 +927,39 @@ MacroAssembler::storeUnboxedValue(const 
                                   const BaseIndex& dest, MIRType slotType);
 
 void
 MacroAssembler::comment(const char* msg)
 {
     Assembler::comment(msg);
 }
 
+// ========================================================================
+// wasm support
+
+void
+MacroAssembler::wasmTruncateDoubleToUInt32(FloatRegister input, Register output, Label* oolEntry)
+{
+    MOZ_CRASH("NYI");
+}
+
+void
+MacroAssembler::wasmTruncateDoubleToInt32(FloatRegister input, Register output, Label* oolEntry)
+{
+    MOZ_CRASH("NYI");
+}
+
+void
+MacroAssembler::wasmTruncateFloat32ToUInt32(FloatRegister input, Register output, Label* oolEntry)
+{
+    MOZ_CRASH("NYI");
+}
+
+void
+MacroAssembler::wasmTruncateFloat32ToInt32(FloatRegister input, Register output, Label* oolEntry)
+{
+    MOZ_CRASH("NYI");
+}
+
 //}}} check_macroassembler_style
 
 } // namespace jit
 } // namespace js
--- a/js/src/wasm/WasmBaselineCompile.cpp
+++ b/js/src/wasm/WasmBaselineCompile.cpp
@@ -1621,16 +1621,21 @@ class BaseCompiler final : public BaseCo
             freeI32(r);
     }
 
     void maybeFreeI64(RegI64 r) {
         if (r.valid())
             freeI64(r);
     }
 
+    void maybeFreeF64(RegF64 r) {
+        if (r.valid())
+            freeF64(r);
+    }
+
     void needI32NoSync(RegI32 r) {
         MOZ_ASSERT(isAvailableI32(r));
         needI32(r);
     }
 
     // TODO / OPTIMIZE: need2xI32() can be optimized along with needI32()
     // to avoid sync(). (Bug 1316802)
 
@@ -3256,26 +3261,22 @@ class BaseCompiler final : public BaseCo
 
     void jumpTable(const LabelVector& labels, Label* theTable) {
         // Flush constant pools to ensure that the table is never interrupted by
         // constant pool entries.
         masm.flush();
 
         masm.bind(theTable);
 
-#if defined(JS_CODEGEN_X64) || defined(JS_CODEGEN_X86) || defined(JS_CODEGEN_ARM)
         for (uint32_t i = 0; i < labels.length(); i++) {
             CodeLabel cl;
             masm.writeCodePointer(cl.patchAt());
             cl.target()->bind(labels[i].offset());
             masm.addCodeLabel(cl);
         }
-#else
-        MOZ_CRASH("BaseCompiler platform hook: jumpTable");
-#endif
     }
 
     void tableSwitch(Label* theTable, RegI32 switchValue, Label* dispatchCode) {
         masm.bind(dispatchCode);
 
 #if defined(JS_CODEGEN_X64) || defined(JS_CODEGEN_X86)
         ScratchI32 scratch(*this);
         CodeLabel tableCl;
@@ -3592,50 +3593,44 @@ class BaseCompiler final : public BaseCo
             (void)fsrc;
             MOZ_CRASH("BaseCompiler platform hook: OutOfLineTruncateF32OrF64ToI32 wasm");
 #endif
         }
     };
 
     MOZ_MUST_USE bool truncateF32ToI32(RegF32 src, RegI32 dest, bool isUnsigned) {
         BytecodeOffset off = bytecodeOffset();
-        OutOfLineCode* ool;
-#if defined(JS_CODEGEN_X86) || defined(JS_CODEGEN_X64) || defined(JS_CODEGEN_ARM)
-        ool = new(alloc_) OutOfLineTruncateF32OrF64ToI32(AnyReg(src), dest, isUnsigned, off);
-        ool = addOutOfLineCode(ool);
+        OutOfLineCode* ool =
+            addOutOfLineCode(new(alloc_) OutOfLineTruncateF32OrF64ToI32(AnyReg(src),
+                                                                        dest,
+                                                                        isUnsigned,
+                                                                        off));
         if (!ool)
             return false;
         if (isUnsigned)
             masm.wasmTruncateFloat32ToUInt32(src, dest, ool->entry());
         else
             masm.wasmTruncateFloat32ToInt32(src, dest, ool->entry());
-#else
-        (void)off;
-        MOZ_CRASH("BaseCompiler platform hook: truncateF32ToI32 wasm");
-#endif
         masm.bind(ool->rejoin());
         return true;
     }
 
     MOZ_MUST_USE bool truncateF64ToI32(RegF64 src, RegI32 dest, bool isUnsigned) {
         BytecodeOffset off = bytecodeOffset();
-        OutOfLineCode* ool;
-#if defined(JS_CODEGEN_X86) || defined(JS_CODEGEN_X64) || defined(JS_CODEGEN_ARM)
-        ool = new(alloc_) OutOfLineTruncateF32OrF64ToI32(AnyReg(src), dest, isUnsigned, off);
-        ool = addOutOfLineCode(ool);
+        OutOfLineCode* ool =
+            addOutOfLineCode(new(alloc_) OutOfLineTruncateF32OrF64ToI32(AnyReg(src),
+                                                                        dest,
+                                                                        isUnsigned,
+                                                                        off));
         if (!ool)
             return false;
         if (isUnsigned)
             masm.wasmTruncateDoubleToUInt32(src, dest, ool->entry());
         else
             masm.wasmTruncateDoubleToInt32(src, dest, ool->entry());
-#else
-        (void)off;
-        MOZ_CRASH("BaseCompiler platform hook: truncateF64ToI32 wasm");
-#endif
         masm.bind(ool->rejoin());
         return true;
     }
 
     // This does not generate a value; if the truncation failed then it traps.
 
     class OutOfLineTruncateCheckF32OrF64ToI64 : public OutOfLineCode
     {
@@ -3672,16 +3667,25 @@ class BaseCompiler final : public BaseCo
             (void)isUnsigned;
             (void)off;
             MOZ_CRASH("BaseCompiler platform hook: OutOfLineTruncateCheckF32OrF64ToI64");
 #endif
         }
     };
 
 #ifndef RABALDR_FLOAT_TO_I64_CALLOUT
+    template<bool isUnsigned>
+    MOZ_MUST_USE RegF64 needTempForFloatingToI64() {
+# if defined(JS_CODEGEN_X86) || defined(JS_CODEGEN_X64)
+        if (isUnsigned)
+            return needF64();
+# endif
+        return RegF64::Invalid();
+    }
+
     MOZ_MUST_USE bool truncateF32ToI64(RegF32 src, RegI64 dest, bool isUnsigned, RegF64 temp) {
 # if defined(JS_CODEGEN_X64) || defined(JS_CODEGEN_X86)
         OutOfLineCode* ool =
             addOutOfLineCode(new (alloc_) OutOfLineTruncateCheckF32OrF64ToI64(AnyReg(src),
                                                                               isUnsigned,
                                                                               bytecodeOffset()));
         if (!ool)
             return false;
@@ -3749,44 +3753,38 @@ class BaseCompiler final : public BaseCo
             masm.convertInt64ToDouble(src, dest);
 # else
         MOZ_CRASH("BaseCompiler platform hook: convertI64ToF64");
 # endif
     }
 #endif // RABALDR_I64_TO_FLOAT_CALLOUT
 
     void cmp64Set(Assembler::Condition cond, RegI64 lhs, RegI64 rhs, RegI32 dest) {
-#if defined(JS_CODEGEN_X64)
-        masm.cmpq(rhs.reg, lhs.reg);
-        masm.emitSet(cond, dest);
-#elif defined(JS_CODEGEN_X86) || defined(JS_CODEGEN_ARM)
+#ifdef JS_PUNBOX64
+        masm.cmpPtrSet(cond, lhs.reg, rhs.reg, dest);
+#else
         // TODO / OPTIMIZE (Bug 1316822): This is pretty branchy, we should be
         // able to do better.
         Label done, condTrue;
         masm.branch64(cond, lhs, rhs, &condTrue);
         moveImm32(0, dest);
         masm.jump(&done);
         masm.bind(&condTrue);
         moveImm32(1, dest);
         masm.bind(&done);
-#else
-        MOZ_CRASH("BaseCompiler platform hook: cmp64Set");
 #endif
     }
 
     void eqz64(RegI64 src, RegI32 dest) {
-#if defined(JS_CODEGEN_X64)
-        masm.cmpq(Imm32(0), src.reg);
-        masm.emitSet(Assembler::Equal, dest);
-#elif defined(JS_CODEGEN_X86) || defined(JS_CODEGEN_ARM)
+#ifdef JS_PUNBOX64
+        masm.cmpPtrSet(Assembler::Equal, src.reg, ImmWord(0), dest);
+#else
         masm.or32(src.high, src.low);
         masm.cmp32(src.low, Imm32(0));
         masm.emitSet(Assembler::Equal, dest);
-#else
-        MOZ_CRASH("BaseCompiler platform hook: eqz64");
 #endif
     }
 
     void unreachableTrap()
     {
         masm.jump(trap(Trap::Unreachable));
 #ifdef DEBUG
         masm.breakpoint();
@@ -5711,45 +5709,35 @@ BaseCompiler::emitTruncateF64ToI32()
 
 #ifndef RABALDR_FLOAT_TO_I64_CALLOUT
 template<bool isUnsigned>
 bool
 BaseCompiler::emitTruncateF32ToI64()
 {
     RegF32 r0 = popF32();
     RegI64 x0 = needI64();
-    if (isUnsigned) {
-        RegF64 tmp = needF64();
-        if (!truncateF32ToI64(r0, x0, isUnsigned, tmp))
-            return false;
-        freeF64(tmp);
-    } else {
-        if (!truncateF32ToI64(r0, x0, isUnsigned, RegF64::Invalid()))
-            return false;
-    }
+    RegF64 tmp = needTempForFloatingToI64<isUnsigned>();
+    if (!truncateF32ToI64(r0, x0, isUnsigned, tmp))
+        return false;
+    maybeFreeF64(tmp);
     freeF32(r0);
     pushI64(x0);
     return true;
 }
 
 template<bool isUnsigned>
 bool
 BaseCompiler::emitTruncateF64ToI64()
 {
     RegF64 r0 = popF64();
     RegI64 x0 = needI64();
-    if (isUnsigned) {
-        RegF64 tmp = needF64();
-        if (!truncateF64ToI64(r0, x0, isUnsigned, tmp))
-            return false;
-        freeF64(tmp);
-    } else {
-        if (!truncateF64ToI64(r0, x0, isUnsigned, RegF64::Invalid()))
-            return false;
-    }
+    RegF64 tmp = needTempForFloatingToI64<isUnsigned>();
+    if (!truncateF64ToI64(r0, x0, isUnsigned, tmp))
+        return false;
+    maybeFreeF64(tmp);
     freeF64(r0);
     pushI64(x0);
     return true;
 }
 #endif // RABALDR_FLOAT_TO_I64_CALLOUT
 
 void
 BaseCompiler::emitWrapI64ToI32()
@@ -6899,20 +6887,20 @@ BaseCompiler::emitConvertFloatingToInt64
 
     RegI64 rv = captureReturnedI64();
 
     RegF64 inputVal = popF64();
 
     bool isUnsigned = callee == SymbolicAddress::TruncateDoubleToUint64;
 
     // The OOL check just succeeds or fails, it does not generate a value.
-    OutOfLineCode* ool = new (alloc_) OutOfLineTruncateCheckF32OrF64ToI64(AnyReg(inputVal),
+    OutOfLineCode* ool =
+        addOutOfLineCode(new (alloc_) OutOfLineTruncateCheckF32OrF64ToI64(AnyReg(inputVal),
                                                                           isUnsigned,
-                                                                          bytecodeOffset());
-    ool = addOutOfLineCode(ool);
+                                                                          bytecodeOffset()));
     if (!ool)
         return false;
 
     masm.branch64(Assembler::Equal, rv, Imm64(0x8000000000000000), ool->entry());
     masm.bind(ool->rejoin());
 
     pushI64(rv);
     freeF64(inputVal);