Bug 1245112 - Part 5: Move MacroAssembler::branchTestPtr into generic macro assembler. r=nbp

This commit is contained in:
Tooru Fujisawa 2016-02-15 23:01:48 +09:00
parent 231afb7336
commit ec4ec88de9
13 changed files with 153 additions and 125 deletions

View File

@ -380,6 +380,13 @@ MacroAssembler::branchTestProxyHandlerFamily(Condition cond, Register proxy, Reg
#ifndef JS_CODEGEN_ARM64
template <typename T>
void
MacroAssembler::branchTestStackPtr(Condition cond, T t, Label* label)
{
branchTestPtr(cond, getStackPointer(), t, label);
}
template <typename T>
void
MacroAssembler::branchStackPtr(Condition cond, T rhs, Label* label)
@ -408,6 +415,19 @@ MacroAssembler::addStackPtrTo(T t)
#endif // !JS_CODEGEN_ARM64
template <typename T>
void
MacroAssembler::storeObjectOrNull(Register src, const T& dest)
{
Label notNull, done;
branchTestPtr(Assembler::NonZero, src, src, &notNull);
storeValue(NullValue(), dest);
jump(&done);
bind(&notNull);
storeValue(JSVAL_TYPE_OBJECT, src, dest);
bind(&done);
}
void
MacroAssembler::bumpKey(Int32Key* key, int diff)
{
@ -417,6 +437,35 @@ MacroAssembler::bumpKey(Int32Key* key, int diff)
key->bumpConstant(diff);
}
void
MacroAssembler::assertStackAlignment(uint32_t alignment, int32_t offset /* = 0 */)
{
#ifdef DEBUG
Label ok, bad;
MOZ_ASSERT(IsPowerOfTwo(alignment));
// Wrap around the offset to be a non-negative number.
offset %= alignment;
if (offset < 0)
offset += alignment;
// Test if each bit from offset is set.
uint32_t off = offset;
while (off) {
uint32_t lowestBit = 1 << mozilla::CountTrailingZeroes32(off);
branchTestStackPtr(Assembler::Zero, Imm32(lowestBit), &bad);
off ^= lowestBit;
}
// Check that all remaining bits are zero.
branchTestStackPtr(Assembler::Zero, Imm32((alignment - 1) ^ offset), &ok);
bind(&bad);
breakpoint();
bind(&ok);
#endif
}
} // namespace jit
} // namespace js

View File

@ -841,6 +841,10 @@ 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;
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;
inline void branchTest64(Condition cond, Register64 lhs, Register64 rhs, Register temp,
Label* label) PER_ARCH;
@ -989,15 +993,7 @@ class MacroAssembler : public MacroAssemblerSpecific
}
template <typename T>
void storeObjectOrNull(Register src, const T& dest) {
Label notNull, done;
branchTestPtr(Assembler::NonZero, src, src, &notNull);
storeValue(NullValue(), dest);
jump(&done);
bind(&notNull);
storeValue(JSVAL_TYPE_OBJECT, src, dest);
bind(&done);
}
inline void storeObjectOrNull(Register src, const T& dest);
template <typename T>
void storeConstantOrRegister(ConstantOrRegister src, const T& dest) {
@ -1363,9 +1359,7 @@ class MacroAssembler : public MacroAssemblerSpecific
// On ARM64, sp can function as the zero register depending on context.
// Code shared across platforms must use these functions to be valid.
template <typename T>
void branchTestStackPtr(Condition cond, T t, Label* label) {
branchTestPtr(cond, getStackPointer(), t, label);
}
inline void branchTestStackPtr(Condition cond, T t, Label* label);
template <typename T>
inline void branchStackPtr(Condition cond, T rhs, Label* label);
template <typename T>
@ -1697,32 +1691,7 @@ class MacroAssembler : public MacroAssemblerSpecific
void alignJitStackBasedOnNArgs(Register nargs);
void alignJitStackBasedOnNArgs(uint32_t nargs);
void assertStackAlignment(uint32_t alignment, int32_t offset = 0) {
#ifdef DEBUG
Label ok, bad;
MOZ_ASSERT(IsPowerOfTwo(alignment));
// Wrap around the offset to be a non-negative number.
offset %= alignment;
if (offset < 0)
offset += alignment;
// Test if each bit from offset is set.
uint32_t off = offset;
while (off) {
uint32_t lowestBit = 1 << mozilla::CountTrailingZeroes32(off);
branchTestStackPtr(Assembler::Zero, Imm32(lowestBit), &bad);
off ^= lowestBit;
}
// Check that all remaining bits are zero.
branchTestStackPtr(Assembler::Zero, Imm32((alignment - 1) ^ offset), &ok);
bind(&bad);
breakpoint();
bind(&ok);
#endif
}
inline void assertStackAlignment(uint32_t alignment, int32_t offset = 0);
};
static inline Assembler::DoubleCondition

View File

