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

update the names of add_ap opcodes #341

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 7 additions & 8 deletions stwo_cairo_prover/crates/prover/src/cairo_air/debug_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ use stwo_prover::core::poly::circle::CanonicCoset;

use super::air::CairoClaim;
use crate::components::{
add_ap_opcode_is_imm_f_op_1_base_fp_f, add_ap_opcode_is_imm_f_op_1_base_fp_t,
add_ap_opcode_is_imm_t_op_1_base_fp_f, add_opcode_is_small_f_is_imm_f,
add_ap_opcode, add_ap_opcode_imm, add_ap_opcode_op_1_base_fp, add_opcode_is_small_f_is_imm_f,
add_opcode_is_small_f_is_imm_t, add_opcode_is_small_t_is_imm_f, add_opcode_is_small_t_is_imm_t,
assert_eq_opcode_is_double_deref_f_is_imm_f, assert_eq_opcode_is_double_deref_f_is_imm_t,
assert_eq_opcode_is_double_deref_t_is_imm_f, call_opcode_is_rel_f_op_1_base_fp_f,
Expand Down Expand Up @@ -119,11 +118,11 @@ where
.entries(trace),
);
}
for claim in claim.opcodes.add_ap_f_f.clone() {
for claim in claim.opcodes.add_ap.clone() {
entries.extend(
RelationTrackerComponent::new(
tree_span_provider,
add_ap_opcode_is_imm_f_op_1_base_fp_f::Eval {
add_ap_opcode::Eval {
claim,
memory_address_to_id_lookup_elements: relations::MemoryAddressToId::dummy(),
memory_id_to_big_lookup_elements: relations::MemoryIdToBig::dummy(),
Expand All @@ -135,11 +134,11 @@ where
.entries(trace),
);
}
for claim in claim.opcodes.add_ap_f_t.clone() {
for claim in claim.opcodes.add_ap_op_1_base_fp.clone() {
entries.extend(
RelationTrackerComponent::new(
tree_span_provider,
add_ap_opcode_is_imm_f_op_1_base_fp_t::Eval {
add_ap_opcode_op_1_base_fp::Eval {
claim,
memory_address_to_id_lookup_elements: relations::MemoryAddressToId::dummy(),
memory_id_to_big_lookup_elements: relations::MemoryIdToBig::dummy(),
Expand All @@ -151,11 +150,11 @@ where
.entries(trace),
);
}
for claim in claim.opcodes.add_ap_t_f.clone() {
for claim in claim.opcodes.add_ap_imm.clone() {
entries.extend(
RelationTrackerComponent::new(
tree_span_provider,
add_ap_opcode_is_imm_t_op_1_base_fp_f::Eval {
add_ap_opcode_imm::Eval {
claim,
memory_address_to_id_lookup_elements: relations::MemoryAddressToId::dummy(),
memory_id_to_big_lookup_elements: relations::MemoryIdToBig::dummy(),
Expand Down
183 changes: 86 additions & 97 deletions stwo_cairo_prover/crates/prover/src/cairo_air/opcodes_air.rs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use num_traits::{One, Zero};
use serde::{Deserialize, Serialize};
use stwo_cairo_serialize::CairoSerialize;
use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements};
use stwo_prover::constraint_framework::preprocessed_columns::PreprocessedColumn;
use stwo_prover::constraint_framework::{
EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ use itertools::{chain, zip_eq, Itertools};
use num_traits::{One, Zero};
use prover_types::cpu::*;
use prover_types::simd::*;
use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator};
use rayon::iter::{
IndexedParallelIterator, IntoParallelIterator, IntoParallelRefIterator, ParallelIterator,
};
use stwo_air_utils::trace::component_trace::ComponentTrace;
use stwo_air_utils_derive::{IterMut, ParIterMut, Uninitialized};
use stwo_prover::constraint_framework::logup::LogupTraceGenerator;
use stwo_prover::constraint_framework::preprocessed_columns::PreprocessedColumn;
use stwo_prover::constraint_framework::Relation;
use stwo_prover::core::air::Component;
use stwo_prover::core::backend::simd::column::BaseColumn;
Expand All @@ -21,6 +24,7 @@ use stwo_prover::core::backend::simd::SimdBackend;
use stwo_prover::core::backend::{BackendForChannel, Col, Column};
use stwo_prover::core::channel::{Channel, MerkleChannel};
use stwo_prover::core::fields::m31::M31;
use stwo_prover::core::fields::FieldExpOps;
use stwo_prover::core::pcs::TreeBuilder;
use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation};
use stwo_prover::core::poly::BitReversedOrder;
Expand Down Expand Up @@ -66,6 +70,7 @@ impl ClaimGenerator {

let packed_inputs = pack_values(&self.inputs);
let (trace, mut sub_components_inputs, lookup_data) = write_trace_simd(
n_rows,
packed_inputs,
memory_address_to_id_state,
memory_id_to_big_state,
Expand Down Expand Up @@ -104,8 +109,8 @@ impl ClaimGenerator {
)
}

pub fn add_inputs(&mut self, inputs: &[InputType]) {
self.inputs.extend(inputs);
pub fn add_inputs(&self, _inputs: &[InputType]) {
unimplemented!("Implement manually");
}
}

Expand All @@ -121,6 +126,7 @@ pub struct SubComponentInputs {
#[allow(clippy::double_parens)]
#[allow(non_snake_case)]
fn write_trace_simd(
n_rows: usize,
inputs: Vec<PackedInputType>,
memory_address_to_id_state: &memory_address_to_id::ClaimGenerator,
memory_id_to_big_state: &memory_id_to_big::ClaimGenerator,
Expand Down Expand Up @@ -156,41 +162,41 @@ fn write_trace_simd(

trace
.par_iter_mut()
.zip(inputs.par_iter())
.enumerate()
.zip(inputs.into_par_iter())
.zip(lookup_data.par_iter_mut())
.zip(sub_components_inputs.par_iter_mut().chunks(N_LANES))
.for_each(
|(
((row, add_ap_opcode_is_imm_f_op_1_base_fp_f_input), lookup_data),
(((row_index, row), add_ap_opcode_input), lookup_data),
mut sub_components_inputs,
)| {
let input_tmp_8b744_0 = add_ap_opcode_is_imm_f_op_1_base_fp_f_input;
let input_pc_col0 = input_tmp_8b744_0.pc;
let input_tmp_c921e_0 = add_ap_opcode_input;
let input_pc_col0 = input_tmp_c921e_0.pc;
*row[0] = input_pc_col0;
let input_ap_col1 = input_tmp_8b744_0.ap;
let input_ap_col1 = input_tmp_c921e_0.ap;
*row[1] = input_ap_col1;
let input_fp_col2 = input_tmp_8b744_0.fp;
let input_fp_col2 = input_tmp_c921e_0.fp;
*row[2] = input_fp_col2;

// Decode Instruction.

let memory_address_to_id_value_tmp_8b744_1 =
let memory_address_to_id_value_tmp_c921e_1 =
memory_address_to_id_state.deduce_output(input_pc_col0);
let memory_id_to_big_value_tmp_8b744_2 =
memory_id_to_big_state.deduce_output(memory_address_to_id_value_tmp_8b744_1);
let offset2_tmp_8b744_3 =
((((PackedUInt16::from_m31(memory_id_to_big_value_tmp_8b744_2.get_m31(3)))
let memory_id_to_big_value_tmp_c921e_2 =
memory_id_to_big_state.deduce_output(memory_address_to_id_value_tmp_c921e_1);
let offset2_tmp_c921e_3 =
((((PackedUInt16::from_m31(memory_id_to_big_value_tmp_c921e_2.get_m31(3)))
>> (UInt16_5))
+ ((PackedUInt16::from_m31(
memory_id_to_big_value_tmp_8b744_2.get_m31(4),
memory_id_to_big_value_tmp_c921e_2.get_m31(4),
)) << (UInt16_4)))
+ (((PackedUInt16::from_m31(
memory_id_to_big_value_tmp_8b744_2.get_m31(5),
memory_id_to_big_value_tmp_c921e_2.get_m31(5),
)) & (UInt16_7))
<< (UInt16_13)));
let offset2_col3 = offset2_tmp_8b744_3.as_m31();
let offset2_col3 = offset2_tmp_c921e_3.as_m31();
*row[3] = offset2_col3;

for (i, &input) in (
input_pc_col0,
[M31_32767, M31_32767, offset2_col3],
Expand Down Expand Up @@ -229,11 +235,11 @@ fn write_trace_simd(

// Read Small.

let memory_address_to_id_value_tmp_8b744_4 = memory_address_to_id_state
let memory_address_to_id_value_tmp_c921e_4 = memory_address_to_id_state
.deduce_output(((input_ap_col1) + ((offset2_col3) - (M31_32768))));
let memory_id_to_big_value_tmp_8b744_5 =
memory_id_to_big_state.deduce_output(memory_address_to_id_value_tmp_8b744_4);
let op1_id_col4 = memory_address_to_id_value_tmp_8b744_4;
let memory_id_to_big_value_tmp_c921e_5 =
memory_id_to_big_state.deduce_output(memory_address_to_id_value_tmp_c921e_4);
let op1_id_col4 = memory_address_to_id_value_tmp_c921e_4;
*row[4] = op1_id_col4;
for (i, &input) in ((input_ap_col1) + ((offset2_col3) - (M31_32768)))
.unpack()
Expand All @@ -249,19 +255,19 @@ fn write_trace_simd(

// Cond Decode Small Sign.

let msb_tmp_8b744_6 = memory_id_to_big_value_tmp_8b744_5.get_m31(27).eq(M31_256);
let msb_col5 = msb_tmp_8b744_6.as_m31();
let msb_tmp_c921e_6 = memory_id_to_big_value_tmp_c921e_5.get_m31(27).eq(M31_256);
let msb_col5 = msb_tmp_c921e_6.as_m31();
*row[5] = msb_col5;
let mid_limbs_set_tmp_8b744_7 =
memory_id_to_big_value_tmp_8b744_5.get_m31(20).eq(M31_511);
let mid_limbs_set_col6 = mid_limbs_set_tmp_8b744_7.as_m31();
let mid_limbs_set_tmp_c921e_7 =
memory_id_to_big_value_tmp_c921e_5.get_m31(20).eq(M31_511);
let mid_limbs_set_col6 = mid_limbs_set_tmp_c921e_7.as_m31();
*row[6] = mid_limbs_set_col6;

let op1_limb_0_col7 = memory_id_to_big_value_tmp_8b744_5.get_m31(0);
let op1_limb_0_col7 = memory_id_to_big_value_tmp_c921e_5.get_m31(0);
*row[7] = op1_limb_0_col7;
let op1_limb_1_col8 = memory_id_to_big_value_tmp_8b744_5.get_m31(1);
let op1_limb_1_col8 = memory_id_to_big_value_tmp_c921e_5.get_m31(1);
*row[8] = op1_limb_1_col8;
let op1_limb_2_col9 = memory_id_to_big_value_tmp_8b744_5.get_m31(2);
let op1_limb_2_col9 = memory_id_to_big_value_tmp_c921e_5.get_m31(2);
*row[9] = op1_limb_2_col9;
for (i, &input) in op1_id_col4.unpack().iter().enumerate() {
*sub_components_inputs[i].memory_id_to_big_inputs[0] = input;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use num_traits::{One, Zero};
use serde::{Deserialize, Serialize};
use stwo_cairo_serialize::CairoSerialize;
use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements};
use stwo_prover::constraint_framework::preprocessed_columns::PreprocessedColumn;
use stwo_prover::constraint_framework::{
EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ use itertools::{chain, zip_eq, Itertools};
use num_traits::{One, Zero};
use prover_types::cpu::*;
use prover_types::simd::*;
use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator};
use rayon::iter::{
IndexedParallelIterator, IntoParallelIterator, IntoParallelRefIterator, ParallelIterator,
};
use stwo_air_utils::trace::component_trace::ComponentTrace;
use stwo_air_utils_derive::{IterMut, ParIterMut, Uninitialized};
use stwo_prover::constraint_framework::logup::LogupTraceGenerator;
use stwo_prover::constraint_framework::preprocessed_columns::PreprocessedColumn;
use stwo_prover::constraint_framework::Relation;
use stwo_prover::core::air::Component;
use stwo_prover::core::backend::simd::column::BaseColumn;
Expand All @@ -21,6 +24,7 @@ use stwo_prover::core::backend::simd::SimdBackend;
use stwo_prover::core::backend::{BackendForChannel, Col, Column};
use stwo_prover::core::channel::{Channel, MerkleChannel};
use stwo_prover::core::fields::m31::M31;
use stwo_prover::core::fields::FieldExpOps;
use stwo_prover::core::pcs::TreeBuilder;
use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation};
use stwo_prover::core::poly::BitReversedOrder;
Expand Down Expand Up @@ -66,6 +70,7 @@ impl ClaimGenerator {

let packed_inputs = pack_values(&self.inputs);
let (trace, mut sub_components_inputs, lookup_data) = write_trace_simd(
n_rows,
packed_inputs,
memory_address_to_id_state,
memory_id_to_big_state,
Expand Down Expand Up @@ -104,8 +109,8 @@ impl ClaimGenerator {
)
}

pub fn add_inputs(&mut self, inputs: &[InputType]) {
self.inputs.extend(inputs);
pub fn add_inputs(&self, _inputs: &[InputType]) {
unimplemented!("Implement manually");
}
}

Expand All @@ -121,6 +126,7 @@ pub struct SubComponentInputs {
#[allow(clippy::double_parens)]
#[allow(non_snake_case)]
fn write_trace_simd(
n_rows: usize,
inputs: Vec<PackedInputType>,
memory_address_to_id_state: &memory_address_to_id::ClaimGenerator,
memory_id_to_big_state: &memory_id_to_big::ClaimGenerator,
Expand Down Expand Up @@ -153,29 +159,29 @@ fn write_trace_simd(

trace
.par_iter_mut()
.zip(inputs.par_iter())
.enumerate()
.zip(inputs.into_par_iter())
.zip(lookup_data.par_iter_mut())
.zip(sub_components_inputs.par_iter_mut().chunks(N_LANES))
.for_each(
|(
((row, add_ap_opcode_is_imm_t_op_1_base_fp_f_input), lookup_data),
(((row_index, row), add_ap_opcode_imm_input), lookup_data),
mut sub_components_inputs,
)| {
let input_tmp_38a0f_0 = add_ap_opcode_is_imm_t_op_1_base_fp_f_input;
let input_pc_col0 = input_tmp_38a0f_0.pc;
let input_tmp_f4f1f_0 = add_ap_opcode_imm_input;
let input_pc_col0 = input_tmp_f4f1f_0.pc;
*row[0] = input_pc_col0;
let input_ap_col1 = input_tmp_38a0f_0.ap;
let input_ap_col1 = input_tmp_f4f1f_0.ap;
*row[1] = input_ap_col1;
let input_fp_col2 = input_tmp_38a0f_0.fp;
let input_fp_col2 = input_tmp_f4f1f_0.fp;
*row[2] = input_fp_col2;

// Decode Instruction.

let memory_address_to_id_value_tmp_38a0f_1 =
let memory_address_to_id_value_tmp_f4f1f_1 =
memory_address_to_id_state.deduce_output(input_pc_col0);
let memory_id_to_big_value_tmp_38a0f_2 =
memory_id_to_big_state.deduce_output(memory_address_to_id_value_tmp_38a0f_1);

let memory_id_to_big_value_tmp_f4f1f_2 =
memory_id_to_big_state.deduce_output(memory_address_to_id_value_tmp_f4f1f_1);
for (i, &input) in (
input_pc_col0,
[M31_32767, M31_32767, M31_32769],
Expand Down Expand Up @@ -214,11 +220,11 @@ fn write_trace_simd(

// Read Small.

let memory_address_to_id_value_tmp_38a0f_3 =
let memory_address_to_id_value_tmp_f4f1f_3 =
memory_address_to_id_state.deduce_output(((input_pc_col0) + (M31_1)));
let memory_id_to_big_value_tmp_38a0f_4 =
memory_id_to_big_state.deduce_output(memory_address_to_id_value_tmp_38a0f_3);
let op1_id_col3 = memory_address_to_id_value_tmp_38a0f_3;
let memory_id_to_big_value_tmp_f4f1f_4 =
memory_id_to_big_state.deduce_output(memory_address_to_id_value_tmp_f4f1f_3);
let op1_id_col3 = memory_address_to_id_value_tmp_f4f1f_3;
*row[3] = op1_id_col3;
for (i, &input) in ((input_pc_col0) + (M31_1)).unpack().iter().enumerate() {
*sub_components_inputs[i].memory_address_to_id_inputs[0] = input;
Expand All @@ -227,19 +233,19 @@ fn write_trace_simd(

// Cond Decode Small Sign.

let msb_tmp_38a0f_5 = memory_id_to_big_value_tmp_38a0f_4.get_m31(27).eq(M31_256);
let msb_col4 = msb_tmp_38a0f_5.as_m31();
let msb_tmp_f4f1f_5 = memory_id_to_big_value_tmp_f4f1f_4.get_m31(27).eq(M31_256);
let msb_col4 = msb_tmp_f4f1f_5.as_m31();
*row[4] = msb_col4;
let mid_limbs_set_tmp_38a0f_6 =
memory_id_to_big_value_tmp_38a0f_4.get_m31(20).eq(M31_511);
let mid_limbs_set_col5 = mid_limbs_set_tmp_38a0f_6.as_m31();
let mid_limbs_set_tmp_f4f1f_6 =
memory_id_to_big_value_tmp_f4f1f_4.get_m31(20).eq(M31_511);
let mid_limbs_set_col5 = mid_limbs_set_tmp_f4f1f_6.as_m31();
*row[5] = mid_limbs_set_col5;

let op1_limb_0_col6 = memory_id_to_big_value_tmp_38a0f_4.get_m31(0);
let op1_limb_0_col6 = memory_id_to_big_value_tmp_f4f1f_4.get_m31(0);
*row[6] = op1_limb_0_col6;
let op1_limb_1_col7 = memory_id_to_big_value_tmp_38a0f_4.get_m31(1);
let op1_limb_1_col7 = memory_id_to_big_value_tmp_f4f1f_4.get_m31(1);
*row[7] = op1_limb_1_col7;
let op1_limb_2_col8 = memory_id_to_big_value_tmp_38a0f_4.get_m31(2);
let op1_limb_2_col8 = memory_id_to_big_value_tmp_f4f1f_4.get_m31(2);
*row[8] = op1_limb_2_col8;
for (i, &input) in op1_id_col3.unpack().iter().enumerate() {
*sub_components_inputs[i].memory_id_to_big_inputs[0] = input;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use num_traits::{One, Zero};
use serde::{Deserialize, Serialize};
use stwo_cairo_serialize::CairoSerialize;
use stwo_prover::constraint_framework::logup::{LogupAtRow, LogupSums, LookupElements};
use stwo_prover::constraint_framework::preprocessed_columns::PreprocessedColumn;
use stwo_prover::constraint_framework::{
EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry,
};
Expand Down
Loading
Loading