From 46fa092fc2458a5deaebec9b9c1ea9edb66f66ed Mon Sep 17 00:00:00 2001 From: CPerezz Date: Mon, 22 Jul 2024 23:40:16 +0200 Subject: [PATCH] add: Support for std::ops::Not for FheUint8 This PR adds support for the `std::ops::Not` operator for `FheUint8` such that we can use the `!` operator within a PhantomZone circuit. --- src/shortint/mod.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/shortint/mod.rs b/src/shortint/mod.rs index a70e0cd..2270f28 100644 --- a/src/shortint/mod.rs +++ b/src/shortint/mod.rs @@ -1,4 +1,4 @@ -mod enc_dec; +pub(crate) mod enc_dec; mod ops; pub type FheUint8 = enc_dec::FheUint8>; @@ -290,5 +290,22 @@ mod frontend { self.mux(other, &self_lt) } } + + impl std::ops::Not for &FheUint8 { + type Output = FheUint8; + fn not(self) -> Self::Output { + BoolEvaluator::with_local(|e| FheUint8 { + data: self.data().iter().map(|b| e.not(b)).collect(), + }) + } + } + + impl std::ops::Not for FheUint8 { + type Output = FheUint8; + fn not(self) -> Self::Output { + // This just calls the impl above with 0 overhead. + !(&self) + } + } } }