@ -575,6 +575,24 @@ MacroAssembler::branchPrivatePtr(Condition cond, const Address& lhs, Register rh
branchPtr(cond, lhs, rhs, label);
}
void
MacroAssembler::branchTestPtr(Condition cond, Register lhs, Register rhs, Label* label)
{
branchTest32(cond, lhs, rhs, label);
}
void
MacroAssembler::branchTestPtr(Condition cond, Register lhs, Imm32 rhs, Label* label)
{
branchTest32(cond, lhs, rhs, label);
}
void
MacroAssembler::branchTestPtr(Condition cond, const Address& lhs, Imm32 rhs, Label* label)
{
branchTest32(cond, lhs, rhs, label);
}
void
MacroAssembler::branchTest64(Condition cond, Register64 lhs, Register64 rhs, Register temp,
Label* label)

View File

@ -865,15 +865,6 @@ class MacroAssemblerARMCompat : public MacroAssemblerARM
load32(address, scratch2);
branchTest32(cond, scratch2, imm, label);
}
void branchTestPtr(Condition cond, Register lhs, Register rhs, Label* label) {
branchTest32(cond, lhs, rhs, label);
}
void branchTestPtr(Condition cond, Register lhs, const Imm32 rhs, Label* label) {
branchTest32(cond, lhs, rhs, label);
}
void branchTestPtr(Condition cond, const Address& lhs, Imm32 imm, Label* label) {
branchTest32(cond, lhs, imm, label);
}
void decBranchPtr(Condition cond, Register lhs, Imm32 imm, Label* label) {
ma_sub(imm, lhs, SetCC);
as_b(label, cond);

View File

@ -652,6 +652,30 @@ MacroAssembler::branchPrivatePtr(Condition cond, const Address& lhs, Register rh
branchPtr(cond, lhs, scratch, label);
}
void
MacroAssembler::branchTestPtr(Condition cond, Register lhs, Register rhs, Label* label)
{
Tst(ARMRegister(lhs, 64), Operand(ARMRegister(rhs, 64)));
B(label, cond);
}
void
MacroAssembler::branchTestPtr(Condition cond, Register lhs, Imm32 rhs, Label* label)
{
Tst(ARMRegister(lhs, 64), Operand(rhs.value));
B(label, cond);
}
void
MacroAssembler::branchTestPtr(Condition cond, const Address& lhs, Imm32 rhs, Label* label)
{
vixl::UseScratchRegisterScope temps(this);
const Register scratch = temps.AcquireX().asUnsized();
MOZ_ASSERT(scratch != lhs.base);
loadPtr(lhs, scratch);
branchTestPtr(cond, scratch, rhs, label);
}
void
MacroAssembler::branchTest64(Condition cond, Register64 lhs, Register64 rhs, Register temp,
Label* label)
@ -719,6 +743,13 @@ MacroAssemblerCompat::branchStackPtrRhs(Condition cond, T lhs, Label* label)
asMasm().branchPtr(cond, lhs, getStackPointer(), label);
}
template <typename T>
void
MacroAssemblerCompat::branchTestStackPtr(Condition cond, T t, Label* label)
{
asMasm().branchTestPtr(cond, getStackPointer(), t, label);
}
} // namespace jit
} // namespace js

View File

