From 3bee99af3dafc2d1c045f3502723ef04b52f4287 Mon Sep 17 00:00:00 2001 From: Tom French Date: Wed, 28 Aug 2024 21:00:39 +0100 Subject: [PATCH] feat: remove unnecessary copying of vector size during reversal --- .../src/brillig/brillig_ir/codegen_memory.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_memory.rs b/compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_memory.rs index d20f736ee6d..ec3b080895b 100644 --- a/compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_memory.rs +++ b/compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_memory.rs @@ -263,20 +263,14 @@ impl BrilligContext { let index_at_end_of_array = self.allocate_register(); let end_value_register = self.allocate_register(); - self.codegen_loop(iteration_count, |ctx, iterator_register| { - // Load both values - ctx.codegen_array_get(vector.pointer, iterator_register, start_value_register); + self.mov_instruction(index_at_end_of_array, vector.size); + self.codegen_loop(iteration_count, |ctx, iterator_register| { // The index at the end of array is size - 1 - iterator - ctx.mov_instruction(index_at_end_of_array, vector.size); ctx.codegen_usize_op_in_place(index_at_end_of_array, BrilligBinaryOp::Sub, 1); - ctx.memory_op_instruction( - index_at_end_of_array, - iterator_register.address, - index_at_end_of_array, - BrilligBinaryOp::Sub, - ); + // Load both values + ctx.codegen_array_get(vector.pointer, iterator_register, start_value_register); ctx.codegen_array_get( vector.pointer, SingleAddrVariable::new_usize(index_at_end_of_array),