Bug 1229057 - Part 16: Move MacroAssembler::inc64 into generic macro assembler. r=bhackett
authorTooru Fujisawa <arai_a@mac.com>
Tue, 01 Dec 2015 17:04:14 +0900
changeset 316157 764452e009e2de62eb9bc8eb6b898d3c45616e14
parent 316156 430ce92b022ca57ff05520310f1c347fcaaf4260
child 316158 fe6173757f32aff365522cb3d8f4a6f1f7f14fd1
push id8516
push userjlund@mozilla.com
push dateFri, 18 Dec 2015 00:52:34 +0000
reviewersbhackett
bugs1229057
milestone46.0a1
Bug 1229057 - Part 16: Move MacroAssembler::inc64 into generic macro assembler. r=bhackett
js/src/jit/MacroAssembler.h
js/src/jit/arm/MacroAssembler-arm-inl.h
js/src/jit/arm/MacroAssembler-arm.cpp
js/src/jit/arm/MacroAssembler-arm.h
js/src/jit/arm64/MacroAssembler-arm64-inl.h
js/src/jit/arm64/MacroAssembler-arm64.h
js/src/jit/mips32/MacroAssembler-mips32-inl.h
js/src/jit/mips32/MacroAssembler-mips32.cpp
js/src/jit/mips32/MacroAssembler-mips32.h
js/src/jit/mips64/MacroAssembler-mips64-inl.h
js/src/jit/mips64/MacroAssembler-mips64.cpp
js/src/jit/mips64/MacroAssembler-mips64.h
js/src/jit/none/MacroAssembler-none.h
js/src/jit/x64/MacroAssembler-x64-inl.h
js/src/jit/x64/MacroAssembler-x64.h
js/src/jit/x86/MacroAssembler-x86-inl.h
js/src/jit/x86/MacroAssembler-x86.h
--- a/js/src/jit/MacroAssembler.h
+++ b/js/src/jit/MacroAssembler.h
@@ -772,16 +772,18 @@ class MacroAssembler : public MacroAssem
     inline void mulBy3(Register src, Register dest) PER_ARCH;
 
     inline void mulDouble(FloatRegister src, FloatRegister dest) PER_SHARED_ARCH;
 
     inline void mulDoublePtr(ImmPtr imm, Register temp, FloatRegister dest) DEFINED_ON(mips_shared, arm, arm64, x86, x64);
 
     inline void divDouble(FloatRegister src, FloatRegister dest) PER_SHARED_ARCH;
 
+    inline void inc64(AbsoluteAddress dest) PER_ARCH;
+
     // ===============================================================
     // Shift functions
 
     inline void lshiftPtr(Imm32 imm, Register dest) PER_ARCH;
 
     inline void lshift64(Imm32 imm, Register64 dest) PER_ARCH;
 
     inline void rshiftPtr(Imm32 imm, Register dest) PER_ARCH;
--- a/js/src/jit/arm/MacroAssembler-arm-inl.h
+++ b/js/src/jit/arm/MacroAssembler-arm-inl.h
@@ -319,16 +319,33 @@ MacroAssembler::mulDoublePtr(ImmPtr imm,
 }
 
 void
 MacroAssembler::divDouble(FloatRegister src, FloatRegister dest)
 {
     ma_vdiv(dest, src, dest);
 }
 
+void
+MacroAssembler::inc64(AbsoluteAddress dest)
+{
+    ScratchRegisterScope scratch(*this);
+
+    ma_strd(r0, r1, EDtrAddr(sp, EDtrOffImm(-8)), PreIndex);
+
+    ma_mov(Imm32((int32_t)dest.addr), scratch);
+    ma_ldrd(EDtrAddr(scratch, EDtrOffImm(0)), r0, r1);
+
+    ma_add(Imm32(1), r0, SetCC);
+    ma_adc(Imm32(0), r1, LeaveCC);
+
+    ma_strd(r0, r1, EDtrAddr(scratch, EDtrOffImm(0)));
+    ma_ldrd(EDtrAddr(sp, EDtrOffImm(8)), r0, r1, PostIndex);
+}
+
 // ===============================================================
 // Shift functions
 
 void
 MacroAssembler::lshiftPtr(Imm32 imm, Register dest)
 {
     ma_lsl(imm, dest, dest);
 }
