From 92313f582cc8fb807041e4dc93cd2b172b88d944 Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 4 Nov 2022 17:56:59 -0600 Subject: [PATCH] optimise sub; jle --- src/rust/codegen.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/rust/codegen.rs b/src/rust/codegen.rs index 00f471bf..0ff037a9 100644 --- a/src/rust/codegen.rs +++ b/src/rust/codegen.rs @@ -2157,6 +2157,49 @@ pub fn gen_test_le(ctx: &mut JitContext, negate: ConditionNegate) { ctx.builder.le_i32(); } }, + Instruction::Sub { + opsize, + dest: _, + source, + } => { + gen_profiler_stat_increment(ctx.builder, profiler::stat::CONDITION_OPTIMISED); + gen_get_last_op1(ctx.builder, &ctx.previous_instruction); + if *opsize == OPSIZE_8 || *opsize == OPSIZE_16 { + ctx.builder + .const_i32(if *opsize == OPSIZE_8 { 24 } else { 16 }); + ctx.builder.shl_i32(); + } + match (opsize, source) { + (&OPSIZE_32, InstructionOperand::WasmLocal(l)) => ctx.builder.get_local(l), + (_, &InstructionOperand::Immediate(i)) => ctx.builder.const_i32( + i << if *opsize == OPSIZE_32 { + 0 + } + else if *opsize == OPSIZE_16 { + 16 + } + else { + 24 + }, + ), + _ => { + gen_get_last_op1(ctx.builder, &ctx.previous_instruction); + gen_get_last_result(ctx.builder, &ctx.previous_instruction); + ctx.builder.sub_i32(); + if *opsize == OPSIZE_8 || *opsize == OPSIZE_16 { + ctx.builder + .const_i32(if *opsize == OPSIZE_8 { 24 } else { 16 }); + ctx.builder.shl_i32(); + } + }, + } + if negate == ConditionNegate::True { + ctx.builder.gt_i32(); + } + else { + ctx.builder.le_i32(); + } + }, _ => { gen_profiler_stat_increment(ctx.builder, profiler::stat::CONDITION_UNOPTIMISED); gen_test_l(ctx, ConditionNegate::False);