Skip to content

Commit

Permalink
Binary OR.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkskeller committed May 27, 2021
1 parent eaf3d00 commit 7f71caf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Compiler/floatingpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def carry(b, a, compute_p=True):
return (t1, t2)

def or_op(a, b, void=None):
return a + b - a*b
return a.bit_or(b)

def mul_op(a, b, void=None):
return a * b
Expand Down
19 changes: 19 additions & 0 deletions Compiler/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,18 @@ def bit_xor(self, other):
return self
return self + other - 2 * self * other

def bit_or(self, other):
""" OR in arithmetic circuits.
:param self/other: 0 or 1 (any compatible type)
:return: type depends on inputs (secret if any of them is) """
if util.is_constant(other):
if other:
return self
else:
return 0
return self + other - self * other

def bit_and(self, other):
""" AND in arithmetic circuits.
Expand Down Expand Up @@ -419,6 +431,13 @@ def bit_and(self, other):
:rtype: depending on inputs (secret if any of them is) """
return self & other

def bit_or(self, other):
""" OR in binary circuits.
:param self/other: 0 or 1 (any compatible type)
:return: type depends on inputs (secret if any of them is) """
return self ^ other - self & other

def bit_not(self):
""" NOT in binary circuits. """
return ~self
Expand Down

0 comments on commit 7f71caf

Please sign in to comment.