Bug 1245112 - Part 35: Move MacroAssembler::branchTestValue into generic macro assembler. r=jandem

This commit is contained in:
Tooru Fujisawa 2016-03-03 08:03:45 +09:00
parent 9623625a31
commit 4f0709e208
16 changed files with 108 additions and 200 deletions

View File

@ -997,6 +997,9 @@ class MacroAssembler : public MacroAssemblerSpecific
inline void branchTestMagicValue(Condition cond, const ValueOperand& val, JSWhyMagic why,
Label* label);
void branchTestValue(Condition cond, const ValueOperand& lhs,
const Value& rhs, Label* label) PER_ARCH;
// Checks if given Value is evaluated to true or false in a condition.
// The type of the value should match the type of the method.
inline void branchTestInt32Truthy(bool truthy, const ValueOperand& value, Label* label)

View File

@ -2853,53 +2853,6 @@ MacroAssemblerARMCompat::testGCThing(Condition cond, const BaseIndex& address)
return cond == Equal ? AboveOrEqual : Below;
}
void
MacroAssemblerARMCompat::branchTestValue(Condition cond, const ValueOperand& value,
const Value& v, Label* label)
{
// If cond == NotEqual, branch when a.payload != b.payload || a.tag !=
// b.tag. If the payloads are equal, compare the tags. If the payloads are
// not equal, short circuit true (NotEqual).
//
// If cand == Equal, branch when a.payload == b.payload && a.tag == b.tag.
// If the payloads are equal, compare the tags. If the payloads are not
// equal, short circuit false (NotEqual).
jsval_layout jv = JSVAL_TO_IMPL(v);
if (v.isMarkable())
ma_cmp(value.payloadReg(), ImmGCPtr(reinterpret_cast<gc::Cell*>(v.toGCThing())));
else
ma_cmp(value.payloadReg(), Imm32(jv.s.payload.i32));
ma_cmp(value.typeReg(), Imm32(jv.s.tag), Equal);
ma_b(label, cond);
}
void
MacroAssemblerARMCompat::branchTestValue(Condition cond, const Address& valaddr,
const ValueOperand& value, Label* label)
{
MOZ_ASSERT(cond == Equal || cond == NotEqual);
ScratchRegisterScope scratch(asMasm());
// Check payload before tag, since payload is more likely to differ.
if (cond == NotEqual) {
ma_ldr(ToPayload(valaddr), scratch);
asMasm().branchPtr(NotEqual, scratch, value.payloadReg(), label);
ma_ldr(ToType(valaddr), scratch);
asMasm().branchPtr(NotEqual, scratch, value.typeReg(), label);
} else {
Label fallthrough;
ma_ldr(ToPayload(valaddr), scratch);
asMasm().branchPtr(NotEqual, scratch, value.payloadReg(), &fallthrough);
ma_ldr(ToType(valaddr), scratch);
asMasm().branchPtr(Equal, scratch, value.typeReg(), label);
bind(&fallthrough);
}
}
// Unboxing code.
void
MacroAssemblerARMCompat::unboxNonDouble(const ValueOperand& operand, Register dest)
@ -5068,4 +5021,25 @@ MacroAssembler::branchValueIsNurseryObject(Condition cond, ValueOperand value,
bind(&done);
}
void
MacroAssembler::branchTestValue(Condition cond, const ValueOperand& lhs,
const Value& rhs, Label* label)
{
MOZ_ASSERT(cond == Equal || cond == NotEqual);
// If cond == NotEqual, branch when a.payload != b.payload || a.tag !=
// b.tag. If the payloads are equal, compare the tags. If the payloads are
// not equal, short circuit true (NotEqual).
//
// If cand == Equal, branch when a.payload == b.payload && a.tag == b.tag.
// If the payloads are equal, compare the tags. If the payloads are not
// equal, short circuit false (NotEqual).
jsval_layout jv = JSVAL_TO_IMPL(rhs);
if (rhs.isMarkable())
ma_cmp(lhs.payloadReg(), ImmGCPtr(reinterpret_cast<gc::Cell*>(rhs.toGCThing())));
else
ma_cmp(lhs.payloadReg(), Imm32(jv.s.payload.i32));
ma_cmp(lhs.typeReg(), Imm32(jv.s.tag), Equal);
ma_b(label, cond);
}
//}}} check_macroassembler_style

View File

@ -684,10 +684,6 @@ class MacroAssemblerARMCompat : public MacroAssemblerARM
Condition testMagic(Condition cond, const BaseIndex& src);
Condition testGCThing(Condition cond, const BaseIndex& src);
void branchTestValue(Condition cond, const ValueOperand& value, const Value& v, Label* label);
void branchTestValue(Condition cond, const Address& valaddr, const ValueOperand& value,
Label* label);
// Unboxing code.
void unboxNonDouble(const ValueOperand& operand, Register dest);
void unboxNonDouble(const Address& src, Register dest);

