|
1 | | -use p3_field::{BasedVectorSpace, Field, PrimeCharacteristicRing, dot_product}; |
| 1 | +use p3_field::{BasedVectorSpace, PrimeCharacteristicRing, dot_product}; |
2 | 2 | use p3_symmetric::Permutation; |
3 | 3 | use utils::{ToUsize, build_poseidon16, build_poseidon24, pretty_integer}; |
4 | 4 | use whir_p3::poly::{evals::EvaluationsList, multilinear::MultilinearPoint}; |
5 | 5 |
|
6 | 6 | use crate::{ |
7 | 7 | DIMENSION, EF, F, MAX_MEMORY_SIZE, Memory, POSEIDON_16_NULL_HASH_PTR, |
8 | 8 | POSEIDON_24_NULL_HASH_PTR, PUBLIC_INPUT_START, RunnerError, ZERO_VEC_PTR, |
9 | | - bytecode::{Bytecode, Hint, Instruction}, |
| 9 | + bytecode::{Bytecode, Instruction}, |
10 | 10 | }; |
11 | 11 |
|
12 | 12 | #[must_use] |
@@ -123,77 +123,17 @@ fn execute_bytecode_helper( |
123 | 123 | cpu_cycles += 1; |
124 | 124 |
|
125 | 125 | for hint in bytecode.hints.get(&pc).unwrap_or(&vec![]) { |
126 | | - match hint { |
127 | | - Hint::RequestMemory { |
128 | | - offset, |
129 | | - size, |
130 | | - vectorized, |
131 | | - } => { |
132 | | - let size = size.read_value(&memory, fp)?.to_usize(); |
133 | | - |
134 | | - if *vectorized { |
135 | | - // find the next multiple of 8 |
136 | | - memory.set(fp + *offset, F::from_usize(ap_vec))?; |
137 | | - ap_vec += size; |
138 | | - } else { |
139 | | - memory.set(fp + *offset, F::from_usize(ap))?; |
140 | | - ap += size; |
141 | | - } |
142 | | - // does not increase PC |
143 | | - } |
144 | | - Hint::DecomposeBits { |
145 | | - res_offset, |
146 | | - to_decompose, |
147 | | - } => { |
148 | | - let to_decompose_value = to_decompose.read_value(&memory, fp)?.to_usize(); |
149 | | - for i in 0..F::bits() { |
150 | | - let bit = if to_decompose_value & (1 << i) != 0 { |
151 | | - F::ONE |
152 | | - } else { |
153 | | - F::ZERO |
154 | | - }; |
155 | | - memory.set(fp + *res_offset + i, bit)?; |
156 | | - } |
157 | | - } |
158 | | - Hint::Inverse { arg, res_offset } => { |
159 | | - let value = arg.read_value(&memory, fp)?; |
160 | | - let result = value.try_inverse().unwrap_or(F::ZERO); |
161 | | - memory.set(fp + *res_offset, result)?; |
162 | | - } |
163 | | - Hint::Print { line_info, content } => { |
164 | | - let values = content |
165 | | - .iter() |
166 | | - .map(|value| Ok(value.read_value(&memory, fp)?.to_string())) |
167 | | - .collect::<Result<Vec<_>, _>>()?; |
168 | | - // Logs for performance analysis: |
169 | | - if values[0] == "123456789" { |
170 | | - if values.len() == 1 { |
171 | | - *std_out += "[CHECKPOINT]\n"; |
172 | | - } else { |
173 | | - assert_eq!(values.len(), 2); |
174 | | - let new_no_vec_memory = ap - checkpoint_ap; |
175 | | - let new_vec_memory = (ap_vec - checkpoint_ap_vec) * DIMENSION; |
176 | | - *std_out += &format!( |
177 | | - "[CHECKPOINT {}] new CPU cycles: {}, new runtime memory: {} ({:.1}% vec)\n", |
178 | | - values[1], |
179 | | - pretty_integer(cpu_cycles - last_checkpoint_cpu_cycles), |
180 | | - pretty_integer(new_no_vec_memory + new_vec_memory), |
181 | | - new_vec_memory as f64 / (new_no_vec_memory + new_vec_memory) as f64 |
182 | | - * 100.0 |
183 | | - ); |
184 | | - } |
185 | | - |
186 | | - last_checkpoint_cpu_cycles = cpu_cycles; |
187 | | - checkpoint_ap = ap; |
188 | | - checkpoint_ap_vec = ap_vec; |
189 | | - continue; |
190 | | - } |
191 | | - |
192 | | - let line_info = line_info.replace(';', ""); |
193 | | - *std_out += &format!("\"{}\" -> {}\n", line_info, values.join(", ")); |
194 | | - // does not increase PC |
195 | | - } |
196 | | - } |
| 126 | + hint.execute( |
| 127 | + &mut memory, |
| 128 | + fp, |
| 129 | + &mut ap, |
| 130 | + &mut ap_vec, |
| 131 | + std_out, |
| 132 | + cpu_cycles, |
| 133 | + &mut last_checkpoint_cpu_cycles, |
| 134 | + &mut checkpoint_ap, |
| 135 | + &mut checkpoint_ap_vec, |
| 136 | + )?; |
197 | 137 | } |
198 | 138 |
|
199 | 139 | let instruction = &bytecode.instructions[pc]; |
|
0 commit comments