@@ -205,6 +205,11 @@ pub fn function_table() -> CInstruction {
205205 format ! ( "{}" , FUNCTION_TABLE )
206206}
207207
208+ pub const FUNCTION_TABLE_PARALLEL : & str = "_functionTableParallel" ;
209+ pub fn function_table_parallel ( ) -> CInstruction {
210+ format ! ( "{}" , FUNCTION_TABLE_PARALLEL )
211+ }
212+
208213pub const SIGNAL_VALUES : & str = "signalValues" ;
209214pub fn declare_signal_values ( ) -> CInstruction {
210215 format ! ( "FrElement* {} = {}->{}" , SIGNAL_VALUES , CIRCOM_CALC_WIT , SIGNAL_VALUES )
@@ -282,6 +287,17 @@ pub fn my_subcomponents() -> CInstruction {
282287 format ! ( "{}" , MY_SUBCOMPONENTS )
283288}
284289
290+ pub const MY_SUBCOMPONENTS_PARALLEL : & str = "mySubcomponentsParallel" ;
291+ pub fn declare_my_subcomponents_parallel ( ) -> CInstruction {
292+ format ! (
293+ "bool* {} = {}->componentMemory[{}].subcomponentsParallel" ,
294+ MY_SUBCOMPONENTS_PARALLEL , CIRCOM_CALC_WIT , CTX_INDEX
295+ )
296+ }
297+ pub fn my_subcomponents_parallel ( ) -> CInstruction {
298+ format ! ( "{}" , MY_SUBCOMPONENTS_PARALLEL )
299+ }
300+
285301pub const CIRCUIT_CONSTANTS : & str = "circuitConstants" ;
286302pub fn declare_circuit_constants ( ) -> CInstruction {
287303 format ! ( "FrElement* {} = {}->{}" , CIRCUIT_CONSTANTS , CIRCOM_CALC_WIT , CIRCUIT_CONSTANTS )
@@ -347,6 +363,15 @@ pub fn set_list(elems: Vec<usize>) -> String {
347363 set_string
348364}
349365
366+ pub fn set_list_bool ( elems : Vec < bool > ) -> String {
367+ let mut set_string = "{" . to_string ( ) ;
368+ for elem in elems {
369+ set_string = format ! ( "{}{}," , set_string, elem) ;
370+ }
371+ set_string. pop ( ) ;
372+ set_string. push ( '}' ) ;
373+ set_string
374+ }
350375
351376pub fn add_return ( ) -> String {
352377 "return;" . to_string ( )
@@ -388,12 +413,11 @@ pub fn merge_code(instructions: Vec<String>) -> String {
388413 code
389414}
390415
391- pub fn collect_template_headers ( instances : & TemplateList ) -> Vec < String > {
416+ pub fn collect_template_headers ( instances : & TemplateListParallel ) -> Vec < String > {
392417 let mut template_headers = vec ! [ ] ;
393418 for instance in instances {
394419 let params_run = vec ! [ declare_ctx_index( ) , declare_circom_calc_wit( ) ] ;
395420 let params_run = argument_list ( params_run) ;
396- let run_header = format ! ( "void {}_run({});" , instance, params_run) ;
397421 let params_create = vec ! [
398422 declare_signal_offset( ) ,
399423 declare_component_offset( ) ,
@@ -402,9 +426,18 @@ pub fn collect_template_headers(instances: &TemplateList) -> Vec<String> {
402426 declare_component_father( ) ,
403427 ] ;
404428 let params_create = argument_list ( params_create) ;
405- let create_header = format ! ( "void {}_create({});" , instance, params_create) ;
406- template_headers. push ( create_header) ;
407- template_headers. push ( run_header) ;
429+ if instance. is_parallel {
430+ let run_header = format ! ( "void {}_run_parallel({});" , instance. name, params_run) ;
431+ let create_header = format ! ( "void {}_create_parallel({});" , instance. name, params_create) ;
432+ template_headers. push ( create_header) ;
433+ template_headers. push ( run_header) ;
434+ }
435+ if instance. is_not_parallel {
436+ let run_header = format ! ( "void {}_run({});" , instance. name, params_run) ;
437+ let create_header = format ! ( "void {}_create({});" , instance. name, params_create) ;
438+ template_headers. push ( create_header) ;
439+ template_headers. push ( run_header) ;
440+ }
408441 }
409442 template_headers
410443}
@@ -645,16 +678,34 @@ pub fn generate_dat_file(dat_file: &mut dyn Write, producer: &CProducer) -> std:
645678 */
646679 Ok ( ( ) )
647680}
648-
649- pub fn generate_function_list ( _producer : & CProducer , list : & TemplateList ) -> String {
650- let mut func_list = "" . to_string ( ) ;
681+ pub fn generate_function_list ( _producer : & CProducer , list : & TemplateListParallel ) -> ( String , String ) {
682+ let mut func_list= "" . to_string ( ) ;
683+ let mut func_list_parallel = "" . to_string ( ) ;
651684 if list. len ( ) > 0 {
652- func_list. push_str ( & format ! ( "\n {}_run" , list[ 0 ] ) ) ;
653- for i in 1 ..list. len ( ) {
654- func_list. push_str ( & format ! ( ",\n {}_run" , list[ i] ) ) ;
685+ if list[ 0 ] . is_parallel {
686+ func_list_parallel. push_str ( & format ! ( "\n {}_run_parallel" , list[ 0 ] . name) ) ;
687+ } else {
688+ func_list_parallel. push_str ( & format ! ( "\n NULL" ) ) ;
689+ }
690+ if list[ 0 ] . is_not_parallel {
691+ func_list. push_str ( & format ! ( "\n {}_run" , list[ 0 ] . name) ) ;
692+ } else {
693+ func_list. push_str ( & format ! ( "\n NULL" ) ) ;
655694 }
695+ for i in 1 ..list. len ( ) {
696+ if list[ i] . is_parallel {
697+ func_list_parallel. push_str ( & format ! ( ",\n {}_run_parallel" , list[ i] . name) ) ;
698+ } else {
699+ func_list_parallel. push_str ( & format ! ( ",\n NULL" ) ) ;
700+ }
701+ if list[ i] . is_not_parallel {
702+ func_list. push_str ( & format ! ( ",\n {}_run" , list[ i] . name) ) ;
703+ } else {
704+ func_list. push_str ( & format ! ( ",\n NULL" ) ) ;
705+ }
706+ }
656707 }
657- func_list
708+ ( func_list, func_list_parallel )
658709}
659710
660711pub fn generate_message_list_def ( _producer : & CProducer , message_list : & MessageList ) -> Vec < String > {
@@ -852,10 +903,18 @@ pub fn generate_c_file(name: String, producer: &CProducer) -> std::io::Result<()
852903 let mut run_defs = collect_template_headers ( producer. get_template_instance_list ( ) ) ;
853904 code. append ( & mut run_defs) ;
854905
906+ let ( func_list_no_parallel, func_list_parallel) = generate_function_list ( producer, producer. get_template_instance_list ( ) ) ;
907+
855908 code. push ( format ! (
856909 "Circom_TemplateFunction _functionTable[{}] = {{ {} }};" ,
857910 producer. get_number_of_template_instances( ) ,
858- generate_function_list( producer, producer. get_template_instance_list( ) )
911+ func_list_no_parallel,
912+ ) ) ;
913+
914+ code. push ( format ! (
915+ "Circom_TemplateFunction _functionTableParallel[{}] = {{ {} }};" ,
916+ producer. get_number_of_template_instances( ) ,
917+ func_list_parallel,
859918 ) ) ;
860919
861920 code. push ( format ! ( "uint get_size_of_input_hashmap() {{return {};}}\n " , len) ) ;
0 commit comments