Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
fcarreiro committed Mar 11, 2024
1 parent 8cbedf6 commit 3d4dd66
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 3 additions & 10 deletions noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 3d4dd66

Please sign in to comment.