use crate::{
columns::{Column, ColumnIndexer},
serialization::interpreter::{N_LIMBS_LARGE, N_LIMBS_SMALL},
};
pub const FEC_N_COLUMNS: usize =
FECColumnInput::N_COL + FECColumnOutput::N_COL + FECColumnInter::N_COL;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum FECColumnInput {
XP(usize), YP(usize), XQ(usize), YQ(usize), }
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum FECColumnOutput {
XR(usize), YR(usize), }
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum FECColumnInter {
F(usize), S(usize), Q1(usize), Q2(usize), Q3(usize), Q1Sign, Q2Sign, Q3Sign, Q1L(usize), Q2L(usize), Q3L(usize), Carry1(usize), Carry2(usize), Carry3(usize), }
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum FECColumn {
Input(FECColumnInput),
Output(FECColumnOutput),
Inter(FECColumnInter),
}
impl ColumnIndexer for FECColumnInput {
const N_COL: usize = 4 * N_LIMBS_LARGE;
fn to_column(self) -> Column {
match self {
FECColumnInput::XP(i) => {
assert!(i < N_LIMBS_LARGE);
Column::Relation(i)
}
FECColumnInput::YP(i) => {
assert!(i < N_LIMBS_LARGE);
Column::Relation(N_LIMBS_LARGE + i)
}
FECColumnInput::XQ(i) => {
assert!(i < N_LIMBS_LARGE);
Column::Relation(2 * N_LIMBS_LARGE + i)
}
FECColumnInput::YQ(i) => {
assert!(i < N_LIMBS_LARGE);
Column::Relation(3 * N_LIMBS_LARGE + i)
}
}
}
}
impl ColumnIndexer for FECColumnOutput {
const N_COL: usize = 2 * N_LIMBS_SMALL;
fn to_column(self) -> Column {
match self {
FECColumnOutput::XR(i) => {
assert!(i < N_LIMBS_SMALL);
Column::Relation(i)
}
FECColumnOutput::YR(i) => {
assert!(i < N_LIMBS_SMALL);
Column::Relation(N_LIMBS_SMALL + i)
}
}
}
}
impl ColumnIndexer for FECColumnInter {
const N_COL: usize = 4 * N_LIMBS_LARGE + 10 * N_LIMBS_SMALL + 9;
fn to_column(self) -> Column {
match self {
FECColumnInter::F(i) => {
assert!(i < N_LIMBS_LARGE);
Column::Relation(i)
}
FECColumnInter::S(i) => {
assert!(i < N_LIMBS_SMALL);
Column::Relation(N_LIMBS_LARGE + i)
}
FECColumnInter::Q1(i) => {
assert!(i < N_LIMBS_SMALL);
Column::Relation(N_LIMBS_LARGE + N_LIMBS_SMALL + i)
}
FECColumnInter::Q2(i) => {
assert!(i < N_LIMBS_SMALL);
Column::Relation(N_LIMBS_LARGE + 2 * N_LIMBS_SMALL + i)
}
FECColumnInter::Q3(i) => {
assert!(i < N_LIMBS_SMALL);
Column::Relation(N_LIMBS_LARGE + 3 * N_LIMBS_SMALL + i)
}
FECColumnInter::Q1Sign => Column::Relation(N_LIMBS_LARGE + 4 * N_LIMBS_SMALL),
FECColumnInter::Q2Sign => Column::Relation(N_LIMBS_LARGE + 4 * N_LIMBS_SMALL + 1),
FECColumnInter::Q3Sign => Column::Relation(N_LIMBS_LARGE + 4 * N_LIMBS_SMALL + 2),
FECColumnInter::Q1L(i) => {
assert!(i < N_LIMBS_LARGE);
Column::Relation(N_LIMBS_LARGE + 4 * N_LIMBS_SMALL + 3 + i)
}
FECColumnInter::Q2L(i) => {
assert!(i < N_LIMBS_LARGE);
Column::Relation(2 * N_LIMBS_LARGE + 4 * N_LIMBS_SMALL + 3 + i)
}
FECColumnInter::Q3L(i) => {
assert!(i < N_LIMBS_LARGE);
Column::Relation(3 * N_LIMBS_LARGE + 4 * N_LIMBS_SMALL + 3 + i)
}
FECColumnInter::Carry1(i) => {
assert!(i < 2 * N_LIMBS_SMALL + 2);
Column::Relation(4 * N_LIMBS_LARGE + 4 * N_LIMBS_SMALL + 3 + i)
}
FECColumnInter::Carry2(i) => {
assert!(i < 2 * N_LIMBS_SMALL + 2);
Column::Relation(4 * N_LIMBS_LARGE + 6 * N_LIMBS_SMALL + 5 + i)
}
FECColumnInter::Carry3(i) => {
assert!(i < 2 * N_LIMBS_SMALL + 2);
Column::Relation(4 * N_LIMBS_LARGE + 8 * N_LIMBS_SMALL + 7 + i)
}
}
}
}
impl ColumnIndexer for FECColumn {
const N_COL: usize = FEC_N_COLUMNS;
fn to_column(self) -> Column {
match self {
FECColumn::Input(input) => input.to_column(),
FECColumn::Inter(inter) => inter.to_column().add_rel_offset(FECColumnInput::N_COL),
FECColumn::Output(output) => output
.to_column()
.add_rel_offset(FECColumnInput::N_COL + FECColumnInter::N_COL),
}
}
}