View File

@ -723,6 +723,19 @@ MacroAssembler::branchValueIsNurseryObject(Condition cond, ValueOperand value, R
temp, ImmWord(nursery.nurserySize()), label);
}
void
MacroAssembler::branchTestValue(Condition cond, const ValueOperand& lhs,
const Value& rhs, Label* label)
{
MOZ_ASSERT(cond == Equal || cond == NotEqual);
vixl::UseScratchRegisterScope temps(this);
const ARMRegister scratch64 = temps.AcquireX();
MOZ_ASSERT(scratch64.asUnsized() != lhs.valueReg());
moveValue(rhs, ValueOperand(scratch64.asUnsized()));
Cmp(ARMRegister(lhs.valueReg(), 64), scratch64);
B(label, cond);
}
//}}} check_macroassembler_style
} // namespace jit

View File

@ -1328,26 +1328,6 @@ class MacroAssemblerCompat : public vixl::MacroAssembler
return jumpWithPatch(label, Always, documentation);
}
void branchTestValue(Condition cond, const ValueOperand& value, const Value& v, Label* label) {
vixl::UseScratchRegisterScope temps(this);
const ARMRegister scratch64 = temps.AcquireX();
MOZ_ASSERT(scratch64.asUnsized() != value.valueReg());
moveValue(v, ValueOperand(scratch64.asUnsized()));
Cmp(ARMRegister(value.valueReg(), 64), scratch64);
B(label, cond);
}
void branchTestValue(Condition cond, const Address& valaddr, const ValueOperand& value,
Label* label)
{
vixl::UseScratchRegisterScope temps(this);
const ARMRegister scratch64 = temps.AcquireX();
MOZ_ASSERT(scratch64.asUnsized() != valaddr.base);
MOZ_ASSERT(scratch64.asUnsized() != value.valueReg());
loadValue(valaddr, scratch64.asUnsized());
Cmp(ARMRegister(value.valueReg(), 64), Operand(scratch64));
B(label, cond);
}
void compareDouble(DoubleCondition cond, FloatRegister lhs, FloatRegister rhs) {
Fcmp(ARMFPRegister(lhs, 64), ARMFPRegister(rhs, 64));
}

View File

@ -1116,42 +1116,6 @@ MacroAssemblerMIPSCompat::testUndefinedSet(Condition cond, const ValueOperand& v
ma_cmp_set(dest, value.typeReg(), ImmType(JSVAL_TYPE_UNDEFINED), cond);
}
void
MacroAssemblerMIPSCompat::branchTestValue(Condition cond, const ValueOperand& value,
const Value& v, Label* label)
{
moveData(v, ScratchRegister);
if (cond == Equal) {
Label done;
ma_b(value.payloadReg(), ScratchRegister, &done, NotEqual, ShortJump);
{
ma_b(value.typeReg(), Imm32(getType(v)), label, Equal);
}
bind(&done);
} else {
MOZ_ASSERT(cond == NotEqual);
ma_b(value.payloadReg(), ScratchRegister, label, NotEqual);
ma_b(value.typeReg(), Imm32(getType(v)), label, NotEqual);
}
}
void
MacroAssemblerMIPSCompat::branchTestValue(Condition cond, const Address& valaddr,
const ValueOperand& value, Label* label)
{
MOZ_ASSERT(cond == Equal || cond == NotEqual);
// Load tag.
ma_lw(ScratchRegister, Address(valaddr.base, valaddr.offset + TAG_OFFSET));
asMasm().branchPtr(cond, ScratchRegister, value.typeReg(), label);
// Load payload
ma_lw(ScratchRegister, Address(valaddr.base, valaddr.offset + PAYLOAD_OFFSET));
asMasm().branchPtr(cond, ScratchRegister, value.payloadReg(), label);
}
// unboxing code
void
MacroAssemblerMIPSCompat::unboxNonDouble(const ValueOperand& operand, Register dest)
@ -2192,4 +2156,26 @@ MacroAssembler::branchValueIsNurseryObject(Condition cond, ValueOperand value,
bind(&done);
}
void
MacroAssembler::branchTestValue(Condition cond, const ValueOperand& lhs,
const Value& rhs, Label* label)
{
MOZ_ASSERT(cond == Equal || cond == NotEqual);
ScratchRegisterScope scratch(*this);
moveData(rhs, scratch);
if (cond == Equal) {
Label done;
ma_b(lhs.payloadReg(), scratch, &done, NotEqual, ShortJump);
{
ma_b(lhs.typeReg(), Imm32(getType(rhs)), label, Equal);
}
bind(&done);
} else {
ma_b(lhs.payloadReg(), scratch, label, NotEqual);
ma_b(lhs.typeReg(), Imm32(getType(rhs)), label, NotEqual);
}
}
//}}} check_macroassembler_style

