mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:57:45 +00:00
LibJIT: Factor out JO instruction from add32()
Also add a jump_if(Condition, Label) helper. This will make it easier to add more 32-bit binary ops that branch on overflow.
This commit is contained in:
parent
dd466ec83a
commit
56b4586d65
1 changed files with 11 additions and 10 deletions
|
@ -105,6 +105,7 @@ struct Assembler {
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class Condition {
|
enum class Condition {
|
||||||
|
Overflow = 0x0,
|
||||||
EqualTo = 0x4,
|
EqualTo = 0x4,
|
||||||
NotEqualTo = 0x5,
|
NotEqualTo = 0x5,
|
||||||
UnsignedGreaterThan = 0x7,
|
UnsignedGreaterThan = 0x7,
|
||||||
|
@ -458,16 +459,20 @@ struct Assembler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void jump_if(Operand lhs, Condition condition, Operand rhs, Label& label)
|
void jump_if(Condition condition, Label& label)
|
||||||
{
|
{
|
||||||
cmp(lhs, rhs);
|
|
||||||
|
|
||||||
emit8(0x0F);
|
emit8(0x0F);
|
||||||
emit8(0x80 | to_underlying(condition));
|
emit8(0x80 | to_underlying(condition));
|
||||||
emit32(0xdeadbeef);
|
emit32(0xdeadbeef);
|
||||||
label.add_jump(*this, m_output.size());
|
label.add_jump(*this, m_output.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void jump_if(Operand lhs, Condition condition, Operand rhs, Label& label)
|
||||||
|
{
|
||||||
|
cmp(lhs, rhs);
|
||||||
|
jump_if(condition, label);
|
||||||
|
}
|
||||||
|
|
||||||
void sign_extend_32_to_64_bits(Reg reg)
|
void sign_extend_32_to_64_bits(Reg reg)
|
||||||
{
|
{
|
||||||
// movsxd (reg as 64-bit), (reg as 32-bit)
|
// movsxd (reg as 64-bit), (reg as 32-bit)
|
||||||
|
@ -613,7 +618,7 @@ struct Assembler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void add32(Operand dst, Operand src, Optional<Label&> label)
|
void add32(Operand dst, Operand src, Optional<Label&> overflow_label)
|
||||||
{
|
{
|
||||||
if (dst.is_register_or_memory() && src.type == Operand::Type::Reg) {
|
if (dst.is_register_or_memory() && src.type == Operand::Type::Reg) {
|
||||||
emit_rex_for_mr(dst, src, REX_W::No);
|
emit_rex_for_mr(dst, src, REX_W::No);
|
||||||
|
@ -633,12 +638,8 @@ struct Assembler {
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (label.has_value()) {
|
if (overflow_label.has_value()) {
|
||||||
// jo label (RIP-relative 32-bit offset)
|
jump_if(Condition::Overflow, *overflow_label);
|
||||||
emit8(0x0f);
|
|
||||||
emit8(0x80);
|
|
||||||
emit32(0xdeadbeef);
|
|
||||||
label->add_jump(*this, m_output.size());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue