diff --git a/js/src/jit/MacroAssembler-inl.h b/js/src/jit/MacroAssembler-inl.h index e394ed93230a..61233490bcd0 100644 --- a/js/src/jit/MacroAssembler-inl.h +++ b/js/src/jit/MacroAssembler-inl.h @@ -320,6 +320,107 @@ MacroAssembler::addPtr(ImmPtr imm, Register dest) //}}} check_macroassembler_style // =============================================================== +template +void +MacroAssembler::branchIfFalseBool(Register reg, L label) +{ + // Note that C++ bool is only 1 byte, so ignore the higher-order bits. + branchTest32(Assembler::Zero, reg, Imm32(0xFF), label); +} + +void +MacroAssembler::branchIfTrueBool(Register reg, Label* label) +{ + // Note that C++ bool is only 1 byte, so ignore the higher-order bits. + branchTest32(Assembler::NonZero, reg, Imm32(0xFF), label); +} + +void +MacroAssembler::branchIfRope(Register str, Label* label) +{ + Address flags(str, JSString::offsetOfFlags()); + static_assert(JSString::ROPE_FLAGS == 0, "Rope type flags must be 0"); + branchTest32(Assembler::Zero, flags, Imm32(JSString::TYPE_FLAGS_MASK), label); +} + +void +MacroAssembler::branchLatin1String(Register string, Label* label) +{ + branchTest32(Assembler::NonZero, Address(string, JSString::offsetOfFlags()), + Imm32(JSString::LATIN1_CHARS_BIT), label); +} + +void +MacroAssembler::branchTwoByteString(Register string, Label* label) +{ + branchTest32(Assembler::Zero, Address(string, JSString::offsetOfFlags()), + Imm32(JSString::LATIN1_CHARS_BIT), label); +} + +void +MacroAssembler::branchIfFunctionHasNoScript(Register fun, Label* label) +{ + // 16-bit loads are slow and unaligned 32-bit loads may be too so + // perform an aligned 32-bit load and adjust the bitmask accordingly. + MOZ_ASSERT(JSFunction::offsetOfNargs() % sizeof(uint32_t) == 0); + MOZ_ASSERT(JSFunction::offsetOfFlags() == JSFunction::offsetOfNargs() + 2); + Address address(fun, JSFunction::offsetOfNargs()); + int32_t bit = IMM32_16ADJ(JSFunction::INTERPRETED); + branchTest32(Assembler::Zero, address, Imm32(bit), label); +} + +void +MacroAssembler::branchIfInterpreted(Register fun, Label* label) +{ + // 16-bit loads are slow and unaligned 32-bit loads may be too so + // perform an aligned 32-bit load and adjust the bitmask accordingly. + MOZ_ASSERT(JSFunction::offsetOfNargs() % sizeof(uint32_t) == 0); + MOZ_ASSERT(JSFunction::offsetOfFlags() == JSFunction::offsetOfNargs() + 2); + Address address(fun, JSFunction::offsetOfNargs()); + int32_t bit = IMM32_16ADJ(JSFunction::INTERPRETED); + branchTest32(Assembler::NonZero, address, Imm32(bit), label); +} + +void +MacroAssembler::branchTestNeedsIncrementalBarrier(Condition cond, Label* label) +{ + MOZ_ASSERT(cond == Zero || cond == NonZero); + CompileZone* zone = GetJitContext()->compartment->zone(); + AbsoluteAddress needsBarrierAddr(zone->addressOfNeedsIncrementalBarrier()); + branchTest32(cond, needsBarrierAddr, Imm32(0x1), label); +} + +void +MacroAssembler::branchTestObjectTruthy(bool truthy, Register objReg, Register scratch, + Label* slowCheck, Label* checked) +{ + // The branches to out-of-line code here implement a conservative version + // of the JSObject::isWrapper test performed in EmulatesUndefined. If none + // of the branches are taken, we can check class flags directly. + loadObjClass(objReg, scratch); + Address flags(scratch, Class::offsetOfFlags()); + + branchTestClassIsProxy(true, scratch, slowCheck); + + Condition cond = truthy ? Assembler::Zero : Assembler::NonZero; + branchTest32(cond, flags, Imm32(JSCLASS_EMULATES_UNDEFINED), checked); +} + +void +MacroAssembler::branchTestClassIsProxy(bool proxy, Register clasp, Label* label) +{ + branchTest32(proxy ? Assembler::NonZero : Assembler::Zero, + Address(clasp, Class::offsetOfFlags()), + Imm32(JSCLASS_IS_PROXY), label); +} + +void +MacroAssembler::branchTestObjectIsProxy(bool proxy, Register object, Register scratch, Label* label) +{ + loadObjClass(object, scratch); + branchTestClassIsProxy(proxy, scratch, label); +} + void MacroAssembler::branchFunctionKind(Condition cond, JSFunction::FunctionKind kind, Register fun, Register scratch, Label* label) diff --git a/js/src/jit/MacroAssembler.h b/js/src/jit/MacroAssembler.h index 76fae711b228..25e2b963389d 100644 --- a/js/src/jit/MacroAssembler.h +++ b/js/src/jit/MacroAssembler.h @@ -841,6 +841,14 @@ class MacroAssembler : public MacroAssemblerSpecific // boxed inside a js::Value, with a raw pointer (rhs). inline void branchPrivatePtr(Condition cond, const Address& lhs, Register rhs, Label* label) PER_ARCH; + template + inline void branchTest32(Condition cond, Register lhs, Register rhs, L label) PER_SHARED_ARCH; + template + inline void branchTest32(Condition cond, Register lhs, Imm32 rhs, L label) PER_SHARED_ARCH; + inline void branchTest32(Condition cond, const Address& lhs, Imm32 rhh, Label* label) PER_SHARED_ARCH; + inline void branchTest32(Condition cond, const AbsoluteAddress& lhs, Imm32 rhs, Label* label) + DEFINED_ON(arm, arm64, mips_shared, x86, x64); + inline void branchTestPtr(Condition cond, Register lhs, Register rhs, Label* label) PER_SHARED_ARCH; inline void branchTestPtr(Condition cond, Register lhs, Imm32 rhs, Label* label) PER_SHARED_ARCH; inline void branchTestPtr(Condition cond, const Address& lhs, Imm32 rhs, Label* label) PER_SHARED_ARCH; @@ -905,16 +913,10 @@ class MacroAssembler : public MacroAssemblerSpecific // Branches to |label| if |reg| is false. |reg| should be a C++ bool. template - void branchIfFalseBool(Register reg, L label) { - // Note that C++ bool is only 1 byte, so ignore the higher-order bits. - branchTest32(Assembler::Zero, reg, Imm32(0xFF), label); - } + inline void branchIfFalseBool(Register reg, L label); // Branches to |label| if |reg| is true. |reg| should be a C++ bool. - void branchIfTrueBool(Register reg, Label* label) { - // Note that C++ bool is only 1 byte, so ignore the higher-order bits. - branchTest32(Assembler::NonZero, reg, Imm32(0xFF), label); - } + inline void branchIfTrueBool(Register reg, Label* label); void loadObjPrivate(Register obj, uint32_t nfixed, Register dest) { loadPtr(Address(obj, NativeObject::getPrivateDataOffset(nfixed)), dest); @@ -932,20 +934,10 @@ class MacroAssembler : public MacroAssemblerSpecific void loadStringChars(Register str, Register dest); void loadStringChar(Register str, Register index, Register output); - void branchIfRope(Register str, Label* label) { - Address flags(str, JSString::offsetOfFlags()); - static_assert(JSString::ROPE_FLAGS == 0, "Rope type flags must be 0"); - branchTest32(Assembler::Zero, flags, Imm32(JSString::TYPE_FLAGS_MASK), label); - } + inline void branchIfRope(Register str, Label* label); - void branchLatin1String(Register string, Label* label) { - branchTest32(Assembler::NonZero, Address(string, JSString::offsetOfFlags()), - Imm32(JSString::LATIN1_CHARS_BIT), label); - } - void branchTwoByteString(Register string, Label* label) { - branchTest32(Assembler::Zero, Address(string, JSString::offsetOfFlags()), - Imm32(JSString::LATIN1_CHARS_BIT), label); - } + inline void branchLatin1String(Register string, Label* label); + inline void branchTwoByteString(Register string, Label* label); void loadJSContext(Register dest) { loadPtr(AbsoluteAddress(GetJitContext()->runtime->addressOfJSContext()), dest); @@ -1064,24 +1056,8 @@ class MacroAssembler : public MacroAssemblerSpecific return extractObject(source, scratch); } - void branchIfFunctionHasNoScript(Register fun, Label* label) { - // 16-bit loads are slow and unaligned 32-bit loads may be too so - // perform an aligned 32-bit load and adjust the bitmask accordingly. - MOZ_ASSERT(JSFunction::offsetOfNargs() % sizeof(uint32_t) == 0); - MOZ_ASSERT(JSFunction::offsetOfFlags() == JSFunction::offsetOfNargs() + 2); - Address address(fun, JSFunction::offsetOfNargs()); - int32_t bit = IMM32_16ADJ(JSFunction::INTERPRETED); - branchTest32(Assembler::Zero, address, Imm32(bit), label); - } - void branchIfInterpreted(Register fun, Label* label) { - // 16-bit loads are slow and unaligned 32-bit loads may be too so - // perform an aligned 32-bit load and adjust the bitmask accordingly. - MOZ_ASSERT(JSFunction::offsetOfNargs() % sizeof(uint32_t) == 0); - MOZ_ASSERT(JSFunction::offsetOfFlags() == JSFunction::offsetOfNargs() + 2); - Address address(fun, JSFunction::offsetOfNargs()); - int32_t bit = IMM32_16ADJ(JSFunction::INTERPRETED); - branchTest32(Assembler::NonZero, address, Imm32(bit), label); - } + inline void branchIfFunctionHasNoScript(Register fun, Label* label); + inline void branchIfInterpreted(Register fun, Label* label); void branchIfNotInterpretedConstructor(Register fun, Register scratch, Label* label); @@ -1102,12 +1078,7 @@ class MacroAssembler : public MacroAssemblerSpecific branch32(cond, length, Imm32(key.constant()), label); } - void branchTestNeedsIncrementalBarrier(Condition cond, Label* label) { - MOZ_ASSERT(cond == Zero || cond == NonZero); - CompileZone* zone = GetJitContext()->compartment->zone(); - AbsoluteAddress needsBarrierAddr(zone->addressOfNeedsIncrementalBarrier()); - branchTest32(cond, needsBarrierAddr, Imm32(0x1), label); - } + inline void branchTestNeedsIncrementalBarrier(Condition cond, Label* label); template void callPreBarrier(const T& address, MIRType type) { @@ -1296,33 +1267,12 @@ class MacroAssembler : public MacroAssemblerSpecific // Generates code used to complete a bailout. void generateBailoutTail(Register scratch, Register bailoutInfo); - void branchTestObjectTruthy(bool truthy, Register objReg, Register scratch, - Label* slowCheck, Label* checked) - { - // The branches to out-of-line code here implement a conservative version - // of the JSObject::isWrapper test performed in EmulatesUndefined. If none - // of the branches are taken, we can check class flags directly. - loadObjClass(objReg, scratch); - Address flags(scratch, Class::offsetOfFlags()); + inline void branchTestObjectTruthy(bool truthy, Register objReg, Register scratch, + Label* slowCheck, Label* checked); - branchTestClassIsProxy(true, scratch, slowCheck); + inline void branchTestClassIsProxy(bool proxy, Register clasp, Label* label); - Condition cond = truthy ? Assembler::Zero : Assembler::NonZero; - branchTest32(cond, flags, Imm32(JSCLASS_EMULATES_UNDEFINED), checked); - } - - void branchTestClassIsProxy(bool proxy, Register clasp, Label* label) - { - branchTest32(proxy ? Assembler::NonZero : Assembler::Zero, - Address(clasp, Class::offsetOfFlags()), - Imm32(JSCLASS_IS_PROXY), label); - } - - void branchTestObjectIsProxy(bool proxy, Register object, Register scratch, Label* label) - { - loadObjClass(object, scratch); - branchTestClassIsProxy(proxy, scratch, label); - } + inline void branchTestObjectIsProxy(bool proxy, Register object, Register scratch, Label* label); inline void branchFunctionKind(Condition cond, JSFunction::FunctionKind kind, Register fun, Register scratch, Label* label); diff --git a/js/src/jit/arm/MacroAssembler-arm-inl.h b/js/src/jit/arm/MacroAssembler-arm-inl.h index 4a268d21d0db..64126b8c16b7 100644 --- a/js/src/jit/arm/MacroAssembler-arm-inl.h +++ b/js/src/jit/arm/MacroAssembler-arm-inl.h @@ -575,6 +575,47 @@ MacroAssembler::branchPrivatePtr(Condition cond, const Address& lhs, Register rh branchPtr(cond, lhs, rhs, label); } +template +void +MacroAssembler::branchTest32(Condition cond, Register lhs, Register rhs, L label) +{ + MOZ_ASSERT(cond == Zero || cond == NonZero || cond == Signed || cond == NotSigned); + // x86 likes test foo, foo rather than cmp foo, #0. + // Convert the former into the latter. + if (lhs == rhs && (cond == Zero || cond == NonZero)) + ma_cmp(lhs, Imm32(0)); + else + ma_tst(lhs, rhs); + ma_b(label, cond); +} + +template +void +MacroAssembler::branchTest32(Condition cond, Register lhs, Imm32 rhs, L label) +{ + MOZ_ASSERT(cond == Zero || cond == NonZero || cond == Signed || cond == NotSigned); + ma_tst(lhs, rhs); + ma_b(label, cond); +} + +void +MacroAssembler::branchTest32(Condition cond, const Address& lhs, Imm32 rhs, Label* label) +{ + // branchTest32 will use ScratchRegister. + AutoRegisterScope scratch2(*this, secondScratchReg_); + load32(lhs, scratch2); + branchTest32(cond, scratch2, rhs, label); +} + +void +MacroAssembler::branchTest32(Condition cond, const AbsoluteAddress& lhs, Imm32 rhs, Label* label) +{ + // branchTest32 will use ScratchRegister. + AutoRegisterScope scratch2(*this, secondScratchReg_); + load32(lhs, scratch2); + branchTest32(cond, scratch2, rhs, label); +} + void MacroAssembler::branchTestPtr(Condition cond, Register lhs, Register rhs, Label* label) { diff --git a/js/src/jit/arm/MacroAssembler-arm.h b/js/src/jit/arm/MacroAssembler-arm.h index 73b1f1362078..c2c83ad4d82e 100644 --- a/js/src/jit/arm/MacroAssembler-arm.h +++ b/js/src/jit/arm/MacroAssembler-arm.h @@ -836,35 +836,6 @@ class MacroAssemblerARMCompat : public MacroAssemblerARM Condition c = testStringTruthy(truthy, value); ma_b(label, c); } - template - void branchTest32(Condition cond, Register lhs, Register rhs, L label) { - MOZ_ASSERT(cond == Zero || cond == NonZero || cond == Signed || cond == NotSigned); - // x86 likes test foo, foo rather than cmp foo, #0. - // Convert the former into the latter. - if (lhs == rhs && (cond == Zero || cond == NonZero)) - ma_cmp(lhs, Imm32(0)); - else - ma_tst(lhs, rhs); - ma_b(label, cond); - } - template - void branchTest32(Condition cond, Register lhs, Imm32 imm, L label) { - MOZ_ASSERT(cond == Zero || cond == NonZero || cond == Signed || cond == NotSigned); - ma_tst(lhs, imm); - ma_b(label, cond); - } - void branchTest32(Condition cond, const Address& address, Imm32 imm, Label* label) { - // branchTest32 will use ScratchRegister. - AutoRegisterScope scratch2(asMasm(), secondScratchReg_); - load32(address, scratch2); - branchTest32(cond, scratch2, imm, label); - } - void branchTest32(Condition cond, AbsoluteAddress address, Imm32 imm, Label* label) { - // branchTest32 will use ScratchRegister. - AutoRegisterScope scratch2(asMasm(), secondScratchReg_); - load32(address, scratch2); - branchTest32(cond, scratch2, imm, label); - } void decBranchPtr(Condition cond, Register lhs, Imm32 imm, Label* label) { ma_sub(imm, lhs, SetCC); as_b(label, cond); diff --git a/js/src/jit/arm64/MacroAssembler-arm64-inl.h b/js/src/jit/arm64/MacroAssembler-arm64-inl.h index 363c719d7be7..64712e7901fe 100644 --- a/js/src/jit/arm64/MacroAssembler-arm64-inl.h +++ b/js/src/jit/arm64/MacroAssembler-arm64-inl.h @@ -652,6 +652,48 @@ MacroAssembler::branchPrivatePtr(Condition cond, const Address& lhs, Register rh branchPtr(cond, lhs, scratch, label); } +template +void +MacroAssembler::branchTest32(Condition cond, Register lhs, Register rhs, L label) +{ + MOZ_ASSERT(cond == Zero || cond == NonZero || cond == Signed || cond == NotSigned); + // x86 prefers |test foo, foo| to |cmp foo, #0|. + // Convert the former to the latter for ARM. + if (lhs == rhs && (cond == Zero || cond == NonZero)) + cmp32(lhs, Imm32(0)); + else + test32(lhs, rhs); + B(label, cond); +} + +template +void +MacroAssembler::branchTest32(Condition cond, Register lhs, Imm32 rhs, L label) +{ + MOZ_ASSERT(cond == Zero || cond == NonZero || cond == Signed || cond == NotSigned); + test32(lhs, rhs); + B(label, cond); +} + +void +MacroAssembler::branchTest32(Condition cond, const Address& lhs, Imm32 rhs, Label* label) +{ + vixl::UseScratchRegisterScope temps(this); + const Register scratch = temps.AcquireX().asUnsized(); + MOZ_ASSERT(scratch != lhs.base); + load32(lhs, scratch); + branchTest32(cond, scratch, rhs, label); +} + +void +MacroAssembler::branchTest32(Condition cond, const AbsoluteAddress& lhs, Imm32 rhs, Label* label) +{ + vixl::UseScratchRegisterScope temps(this); + const Register scratch = temps.AcquireX().asUnsized(); + load32(lhs, scratch); + branchTest32(cond, scratch, rhs, label); +} + void MacroAssembler::branchTestPtr(Condition cond, Register lhs, Register rhs, Label* label) { diff --git a/js/src/jit/arm64/MacroAssembler-arm64.h b/js/src/jit/arm64/MacroAssembler-arm64.h index 9c700566d0e5..d758315571e9 100644 --- a/js/src/jit/arm64/MacroAssembler-arm64.h +++ b/js/src/jit/arm64/MacroAssembler-arm64.h @@ -1355,36 +1355,6 @@ class MacroAssemblerCompat : public vixl::MacroAssembler addPendingJump(loc, ImmPtr(target->raw()), Relocation::JITCODE); } - template - void branchTest32(Condition cond, Register lhs, Register rhs, L label) { - MOZ_ASSERT(cond == Zero || cond == NonZero || cond == Signed || cond == NotSigned); - // x86 prefers |test foo, foo| to |cmp foo, #0|. - // Convert the former to the latter for ARM. - if (lhs == rhs && (cond == Zero || cond == NonZero)) - cmp32(lhs, Imm32(0)); - else - test32(lhs, rhs); - B(label, cond); - } - template - void branchTest32(Condition cond, Register lhs, Imm32 imm, L label) { - MOZ_ASSERT(cond == Zero || cond == NonZero || cond == Signed || cond == NotSigned); - test32(lhs, imm); - B(label, cond); - } - void branchTest32(Condition cond, const Address& address, Imm32 imm, Label* label) { - vixl::UseScratchRegisterScope temps(this); - const Register scratch = temps.AcquireX().asUnsized(); - MOZ_ASSERT(scratch != address.base); - load32(address, scratch); - branchTest32(cond, scratch, imm, label); - } - void branchTest32(Condition cond, AbsoluteAddress address, Imm32 imm, Label* label) { - vixl::UseScratchRegisterScope temps(this); - const Register scratch = temps.AcquireX().asUnsized(); - loadPtr(address, scratch); - branchTest32(cond, scratch, imm, label); - } CodeOffsetJump jumpWithPatch(RepatchLabel* label, Condition cond = Always, Label* documentation = nullptr) { diff --git a/js/src/jit/mips-shared/MacroAssembler-mips-shared-inl.h b/js/src/jit/mips-shared/MacroAssembler-mips-shared-inl.h index fe63ff0a353b..dce5d53a6728 100644 --- a/js/src/jit/mips-shared/MacroAssembler-mips-shared-inl.h +++ b/js/src/jit/mips-shared/MacroAssembler-mips-shared-inl.h @@ -345,6 +345,41 @@ MacroAssembler::branchPtr(Condition cond, wasm::SymbolicAddress lhs, Register rh branchPtr(cond, SecondScratchReg, rhs, label); } +template +void +MacroAssembler::branchTest32(Condition cond, Register lhs, Register rhs, L label) +{ + MOZ_ASSERT(cond == Zero || cond == NonZero || cond == Signed || cond == NotSigned); + if (lhs == rhs) { + ma_b(lhs, rhs, label, cond); + } else { + as_and(ScratchRegister, lhs, rhs); + ma_b(ScratchRegister, ScratchRegister, label, cond); + } +} + +template +void +MacroAssembler::branchTest32(Condition cond, Register lhs, Imm32 rhs, L label) +{ + ma_li(ScratchRegister, rhs); + branchTest32(cond, lhs, ScratchRegister, label); +} + +void +MacroAssembler::branchTest32(Condition cond, const Address& lhs, Imm32 rhs, Label* label) +{ + load32(lhs, SecondScratchReg); + branchTest32(cond, SecondScratchReg, rhs, label); +} + +void +MacroAssembler::branchTest32(Condition cond, const AbsoluteAddress& lhs, Imm32 rhs, Label* label) +{ + load32(lhs, ScratchRegister); + branchTest32(cond, ScratchRegister, rhs, label); +} + void MacroAssembler::branchTestPtr(Condition cond, Register lhs, Register rhs, Label* label) { diff --git a/js/src/jit/mips32/MacroAssembler-mips32.h b/js/src/jit/mips32/MacroAssembler-mips32.h index bde25eccdd8f..3e71c7485568 100644 --- a/js/src/jit/mips32/MacroAssembler-mips32.h +++ b/js/src/jit/mips32/MacroAssembler-mips32.h @@ -437,27 +437,6 @@ class MacroAssemblerMIPSCompat : public MacroAssemblerMIPS void branchTestBooleanTruthy(bool b, const ValueOperand& operand, Label* label); - void branchTest32(Condition cond, Register lhs, Register rhs, Label* label) { - MOZ_ASSERT(cond == Zero || cond == NonZero || cond == Signed || cond == NotSigned); - if (lhs == rhs) { - ma_b(lhs, rhs, label, cond); - } else { - as_and(ScratchRegister, lhs, rhs); - ma_b(ScratchRegister, ScratchRegister, label, cond); - } - } - void branchTest32(Condition cond, Register lhs, Imm32 imm, Label* label) { - ma_li(ScratchRegister, imm); - branchTest32(cond, lhs, ScratchRegister, label); - } - void branchTest32(Condition cond, const Address& address, Imm32 imm, Label* label) { - load32(address, SecondScratchReg); - branchTest32(cond, SecondScratchReg, imm, label); - } - void branchTest32(Condition cond, AbsoluteAddress address, Imm32 imm, Label* label) { - load32(address, ScratchRegister); - branchTest32(cond, ScratchRegister, imm, label); - } inline void decBranchPtr(Condition cond, Register lhs, Imm32 imm, Label* label); // higher level tag testing code diff --git a/js/src/jit/mips64/MacroAssembler-mips64.h b/js/src/jit/mips64/MacroAssembler-mips64.h index 59c6569c91d5..c365669bcd2f 100644 --- a/js/src/jit/mips64/MacroAssembler-mips64.h +++ b/js/src/jit/mips64/MacroAssembler-mips64.h @@ -478,27 +478,6 @@ class MacroAssemblerMIPS64Compat : public MacroAssemblerMIPS64 void branchTestBooleanTruthy(bool b, const ValueOperand& operand, Label* label); - void branchTest32(Condition cond, Register lhs, Register rhs, Label* label) { - MOZ_ASSERT(cond == Zero || cond == NonZero || cond == Signed || cond == NotSigned); - if (lhs == rhs) { - ma_b(lhs, rhs, label, cond); - } else { - as_and(ScratchRegister, lhs, rhs); - ma_b(ScratchRegister, ScratchRegister, label, cond); - } - } - void branchTest32(Condition cond, Register lhs, Imm32 imm, Label* label) { - ma_li(ScratchRegister, imm); - branchTest32(cond, lhs, ScratchRegister, label); - } - void branchTest32(Condition cond, const Address& address, Imm32 imm, Label* label) { - load32(address, SecondScratchReg); - branchTest32(cond, SecondScratchReg, imm, label); - } - void branchTest32(Condition cond, AbsoluteAddress address, Imm32 imm, Label* label) { - load32(address, ScratchRegister); - branchTest32(cond, ScratchRegister, imm, label); - } inline void decBranchPtr(Condition cond, Register lhs, Imm32 imm, Label* label); // higher level tag testing code diff --git a/js/src/jit/none/MacroAssembler-none.h b/js/src/jit/none/MacroAssembler-none.h index 6e8ff54ad522..6ccee3ff8c96 100644 --- a/js/src/jit/none/MacroAssembler-none.h +++ b/js/src/jit/none/MacroAssembler-none.h @@ -244,7 +244,6 @@ class MacroAssemblerNone : public Assembler template void cmpPtrSet(Condition, T, S, Register) { MOZ_CRASH(); } template void cmp32Set(Condition, T, S, Register) { MOZ_CRASH(); } - template void branchTest32(Condition, T, S, L) { MOZ_CRASH(); } template void branchAdd32(Condition, T, S, Label*) { MOZ_CRASH(); } template void branchSub32(Condition, T, S, Label*) { MOZ_CRASH(); } template void branchDouble(DoubleCondition, T, S, Label*) { MOZ_CRASH(); } diff --git a/js/src/jit/x64/MacroAssembler-x64-inl.h b/js/src/jit/x64/MacroAssembler-x64-inl.h index c76a6fdff166..2779d8580622 100644 --- a/js/src/jit/x64/MacroAssembler-x64-inl.h +++ b/js/src/jit/x64/MacroAssembler-x64-inl.h @@ -298,6 +298,19 @@ MacroAssembler::branchPrivatePtr(Condition cond, const Address& lhs, Register rh branchPtr(cond, lhs, scratch, label); } +void +MacroAssembler::branchTest32(Condition cond, const AbsoluteAddress& lhs, Imm32 rhs, Label* label) +{ + if (X86Encoding::IsAddressImmediate(lhs.addr)) { + test32(Operand(lhs), rhs); + } else { + ScratchRegisterScope scratch(*this); + mov(ImmPtr(lhs.addr), scratch); + test32(Operand(scratch, 0), rhs); + } + j(cond, label); +} + void MacroAssembler::branchTest64(Condition cond, Register64 lhs, Register64 rhs, Register temp, Label* label) diff --git a/js/src/jit/x64/MacroAssembler-x64.h b/js/src/jit/x64/MacroAssembler-x64.h index 778fc7054b65..f3043a525e9a 100644 --- a/js/src/jit/x64/MacroAssembler-x64.h +++ b/js/src/jit/x64/MacroAssembler-x64.h @@ -42,7 +42,6 @@ class MacroAssemblerX64 : public MacroAssemblerX86Shared void bindOffsets(const MacroAssemblerX86Shared::UsesVector&); public: - using MacroAssemblerX86Shared::branchTest32; using MacroAssemblerX86Shared::load32; using MacroAssemblerX86Shared::store32; @@ -527,17 +526,6 @@ class MacroAssemblerX64 : public MacroAssemblerX86Shared // Common interface. ///////////////////////////////////////////////////////////////// - void branchTest32(Condition cond, AbsoluteAddress address, Imm32 imm, Label* label) { - if (X86Encoding::IsAddressImmediate(address.addr)) { - test32(Operand(address), imm); - } else { - ScratchRegisterScope scratch(asMasm()); - mov(ImmPtr(address.addr), scratch); - test32(Operand(scratch, 0), imm); - } - j(cond, label); - } - template inline void branchPtrImpl(Condition cond, const T& lhs, const S& rhs, Label* label); diff --git a/js/src/jit/x86-shared/MacroAssembler-x86-shared-inl.h b/js/src/jit/x86-shared/MacroAssembler-x86-shared-inl.h index 4c43952d73a7..05b4ce43dea2 100644 --- a/js/src/jit/x86-shared/MacroAssembler-x86-shared-inl.h +++ b/js/src/jit/x86-shared/MacroAssembler-x86-shared-inl.h @@ -294,6 +294,32 @@ MacroAssembler::branchPtr(Condition cond, const Address& lhs, ImmWord rhs, Label branchPtrImpl(cond, lhs, rhs, label); } +template +void +MacroAssembler::branchTest32(Condition cond, Register lhs, Register rhs, L label) +{ + MOZ_ASSERT(cond == Zero || cond == NonZero || cond == Signed || cond == NotSigned); + test32(lhs, rhs); + j(cond, label); +} + +template +void +MacroAssembler::branchTest32(Condition cond, Register lhs, Imm32 rhs, L label) +{ + MOZ_ASSERT(cond == Zero || cond == NonZero || cond == Signed || cond == NotSigned); + test32(lhs, rhs); + j(cond, label); +} + +void +MacroAssembler::branchTest32(Condition cond, const Address& lhs, Imm32 rhs, Label* label) +{ + MOZ_ASSERT(cond == Zero || cond == NonZero || cond == Signed || cond == NotSigned); + test32(Operand(lhs), rhs); + j(cond, label); +} + void MacroAssembler::branchTestPtr(Condition cond, Register lhs, Register rhs, Label* label) { @@ -318,6 +344,19 @@ MacroAssembler::branchTestPtr(Condition cond, const Address& lhs, Imm32 rhs, Lab //}}} check_macroassembler_style // =============================================================== +void +MacroAssemblerX86Shared::clampIntToUint8(Register reg) +{ + Label inRange; + asMasm().branchTest32(Assembler::Zero, reg, Imm32(0xffffff00), &inRange); + { + sarl(Imm32(31), reg); + notl(reg); + andl(Imm32(255), reg); + } + bind(&inRange); +} + } // namespace jit } // namespace js diff --git a/js/src/jit/x86-shared/MacroAssembler-x86-shared.cpp b/js/src/jit/x86-shared/MacroAssembler-x86-shared.cpp index 7f27c9e3c725..1c0e86386ed9 100644 --- a/js/src/jit/x86-shared/MacroAssembler-x86-shared.cpp +++ b/js/src/jit/x86-shared/MacroAssembler-x86-shared.cpp @@ -112,7 +112,7 @@ MacroAssemblerX86Shared::branchNegativeZero(FloatRegister reg, // If reg is 1 or 3, input is negative zero. // If reg is 0 or 2, input is a normal zero. - branchTest32(NonZero, scratch, Imm32(1), label); + asMasm().branchTest32(NonZero, scratch, Imm32(1), label); bind(&nonZero); #elif defined(JS_CODEGEN_X64) diff --git a/js/src/jit/x86-shared/MacroAssembler-x86-shared.h b/js/src/jit/x86-shared/MacroAssembler-x86-shared.h index 718cd0b105bd..e0477c180482 100644 --- a/js/src/jit/x86-shared/MacroAssembler-x86-shared.h +++ b/js/src/jit/x86-shared/MacroAssembler-x86-shared.h @@ -572,28 +572,6 @@ class MacroAssemblerX86Shared : public Assembler testw(rhs, lhs); j(cond, label); } - template - void branchTest32(Condition cond, Register lhs, Register rhs, L label) { - MOZ_ASSERT(cond == Zero || cond == NonZero || cond == Signed || cond == NotSigned); - test32(lhs, rhs); - j(cond, label); - } - template - void branchTest32(Condition cond, Register lhs, Imm32 imm, L label) { - MOZ_ASSERT(cond == Zero || cond == NonZero || cond == Signed || cond == NotSigned); - test32(lhs, imm); - j(cond, label); - } - void branchTest32(Condition cond, const Address& address, Imm32 imm, Label* label) { - MOZ_ASSERT(cond == Zero || cond == NonZero || cond == Signed || cond == NotSigned); - test32(Operand(address), imm); - j(cond, label); - } - void branchTest32(Condition cond, const Operand& lhs, Imm32 imm, Label* label) { - MOZ_ASSERT(cond == Zero || cond == NonZero || cond == Signed || cond == NotSigned); - test32(lhs, imm); - j(cond, label); - } void jump(Label* label) { jmp(label); @@ -1283,16 +1261,7 @@ class MacroAssemblerX86Shared : public Assembler j(Assembler::NotEqual, fail); } - void clampIntToUint8(Register reg) { - Label inRange; - branchTest32(Assembler::Zero, reg, Imm32(0xffffff00), &inRange); - { - sarl(Imm32(31), reg); - notl(reg); - andl(Imm32(255), reg); - } - bind(&inRange); - } + inline void clampIntToUint8(Register reg); bool maybeInlineDouble(double d, FloatRegister dest) { uint64_t u = mozilla::BitwiseCast(d); diff --git a/js/src/jit/x86/MacroAssembler-x86-inl.h b/js/src/jit/x86/MacroAssembler-x86-inl.h index 46f7e9d86e1f..673d78448747 100644 --- a/js/src/jit/x86/MacroAssembler-x86-inl.h +++ b/js/src/jit/x86/MacroAssembler-x86-inl.h @@ -304,6 +304,13 @@ MacroAssembler::branchPrivatePtr(Condition cond, const Address& lhs, Register rh branchPtr(cond, lhs, rhs, label); } +void +MacroAssembler::branchTest32(Condition cond, const AbsoluteAddress& lhs, Imm32 rhs, Label* label) +{ + test32(Operand(lhs), rhs); + j(cond, label); +} + void MacroAssembler::branchTest64(Condition cond, Register64 lhs, Register64 rhs, Register temp, Label* label) diff --git a/js/src/jit/x86/MacroAssembler-x86.h b/js/src/jit/x86/MacroAssembler-x86.h index f0fc4481be7c..bd8e8164c075 100644 --- a/js/src/jit/x86/MacroAssembler-x86.h +++ b/js/src/jit/x86/MacroAssembler-x86.h @@ -50,7 +50,6 @@ class MacroAssemblerX86 : public MacroAssemblerX86Shared void setupABICall(uint32_t args); public: - using MacroAssemblerX86Shared::branchTest32; using MacroAssemblerX86Shared::load32; using MacroAssemblerX86Shared::store32; using MacroAssemblerX86Shared::call; @@ -551,11 +550,6 @@ class MacroAssemblerX86 : public MacroAssemblerX86Shared // Common interface. ///////////////////////////////////////////////////////////////// - void branchTest32(Condition cond, AbsoluteAddress address, Imm32 imm, Label* label) { - test32(Operand(address), imm); - j(cond, label); - } - template void branchPtr(Condition cond, T lhs, S ptr, RepatchLabel* label) { cmpPtr(Operand(lhs), ptr);