@@ -5,10 +5,7 @@ use std::{
5
5
6
6
use num_bigint:: BigUint ;
7
7
use openvm_algebra_transpiler:: { Fp2Opcode , Rv32ModularArithmeticOpcode } ;
8
- use openvm_circuit:: {
9
- arch:: * ,
10
- system:: memory:: { online:: GuestMemory , POINTER_MAX_BITS } ,
11
- } ;
8
+ use openvm_circuit:: arch:: * ;
12
9
use openvm_circuit_primitives:: AlignedBytesBorrow ;
13
10
use openvm_instructions:: {
14
11
instruction:: Instruction ,
@@ -177,6 +174,94 @@ impl<'a, const BLOCKS: usize, const BLOCK_SIZE: usize, const IS_FP2: bool>
177
174
impl < F : PrimeField32 , const BLOCKS : usize , const BLOCK_SIZE : usize , const IS_FP2 : bool > Executor < F >
178
175
for FieldExprVecHeapExecutor < BLOCKS , BLOCK_SIZE , IS_FP2 >
179
176
{
177
+ #[ cfg( feature = "tco" ) ]
178
+ fn handler < Ctx > (
179
+ & self ,
180
+ pc : u32 ,
181
+ inst : & Instruction < F > ,
182
+ data : & mut [ u8 ] ,
183
+ ) -> Result < Handler < F , Ctx > , StaticProgramError >
184
+ where
185
+ Ctx : ExecutionCtxTrait ,
186
+ {
187
+ let pre_compute: & mut FieldExpressionPreCompute = data. borrow_mut ( ) ;
188
+
189
+ let op = self . pre_compute_impl ( pc, inst, pre_compute) ?;
190
+
191
+ if let Some ( op) = op {
192
+ let modulus = & pre_compute. expr . prime ;
193
+ if IS_FP2 {
194
+ if let Some ( field_type) = get_fp2_field_type ( modulus) {
195
+ generate_fp2_dispatch ! (
196
+ field_type,
197
+ op,
198
+ BLOCKS ,
199
+ BLOCK_SIZE ,
200
+ execute_e1_tco_handler,
201
+ [
202
+ ( BN254Coordinate , Add ) ,
203
+ ( BN254Coordinate , Sub ) ,
204
+ ( BN254Coordinate , Mul ) ,
205
+ ( BN254Coordinate , Div ) ,
206
+ ( BLS12_381Coordinate , Add ) ,
207
+ ( BLS12_381Coordinate , Sub ) ,
208
+ ( BLS12_381Coordinate , Mul ) ,
209
+ ( BLS12_381Coordinate , Div ) ,
210
+ ]
211
+ )
212
+ } else {
213
+ Ok ( execute_e1_generic_tco_handler :: < _ , _ , BLOCKS , BLOCK_SIZE , IS_FP2 > )
214
+ }
215
+ } else if let Some ( field_type) = get_field_type ( modulus) {
216
+ generate_field_dispatch ! (
217
+ field_type,
218
+ op,
219
+ BLOCKS ,
220
+ BLOCK_SIZE ,
221
+ execute_e1_tco_handler,
222
+ [
223
+ ( K256Coordinate , Add ) ,
224
+ ( K256Coordinate , Sub ) ,
225
+ ( K256Coordinate , Mul ) ,
226
+ ( K256Coordinate , Div ) ,
227
+ ( K256Scalar , Add ) ,
228
+ ( K256Scalar , Sub ) ,
229
+ ( K256Scalar , Mul ) ,
230
+ ( K256Scalar , Div ) ,
231
+ ( P256Coordinate , Add ) ,
232
+ ( P256Coordinate , Sub ) ,
233
+ ( P256Coordinate , Mul ) ,
234
+ ( P256Coordinate , Div ) ,
235
+ ( P256Scalar , Add ) ,
236
+ ( P256Scalar , Sub ) ,
237
+ ( P256Scalar , Mul ) ,
238
+ ( P256Scalar , Div ) ,
239
+ ( BN254Coordinate , Add ) ,
240
+ ( BN254Coordinate , Sub ) ,
241
+ ( BN254Coordinate , Mul ) ,
242
+ ( BN254Coordinate , Div ) ,
243
+ ( BN254Scalar , Add ) ,
244
+ ( BN254Scalar , Sub ) ,
245
+ ( BN254Scalar , Mul ) ,
246
+ ( BN254Scalar , Div ) ,
247
+ ( BLS12_381Coordinate , Add ) ,
248
+ ( BLS12_381Coordinate , Sub ) ,
249
+ ( BLS12_381Coordinate , Mul ) ,
250
+ ( BLS12_381Coordinate , Div ) ,
251
+ ( BLS12_381Scalar , Add ) ,
252
+ ( BLS12_381Scalar , Sub ) ,
253
+ ( BLS12_381Scalar , Mul ) ,
254
+ ( BLS12_381Scalar , Div ) ,
255
+ ]
256
+ )
257
+ } else {
258
+ Ok ( execute_e1_generic_tco_handler :: < _ , _ , BLOCKS , BLOCK_SIZE , IS_FP2 > )
259
+ }
260
+ } else {
261
+ Ok ( execute_e1_setup_tco_handler :: < _ , _ , BLOCKS , BLOCK_SIZE , IS_FP2 > )
262
+ }
263
+ }
264
+
180
265
#[ inline( always) ]
181
266
fn pre_compute_size ( & self ) -> usize {
182
267
std:: mem:: size_of :: < FieldExpressionPreCompute > ( )
@@ -527,6 +612,7 @@ unsafe fn execute_e2_setup_impl<
527
612
execute_e12_setup_impl :: < _ , _ , BLOCKS , BLOCK_SIZE , IS_FP2 > ( & pre_compute. data , vm_state) ;
528
613
}
529
614
615
+ #[ create_tco_handler]
530
616
unsafe fn execute_e1_impl <
531
617
F : PrimeField32 ,
532
618
CTX : ExecutionCtxTrait ,
0 commit comments