Skip to content

Commit

Permalink
update gate order to compare input first
Browse files Browse the repository at this point in the history
  • Loading branch information
siq1 committed Nov 19, 2024
1 parent 43d7f45 commit 0f229c4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
36 changes: 18 additions & 18 deletions expander_compiler/src/circuit/layered/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@ impl<C: Config, const INPUT_NUM: usize> PartialOrd for Gate<C, INPUT_NUM> {

impl<C: Config, const INPUT_NUM: usize> Ord for Gate<C, INPUT_NUM> {
fn cmp(&self, other: &Self) -> Ordering {
match self.output.cmp(&other.output) {
Ordering::Less => {
return Ordering::Less;
}
Ordering::Greater => {
return Ordering::Greater;
}
Ordering::Equal => {}
};
for i in 0..INPUT_NUM {
match self.inputs[i].cmp(&other.inputs[i]) {
Ordering::Less => {
Expand All @@ -37,6 +28,15 @@ impl<C: Config, const INPUT_NUM: usize> Ord for Gate<C, INPUT_NUM> {
Ordering::Equal => {}
};
}
match self.output.cmp(&other.output) {
Ordering::Less => {
return Ordering::Less;
}
Ordering::Greater => {
return Ordering::Greater;
}
Ordering::Equal => {}
};
self.coef.cmp(&other.coef)
}
}
Expand All @@ -58,15 +58,6 @@ impl<C: Config> Ord for GateCustom<C> {
}
Ordering::Equal => {}
};
match self.output.cmp(&other.output) {
Ordering::Less => {
return Ordering::Less;
}
Ordering::Greater => {
return Ordering::Greater;
}
Ordering::Equal => {}
};
match self.inputs.len().cmp(&other.inputs.len()) {
Ordering::Less => {
return Ordering::Less;
Expand All @@ -87,6 +78,15 @@ impl<C: Config> Ord for GateCustom<C> {
Ordering::Equal => {}
};
}
match self.output.cmp(&other.output) {
Ordering::Less => {
return Ordering::Less;
}
Ordering::Greater => {
return Ordering::Greater;
}
Ordering::Equal => {}
};
self.coef.cmp(&other.coef)
}
}
Expand Down
5 changes: 4 additions & 1 deletion expander_compiler/src/layering/wire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,11 @@ impl<'a, C: Config> CompileContext<'a, C> {
});
}
VarSpec::Quad(vid0, vid1) => {
let x = aq.var_pos[vid0];
let y = aq.var_pos[vid1];
let inputs = if x < y { [x, y] } else { [y, x] };
res.gate_muls.push(GateMul {
inputs: [aq.var_pos[vid0], aq.var_pos[vid1]],
inputs,
output: pos,
coef: Coef::Constant(term.coef),
});
Expand Down

0 comments on commit 0f229c4

Please sign in to comment.