Commit 23b08e2a authored by Junliang Yan's avatar Junliang Yan Committed by Commit Bot

s390x: [liftoff] implement i32/i64 div/rem operations

Change-Id: I838bf9f9c0d83fc3cb96f7fb47b0fba3498680c1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2709950Reviewed-by: 's avatarMilad Fa <mfarazma@redhat.com>
Commit-Queue: Junliang Yan <junyan@redhat.com>
Cr-Commit-Position: refs/heads/master@{#72921}
parent c30d366c
......@@ -997,50 +997,134 @@ void LiftoffAssembler::emit_f32_max(DoubleRegister dst, DoubleRegister lhs,
void LiftoffAssembler::emit_i32_divs(Register dst, Register lhs, Register rhs,
Label* trap_div_by_zero,
Label* trap_div_unrepresentable) {
bailout(kUnsupportedArchitecture, "i32_divs");
Label cont;
// Check for division by zero.
ltr(r0, rhs);
b(eq, trap_div_by_zero);
// Check for kMinInt / -1. This is unrepresentable.
CmpS32(rhs, Operand(-1));
bne(&cont);
CmpS32(lhs, Operand(kMinInt));
b(eq, trap_div_unrepresentable);
bind(&cont);
DivS32(dst, lhs, rhs);
}
void LiftoffAssembler::emit_i32_divu(Register dst, Register lhs, Register rhs,
Label* trap_div_by_zero) {
bailout(kUnsupportedArchitecture, "i32_divu");
// Check for division by zero.
ltr(r0, rhs);
beq(trap_div_by_zero);
DivU32(dst, lhs, rhs);
}
void LiftoffAssembler::emit_i32_rems(Register dst, Register lhs, Register rhs,
Label* trap_div_by_zero) {
bailout(kUnsupportedArchitecture, "i32_rems");
Label cont;
Label done;
Label trap_div_unrepresentable;
// Check for division by zero.
ltr(r0, rhs);
beq(trap_div_by_zero);
// Check kMinInt/-1 case.
CmpS32(rhs, Operand(-1));
bne(&cont);
CmpS32(lhs, Operand(kMinInt));
beq(&trap_div_unrepresentable);
// Continue noraml calculation.
bind(&cont);
ModS32(dst, lhs, rhs);
bne(&done);
// trap by kMinInt/-1 case.
bind(&trap_div_unrepresentable);
mov(dst, Operand(0));
bind(&done);
}
void LiftoffAssembler::emit_i32_remu(Register dst, Register lhs, Register rhs,
Label* trap_div_by_zero) {
bailout(kUnsupportedArchitecture, "i32_remu");
// Check for division by zero.
ltr(r0, rhs);
beq(trap_div_by_zero);
ModU32(dst, lhs, rhs);
}
bool LiftoffAssembler::emit_i64_divs(LiftoffRegister dst, LiftoffRegister lhs,
LiftoffRegister rhs,
Label* trap_div_by_zero,
Label* trap_div_unrepresentable) {
bailout(kUnsupportedArchitecture, "i64_divs");
// Use r0 to check for kMinInt / -1.
constexpr int64_t kMinInt64 = static_cast<int64_t>(1) << 63;
Label cont;
// Check for division by zero.
ltgr(r0, rhs.gp());
beq(trap_div_by_zero);
// Check for kMinInt / -1. This is unrepresentable.
CmpS64(rhs.gp(), Operand(-1));
bne(&cont);
mov(r0, Operand(kMinInt64));
CmpS64(lhs.gp(), r0);
b(eq, trap_div_unrepresentable);
bind(&cont);
DivS64(dst.gp(), lhs.gp(), rhs.gp());
return true;
}
bool LiftoffAssembler::emit_i64_divu(LiftoffRegister dst, LiftoffRegister lhs,
LiftoffRegister rhs,
Label* trap_div_by_zero) {
bailout(kUnsupportedArchitecture, "i64_divu");
ltgr(r0, rhs.gp());
b(eq, trap_div_by_zero);
// Do div.
DivU64(dst.gp(), lhs.gp(), rhs.gp());
return true;
}
bool LiftoffAssembler::emit_i64_rems(LiftoffRegister dst, LiftoffRegister lhs,
LiftoffRegister rhs,
Label* trap_div_by_zero) {
bailout(kUnsupportedArchitecture, "i64_rems");
constexpr int64_t kMinInt64 = static_cast<int64_t>(1) << 63;
Label trap_div_unrepresentable;
Label done;
Label cont;
// Check for division by zero.
ltgr(r0, rhs.gp());
beq(trap_div_by_zero);
// Check for kMinInt / -1. This is unrepresentable.
CmpS64(rhs.gp(), Operand(-1));
bne(&cont);
mov(r0, Operand(kMinInt64));
CmpS64(lhs.gp(), r0);
beq(&trap_div_unrepresentable);
bind(&cont);
ModS64(dst.gp(), lhs.gp(), rhs.gp());
bne(&done);
bind(&trap_div_unrepresentable);
mov(dst.gp(), Operand(0));
bind(&done);
return true;
}
bool LiftoffAssembler::emit_i64_remu(LiftoffRegister dst, LiftoffRegister lhs,
LiftoffRegister rhs,
Label* trap_div_by_zero) {
bailout(kUnsupportedArchitecture, "i64_remu");
// Check for division by zero.
ltgr(r0, rhs.gp());
beq(trap_div_by_zero);
ModU64(dst.gp(), lhs.gp(), rhs.gp());
return true;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment