use super::buses::{
ChipletActiveFlags,
chiplet_responses::{self, emit_chiplet_responses},
hash_kernel::{self, emit_hash_kernel_table},
wiring::{self, emit_v_wiring},
};
use crate::{ChipletCols, Felt, lookup::LookupBuilder};
pub(crate) trait ChipletLookupBuilder: LookupBuilder<F = Felt> {
fn build_chiplet_active(
&self,
local: &ChipletCols<Self::Var>,
) -> ChipletActiveFlags<Self::Expr> {
ChipletActiveFlags::from_chiplet_cols(local)
}
}
pub(crate) struct ChipletBusContext<'a, LB>
where
LB: LookupBuilder<F = Felt>,
{
pub local: &'a ChipletCols<LB::Var>,
pub next: &'a ChipletCols<LB::Var>,
pub chiplet_active: ChipletActiveFlags<LB::Expr>,
}
impl<'a, LB> ChipletBusContext<'a, LB>
where
LB: ChipletLookupBuilder,
{
pub fn new(
builder: &LB,
local: &'a ChipletCols<LB::Var>,
next: &'a ChipletCols<LB::Var>,
) -> Self {
let chiplet_active = builder.build_chiplet_active(local);
Self { local, next, chiplet_active }
}
}
pub(crate) const CHIPLET_COLUMN_SHAPE: [usize; 3] = [
chiplet_responses::MAX_INTERACTIONS_PER_ROW,
hash_kernel::MAX_INTERACTIONS_PER_ROW,
wiring::MAX_INTERACTIONS_PER_ROW,
];
pub(crate) fn emit_chiplet_lookup_columns<LB: ChipletLookupBuilder>(
builder: &mut LB,
local: &ChipletCols<LB::Var>,
next: &ChipletCols<LB::Var>,
) {
let ctx = ChipletBusContext::new(&*builder, local, next);
emit_chiplet_responses::<LB>(builder, &ctx);
emit_hash_kernel_table::<LB>(builder, &ctx);
emit_v_wiring::<LB>(builder, &ctx);
}