Skip to content

Commit

Permalink
Add mulmod offsets to CircuitDescriptor. (starkware-libs#5532)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyalesokhin-starkware authored May 12, 2024
1 parent cd81050 commit 0ba77c2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
15 changes: 11 additions & 4 deletions crates/cairo-lang-sierra-to-casm/src/invocations/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ fn build_get_descriptor(
circuit_ty: &ConcreteTypeId,
builder: CompiledInvocationBuilder<'_>,
) -> Result<CompiledInvocation, InvocationError> {
let CircuitInfo { add_offsets, .. } =
builder.program_info.circuits_info.circuits.get(circuit_ty).unwrap();

let ctx = casm! {
// The relocation will point the `call` to the `ret;` instruction that precedes the
// relevant const.
Expand All @@ -108,7 +111,9 @@ fn build_get_descriptor(
// constant value (the `1` is to skip the `ret` instruction).
// TODO(Gil): Support relocatable CellExpression and return an unstored "[ap - 1] + 1".
[ap] = [ap - 1] + 1, ap++;
[ap] = [ap - 1] + (add_offsets.len() * VALUE_SIZE), ap++;
};

let relocations = vec![
RelocationEntry {
instruction_idx: 0,
Expand All @@ -122,10 +127,12 @@ fn build_get_descriptor(
Ok(builder.build(
ctx.instructions,
relocations,
[vec![ReferenceExpression::from_cell(CellExpression::Deref(CellRef {
register: Register::AP,
offset: -1,
}))]
[vec![ReferenceExpression {
cells: vec![
CellExpression::Deref(CellRef { register: Register::AP, offset: -2 }),
CellExpression::Deref(CellRef { register: Register::AP, offset: -1 }),
],
}]
.into_iter()]
.into_iter(),
))
Expand Down
4 changes: 2 additions & 2 deletions crates/cairo-lang-sierra-type-size/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ pub fn get_type_size_map(
Some(size)
}

CoreTypeConcrete::Circuit(CircuitTypeConcrete::CircuitInputAccumulator(_)) => Some(2),
CoreTypeConcrete::Circuit(CircuitTypeConcrete::CircuitInputAccumulator(_))
| CoreTypeConcrete::Circuit(CircuitTypeConcrete::CircuitDescriptor(_)) => Some(2),
CoreTypeConcrete::Circuit(CircuitTypeConcrete::CircuitData(_))
| CoreTypeConcrete::Circuit(CircuitTypeConcrete::CircuitOutput(_))
| CoreTypeConcrete::Circuit(CircuitTypeConcrete::CircuitDescriptor(_))
| CoreTypeConcrete::Circuit(CircuitTypeConcrete::AddMod(_))
| CoreTypeConcrete::Circuit(CircuitTypeConcrete::MulMod(_)) => Some(1),

Expand Down
3 changes: 2 additions & 1 deletion tests/e2e_test_data/libfuncs/circuit
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ fn foo() -> CircuitDescriptor<MyCircuit> {
}

//! > casm
call rel 5;
call rel 7;
[ap + 0] = [ap + -1] + 6, ap++;
[ap + 0] = [ap + -1] + 4, ap++;
ret;
ret;
Expand Down

0 comments on commit 0ba77c2

Please sign in to comment.