Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ssa): add block opcode #1291

Merged
merged 2 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/noirc_evaluator/src/ssa/acir_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Acir {
//TODO we should rather follow the jumps
current_block = block.left.map(|block_id| &ctx[block_id]);
}
self.memory.acir_gen(evaluator);
self.memory.acir_gen(evaluator, ctx);
Ok(())
}

Expand Down
26 changes: 13 additions & 13 deletions crates/noirc_evaluator/src/ssa/acir_gen/acir_mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use crate::{
};
use acvm::{
acir::{
circuit::{directives::Directive, opcodes::Opcode as AcirOpcode},
circuit::{
directives::Directive,
opcodes::{BlockId as AcirBlockId, MemOp, MemoryBlock, Opcode as AcirOpcode},
},
native_types::{Expression, Witness},
},
FieldElement,
Expand All @@ -22,15 +25,6 @@ use super::{
operations::{self},
};

/// Represent a memory operation on the ArrayHeap, at the specified index
/// Operation is one for a store and 0 for a load
#[derive(Clone, Debug)]
pub(crate) struct MemOp {
operation: Expression,
value: Expression,
index: Expression,
}

type MemAddress = u32;

enum ArrayType {
Expand Down Expand Up @@ -137,7 +131,7 @@ impl ArrayHeap {
outputs
}

pub(crate) fn acir_gen(&self, evaluator: &mut Evaluator) {
pub(crate) fn acir_gen(&self, evaluator: &mut Evaluator, array_id: ArrayId, array_len: u32) {
let (len, read_write) = match self.typ {
ArrayType::Init(_, _) | ArrayType::WriteOnly => (0, true),
ArrayType::ReadOnly(last) => (last.unwrap_or(self.trace.len()), false),
Expand All @@ -147,6 +141,11 @@ impl ArrayHeap {
if len == 0 {
return;
}
evaluator.opcodes.push(AcirOpcode::Block(MemoryBlock {
id: AcirBlockId(array_id.as_u32()),
len: array_len,
trace: self.trace.clone(),
}));
let len_bits = AcirMem::bits(len);
// permutations
let mut in_counter = Vec::new();
Expand Down Expand Up @@ -318,9 +317,10 @@ impl AcirMem {
let item = MemOp { operation: op, value, index };
self.array_heap_mut(*array_id).push(item);
}
pub(crate) fn acir_gen(&self, evaluator: &mut Evaluator) {
pub(crate) fn acir_gen(&self, evaluator: &mut Evaluator, ctx: &SsaContext) {
for mem in &self.virtual_memory {
mem.1.acir_gen(evaluator);
let array = &ctx.mem[*mem.0];
mem.1.acir_gen(evaluator, array.id, array.len);
}
}
}
4 changes: 4 additions & 0 deletions crates/noirc_evaluator/src/ssa/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ impl ArrayId {
pub(crate) fn dummy() -> ArrayId {
ArrayId(std::u32::MAX)
}

pub(crate) fn as_u32(&self) -> u32 {
self.0
}
}

/// MemArray represents a contiguous array of elements of the same type.
Expand Down