Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move subcomponent counter decrease operation outside of assert #187

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions compiler/src/intermediate_representation/call_bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,16 +496,20 @@ impl WriteC for CallBucket {
match &data.dest_address_type {
AddressType::SubcmpSignal { uniform_parallel_value, input_information, .. } => {
// if subcomponent input check if run needed
let sub_cmp_counter_decrease = format!(
"{}->componentMemory[{}[{}]].inputCounter -= {}",
CIRCOM_CALC_WIT, MY_SUBCOMPONENTS, cmp_index_ref, &data.context.size
);
let sub_cmp_counter = format!(
"{}->componentMemory[{}[{}]].inputCounter",
CIRCOM_CALC_WIT, MY_SUBCOMPONENTS, cmp_index_ref
);
let sub_cmp_counter_decrease = format!(
"{} -= {}",
sub_cmp_counter, &data.context.size
);
if let InputInformation::Input{status} = input_information {
if let StatusInput::NoLast = status {
// no need to run subcomponent
prologue.push("// no need to run sub component".to_string());
//prologue.push(format!("{};",sub_cmp_counter_decrease));
prologue.push(format!("assert({});",sub_cmp_counter_decrease));
prologue.push(format!("{};", sub_cmp_counter_decrease));
prologue.push(format!("assert({} > 0);", sub_cmp_counter));
} else {
let sub_cmp_pos = format!("{}[{}]", MY_SUBCOMPONENTS, cmp_index_ref);
let sub_cmp_call_arguments =
Expand Down Expand Up @@ -551,7 +555,8 @@ impl WriteC for CallBucket {
prologue.push(build_conditional(if_condition,call_instructions,else_instructions));
} else {
prologue.push("// need to run sub component".to_string());
prologue.push(format!("assert(!({}));",sub_cmp_counter_decrease));
prologue.push(format!("{};", sub_cmp_counter_decrease));
prologue.push(format!("assert(!({}));", sub_cmp_counter));
prologue.append(&mut call_instructions);
}
}
Expand Down Expand Up @@ -584,7 +589,8 @@ impl WriteC for CallBucket {
prologue.push(build_conditional(if_condition,call_instructions,else_instructions));
} else {
prologue.push("// need to run sub component".to_string());
prologue.push(format!("assert(!({}));",sub_cmp_counter_decrease));
prologue.push(format!("{};", sub_cmp_counter_decrease));
prologue.push(format!("assert(!({}));", sub_cmp_counter));
prologue.append(&mut call_instructions);
}
// end of case parallel
Expand All @@ -609,7 +615,8 @@ impl WriteC for CallBucket {
prologue.push(build_conditional(if_condition,call_instructions,else_instructions));
} else {
prologue.push("// need to run sub component".to_string());
prologue.push(format!("assert(!({}));",sub_cmp_counter_decrease));
prologue.push(format!("{};", sub_cmp_counter_decrease));
prologue.push(format!("assert(!({}));", sub_cmp_counter));
prologue.append(&mut call_instructions);
}

Expand Down
21 changes: 14 additions & 7 deletions compiler/src/intermediate_representation/store_bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,16 +405,20 @@ impl WriteC for StoreBucket {
match &self.dest_address_type {
AddressType::SubcmpSignal{ uniform_parallel_value, input_information, .. } => {
// if subcomponent input check if run needed
let sub_cmp_counter = format!(
"{}->componentMemory[{}[{}]].inputCounter",
CIRCOM_CALC_WIT, MY_SUBCOMPONENTS, cmp_index_ref
);
let sub_cmp_counter_decrease = format!(
"{}->componentMemory[{}[{}]].inputCounter -= {}",
CIRCOM_CALC_WIT, MY_SUBCOMPONENTS, cmp_index_ref, self.context.size
"{} -= {}",
sub_cmp_counter, self.context.size
);
if let InputInformation::Input{status} = input_information {
if let StatusInput::NoLast = status {
// no need to run subcomponent
prologue.push("// no need to run sub component".to_string());
//prologue.push(format!("{};",sub_cmp_counter_decrease));
prologue.push(format!("assert({});",sub_cmp_counter_decrease));
prologue.push(format!("{};", sub_cmp_counter_decrease));
prologue.push(format!("assert({} > 0);", sub_cmp_counter));
} else {
let sub_cmp_pos = format!("{}[{}]", MY_SUBCOMPONENTS, cmp_index_ref);
let sub_cmp_call_arguments =
Expand Down Expand Up @@ -458,7 +462,8 @@ impl WriteC for StoreBucket {
prologue.push(build_conditional(if_condition,call_instructions,else_instructions));
} else {
prologue.push("// need to run sub component".to_string());
prologue.push(format!("assert(!({}));",sub_cmp_counter_decrease));
prologue.push(format!("{};", sub_cmp_counter_decrease));
prologue.push(format!("assert(!({}));", sub_cmp_counter));
prologue.append(&mut call_instructions);
}
}
Expand Down Expand Up @@ -491,7 +496,8 @@ impl WriteC for StoreBucket {
prologue.push(build_conditional(if_condition,call_instructions,else_instructions));
} else {
prologue.push("// need to run sub component".to_string());
prologue.push(format!("assert(!({}));",sub_cmp_counter_decrease));
prologue.push(format!("{};", sub_cmp_counter_decrease));
prologue.push(format!("assert(!({}));", sub_cmp_counter));
prologue.append(&mut call_instructions);
}
// end of case parallel
Expand All @@ -516,7 +522,8 @@ impl WriteC for StoreBucket {
prologue.push(build_conditional(if_condition,call_instructions,else_instructions));
} else {
prologue.push("// need to run sub component".to_string());
prologue.push(format!("assert(!({}));",sub_cmp_counter_decrease));
prologue.push(format!("{};", sub_cmp_counter_decrease));
prologue.push(format!("assert(!({}));", sub_cmp_counter));
prologue.append(&mut call_instructions);
}
// end of not parallel case
Expand Down