@ -1057,9 +1057,7 @@ class MacroAssemblerCompat : public vixl::MacroAssembler
// StackPointer testing functions.
template <typename T>
void branchTestStackPtr(Condition cond, T t, Label* label) {
branchTestPtr(cond, getStackPointer(), t, label);
}
inline void branchTestStackPtr(Condition cond, T t, Label* label);
template <typename T>
void branchStackPtr(Condition cond, T rhs, Label* label);
template <typename T>
@ -1435,22 +1433,6 @@ class MacroAssemblerCompat : public vixl::MacroAssembler
return jumpWithPatch(label, cond);
}
void branchTestPtr(Condition cond, Register lhs, Register rhs, Label* label) {
Tst(ARMRegister(lhs, 64), Operand(ARMRegister(rhs, 64)));
B(label, cond);
}
void branchTestPtr(Condition cond, Register lhs, Imm32 imm, Label* label) {
Tst(ARMRegister(lhs, 64), Operand(imm.value));
B(label, cond);
}
void branchTestPtr(Condition cond, const Address& lhs, Imm32 imm, Label* label) {
vixl::UseScratchRegisterScope temps(this);
const Register scratch = temps.AcquireX().asUnsized();
MOZ_ASSERT(scratch != lhs.base);
loadPtr(lhs, scratch);
branchTestPtr(cond, scratch, imm, label);
}
void decBranchPtr(Condition cond, Register lhs, Imm32 imm, Label* label) {
Subs(ARMRegister(lhs, 64), ARMRegister(lhs, 64), Operand(imm.value));
B(cond, label);

View File

@ -345,6 +345,32 @@ MacroAssembler::branchPtr(Condition cond, wasm::SymbolicAddress lhs, Register rh
branchPtr(cond, SecondScratchReg, rhs, label);
}
void
MacroAssembler::branchTestPtr(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
MacroAssembler::branchTestPtr(Condition cond, Register lhs, Imm32 rhs, Label* label)
{
ma_li(ScratchRegister, rhs);
branchTestPtr(cond, lhs, ScratchRegister, label);
}
void
MacroAssembler::branchTestPtr(Condition cond, const Address& lhs, Imm32 rhs, Label* label)
{
loadPtr(lhs, SecondScratchReg);
branchTestPtr(cond, SecondScratchReg, rhs, label);
}
//}}} check_macroassembler_style
// ===============================================================

View File

@ -458,23 +458,6 @@ class MacroAssemblerMIPSCompat : public MacroAssemblerMIPS
load32(address, ScratchRegister);
branchTest32(cond, ScratchRegister, imm, label);
}
void branchTestPtr(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 branchTestPtr(Condition cond, Register lhs, const Imm32 rhs, Label* label) {
ma_li(ScratchRegister, rhs);
branchTestPtr(cond, lhs, ScratchRegister, label);
}
void branchTestPtr(Condition cond, const Address& lhs, Imm32 imm, Label* label) {
loadPtr(lhs, SecondScratchReg);
branchTestPtr(cond, SecondScratchReg, imm, label);
}
inline void decBranchPtr(Condition cond, Register lhs, Imm32 imm, Label* label);
// higher level tag testing code

View File

@ -499,23 +499,6 @@ class MacroAssemblerMIPS64Compat : public MacroAssemblerMIPS64
load32(address, ScratchRegister);
branchTest32(cond, ScratchRegister, imm, label);
}
void branchTestPtr(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 branchTestPtr(Condition cond, Register lhs, const Imm32 rhs, Label* label) {
ma_li(ScratchRegister, rhs);
branchTestPtr(cond, lhs, ScratchRegister, label);
}
void branchTestPtr(Condition cond, const Address& lhs, Imm32 imm, Label* label) {
loadPtr(lhs, SecondScratchReg);
branchTestPtr(cond, SecondScratchReg, imm, label);
}
inline void decBranchPtr(Condition cond, Register lhs, Imm32 imm, Label* label);
// higher level tag testing code

View File

@ -247,7 +247,6 @@ class MacroAssemblerNone : public Assembler
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 branchTestPtr(Condition, T, S, Label*) { MOZ_CRASH(); }
template <typename T, typename S> void branchDouble(DoubleCondition, T, S, Label*) { MOZ_CRASH(); }
template <typename T, typename S> void branchFloat(DoubleCondition, T, S, Label*) { MOZ_CRASH(); }
template <typename T, typename S> void decBranchPtr(Condition, T, S, Label*) { MOZ_CRASH(); }

View File

@ -562,18 +562,6 @@ class MacroAssemblerX64 : public MacroAssemblerX86Shared
cmpPtr(lhs, ptr);
return jumpWithPatch(label, cond);
}
void branchTestPtr(Condition cond, Register lhs, Register rhs, Label* label) {
testPtr(lhs, rhs);
j(cond, label);
}
void branchTestPtr(Condition cond, Register lhs, Imm32 imm, Label* label) {
testPtr(lhs, imm);
j(cond, label);
}
void branchTestPtr(Condition cond, const Address& lhs, Imm32 imm, Label* label) {
testPtr(Operand(lhs), imm);
j(cond, label);
}
void decBranchPtr(Condition cond, Register lhs, Imm32 imm, Label* label) {
subq(imm, lhs);
j(cond, label);

View File

@ -294,6 +294,27 @@ MacroAssembler::branchPtr(Condition cond, const Address& lhs, ImmWord rhs, Label
branchPtrImpl(cond, lhs, rhs, label);
}
void
MacroAssembler::branchTestPtr(Condition cond, Register lhs, Register rhs, Label* label)
{
testPtr(lhs, rhs);
j(cond, label);
}
void
MacroAssembler::branchTestPtr(Condition cond, Register lhs, Imm32 rhs, Label* label)
{
testPtr(lhs, rhs);
j(cond, label);
}
void
MacroAssembler::branchTestPtr(Condition cond, const Address& lhs, Imm32 rhs, Label* label)
{
testPtr(Operand(lhs), rhs);
j(cond, label);
}
//}}} check_macroassembler_style
// ===============================================================

View File

@ -590,18 +590,6 @@ class MacroAssemblerX86 : public MacroAssemblerX86Shared
cmpPtr(lhs, rhs);
j(cond, label);
}
void branchTestPtr(Condition cond, Register lhs, Register rhs, Label* label) {
testPtr(lhs, rhs);
j(cond, label);
}
void branchTestPtr(Condition cond, Register lhs, Imm32 imm, Label* label) {
testPtr(lhs, imm);
j(cond, label);
}
void branchTestPtr(Condition cond, const Address& lhs, Imm32 imm, Label* label) {
testPtr(Operand(lhs), imm);
j(cond, label);
}
void decBranchPtr(Condition cond, Register lhs, Imm32 imm, Label* label) {
subl(imm, lhs);
j(cond, label);