View File

@ -309,10 +309,6 @@ class MacroAssemblerMIPSCompat : public MacroAssemblerMIPS
return value.typeReg();
}
void branchTestValue(Condition cond, const ValueOperand& value, const Value& v, Label* label);
void branchTestValue(Condition cond, const Address& valaddr, const ValueOperand& value,
Label* label);
// unboxing code
void unboxNonDouble(const ValueOperand& operand, Register dest);
void unboxNonDouble(const Address& src, Register dest);

View File

@ -1246,24 +1246,6 @@ MacroAssemblerMIPS64Compat::testUndefinedSet(Condition cond, const ValueOperand&
ma_cmp_set(dest, SecondScratchReg, ImmTag(JSVAL_TAG_UNDEFINED), cond);
}
void
MacroAssemblerMIPS64Compat::branchTestValue(Condition cond, const ValueOperand& value,
const Value& v, Label* label)
{
MOZ_ASSERT(cond == Equal || cond == NotEqual);
moveValue(v, ScratchRegister);
ma_b(value.valueReg(), ScratchRegister, label, cond);
}
void
MacroAssemblerMIPS64Compat::branchTestValue(Condition cond, const Address& valaddr,
const ValueOperand& value, Label* label)
{
MOZ_ASSERT(cond == Equal || cond == NotEqual);
loadPtr(Address(valaddr.base, valaddr.offset), ScratchRegister);
ma_b(value.valueReg(), ScratchRegister, label, cond);
}
// unboxing code
void
MacroAssemblerMIPS64Compat::unboxNonDouble(const ValueOperand& operand, Register dest)
@ -2338,4 +2320,14 @@ MacroAssembler::branchValueIsNurseryObject(Condition cond, ValueOperand value,
SecondScratchReg, Imm32(nursery.nurserySize()), label);
}
void
MacroAssembler::branchTestValue(Condition cond, const ValueOperand& lhs,
const Value& rhs, Label* label)
{
MOZ_ASSERT(cond == Equal || cond == NotEqual);
ScratchRegisterScope scratch(*this);
moveValue(rhs, scratch);
ma_b(lhs.valueReg(), scratch, label, cond);
}
//}}} check_macroassembler_style

View File

@ -337,10 +337,6 @@ class MacroAssemblerMIPS64Compat : public MacroAssemblerMIPS64
return SecondScratchReg;
}
void branchTestValue(Condition cond, const ValueOperand& value, const Value& v, Label* label);
void branchTestValue(Condition cond, const Address& valaddr, const ValueOperand& value,
Label* label);
// unboxing code
void unboxNonDouble(const ValueOperand& operand, Register dest);
void unboxNonDouble(const Address& src, Register dest);

View File

@ -234,7 +234,6 @@ class MacroAssemblerNone : public Assembler
CodeOffsetJump jumpWithPatch(RepatchLabel*, Condition, Label* doc = nullptr) { MOZ_CRASH(); }
CodeOffsetJump backedgeJump(RepatchLabel* label, Label* doc = nullptr) { MOZ_CRASH(); }
template <typename T, typename S> void branchTestValue(Condition, T, S, Label*) { MOZ_CRASH(); }
void testNullSet(Condition, ValueOperand, Register) { MOZ_CRASH(); }
void testObjectSet(Condition, ValueOperand, Register) { MOZ_CRASH(); }
void testUndefinedSet(Condition, ValueOperand, Register) { MOZ_CRASH(); }

View File

@ -414,14 +414,6 @@ MacroAssemblerX64::incrementInt32Value(const Address& addr)
asMasm().addPtr(Imm32(1), addr);
}
void
MacroAssemblerX64::branchTestValue(Condition cond, const Address& valaddr, const
ValueOperand& value, Label* label)
{
MOZ_ASSERT(cond == Equal || cond == NotEqual);
asMasm().branchPtr(cond, valaddr, value.valueReg(), label);
}
template <typename T, typename S>
void
MacroAssemblerX64::branchPtrImpl(Condition cond, const T& lhs, const S& rhs, Label* label)

View File

@ -467,4 +467,16 @@ MacroAssembler::branchValueIsNurseryObject(Condition cond, ValueOperand value, R
scratch, Imm32(nursery.nurserySize()), label);
}
void
MacroAssembler::branchTestValue(Condition cond, const ValueOperand& lhs,
const Value& rhs, Label* label)
{
MOZ_ASSERT(cond == Equal || cond == NotEqual);
ScratchRegisterScope scratch(*this);
MOZ_ASSERT(lhs.valueReg() != scratch);
moveValue(rhs, scratch);
cmpPtr(lhs.valueReg(), scratch);
j(cond, label);
}
//}}} check_macroassembler_style

