PPC/s390: [liftoff] Use cross-platform conditions

Port a5eb40d90d

R=victorgomes@chromium.org, joransiu@ca.ibm.com, junyan@redhat.com, midawson@redhat.com
BUG=
LOG=N

Change-Id: I0429a643658ac513c32587d71b4f4dceb65cfdf7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4214882
Reviewed-by: Victor Gomes <victorgomes@chromium.org>
Reviewed-by: Junliang Yan <junyan@redhat.com>
Commit-Queue: Milad Farazmand <mfarazma@redhat.com>
Cr-Commit-Position: refs/heads/main@{#85625}
This commit is contained in:
Milad Fa 2023-02-02 01:25:08 +00:00 committed by V8 LUCI CQ
parent a5192ac12f
commit 31487e43a6
6 changed files with 84 additions and 124 deletions

View File

@ -49,31 +49,6 @@ class BaselineAssembler::ScratchRegisterScope {
int registers_used_;
};
inline bool IsSignedCondition(Condition cond) {
switch (cond) {
case kEqual:
case kNotEqual:
case kLessThan:
case kGreaterThan:
case kLessThanEqual:
case kGreaterThanEqual:
case kOverflow:
case kNoOverflow:
case kZero:
case kNotZero:
return true;
case kUnsignedLessThan:
case kUnsignedGreaterThan:
case kUnsignedLessThanEqual:
case kUnsignedGreaterThanEqual:
return false;
default:
UNREACHABLE();
}
}
#define __ assm->
// ppc helper
template <int width = 64>
@ -82,19 +57,19 @@ static void JumpIfHelper(MacroAssembler* assm, Condition cc, Register lhs,
static_assert(width == 64 || width == 32,
"only support 64 and 32 bit compare");
if (width == 64) {
if (IsSignedCondition(cc)) {
if (is_signed(cc)) {
__ CmpS64(lhs, rhs);
} else {
__ CmpU64(lhs, rhs);
}
} else {
if (IsSignedCondition(cc)) {
if (is_signed(cc)) {
__ CmpS32(lhs, rhs);
} else {
__ CmpU32(lhs, rhs);
}
}
__ b(check_condition(cc), target);
__ b(to_condition(cc), target);
}
#undef __
@ -160,18 +135,18 @@ void BaselineAssembler::TestAndBranch(Register value, int mask, Condition cc,
Label* target, Label::Distance) {
ASM_CODE_COMMENT(masm_);
__ AndU64(r0, value, Operand(mask), ip, SetRC);
__ b(check_condition(cc), target, cr0);
__ b(to_condition(cc), target, cr0);
}
void BaselineAssembler::JumpIf(Condition cc, Register lhs, const Operand& rhs,
Label* target, Label::Distance) {
ASM_CODE_COMMENT(masm_);
if (IsSignedCondition(cc)) {
if (is_signed(cc)) {
__ CmpS64(lhs, rhs, r0);
} else {
__ CmpU64(lhs, rhs, r0);
}
__ b(check_condition(cc), target);
__ b(to_condition(cc), target);
}
void BaselineAssembler::JumpIfObjectType(Condition cc, Register object,

View File

@ -48,31 +48,6 @@ class BaselineAssembler::ScratchRegisterScope {
int registers_used_;
};
inline bool IsSignedCondition(Condition cond) {
switch (cond) {
case kEqual:
case kNotEqual:
case kLessThan:
case kGreaterThan:
case kLessThanEqual:
case kGreaterThanEqual:
case kOverflow:
case kNoOverflow:
case kZero:
case kNotZero:
return true;
case kUnsignedLessThan:
case kUnsignedGreaterThan:
case kUnsignedLessThanEqual:
case kUnsignedGreaterThanEqual:
return false;
default:
UNREACHABLE();
}
}
#define __ assm->
// s390x helper
template <int width = 64>
@ -81,19 +56,19 @@ static void JumpIfHelper(MacroAssembler* assm, Condition cc, Register lhs,
static_assert(width == 64 || width == 32,
"only support 64 and 32 bit compare");
if (width == 64) {
if (IsSignedCondition(cc)) {
if (is_signed(cc)) {
__ CmpS64(lhs, rhs);
} else {
__ CmpU64(lhs, rhs);
}
} else {
if (IsSignedCondition(cc)) {
if (is_signed(cc)) {
__ CmpS32(lhs, rhs);
} else {
__ CmpU32(lhs, rhs);
}
}
__ b(check_condition(cc), target);
__ b(to_condition(cc), target);
}
#undef __
@ -159,18 +134,18 @@ void BaselineAssembler::TestAndBranch(Register value, int mask, Condition cc,
Label* target, Label::Distance) {
ASM_CODE_COMMENT(masm_);
__ AndP(r0, value, Operand(mask));
__ b(check_condition(cc), target);
__ b(to_condition(cc), target);
}
void BaselineAssembler::JumpIf(Condition cc, Register lhs, const Operand& rhs,
Label* target, Label::Distance) {
ASM_CODE_COMMENT(masm_);
if (IsSignedCondition(cc)) {
if (is_signed(cc)) {
__ CmpS64(lhs, rhs);
} else {
__ CmpU64(lhs, rhs);
}
__ b(check_condition(cc), target);
__ b(to_condition(cc), target);
}
void BaselineAssembler::JumpIfObjectType(Condition cc, Register object,

View File

@ -151,7 +151,7 @@ enum Condition {
kNotZero = 16,
};
inline Condition check_condition(Condition cond) {
inline Condition to_condition(Condition cond) {
switch (cond) {
case kUnsignedLessThan:
return lt;
@ -171,6 +171,31 @@ inline Condition check_condition(Condition cond) {
return cond;
}
inline bool is_signed(Condition cond) {
switch (cond) {
case kEqual:
case kNotEqual:
case kLessThan:
case kGreaterThan:
case kLessThanEqual:
case kGreaterThanEqual:
case kOverflow:
case kNoOverflow:
case kZero:
case kNotZero:
return true;
case kUnsignedLessThan:
case kUnsignedGreaterThan:
case kUnsignedLessThanEqual:
case kUnsignedGreaterThanEqual:
return false;
default:
UNREACHABLE();
}
}
inline Condition NegateCondition(Condition cond) {
DCHECK(cond != al);
return static_cast<Condition>(cond ^ ne);

View File

@ -123,7 +123,7 @@ enum Condition {
kNotZero = 21,
};
inline Condition check_condition(Condition cond) {
inline Condition to_condition(Condition cond) {
switch (cond) {
case kUnsignedLessThan:
return lt;
@ -143,6 +143,31 @@ inline Condition check_condition(Condition cond) {
return cond;
}
inline bool is_signed(Condition cond) {
switch (cond) {
case kEqual:
case kNotEqual:
case kLessThan:
case kGreaterThan:
case kLessThanEqual:
case kGreaterThanEqual:
case kOverflow:
case kNoOverflow:
case kZero:
case kNotZero:
return true;
case kUnsignedLessThan:
case kUnsignedGreaterThan:
case kUnsignedLessThanEqual:
case kUnsignedGreaterThanEqual:
return false;
default:
UNREACHABLE();
}
}
inline Condition NegateCondition(Condition cond) {
DCHECK(cond != al);
switch (cond) {

View File

@ -62,26 +62,6 @@ inline MemOperand GetStackSlot(uint32_t offset) {
inline MemOperand GetInstanceOperand() { return GetStackSlot(kInstanceOffset); }
inline constexpr bool UseSignedOp(Condition cond) {
switch (cond) {
case kEqual:
case kNotEqual:
case kLessThan:
case kLessThanEqual:
case kGreaterThan:
case kGreaterThanEqual:
return true;
case kUnsignedLessThan:
case kUnsignedLessThanEqual:
case kUnsignedGreaterThan:
case kUnsignedGreaterThanEqual:
return false;
default:
UNREACHABLE();
}
return false;
}
} // namespace liftoff
int LiftoffAssembler::PrepareStackFrame() {
@ -1641,7 +1621,7 @@ void LiftoffAssembler::emit_cond_jump(Condition cond, Label* label,
ValueKind kind, Register lhs,
Register rhs,
const FreezeCacheState& frozen) {
bool use_signed = liftoff::UseSignedOp(cond);
bool use_signed = is_signed(cond);
if (rhs != no_reg) {
switch (kind) {
@ -1686,19 +1666,19 @@ void LiftoffAssembler::emit_cond_jump(Condition cond, Label* label,
CmpS32(lhs, Operand::Zero(), r0);
}
b(cond, label);
b(to_condition(cond), label);
}
void LiftoffAssembler::emit_i32_cond_jumpi(Condition cond, Label* label,
Register lhs, int32_t imm,
const FreezeCacheState& frozen) {
bool use_signed = liftoff::UseSignedOp(cond);
bool use_signed = is_signed(cond);
if (use_signed) {
CmpS32(lhs, Operand(imm), r0);
} else {
CmpU32(lhs, Operand(imm), r0);
}
b(cond, label);
b(to_condition(cond), label);
}
void LiftoffAssembler::emit_i32_subi_jump_negative(
@ -1719,7 +1699,7 @@ void LiftoffAssembler::emit_i32_eqz(Register dst, Register src) {
void LiftoffAssembler::emit_i32_set_cond(Condition cond, Register dst,
Register lhs, Register rhs) {
bool use_signed = liftoff::UseSignedOp(cond);
bool use_signed = is_signed(cond);
if (use_signed) {
CmpS32(lhs, rhs);
} else {
@ -1727,7 +1707,7 @@ void LiftoffAssembler::emit_i32_set_cond(Condition cond, Register dst,
}
Label done;
mov(dst, Operand(1));
b(liftoff::ToCondition(cond), &done);
b(to_condition(to_condition(cond)), &done);
mov(dst, Operand::Zero());
bind(&done);
}
@ -1744,7 +1724,7 @@ void LiftoffAssembler::emit_i64_eqz(Register dst, LiftoffRegister src) {
void LiftoffAssembler::emit_i64_set_cond(Condition cond, Register dst,
LiftoffRegister lhs,
LiftoffRegister rhs) {
bool use_signed = liftoff::UseSignedOp(cond);
bool use_signed = is_signed(cond);
if (use_signed) {
CmpS64(lhs.gp(), rhs.gp());
} else {
@ -1752,7 +1732,7 @@ void LiftoffAssembler::emit_i64_set_cond(Condition cond, Register dst,
}
Label done;
mov(dst, Operand(1));
b(liftoff::ToCondition(cond), &done);
b(to_condition(to_condition(cond)), &done);
mov(dst, Operand::Zero());
bind(&done);
}
@ -1764,7 +1744,7 @@ void LiftoffAssembler::emit_f32_set_cond(Condition cond, Register dst,
Label nan, done;
bunordered(&nan, cr0);
mov(dst, Operand::Zero());
b(NegateCondition(liftoff::ToCondition(cond)), &done, cr0);
b(NegateCondition(to_condition(to_condition(cond))), &done, cr0);
mov(dst, Operand(1));
b(&done);
bind(&nan);
@ -1779,7 +1759,7 @@ void LiftoffAssembler::emit_f32_set_cond(Condition cond, Register dst,
void LiftoffAssembler::emit_f64_set_cond(Condition cond, Register dst,
DoubleRegister lhs,
DoubleRegister rhs) {
emit_f32_set_cond(cond, dst, lhs, rhs);
emit_f32_set_cond(to_condition(cond), dst, lhs, rhs);
}
bool LiftoffAssembler::emit_select(LiftoffRegister dst, Register condition,

View File

@ -18,26 +18,6 @@ namespace wasm {
namespace liftoff {
inline constexpr bool UseSignedOp(Condition cond) {
switch (cond) {
case kEqual:
case kNotEqual:
case kLessThan:
case kLessThanEqual:
case kGreaterThan:
case kGreaterThanEqual:
return true;
case kUnsignedLessThan:
case kUnsignedLessThanEqual:
case kUnsignedGreaterThan:
case kUnsignedGreaterThanEqual:
return false;
default:
UNREACHABLE();
}
return false;
}
// half
// slot Frame
// -----+--------------------+---------------------------
@ -2106,7 +2086,7 @@ void LiftoffAssembler::emit_cond_jump(Condition cond, Label* label,
ValueKind kind, Register lhs,
Register rhs,
const FreezeCacheState& frozen) {
bool use_signed = liftoff::UseSignedOp(cond);
bool use_signed = is_signed(cond);
if (rhs != no_reg) {
switch (kind) {
@ -2151,19 +2131,19 @@ void LiftoffAssembler::emit_cond_jump(Condition cond, Label* label,
CmpS32(lhs, Operand::Zero());
}
b(cond, label);
b(to_condition(cond), label);
}
void LiftoffAssembler::emit_i32_cond_jumpi(Condition cond, Label* label,
Register lhs, int32_t imm,
const FreezeCacheState& frozen) {
bool use_signed = liftoff::UseSignedOp(cond);
bool use_signed = is_signed(cond);
if (use_signed) {
CmpS32(lhs, Operand(imm));
} else {
CmpU32(lhs, Operand(imm));
}
b(cond, label);
b(to_condition(cond), label);
}
#define EMIT_EQZ(test, src) \
@ -2198,14 +2178,14 @@ void LiftoffAssembler::emit_i32_eqz(Register dst, Register src) {
void LiftoffAssembler::emit_i32_set_cond(Condition cond, Register dst,
Register lhs, Register rhs) {
bool use_signed = liftoff::UseSignedOp(cond);
bool use_signed = is_signed(cond);
if (use_signed) {
CmpS32(lhs, rhs);
} else {
CmpU32(lhs, rhs);
}
EMIT_SET_CONDITION(dst, cond);
EMIT_SET_CONDITION(dst, to_condition(cond));
}
void LiftoffAssembler::emit_i64_eqz(Register dst, LiftoffRegister src) {
@ -2215,28 +2195,28 @@ void LiftoffAssembler::emit_i64_eqz(Register dst, LiftoffRegister src) {
void LiftoffAssembler::emit_i64_set_cond(Condition cond, Register dst,
LiftoffRegister lhs,
LiftoffRegister rhs) {
bool use_signed = liftoff::UseSignedOp(cond);
bool use_signed = is_signed(cond);
if (use_signed) {
CmpS64(lhs.gp(), rhs.gp());
} else {
CmpU64(lhs.gp(), rhs.gp());
}
EMIT_SET_CONDITION(dst, cond);
EMIT_SET_CONDITION(dst, to_condition(cond));
}
void LiftoffAssembler::emit_f32_set_cond(Condition cond, Register dst,
DoubleRegister lhs,
DoubleRegister rhs) {
cebr(lhs, rhs);
EMIT_SET_CONDITION(dst, cond);
EMIT_SET_CONDITION(dst, to_condition(cond));
}
void LiftoffAssembler::emit_f64_set_cond(Condition cond, Register dst,
DoubleRegister lhs,
DoubleRegister rhs) {
cdbr(lhs, rhs);
EMIT_SET_CONDITION(dst, cond);
EMIT_SET_CONDITION(dst, to_condition(cond));
}
bool LiftoffAssembler::emit_select(LiftoffRegister dst, Register condition,