Bug 1245112 - Part 6: Move MacroAssembler::branchTest32 into generic macro assembler. r=nbp

This commit is contained in:
Tooru Fujisawa 2016-02-15 23:01:48 +09:00
Родитель 2a4d148698
Коммит 6a19ac1a38
17 изменённых файлов: 300 добавлений и 223 удалений

Просмотреть файл

@ -320,6 +320,107 @@ MacroAssembler::addPtr(ImmPtr imm, Register dest)
//}}} check_macroassembler_style
// ===============================================================
template <class L>
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)

Просмотреть файл

@ -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 <class L>
inline void branchTest32(Condition cond, Register lhs, Register rhs, L label) PER_SHARED_ARCH;
template <class L>
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 <class L>
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 <typename T>
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);

Просмотреть файл

@ -575,6 +575,47 @@ MacroAssembler::branchPrivatePtr(Condition cond, const Address& lhs, Register rh
branchPtr(cond, lhs, rhs, label);
}
template <class L>
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 <class L>
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)
{

Просмотреть файл

@ -836,35 +836,6 @@ class MacroAssemblerARMCompat : public MacroAssemblerARM
Condition c = testStringTruthy(truthy, value);
ma_b(label, c);
}
template <class L>
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 <class L>
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);

Просмотреть файл

@ -652,6 +652,48 @@ MacroAssembler::branchPrivatePtr(Condition cond, const Address& lhs, Register rh
branchPtr(cond, lhs, scratch, label);
}
template <class L>
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 <class L>
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)
{

Просмотреть файл

@ -1355,36 +1355,6 @@ class MacroAssemblerCompat : public vixl::MacroAssembler
addPendingJump(loc, ImmPtr(target->raw()), Relocation::JITCODE);
}
template <class L>
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 <class L>
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)
{

Просмотреть файл

@ -345,6 +345,41 @@ MacroAssembler::branchPtr(Condition cond, wasm::SymbolicAddress lhs, Register rh
branchPtr(cond, SecondScratchReg, rhs, label);
}
template <class L>
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 <class L>
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)
{

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -244,7 +244,6 @@ class MacroAssemblerNone : public Assembler
template <typename T, typename S> void cmpPtrSet(Condition, T, S, Register) { MOZ_CRASH(); }
template <typename T, typename S> void cmp32Set(Condition, T, S, Register) { MOZ_CRASH(); }
template <typename T, typename S, typename L> void branchTest32(Condition, T, S, L) { MOZ_CRASH(); }
template <typename T, typename S> void branchAdd32(Condition, T, S, Label*) { MOZ_CRASH(); }
template <typename T, typename S> void branchSub32(Condition, T, S, Label*) { MOZ_CRASH(); }
template <typename T, typename S> void branchDouble(DoubleCondition, T, S, Label*) { MOZ_CRASH(); }

Просмотреть файл

@ -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)

Просмотреть файл

@ -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 <typename T, typename S>
inline void branchPtrImpl(Condition cond, const T& lhs, const S& rhs, Label* label);

Просмотреть файл

@ -294,6 +294,32 @@ MacroAssembler::branchPtr(Condition cond, const Address& lhs, ImmWord rhs, Label
branchPtrImpl(cond, lhs, rhs, label);
}
template <class L>
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 <class L>
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

Просмотреть файл

@ -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)

Просмотреть файл

@ -572,28 +572,6 @@ class MacroAssemblerX86Shared : public Assembler
testw(rhs, lhs);
j(cond, label);
}
template <class L>
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 <class L>
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<uint64_t>(d);

Просмотреть файл

@ -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)

Просмотреть файл

@ -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 <typename T, typename S>
void branchPtr(Condition cond, T lhs, S ptr, RepatchLabel* label) {
cmpPtr(Operand(lhs), ptr);