--- a/js/src/jit/arm/MacroAssembler-arm.cpp
+++ b/js/src/jit/arm/MacroAssembler-arm.cpp
@@ -247,33 +247,16 @@ MacroAssemblerARM::convertInt32ToFloat32
 }
 
 void
 MacroAssemblerARM::negateDouble(FloatRegister reg)
 {
     ma_vneg(reg, reg);
 }
 
-void
-MacroAssemblerARM::inc64(AbsoluteAddress dest)
-{
-    ScratchRegisterScope scratch(asMasm());
-
-    ma_strd(r0, r1, EDtrAddr(sp, EDtrOffImm(-8)), PreIndex);
-
-    ma_mov(Imm32((int32_t)dest.addr), scratch);
-    ma_ldrd(EDtrAddr(scratch, EDtrOffImm(0)), r0, r1);
-
-    ma_add(Imm32(1), r0, SetCC);
-    ma_adc(Imm32(0), r1, LeaveCC);
-
-    ma_strd(r0, r1, EDtrAddr(scratch, EDtrOffImm(0)));
-    ma_ldrd(EDtrAddr(sp, EDtrOffImm(8)), r0, r1, PostIndex);
-}
-
 bool
 MacroAssemblerARM::alu_dbl(Register src1, Imm32 imm, Register dest, ALUOp op,
                            SBit s, Condition c)
 {
     if ((s == SetCC && ! condsAreSafe(op)) || !can_dbl(op))
         return false;
 
     ALUOp interop = getDestVariant(op);
--- a/js/src/jit/arm/MacroAssembler-arm.h
+++ b/js/src/jit/arm/MacroAssembler-arm.h
@@ -93,17 +93,16 @@ class MacroAssemblerARM : public Assembl
                                bool negativeZeroCheck = true);
 
     void convertFloat32ToDouble(FloatRegister src, FloatRegister dest);
     void branchTruncateFloat32(FloatRegister src, Register dest, Label* fail);
     void convertInt32ToFloat32(Register src, FloatRegister dest);
     void convertInt32ToFloat32(const Address& src, FloatRegister dest);
 
     void negateDouble(FloatRegister reg);
-    void inc64(AbsoluteAddress dest);
 
     // Somewhat direct wrappers for the low-level assembler funcitons
     // bitops. Attempt to encode a virtual alu instruction using two real
     // instructions.
   private:
     bool alu_dbl(Register src1, Imm32 imm, Register dest, ALUOp op,
                  SBit s, Condition c);
 
--- a/js/src/jit/arm64/MacroAssembler-arm64-inl.h
+++ b/js/src/jit/arm64/MacroAssembler-arm64-inl.h
@@ -360,16 +360,29 @@ MacroAssembler::mulDoublePtr(ImmPtr imm,
 }
 
 void
 MacroAssembler::divDouble(FloatRegister src, FloatRegister dest)
 {
     fdiv(ARMFPRegister(dest, 64), ARMFPRegister(dest, 64), ARMFPRegister(src, 64));
 }
 
+void
+MacroAssembler::inc64(AbsoluteAddress dest)
+{
+    vixl::UseScratchRegisterScope temps(this);
+    const ARMRegister scratchAddr64 = temps.AcquireX();
+    const ARMRegister scratch64 = temps.AcquireX();
+
+    Mov(scratchAddr64, uint64_t(dest.addr));
+    Ldr(scratch64, MemOperand(scratchAddr64, 0));
+    Add(scratch64, scratch64, Operand(1));
+    Str(scratch64, MemOperand(scratchAddr64, 0));
+}
+
 // ===============================================================
 // Shift functions
 
 void
 MacroAssembler::lshiftPtr(Imm32 imm, Register dest)
 {
     Lsl(ARMRegister(dest, 64), ARMRegister(dest, 64), imm.value);
 }
