Skip to content

Commit

Permalink
Add number of add and mul gates to CircuitDescriptor. (starkware-libs…
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyalesokhin-starkware authored May 12, 2024
1 parent 8cda0b5 commit c57bf0d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion crates/cairo-lang-sierra-gas/src/core_libfunc_cost_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ pub fn core_libfunc_cost(
vec![ConstCost::steps(7).into(), ConstCost::steps(8).into()]
}
Circuit(CircuitConcreteLibfunc::GetDescriptor(_)) => {
vec![ConstCost::steps(3).into()]
vec![ConstCost::steps(6).into()]
}
Circuit(CircuitConcreteLibfunc::InitCircuitData(_)) => vec![ConstCost::steps(0).into()],
}
Expand Down
6 changes: 5 additions & 1 deletion crates/cairo-lang-sierra-to-casm/src/invocations/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fn build_get_descriptor(
circuit_ty: &ConcreteTypeId,
builder: CompiledInvocationBuilder<'_>,
) -> Result<CompiledInvocation, InvocationError> {
let CircuitInfo { add_offsets, .. } =
let CircuitInfo { add_offsets, mul_offsets, .. } =
builder.program_info.circuits_info.circuits.get(circuit_ty).unwrap();

let ctx = casm! {
Expand All @@ -111,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] = (add_offsets.len()), ap++;
[ap] = [ap - 1] + (add_offsets.len() * VALUE_SIZE), ap++;
[ap] = (mul_offsets.len()), ap++;
};

let relocations = vec![
Expand All @@ -129,6 +131,8 @@ fn build_get_descriptor(
relocations,
[vec![ReferenceExpression {
cells: vec![
CellExpression::Deref(CellRef { register: Register::AP, offset: -4 }),
CellExpression::Deref(CellRef { register: Register::AP, offset: -3 }),
CellExpression::Deref(CellRef { register: Register::AP, offset: -2 }),
CellExpression::Deref(CellRef { register: Register::AP, offset: -1 }),
],
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,8 +80,8 @@ pub fn get_type_size_map(
Some(size)
}

CoreTypeConcrete::Circuit(CircuitTypeConcrete::CircuitInputAccumulator(_))
| CoreTypeConcrete::Circuit(CircuitTypeConcrete::CircuitDescriptor(_)) => Some(2),
CoreTypeConcrete::Circuit(CircuitTypeConcrete::CircuitInputAccumulator(_)) => Some(2),
CoreTypeConcrete::Circuit(CircuitTypeConcrete::CircuitDescriptor(_)) => Some(4),
CoreTypeConcrete::Circuit(CircuitTypeConcrete::CircuitData(_))
| CoreTypeConcrete::Circuit(CircuitTypeConcrete::CircuitOutput(_))
| CoreTypeConcrete::Circuit(CircuitTypeConcrete::AddMod(_))
Expand Down
8 changes: 5 additions & 3 deletions tests/e2e_test_data/libfuncs/circuit
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,11 @@ fn foo() -> CircuitDescriptor<MyCircuit> {
}

//! > casm
call rel 7;
[ap + 0] = [ap + -1] + 6, ap++;
call rel 11;
[ap + 0] = [ap + -1] + 10, ap++;
[ap + 0] = 1, ap++;
[ap + 0] = [ap + -1] + 4, ap++;
[ap + 0] = 2, ap++;
ret;
ret;
dw 16;
Expand Down Expand Up @@ -170,7 +172,7 @@ return([0]); // 1
test::foo@0() -> (CircuitDescriptor<(core::circuit::AddModGate::<core::circuit::CircuitInput::<0>, core::circuit::CircuitInput::<1>>, core::circuit::CircuitInput::<2>)>);

//! > function_costs
test::foo: OrderedHashMap({Const: 300})
test::foo: OrderedHashMap({Const: 600})

//! > ==========================================================================

Expand Down

0 comments on commit c57bf0d

Please sign in to comment.