LibJIT: Use test x, x instead of cmp x, 0 in all cases

The `test` instruction will have the same result as `cmp` when
comparing to zero, so let's always emit that code. This has no effect
until the following commit.
This commit is contained in:
Zaggy1024 2023-10-29 04:51:25 -05:00 committed by Andreas Kling
commit e717961000
Notes: sideshowbarker 2024-07-17 04:09:56 +09:00

View file

@ -293,7 +293,9 @@ struct Assembler {
void cmp(Operand lhs, Operand rhs)
{
if (lhs.type == Operand::Type::Reg && rhs.type == Operand::Type::Reg) {
if (rhs.type == Operand::Type::Imm && rhs.offset_or_immediate == 0) {
test(lhs, lhs);
} else if (lhs.type == Operand::Type::Reg && rhs.type == Operand::Type::Reg) {
emit8(0x48
| ((to_underlying(rhs.reg) >= 8) ? 1 << 2 : 0)
| ((to_underlying(lhs.reg) >= 8) ? 1 << 0 : 0));