Skip to content

Commit

Permalink
fix(ssa refactor): euclidean division for unsigned (#1721)
Browse files Browse the repository at this point in the history
* fix(ssa refactor): euclidean div for unsigned

* chore(ssa refactor): cp working test
  • Loading branch information
joss-aztec committed Jun 16, 2023
1 parent 8e9b612 commit a1596bc
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
authors = [""]
compiler_version = "0.1"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
x = "7"
y = "3"
z = "2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Testing integer division: 7/3 = 2
fn main(mut x: u32, y: u32, z: u32) {
let a = x % y;
assert(x / y == z);
assert(a == x - z*y);
assert((50 as u64) % (9 as u64) == 5);
}
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,22 @@ impl AcirContext {
&mut self,
lhs: AcirVar,
rhs: AcirVar,
_typ: AcirType,
typ: AcirType,
) -> Result<AcirVar, AcirGenError> {
let inv_rhs = self.inv_var(rhs)?;
self.mul_var(lhs, inv_rhs)
match typ.0 {
NumericType::NativeField => {
let inv_rhs = self.inv_var(rhs)?;
self.mul_var(lhs, inv_rhs)
}
NumericType::Unsigned { bit_size } => {
let (quotient_var, _remainder_var) =
self.euclidean_division_var(lhs, rhs, bit_size)?;
Ok(quotient_var)
}
NumericType::Signed { .. } => {
todo!("Signed division");
}
}
}

/// Adds a new Variable to context whose value will
Expand Down

0 comments on commit a1596bc

Please sign in to comment.