--- a/js/src/jit/arm64/MacroAssembler-arm64.h
+++ b/js/src/jit/arm64/MacroAssembler-arm64.h
@@ -2875,26 +2875,16 @@ class MacroAssemblerCompat : public vixl
         vixl::UseScratchRegisterScope temps(this);
         const ARMRegister scratch32 = temps.AcquireW();
         MOZ_ASSERT(scratch32.asUnsized() != addr.base);
 
         load32(addr, scratch32.asUnsized());
         Add(scratch32, scratch32, Operand(1));
         store32(scratch32.asUnsized(), addr);
     }
-    void inc64(AbsoluteAddress dest) {
-        vixl::UseScratchRegisterScope temps(this);
-        const ARMRegister scratchAddr64 = temps.AcquireX();
-        const ARMRegister scratch64 = temps.AcquireX();
-
-        Mov(scratchAddr64, uint64_t(dest.addr));
-        Ldr(scratch64, MemOperand(scratchAddr64, 0));
-        Add(scratch64, scratch64, Operand(1));
-        Str(scratch64, MemOperand(scratchAddr64, 0));
-    }
 
     void BoundsCheck(Register ptrReg, Label* onFail, vixl::CPURegister zeroMe = vixl::NoReg) {
         // use tst rather than Tst to *ensure* that a single instrution is generated.
         Cmp(ARMRegister(ptrReg, 32), ARMRegister(HeapLenReg, 32));
         if (!zeroMe.IsNone()) {
             if (zeroMe.IsRegister()) {
                 Csel(ARMRegister(zeroMe),
                      ARMRegister(zeroMe),
--- a/js/src/jit/mips32/MacroAssembler-mips32-inl.h
+++ b/js/src/jit/mips32/MacroAssembler-mips32-inl.h
@@ -172,16 +172,34 @@ MacroAssembler::mul64(Imm64 imm, const R
 
 void
 MacroAssembler::mulBy3(Register src, Register dest)
 {
     as_addu(dest, src, src);
     as_addu(dest, dest, src);
 }
 
+void
+MacroAssembler::inc64(AbsoluteAddress dest)
+{
+    ma_li(ScratchRegister, Imm32((int32_t)dest.addr));
+    as_lw(SecondScratchReg, ScratchRegister, 0);
+
+    as_addiu(SecondScratchReg, SecondScratchReg, 1);
+    as_sw(SecondScratchReg, ScratchRegister, 0);
+
+    as_sltiu(SecondScratchReg, SecondScratchReg, 1);
+    as_lw(ScratchRegister, ScratchRegister, 4);
+
+    as_addu(SecondScratchReg, ScratchRegister, SecondScratchReg);
+
+    ma_li(ScratchRegister, Imm32((int32_t)dest.addr));
+    as_sw(SecondScratchReg, ScratchRegister, 4);
+}
+
 // ===============================================================
 // Shift functions
 
 void
 MacroAssembler::lshiftPtr(Imm32 imm, Register dest)
 {
     ma_sll(dest, dest, imm);
 }
--- a/js/src/jit/mips32/MacroAssembler-mips32.cpp
+++ b/js/src/jit/mips32/MacroAssembler-mips32.cpp
@@ -220,34 +220,16 @@ MacroAssemblerMIPSCompat::convertInt32To
 
 void
 MacroAssemblerMIPSCompat::negateDouble(FloatRegister reg)
 {
     as_negd(reg, reg);
 }
 
 void
-MacroAssemblerMIPSCompat::inc64(AbsoluteAddress dest)
-{
-    ma_li(ScratchRegister, Imm32((int32_t)dest.addr));
-    as_lw(SecondScratchReg, ScratchRegister, 0);
-
-    as_addiu(SecondScratchReg, SecondScratchReg, 1);
-    as_sw(SecondScratchReg, ScratchRegister, 0);
-
-    as_sltiu(SecondScratchReg, SecondScratchReg, 1);
-    as_lw(ScratchRegister, ScratchRegister, 4);
-
-    as_addu(SecondScratchReg, ScratchRegister, SecondScratchReg);
-
-    ma_li(ScratchRegister, Imm32((int32_t)dest.addr));
-    as_sw(SecondScratchReg, ScratchRegister, 4);
-}
-
-void
 MacroAssemblerMIPS::ma_li(Register dest, CodeOffset* label)
 {
     BufferOffset bo = m_buffer.nextOffset();
     ma_liPatchable(dest, ImmWord(/* placeholder */ 0));
     label->bind(bo.getOffset());
 }
 
 void
--- a/js/src/jit/mips32/MacroAssembler-mips32.h
+++ b/js/src/jit/mips32/MacroAssembler-mips32.h
@@ -171,17 +171,16 @@ class MacroAssemblerMIPSCompat : public 
                                bool negativeZeroCheck = true);
 
     void convertFloat32ToDouble(FloatRegister src, FloatRegister dest);
     void branchTruncateFloat32(FloatRegister src, Register dest, Label* fail);
     void convertInt32ToFloat32(Register src, FloatRegister dest);
     void convertInt32ToFloat32(const Address& src, FloatRegister dest);
 
     void negateDouble(FloatRegister reg);
-    void inc64(AbsoluteAddress dest);
 
     void computeScaledAddress(const BaseIndex& address, Register dest);
 
     void computeEffectiveAddress(const Address& address, Register dest) {
         ma_addu(dest, address.base, Imm32(address.offset));
     }
 
     inline void computeEffectiveAddress(const BaseIndex& address, Register dest);
--- a/js/src/jit/mips64/MacroAssembler-mips64-inl.h
+++ b/js/src/jit/mips64/MacroAssembler-mips64-inl.h
@@ -130,16 +130,25 @@ MacroAssembler::mul64(Imm64 imm, const R
 
 void
 MacroAssembler::mulBy3(Register src, Register dest)
 {
     as_daddu(dest, src, src);
     as_daddu(dest, dest, src);
 }
 
+void
+MacroAssembler::inc64(AbsoluteAddress dest)
+{
+    ma_li(ScratchRegister, ImmWord(uintptr_t(dest.addr)));
+    as_ld(SecondScratchReg, ScratchRegister, 0);
+    as_daddiu(SecondScratchReg, SecondScratchReg, 1);
+    as_sd(SecondScratchReg, ScratchRegister, 0);
+}
+
 // ===============================================================
 // Shift functions
 
 void
 MacroAssembler::lshiftPtr(Imm32 imm, Register dest)
 {
     ma_dsll(dest, dest, imm);
 }
--- a/js/src/jit/mips64/MacroAssembler-mips64.cpp
+++ b/js/src/jit/mips64/MacroAssembler-mips64.cpp
@@ -229,25 +229,16 @@ MacroAssemblerMIPS64Compat::convertInt32
 
 void
 MacroAssemblerMIPS64Compat::negateDouble(FloatRegister reg)
 {
     as_negd(reg, reg);
 }
 
 void
-MacroAssemblerMIPS64Compat::inc64(AbsoluteAddress dest)
-{
-    ma_li(ScratchRegister, ImmWord(uintptr_t(dest.addr)));
-    as_ld(SecondScratchReg, ScratchRegister, 0);
-    as_daddiu(SecondScratchReg, SecondScratchReg, 1);
-    as_sd(SecondScratchReg, ScratchRegister, 0);
-}
-
-void
 MacroAssemblerMIPS64Compat::movq(Register rs, Register rd)
 {
     ma_move(rd, rs);
 }
 
 void
 MacroAssemblerMIPS64::ma_li(Register dest, CodeOffset* label)
 {
--- a/js/src/jit/mips64/MacroAssembler-mips64.h
+++ b/js/src/jit/mips64/MacroAssembler-mips64.h
@@ -181,17 +181,16 @@ class MacroAssemblerMIPS64Compat : publi
                                bool negativeZeroCheck = true);
 
     void convertFloat32ToDouble(FloatRegister src, FloatRegister dest);
     void branchTruncateFloat32(FloatRegister src, Register dest, Label* fail);
     void convertInt32ToFloat32(Register src, FloatRegister dest);
     void convertInt32ToFloat32(const Address& src, FloatRegister dest);
 
     void negateDouble(FloatRegister reg);
-    void inc64(AbsoluteAddress dest);
 
     void movq(Register rs, Register rd);
 
     void computeScaledAddress(const BaseIndex& address, Register dest);
 
     void computeEffectiveAddress(const Address& address, Register dest) {
         ma_daddu(dest, address.base, Imm32(address.offset));
     }
--- a/js/src/jit/none/MacroAssembler-none.h
+++ b/js/src/jit/none/MacroAssembler-none.h
@@ -411,17 +411,16 @@ class MacroAssemblerNone : public Assemb
     void branchTestDoubleTruthy(bool, FloatRegister, Label*) { MOZ_CRASH(); }
 
     template <typename T> void loadUnboxedValue(T, MIRType, AnyRegister) { MOZ_CRASH(); }
     template <typename T> void storeUnboxedValue(ConstantOrRegister, MIRType, T, MIRType) { MOZ_CRASH(); }
     template <typename T> void storeUnboxedPayload(ValueOperand value, T, size_t) { MOZ_CRASH(); }
 
     void convertUInt32ToDouble(Register, FloatRegister) { MOZ_CRASH(); }
     void convertUInt32ToFloat32(Register, FloatRegister) { MOZ_CRASH(); }
-    void inc64(AbsoluteAddress) { MOZ_CRASH(); }
     void incrementInt32Value(Address) { MOZ_CRASH(); }
     void ensureDouble(ValueOperand, FloatRegister, Label*) { MOZ_CRASH(); }
     void handleFailureWithHandlerTail(void*) { MOZ_CRASH(); }
 
     void branchPtrInNurseryRange(Condition, Register, Register, Label*) { MOZ_CRASH(); }
     void branchValueIsNurseryObject(Condition, ValueOperand, Register, Label*) { MOZ_CRASH(); }
 
     void buildFakeExitFrame(Register, uint32_t*) { MOZ_CRASH(); }
--- a/js/src/jit/x64/MacroAssembler-x64-inl.h
+++ b/js/src/jit/x64/MacroAssembler-x64-inl.h
@@ -169,16 +169,28 @@ MacroAssembler::mulBy3(Register src, Reg
 
 void
 MacroAssembler::mulDoublePtr(ImmPtr imm, Register temp, FloatRegister dest)
 {
     movq(imm, ScratchReg);
     vmulsd(Operand(ScratchReg, 0), dest, dest);
 }
 
+void
+MacroAssembler::inc64(AbsoluteAddress dest)
+{
+    if (X86Encoding::IsAddressImmediate(dest.addr)) {
+        addPtr(Imm32(1), dest);
+    } else {
+        ScratchRegisterScope scratch(*this);
+        mov(ImmPtr(dest.addr), scratch);
+        addPtr(Imm32(1), Address(scratch, 0));
+    }
+}
+
 // ===============================================================
 // Shift functions
 
 void
 MacroAssembler::lshiftPtr(Imm32 imm, Register dest)
 {
     shlq(imm, dest);
 }
@@ -206,28 +218,16 @@ MacroAssembler::rshift64(Imm32 imm, Regi
 {
     shrq(imm, dest.reg);
 }
 
 //}}} check_macroassembler_style
 // ===============================================================
 
 void
-MacroAssemblerX64::inc64(AbsoluteAddress dest)
-{
-    if (X86Encoding::IsAddressImmediate(dest.addr)) {
-        asMasm().addPtr(Imm32(1), dest);
-    } else {
-        ScratchRegisterScope scratch(asMasm());
-        mov(ImmPtr(dest.addr), scratch);
-        asMasm().addPtr(Imm32(1), Address(scratch, 0));
-    }
-}
-
-void
 MacroAssemblerX64::incrementInt32Value(const Address& addr)
 {
     asMasm().addPtr(Imm32(1), addr);
 }
 
 } // namespace jit
 } // namespace js
 
--- a/js/src/jit/x64/MacroAssembler-x64.h
+++ b/js/src/jit/x64/MacroAssembler-x64.h
@@ -1290,18 +1290,16 @@ class MacroAssemblerX64 : public MacroAs
     void convertUInt32ToFloat32(Register src, FloatRegister dest) {
         vcvtsq2ss(src, dest, dest);
     }
 
     void convertUInt64ToDouble(Register64 src, Register temp, FloatRegister dest) {
         vcvtsi2sdq(src.reg, dest);
     }
 
-    inline void inc64(AbsoluteAddress dest);
-
     inline void incrementInt32Value(const Address& addr);
 
     // If source is a double, load it into dest. If source is int32,
     // convert it to double. Else, branch to failure.
     void ensureDouble(const ValueOperand& source, FloatRegister dest, Label* failure) {
         Label isDouble, done;
         Register tag = splitTagForTest(source);
         branchTestDouble(Assembler::Equal, tag, &isDouble);
--- a/js/src/jit/x86/MacroAssembler-x86-inl.h
+++ b/js/src/jit/x86/MacroAssembler-x86-inl.h
@@ -205,16 +205,26 @@ MacroAssembler::mulBy3(Register src, Reg
 
 void
 MacroAssembler::mulDoublePtr(ImmPtr imm, Register temp, FloatRegister dest)
 {
     movl(imm, temp);
     vmulsd(Operand(temp, 0), dest, dest);
 }
 
+void
+MacroAssembler::inc64(AbsoluteAddress dest)
+{
+    addl(Imm32(1), Operand(dest));
+    Label noOverflow;
+    j(NonZero, &noOverflow);
+    addl(Imm32(1), Operand(dest.offset(4)));
+    bind(&noOverflow);
+}
+
 // ===============================================================
 // Shift functions
 
 void
 MacroAssembler::lshiftPtr(Imm32 imm, Register dest)
 {
     shll(imm, dest);
 }
--- a/js/src/jit/x86/MacroAssembler-x86.h
+++ b/js/src/jit/x86/MacroAssembler-x86.h
@@ -1025,24 +1025,16 @@ class MacroAssemblerX86 : public MacroAs
     // Note: this function clobbers the source register.
     inline void convertUInt32ToDouble(Register src, FloatRegister dest);
 
     // Note: this function clobbers the source register.
     inline void convertUInt32ToFloat32(Register src, FloatRegister dest);
 
     void convertUInt64ToDouble(Register64 src, Register temp, FloatRegister dest);
 
-    void inc64(AbsoluteAddress dest) {
-        addl(Imm32(1), Operand(dest));
-        Label noOverflow;
-        j(NonZero, &noOverflow);
-        addl(Imm32(1), Operand(dest.offset(4)));
-        bind(&noOverflow);
-    }
-
     void incrementInt32Value(const Address& addr) {
         addl(Imm32(1), payloadOf(addr));
     }
 
     // If source is a double, load it into dest. If source is int32,
     // convert it to double. Else, branch to failure.
     void ensureDouble(const ValueOperand& source, FloatRegister dest, Label* failure) {
         Label isDouble, done;