From 3d4dd6619a004b8b54280fdf7c1604a378dcecc7 Mon Sep 17 00:00:00 2001 From: fcarreiro Date: Mon, 11 Mar 2024 09:39:08 +0000 Subject: [PATCH] address comments --- .../src/brillig/brillig_gen/brillig_block.rs | 13 ++----------- .../noirc_evaluator/src/brillig/brillig_ir.rs | 13 +++---------- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs b/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs index 64a2b59daa9..0189a499d49 100644 --- a/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs +++ b/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs @@ -832,18 +832,9 @@ impl<'block> BrilligBlock<'block> { }; // Here we want to compare the reference count against 1. - // I don't think we have the bit_size for the reference count available, so I'm hardcoding it. - let bit_size = usize::BITS; - let one = self.brillig_context.make_constant(1_usize.into(), bit_size); + let one = self.brillig_context.make_usize_constant(1_usize.into()); let condition = self.brillig_context.allocate_register(); - - self.brillig_context.binary_instruction( - reference_count, - one, - condition, - BrilligBinaryOp::Integer { op: BinaryIntOp::Equals, bit_size }, - ); - + self.brillig_context.memory_op(reference_count, one, condition, BinaryIntOp::Equals); self.brillig_context.branch_instruction(condition, |ctx, cond| { if cond { // Reference count is 1, we can mutate the array directly diff --git a/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir.rs b/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir.rs index 57050cafaa5..b66efa4da27 100644 --- a/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir.rs +++ b/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir.rs @@ -212,16 +212,7 @@ impl BrilligContext { self.debug_show.array_get(array_ptr, index, result); // Computes array_ptr + index, ie array[index] let index_of_element_in_memory = self.allocate_register(); - self.binary_instruction( - array_ptr, - index, - index_of_element_in_memory, - BrilligBinaryOp::Integer { - op: BinaryIntOp::Add, - bit_size: BRILLIG_MEMORY_ADDRESSING_BIT_SIZE, - }, - ); - + self.memory_op(array_ptr, index, index_of_element_in_memory, BinaryIntOp::Add); self.load_instruction(result, index_of_element_in_memory); // Free up temporary register self.deallocate_register(index_of_element_in_memory); @@ -731,6 +722,8 @@ impl BrilligContext { /// Instead truncation instructions are emitted as to when a /// truncation should be done. /// For Brillig, all integer operations will overflow as its cheap. + /// We currently use cast to truncate: we cast to the required bit size + /// and back to the original bit size. pub(crate) fn truncate_instruction( &mut self, destination_of_truncated_value: SingleAddrVariable,