View File

@ -691,15 +691,6 @@ class MacroAssemblerX64 : public MacroAssemblerX86Shared
Condition testError(Condition cond, const ValueOperand& src) {
return testMagic(cond, src);
}
void branchTestValue(Condition cond, const ValueOperand& value, const Value& v, Label* label) {
ScratchRegisterScope scratch(asMasm());
MOZ_ASSERT(value.valueReg() != scratch);
moveValue(v, scratch);
cmpPtr(value.valueReg(), scratch);
j(cond, label);
}
inline void branchTestValue(Condition cond, const Address& valaddr, const ValueOperand& value,
Label* label);
void testNullSet(Condition cond, const ValueOperand& value, Register dest) {
cond = testNull(cond, value);

View File

@ -412,23 +412,6 @@ MacroAssemblerX86::convertUInt32ToFloat32(Register src, FloatRegister dest)
convertDoubleToFloat32(dest, dest);
}
void
MacroAssemblerX86::branchTestValue(Condition cond, const Address& valaddr, const ValueOperand& value,
Label* label)
{
MOZ_ASSERT(cond == Equal || cond == NotEqual);
// Check payload before tag, since payload is more likely to differ.
if (cond == NotEqual) {
branchPtrImpl(NotEqual, payloadOf(valaddr), value.payloadReg(), label);
branchPtrImpl(NotEqual, tagOf(valaddr), value.typeReg(), label);
} else {
Label fallthrough;
branchPtrImpl(NotEqual, payloadOf(valaddr), value.payloadReg(), &fallthrough);
branchPtrImpl(Equal, tagOf(valaddr), value.typeReg(), label);
bind(&fallthrough);
}
}
template <typename T, typename S>
void
MacroAssemblerX86::branchPtrImpl(Condition cond, const T& lhs, const S& rhs, Label* label)

View File

@ -273,32 +273,6 @@ MacroAssemblerX86::handleFailureWithHandlerTail(void* handler)
jmp(Operand(esp, offsetof(ResumeFromException, target)));
}
void
MacroAssemblerX86::branchTestValue(Condition cond, const ValueOperand& value, const Value& v, Label* label)
{
jsval_layout jv = JSVAL_TO_IMPL(v);
if (v.isMarkable())
cmpPtr(value.payloadReg(), ImmGCPtr(reinterpret_cast<gc::Cell*>(v.toGCThing())));
else
cmpPtr(value.payloadReg(), ImmWord(jv.s.payload.i32));
if (cond == Equal) {
Label done;
j(NotEqual, &done);
{
cmp32(value.typeReg(), Imm32(jv.s.tag));
j(Equal, label);
}
bind(&done);
} else {
MOZ_ASSERT(cond == NotEqual);
j(NotEqual, label);
cmp32(value.typeReg(), Imm32(jv.s.tag));
j(NotEqual, label);
}
}
template <typename T>
void
MacroAssemblerX86::storeUnboxedValue(ConstantOrRegister value, MIRType valueType, const T& dest,
@ -501,4 +475,31 @@ MacroAssembler::branchValueIsNurseryObject(Condition cond, ValueOperand value, R
bind(&done);
}
void
MacroAssembler::branchTestValue(Condition cond, const ValueOperand& lhs,
const Value& rhs, Label* label)
{
MOZ_ASSERT(cond == Equal || cond == NotEqual);
jsval_layout jv = JSVAL_TO_IMPL(rhs);
if (rhs.isMarkable())
cmpPtr(lhs.payloadReg(), ImmGCPtr(reinterpret_cast<gc::Cell*>(rhs.toGCThing())));
else
cmpPtr(lhs.payloadReg(), ImmWord(jv.s.payload.i32));
if (cond == Equal) {
Label done;
j(NotEqual, &done);
{
cmp32(lhs.typeReg(), Imm32(jv.s.tag));
j(Equal, label);
}
bind(&done);
} else {
j(NotEqual, label);
cmp32(lhs.typeReg(), Imm32(jv.s.tag));
j(NotEqual, label);
}
}
//}}} check_macroassembler_style

View File

@ -467,12 +467,6 @@ class MacroAssemblerX86 : public MacroAssemblerX86Shared
return cond == Equal ? AboveOrEqual : Below;
}
void branchTestValue(Condition cond, const ValueOperand& value, const Value& v, Label* label);
inline void branchTestValue(Condition cond, const Address& valaddr, const ValueOperand& value,
Label* label);
void testNullSet(Condition cond, const ValueOperand& value, Register dest) {
cond = testNull(cond, value);
emitSet(cond, dest);