From 8f15b554ee6ebcc8e1b809a1c1b88963ad92cc88 Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 4 Nov 2022 14:39:56 -0600 Subject: [PATCH] optimise cmp8/16 x, imm; jc --- src/rust/codegen.rs | 35 +++++++---------------------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/src/rust/codegen.rs b/src/rust/codegen.rs index 2d8ba36b..d4afc43f 100644 --- a/src/rust/codegen.rs +++ b/src/rust/codegen.rs @@ -1692,37 +1692,16 @@ pub fn gen_getzf(ctx: &mut JitContext, negate: ConditionNegate) { pub fn gen_getcf(ctx: &mut JitContext, negate: ConditionNegate) { match &ctx.previous_instruction { - Instruction::Cmp { - dest, - source, - opsize, - } => { + Instruction::Cmp { source, opsize, .. } => { // TODO: add/sub + // Note: x < y and x < x - y can be used interchangeably (see getcf) gen_profiler_stat_increment(ctx.builder, profiler::stat::CONDITION_OPTIMISED); - if source == &InstructionOperand::Other || *opsize != OPSIZE_32 { - gen_get_last_op1(ctx.builder, &ctx.previous_instruction); - gen_get_last_result(ctx.builder, &ctx.previous_instruction); + gen_get_last_op1(ctx.builder, &ctx.previous_instruction); + match (opsize, source) { + (&OPSIZE_32, InstructionOperand::WasmLocal(l)) => ctx.builder.get_local(l), + (_, &InstructionOperand::Immediate(i)) => ctx.builder.const_i32(i), + _ => gen_get_last_result(ctx.builder, &ctx.previous_instruction), } - else { - match dest { - InstructionOperandDest::WasmLocal(l) => { - ctx.builder.get_local(l); - }, - InstructionOperandDest::Other => { - gen_get_last_op1(ctx.builder, &ctx.previous_instruction); - }, - } - match source { - InstructionOperand::WasmLocal(l) => { - ctx.builder.get_local(l); - }, - InstructionOperand::Other => panic!(), - &InstructionOperand::Immediate(i) => { - ctx.builder.const_i32(i); - }, - } - } - if negate == ConditionNegate::True { ctx.builder.geu_i32(); }