From be08d812db94a2f2b981fc950e48cb796eb72a15 Mon Sep 17 00:00:00 2001 From: Fabian Date: Thu, 3 Nov 2022 12:29:18 -0600 Subject: [PATCH] move code around (local_to_instruction_operand/LocalOrImmediate.to_instruction_operand) --- src/rust/jit_instructions.rs | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/rust/jit_instructions.rs b/src/rust/jit_instructions.rs index 449a5a4c..9e3ede9e 100644 --- a/src/rust/jit_instructions.rs +++ b/src/rust/jit_instructions.rs @@ -51,6 +51,23 @@ impl<'a> LocalOrImmediate<'a> { _ => false, } } + + fn to_instruction_operand(&self, ctx: &mut JitContext) -> InstructionOperand { + match self { + &LocalOrImmediate::WasmLocal(source) => local_to_instruction_operand(ctx, source), + &LocalOrImmediate::Immediate(i) => InstructionOperand::Immediate(i), + } + } +} + +fn local_to_instruction_operand(ctx: &mut JitContext, local: &WasmLocal) -> InstructionOperand { + if ctx.register_locals.iter().any(|l| l == local) { + // safe because register locals are alive for the duration of the entire function + InstructionOperand::WasmLocal(local.unsafe_clone()) + } + else { + InstructionOperand::Other + } } pub fn jit_instruction(ctx: &mut JitContext, instr_flags: &mut u32) { @@ -1017,23 +1034,8 @@ fn gen_cmp( size: i32, ) { ctx.current_instruction = Instruction::Cmp { - dest: if ctx.register_locals.iter().any(|l| l == dest_operand) { - InstructionOperand::WasmLocal(dest_operand.unsafe_clone()) - } - else { - InstructionOperand::Other - }, - source: match source_operand { - &LocalOrImmediate::WasmLocal(source) => { - if ctx.register_locals.iter().any(|l| l == source) { - InstructionOperand::WasmLocal(source.unsafe_clone()) - } - else { - InstructionOperand::Other - } - }, - &LocalOrImmediate::Immediate(i) => InstructionOperand::Immediate(i), - }, + dest: local_to_instruction_operand(ctx, dest_operand), + source: source_operand.to_instruction_operand(ctx), opsize: size, };