miden_ace_codegen/layout/
keys.rs1use super::InputLayout;
2use crate::EXT_DEGREE;
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6pub enum InputKey {
7 Public(usize),
9 AuxRandAlpha,
11 AuxRandBeta,
13 Main { offset: usize, index: usize },
15 AuxCoord {
17 offset: usize,
18 index: usize,
19 coord: usize,
20 },
21 AuxBusBoundary(usize),
23 VlpiReduction(usize),
25 Gamma,
28 Alpha,
30 ZPowN,
32 ZK,
34 IsFirst,
36 IsLast,
38 IsTransition,
40 Weight0,
42 F,
44 S0,
46 QuotientChunkCoord {
49 offset: usize,
50 chunk: usize,
51 coord: usize,
52 },
53}
54
55#[derive(Debug, Clone, Copy)]
57pub(crate) struct InputKeyMapper<'a> {
58 pub(super) layout: &'a InputLayout,
59}
60
61impl InputKeyMapper<'_> {
62 pub(crate) fn index_of(&self, key: InputKey) -> Option<usize> {
64 let layout = self.layout;
65 match key {
66 InputKey::Public(i) => layout.regions.public_values.index(i),
67 InputKey::AuxRandAlpha => Some(layout.aux_rand_alpha),
68 InputKey::AuxRandBeta => Some(layout.aux_rand_beta),
69 InputKey::Main { offset, index } => match offset {
70 0 => layout.regions.main_curr.index(index),
71 1 => layout.regions.main_next.index(index),
72 _ => None,
73 },
74 InputKey::AuxCoord { offset, index, coord } => {
75 if index >= layout.counts.aux_width || coord >= EXT_DEGREE {
76 return None;
77 }
78 let local = index * EXT_DEGREE + coord;
79 match offset {
80 0 => layout.regions.aux_curr.index(local),
81 1 => layout.regions.aux_next.index(local),
82 _ => None,
83 }
84 },
85 InputKey::AuxBusBoundary(i) => layout.regions.aux_bus_boundary.index(i),
86 InputKey::VlpiReduction(i) => {
87 let local = i * layout.vlpi_stride;
88 layout.regions.vlpi_reductions.index(local)
89 },
90 InputKey::Alpha => Some(layout.stark.alpha),
92 InputKey::ZPowN => Some(layout.stark.z_pow_n),
93 InputKey::ZK => Some(layout.stark.z_k),
94 InputKey::IsFirst => Some(layout.stark.is_first),
95 InputKey::IsLast => Some(layout.stark.is_last),
96 InputKey::IsTransition => Some(layout.stark.is_transition),
97 InputKey::Gamma => Some(layout.stark.gamma),
98 InputKey::Weight0 => Some(layout.stark.weight0),
100 InputKey::F => Some(layout.stark.f),
101 InputKey::S0 => Some(layout.stark.s0),
102 InputKey::QuotientChunkCoord { offset, chunk, coord } => {
103 if chunk >= layout.counts.num_quotient_chunks || coord >= EXT_DEGREE {
104 return None;
105 }
106 let idx = chunk * EXT_DEGREE + coord;
107 match offset {
108 0 => layout.regions.quotient_curr.index(idx),
109 1 => layout.regions.quotient_next.index(idx),
110 _ => None,
111 }
112 },
113 }
114 }
115}