Skip to content

Commit 5739904

Browse files
authored
feat: remove unnecessary copying of vector size during reversal (#5852)
# Description ## Problem\* Resolves <!-- Link to GitHub Issue --> ## Summary\* In order to calculate `vector_size - 1 - iterator`, rather than initialising a register to `vector_size` and then decrementing it on each loop iteration, we're currently recalculating it from scratch on each iteration. I've modified this so that we can avoid these extra ops ## Additional Context ## Documentation\* Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
1 parent c23463e commit 5739904

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_memory.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -263,20 +263,14 @@ impl<F: AcirField + DebugToString> BrilligContext<F> {
263263
let index_at_end_of_array = self.allocate_register();
264264
let end_value_register = self.allocate_register();
265265

266-
self.codegen_loop(iteration_count, |ctx, iterator_register| {
267-
// Load both values
268-
ctx.codegen_array_get(vector.pointer, iterator_register, start_value_register);
266+
self.mov_instruction(index_at_end_of_array, vector.size);
269267

268+
self.codegen_loop(iteration_count, |ctx, iterator_register| {
270269
// The index at the end of array is size - 1 - iterator
271-
ctx.mov_instruction(index_at_end_of_array, vector.size);
272270
ctx.codegen_usize_op_in_place(index_at_end_of_array, BrilligBinaryOp::Sub, 1);
273-
ctx.memory_op_instruction(
274-
index_at_end_of_array,
275-
iterator_register.address,
276-
index_at_end_of_array,
277-
BrilligBinaryOp::Sub,
278-
);
279271

272+
// Load both values
273+
ctx.codegen_array_get(vector.pointer, iterator_register, start_value_register);
280274
ctx.codegen_array_get(
281275
vector.pointer,
282276
SingleAddrVariable::new_usize(index_at_end_of_array),

0 commit comments

Comments
 (0)