update BDD circuits & fix non-zero scratch related bug

This commit is contained in:
Pro7ech
2025-10-22 18:10:15 +02:00
parent c31562d7bb
commit 9067de8d96
15 changed files with 17875 additions and 11971 deletions

View File

@@ -8,7 +8,7 @@ use poulpy_core::{
#[cfg(test)]
use poulpy_core::GLWEEncryptSk;
use poulpy_core::ScratchTakeCore;
use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, ZnxZero};
#[cfg(test)]
#[cfg(test)]
use poulpy_hal::source::Source;
@@ -80,6 +80,7 @@ impl<D: DataMut, T: UnsignedInteger + ToBits> FheUintBlocks<D, T> {
Scratch<BE>: ScratchTakeCore<BE>,
{
use poulpy_core::layouts::GLWEPlaintextLayout;
use poulpy_hal::layouts::ZnxZero;
#[cfg(debug_assertions)]
{
@@ -95,6 +96,7 @@ impl<D: DataMut, T: UnsignedInteger + ToBits> FheUintBlocks<D, T> {
};
let (mut pt, scratch_1) = scratch.take_glwe_plaintext(&pt_infos);
pt.data.zero();
for i in 0..T::WORD_SIZE {
pt.encode_coeff_i64(value.bit(i) as i64, TorusPrecision(2), 0);
@@ -159,6 +161,7 @@ impl<D: DataRef, T: UnsignedInteger + FromBits + ToBits> FheUintBlocks<D, T> {
};
let (mut pt_want, scratch_1) = scratch.take_glwe_plaintext(&pt_infos);
pt_want.data.zero();
let mut noise: Vec<f64> = vec![0f64; T::WORD_SIZE];

View File

@@ -88,6 +88,7 @@ impl<D: DataRef, T: UnsignedInteger> GGSWInfos for FheUintBlocksPreparedDebug<D,
}
impl<D: DataRef, T: UnsignedInteger + ToBits> FheUintBlocksPreparedDebug<D, T> {
#[allow(dead_code)]
pub(crate) fn noise<S, M, BE: Backend>(&self, module: &M, sk: &S, want: T)
where
S: GLWESecretPreparedToRef<BE>,
@@ -129,6 +130,7 @@ where
}
impl<D: DataMut, T: UnsignedInteger> FheUintBlocksPreparedDebug<D, T> {
#[allow(dead_code)]
pub fn prepare<BRA, M, O, K, BE: Backend>(
&mut self,
module: &M,

View File

@@ -107,7 +107,7 @@ where
S: GLWESecretPreparedToRef<BE> + GLWEInfos,
Scratch<BE>: ScratchTakeCore<BE>,
{
use poulpy_hal::api::ScratchTakeBasic;
use poulpy_hal::{api::ScratchTakeBasic, layouts::ZnxZero};
assert!(self.n().is_multiple_of(T::WORD_SIZE));
assert_eq!(res.n(), self.n() as u32);
@@ -115,10 +115,10 @@ where
let (mut tmp_ggsw, scratch_1) = scratch.take_ggsw(res);
let (mut pt, scratch_2) = scratch_1.take_scalar_znx(self.n(), 1);
pt.zero();
for i in 0..T::WORD_SIZE {
use poulpy_hal::layouts::ZnxViewMut;
pt.at_mut(0, 0)[0] = value.bit(i) as i64;
tmp_ggsw.encrypt_sk(self, &pt, sk, source_xa, source_xe, scratch_2);
res.blocks[i].prepare(self, &tmp_ggsw, scratch_2);

View File

@@ -1,201 +1,73 @@
use crate::tfhe::bdd_arithmetic::{BitCircuit, BitCircuitInfo, Circuit, GetBitCircuitInfo, Node};
pub(crate) enum AnyBitCircuit {
B0(BitCircuit<3, 2>),
B1(BitCircuit<3, 2>),
B2(BitCircuit<3, 2>),
B3(BitCircuit<3, 2>),
B4(BitCircuit<3, 2>),
B5(BitCircuit<3, 2>),
B6(BitCircuit<3, 2>),
B7(BitCircuit<3, 2>),
B8(BitCircuit<3, 2>),
B9(BitCircuit<3, 2>),
B10(BitCircuit<3, 2>),
B11(BitCircuit<3, 2>),
B12(BitCircuit<3, 2>),
B13(BitCircuit<3, 2>),
B14(BitCircuit<3, 2>),
B15(BitCircuit<3, 2>),
B16(BitCircuit<3, 2>),
B17(BitCircuit<3, 2>),
B18(BitCircuit<3, 2>),
B19(BitCircuit<3, 2>),
B20(BitCircuit<3, 2>),
B21(BitCircuit<3, 2>),
B22(BitCircuit<3, 2>),
B23(BitCircuit<3, 2>),
B24(BitCircuit<3, 2>),
B25(BitCircuit<3, 2>),
B26(BitCircuit<3, 2>),
B27(BitCircuit<3, 2>),
B28(BitCircuit<3, 2>),
B29(BitCircuit<3, 2>),
B30(BitCircuit<3, 2>),
B31(BitCircuit<3, 2>),
B0(BitCircuit<4>),
B1(BitCircuit<4>),
B2(BitCircuit<4>),
B3(BitCircuit<4>),
B4(BitCircuit<4>),
B5(BitCircuit<4>),
B6(BitCircuit<4>),
B7(BitCircuit<4>),
B8(BitCircuit<4>),
B9(BitCircuit<4>),
B10(BitCircuit<4>),
B11(BitCircuit<4>),
B12(BitCircuit<4>),
B13(BitCircuit<4>),
B14(BitCircuit<4>),
B15(BitCircuit<4>),
B16(BitCircuit<4>),
B17(BitCircuit<4>),
B18(BitCircuit<4>),
B19(BitCircuit<4>),
B20(BitCircuit<4>),
B21(BitCircuit<4>),
B22(BitCircuit<4>),
B23(BitCircuit<4>),
B24(BitCircuit<4>),
B25(BitCircuit<4>),
B26(BitCircuit<4>),
B27(BitCircuit<4>),
B28(BitCircuit<4>),
B29(BitCircuit<4>),
B30(BitCircuit<4>),
B31(BitCircuit<4>),
}
impl BitCircuitInfo for AnyBitCircuit {
fn info(&self) -> (&[Node], &[usize], usize) {
fn info(&self) -> (&[Node], usize) {
match self {
AnyBitCircuit::B0(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B1(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B2(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B3(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B4(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B5(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B6(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B7(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B8(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B9(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B10(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B11(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B12(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B13(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B14(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B15(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B16(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B17(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B18(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B19(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B20(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B21(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B22(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B23(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B24(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B25(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B26(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B27(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B28(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B29(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B30(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B31(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B0(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B1(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B2(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B3(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B4(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B5(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B6(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B7(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B8(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B9(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B10(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B11(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B12(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B13(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B14(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B15(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B16(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B17(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B18(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B19(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B20(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B21(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B22(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B23(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B24(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B25(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B26(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B27(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B28(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B29(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B30(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B31(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
}
}
}
@@ -207,170 +79,298 @@ impl GetBitCircuitInfo<u32> for Circuit<AnyBitCircuit, 32usize> {
fn output_size(&self) -> usize {
u32::BITS as usize
}
fn get_circuit(&self, bit: usize) -> (&[Node], &[usize], usize) {
fn get_circuit(&self, bit: usize) -> (&[Node], usize) {
self.0[bit].info()
}
}
pub(crate) static OUTPUT_CIRCUITS: Circuit<AnyBitCircuit, 32usize> = Circuit([
AnyBitCircuit::B0(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(32, 1, 0), Node::new(0, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(32, 1, 0),
Node::Cmux(0, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B1(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(33, 1, 0), Node::new(1, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(33, 1, 0),
Node::Cmux(1, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B2(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(34, 1, 0), Node::new(2, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(34, 1, 0),
Node::Cmux(2, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B3(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(35, 1, 0), Node::new(3, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(35, 1, 0),
Node::Cmux(3, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B4(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(36, 1, 0), Node::new(4, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(36, 1, 0),
Node::Cmux(4, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B5(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(37, 1, 0), Node::new(5, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(37, 1, 0),
Node::Cmux(5, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B6(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(38, 1, 0), Node::new(6, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(38, 1, 0),
Node::Cmux(6, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B7(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(39, 1, 0), Node::new(7, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(39, 1, 0),
Node::Cmux(7, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B8(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(40, 1, 0), Node::new(8, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(40, 1, 0),
Node::Cmux(8, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B9(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(41, 1, 0), Node::new(9, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(41, 1, 0),
Node::Cmux(9, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B10(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(42, 1, 0), Node::new(10, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(42, 1, 0),
Node::Cmux(10, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B11(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(43, 1, 0), Node::new(11, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(43, 1, 0),
Node::Cmux(11, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B12(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(44, 1, 0), Node::new(12, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(44, 1, 0),
Node::Cmux(12, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B13(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(45, 1, 0), Node::new(13, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(45, 1, 0),
Node::Cmux(13, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B14(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(46, 1, 0), Node::new(14, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(46, 1, 0),
Node::Cmux(14, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B15(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(47, 1, 0), Node::new(15, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(47, 1, 0),
Node::Cmux(15, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B16(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(48, 1, 0), Node::new(16, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(48, 1, 0),
Node::Cmux(16, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B17(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(49, 1, 0), Node::new(17, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(49, 1, 0),
Node::Cmux(17, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B18(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(50, 1, 0), Node::new(18, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(50, 1, 0),
Node::Cmux(18, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B19(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(51, 1, 0), Node::new(19, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(51, 1, 0),
Node::Cmux(19, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B20(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(52, 1, 0), Node::new(20, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(52, 1, 0),
Node::Cmux(20, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B21(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(53, 1, 0), Node::new(21, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(53, 1, 0),
Node::Cmux(21, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B22(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(54, 1, 0), Node::new(22, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(54, 1, 0),
Node::Cmux(22, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B23(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(55, 1, 0), Node::new(23, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(55, 1, 0),
Node::Cmux(23, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B24(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(56, 1, 0), Node::new(24, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(56, 1, 0),
Node::Cmux(24, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B25(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(57, 1, 0), Node::new(25, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(57, 1, 0),
Node::Cmux(25, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B26(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(58, 1, 0), Node::new(26, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(58, 1, 0),
Node::Cmux(26, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B27(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(59, 1, 0), Node::new(27, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(59, 1, 0),
Node::Cmux(27, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B28(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(60, 1, 0), Node::new(28, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(60, 1, 0),
Node::Cmux(28, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B29(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(61, 1, 0), Node::new(29, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(61, 1, 0),
Node::Cmux(29, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B30(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(62, 1, 0), Node::new(30, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(62, 1, 0),
Node::Cmux(30, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B31(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(63, 1, 0), Node::new(31, 1, 0)],
[0, 2],
[
Node::Copy,
Node::Cmux(63, 1, 0),
Node::Cmux(31, 1, 0),
Node::None,
],
2,
)),
]);

View File

@@ -1,201 +1,73 @@
use crate::tfhe::bdd_arithmetic::{BitCircuit, BitCircuitInfo, Circuit, GetBitCircuitInfo, Node};
pub(crate) enum AnyBitCircuit {
B0(BitCircuit<3, 2>),
B1(BitCircuit<3, 2>),
B2(BitCircuit<3, 2>),
B3(BitCircuit<3, 2>),
B4(BitCircuit<3, 2>),
B5(BitCircuit<3, 2>),
B6(BitCircuit<3, 2>),
B7(BitCircuit<3, 2>),
B8(BitCircuit<3, 2>),
B9(BitCircuit<3, 2>),
B10(BitCircuit<3, 2>),
B11(BitCircuit<3, 2>),
B12(BitCircuit<3, 2>),
B13(BitCircuit<3, 2>),
B14(BitCircuit<3, 2>),
B15(BitCircuit<3, 2>),
B16(BitCircuit<3, 2>),
B17(BitCircuit<3, 2>),
B18(BitCircuit<3, 2>),
B19(BitCircuit<3, 2>),
B20(BitCircuit<3, 2>),
B21(BitCircuit<3, 2>),
B22(BitCircuit<3, 2>),
B23(BitCircuit<3, 2>),
B24(BitCircuit<3, 2>),
B25(BitCircuit<3, 2>),
B26(BitCircuit<3, 2>),
B27(BitCircuit<3, 2>),
B28(BitCircuit<3, 2>),
B29(BitCircuit<3, 2>),
B30(BitCircuit<3, 2>),
B31(BitCircuit<3, 2>),
B0(BitCircuit<4>),
B1(BitCircuit<4>),
B2(BitCircuit<4>),
B3(BitCircuit<4>),
B4(BitCircuit<4>),
B5(BitCircuit<4>),
B6(BitCircuit<4>),
B7(BitCircuit<4>),
B8(BitCircuit<4>),
B9(BitCircuit<4>),
B10(BitCircuit<4>),
B11(BitCircuit<4>),
B12(BitCircuit<4>),
B13(BitCircuit<4>),
B14(BitCircuit<4>),
B15(BitCircuit<4>),
B16(BitCircuit<4>),
B17(BitCircuit<4>),
B18(BitCircuit<4>),
B19(BitCircuit<4>),
B20(BitCircuit<4>),
B21(BitCircuit<4>),
B22(BitCircuit<4>),
B23(BitCircuit<4>),
B24(BitCircuit<4>),
B25(BitCircuit<4>),
B26(BitCircuit<4>),
B27(BitCircuit<4>),
B28(BitCircuit<4>),
B29(BitCircuit<4>),
B30(BitCircuit<4>),
B31(BitCircuit<4>),
}
impl BitCircuitInfo for AnyBitCircuit {
fn info(&self) -> (&[Node], &[usize], usize) {
fn info(&self) -> (&[Node], usize) {
match self {
AnyBitCircuit::B0(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B1(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B2(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B3(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B4(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B5(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B6(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B7(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B8(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B9(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B10(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B11(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B12(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B13(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B14(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B15(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B16(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B17(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B18(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B19(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B20(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B21(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B22(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B23(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B24(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B25(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B26(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B27(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B28(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B29(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B30(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B31(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B0(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B1(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B2(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B3(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B4(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B5(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B6(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B7(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B8(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B9(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B10(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B11(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B12(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B13(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B14(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B15(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B16(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B17(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B18(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B19(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B20(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B21(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B22(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B23(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B24(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B25(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B26(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B27(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B28(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B29(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B30(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B31(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
}
}
}
@@ -207,170 +79,298 @@ impl GetBitCircuitInfo<u32> for Circuit<AnyBitCircuit, 32usize> {
fn output_size(&self) -> usize {
u32::BITS as usize
}
fn get_circuit(&self, bit: usize) -> (&[Node], &[usize], usize) {
fn get_circuit(&self, bit: usize) -> (&[Node], usize) {
self.0[bit].info()
}
}
pub(crate) static OUTPUT_CIRCUITS: Circuit<AnyBitCircuit, 32usize> = Circuit([
AnyBitCircuit::B0(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(32, 1, 0), Node::new(0, 1, 1)],
[0, 2],
[
Node::Cmux(32, 1, 0),
Node::Copy,
Node::Cmux(0, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B1(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(33, 1, 0), Node::new(1, 1, 1)],
[0, 2],
[
Node::Cmux(33, 1, 0),
Node::Copy,
Node::Cmux(1, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B2(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(34, 1, 0), Node::new(2, 1, 1)],
[0, 2],
[
Node::Cmux(34, 1, 0),
Node::Copy,
Node::Cmux(2, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B3(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(35, 1, 0), Node::new(3, 1, 1)],
[0, 2],
[
Node::Cmux(35, 1, 0),
Node::Copy,
Node::Cmux(3, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B4(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(36, 1, 0), Node::new(4, 1, 1)],
[0, 2],
[
Node::Cmux(36, 1, 0),
Node::Copy,
Node::Cmux(4, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B5(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(37, 1, 0), Node::new(5, 1, 1)],
[0, 2],
[
Node::Cmux(37, 1, 0),
Node::Copy,
Node::Cmux(5, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B6(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(38, 1, 0), Node::new(6, 1, 1)],
[0, 2],
[
Node::Cmux(38, 1, 0),
Node::Copy,
Node::Cmux(6, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B7(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(39, 1, 0), Node::new(7, 1, 1)],
[0, 2],
[
Node::Cmux(39, 1, 0),
Node::Copy,
Node::Cmux(7, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B8(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(40, 1, 0), Node::new(8, 1, 1)],
[0, 2],
[
Node::Cmux(40, 1, 0),
Node::Copy,
Node::Cmux(8, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B9(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(41, 1, 0), Node::new(9, 1, 1)],
[0, 2],
[
Node::Cmux(41, 1, 0),
Node::Copy,
Node::Cmux(9, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B10(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(42, 1, 0), Node::new(10, 1, 1)],
[0, 2],
[
Node::Cmux(42, 1, 0),
Node::Copy,
Node::Cmux(10, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B11(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(43, 1, 0), Node::new(11, 1, 1)],
[0, 2],
[
Node::Cmux(43, 1, 0),
Node::Copy,
Node::Cmux(11, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B12(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(44, 1, 0), Node::new(12, 1, 1)],
[0, 2],
[
Node::Cmux(44, 1, 0),
Node::Copy,
Node::Cmux(12, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B13(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(45, 1, 0), Node::new(13, 1, 1)],
[0, 2],
[
Node::Cmux(45, 1, 0),
Node::Copy,
Node::Cmux(13, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B14(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(46, 1, 0), Node::new(14, 1, 1)],
[0, 2],
[
Node::Cmux(46, 1, 0),
Node::Copy,
Node::Cmux(14, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B15(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(47, 1, 0), Node::new(15, 1, 1)],
[0, 2],
[
Node::Cmux(47, 1, 0),
Node::Copy,
Node::Cmux(15, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B16(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(48, 1, 0), Node::new(16, 1, 1)],
[0, 2],
[
Node::Cmux(48, 1, 0),
Node::Copy,
Node::Cmux(16, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B17(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(49, 1, 0), Node::new(17, 1, 1)],
[0, 2],
[
Node::Cmux(49, 1, 0),
Node::Copy,
Node::Cmux(17, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B18(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(50, 1, 0), Node::new(18, 1, 1)],
[0, 2],
[
Node::Cmux(50, 1, 0),
Node::Copy,
Node::Cmux(18, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B19(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(51, 1, 0), Node::new(19, 1, 1)],
[0, 2],
[
Node::Cmux(51, 1, 0),
Node::Copy,
Node::Cmux(19, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B20(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(52, 1, 0), Node::new(20, 1, 1)],
[0, 2],
[
Node::Cmux(52, 1, 0),
Node::Copy,
Node::Cmux(20, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B21(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(53, 1, 0), Node::new(21, 1, 1)],
[0, 2],
[
Node::Cmux(53, 1, 0),
Node::Copy,
Node::Cmux(21, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B22(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(54, 1, 0), Node::new(22, 1, 1)],
[0, 2],
[
Node::Cmux(54, 1, 0),
Node::Copy,
Node::Cmux(22, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B23(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(55, 1, 0), Node::new(23, 1, 1)],
[0, 2],
[
Node::Cmux(55, 1, 0),
Node::Copy,
Node::Cmux(23, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B24(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(56, 1, 0), Node::new(24, 1, 1)],
[0, 2],
[
Node::Cmux(56, 1, 0),
Node::Copy,
Node::Cmux(24, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B25(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(57, 1, 0), Node::new(25, 1, 1)],
[0, 2],
[
Node::Cmux(57, 1, 0),
Node::Copy,
Node::Cmux(25, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B26(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(58, 1, 0), Node::new(26, 1, 1)],
[0, 2],
[
Node::Cmux(58, 1, 0),
Node::Copy,
Node::Cmux(26, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B27(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(59, 1, 0), Node::new(27, 1, 1)],
[0, 2],
[
Node::Cmux(59, 1, 0),
Node::Copy,
Node::Cmux(27, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B28(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(60, 1, 0), Node::new(28, 1, 1)],
[0, 2],
[
Node::Cmux(60, 1, 0),
Node::Copy,
Node::Cmux(28, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B29(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(61, 1, 0), Node::new(29, 1, 1)],
[0, 2],
[
Node::Cmux(61, 1, 0),
Node::Copy,
Node::Cmux(29, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B30(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(62, 1, 0), Node::new(30, 1, 1)],
[0, 2],
[
Node::Cmux(62, 1, 0),
Node::Copy,
Node::Cmux(30, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B31(BitCircuit::new(
[Node::new(0, 0, 0), Node::new(63, 1, 0), Node::new(31, 1, 1)],
[0, 2],
[
Node::Cmux(63, 1, 0),
Node::Copy,
Node::Cmux(31, 1, 0),
Node::None,
],
2,
)),
]);

View File

@@ -1,15 +1,11 @@
use crate::tfhe::bdd_arithmetic::{BitCircuit, BitCircuitInfo, Circuit, GetBitCircuitInfo, Node};
pub(crate) enum AnyBitCircuit {
B0(BitCircuit<219, 64>),
B0(BitCircuit<256>),
}
impl BitCircuitInfo for AnyBitCircuit {
fn info(&self) -> (&[Node], &[usize], usize) {
fn info(&self) -> (&[Node], usize) {
match self {
AnyBitCircuit::B0(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B0(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
}
}
}
@@ -21,237 +17,269 @@ impl GetBitCircuitInfo<u32> for Circuit<AnyBitCircuit, 1usize> {
fn output_size(&self) -> usize {
1
}
fn get_circuit(&self, bit: usize) -> (&[Node], &[usize], usize) {
fn get_circuit(&self, bit: usize) -> (&[Node], usize) {
self.0[bit].info()
}
}
pub(crate) static OUTPUT_CIRCUITS: Circuit<AnyBitCircuit, 1usize> = Circuit([AnyBitCircuit::B0(BitCircuit::new(
[
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(32, 1, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(0, 0, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(33, 1, 2),
Node::new(33, 2, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(1, 3, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(34, 1, 2),
Node::new(34, 2, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(2, 3, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(35, 2, 0),
Node::new(35, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(3, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(36, 1, 2),
Node::new(36, 2, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(4, 3, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(37, 1, 2),
Node::new(37, 2, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(5, 3, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(38, 2, 0),
Node::new(38, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(6, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(39, 2, 0),
Node::new(39, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(7, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(40, 1, 2),
Node::new(40, 2, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(8, 3, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(41, 1, 2),
Node::new(41, 2, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(9, 3, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(42, 2, 0),
Node::new(42, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(10, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(43, 2, 0),
Node::new(43, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(11, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(44, 1, 2),
Node::new(44, 2, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(12, 3, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(45, 1, 2),
Node::new(45, 2, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(13, 3, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(46, 2, 0),
Node::new(46, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(14, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(47, 1, 2),
Node::new(47, 2, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(15, 3, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(48, 2, 0),
Node::new(48, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(16, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(49, 1, 2),
Node::new(49, 2, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(17, 3, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(50, 2, 0),
Node::new(50, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(18, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(51, 2, 0),
Node::new(51, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(19, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(52, 1, 2),
Node::new(52, 2, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(20, 3, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(53, 2, 0),
Node::new(53, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(21, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(54, 1, 2),
Node::new(54, 2, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(22, 3, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(55, 1, 2),
Node::new(55, 2, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(23, 3, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(56, 2, 0),
Node::new(56, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(24, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(57, 1, 2),
Node::new(57, 2, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(25, 3, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(58, 2, 0),
Node::new(58, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(26, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(59, 2, 0),
Node::new(59, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(27, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(60, 2, 0),
Node::new(60, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(28, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(61, 1, 2),
Node::new(61, 2, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(29, 3, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(62, 1, 2),
Node::new(62, 2, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(30, 3, 2),
Node::new(63, 2, 1),
Node::new(63, 0, 2),
Node::new(31, 0, 1),
],
[
0, 3, 6, 10, 13, 17, 20, 24, 27, 31, 34, 38, 41, 45, 48, 52, 55, 59, 62, 66, 69, 73, 76, 80, 83, 87, 90, 94, 97, 101,
104, 108, 111, 115, 118, 122, 125, 129, 132, 136, 139, 143, 146, 150, 153, 157, 160, 164, 167, 171, 174, 178, 181, 185,
188, 192, 195, 199, 202, 206, 209, 213, 216, 218,
Node::Copy,
Node::Copy,
Node::None,
Node::Cmux(32, 1, 0),
Node::Copy,
Node::Copy,
Node::None,
Node::Cmux(0, 0, 3),
Node::Copy,
Node::Copy,
Node::Cmux(33, 3, 0),
Node::Cmux(33, 1, 3),
Node::Copy,
Node::Copy,
Node::Cmux(1, 2, 3),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(34, 1, 2),
Node::Cmux(34, 2, 0),
Node::Copy,
Node::Copy,
Node::None,
Node::Cmux(2, 3, 2),
Node::Copy,
Node::Copy,
Node::Cmux(35, 1, 3),
Node::Cmux(35, 3, 0),
Node::Copy,
Node::Copy,
Node::Cmux(3, 3, 2),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(36, 1, 2),
Node::Cmux(36, 2, 0),
Node::Copy,
Node::Copy,
Node::Cmux(4, 3, 2),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(37, 1, 2),
Node::Cmux(37, 2, 0),
Node::Copy,
Node::Copy,
Node::Cmux(5, 3, 2),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(38, 1, 2),
Node::Cmux(38, 2, 0),
Node::Copy,
Node::Copy,
Node::None,
Node::Cmux(6, 3, 2),
Node::Copy,
Node::Copy,
Node::Cmux(39, 1, 3),
Node::Cmux(39, 3, 0),
Node::Copy,
Node::Copy,
Node::None,
Node::Cmux(7, 3, 2),
Node::Copy,
Node::Copy,
Node::Cmux(40, 3, 0),
Node::Cmux(40, 1, 3),
Node::Copy,
Node::Copy,
Node::None,
Node::Cmux(8, 2, 3),
Node::Copy,
Node::Copy,
Node::Cmux(41, 1, 3),
Node::Cmux(41, 3, 0),
Node::Copy,
Node::Copy,
Node::None,
Node::Cmux(9, 3, 2),
Node::Copy,
Node::Copy,
Node::Cmux(42, 1, 3),
Node::Cmux(42, 3, 0),
Node::Copy,
Node::Copy,
Node::Cmux(10, 3, 2),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(43, 1, 2),
Node::Cmux(43, 2, 0),
Node::Copy,
Node::Copy,
Node::Cmux(11, 3, 2),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(44, 2, 0),
Node::Cmux(44, 1, 2),
Node::Copy,
Node::Copy,
Node::Cmux(12, 2, 3),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(45, 2, 0),
Node::Cmux(45, 1, 2),
Node::Copy,
Node::Copy,
Node::None,
Node::Cmux(13, 2, 3),
Node::Copy,
Node::Copy,
Node::Cmux(46, 1, 3),
Node::Cmux(46, 3, 0),
Node::Copy,
Node::Copy,
Node::Cmux(14, 3, 2),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(47, 2, 0),
Node::Cmux(47, 1, 2),
Node::Copy,
Node::Copy,
Node::Cmux(15, 2, 3),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(48, 2, 0),
Node::Cmux(48, 1, 2),
Node::Copy,
Node::Copy,
Node::Cmux(16, 2, 3),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(49, 1, 2),
Node::Cmux(49, 2, 0),
Node::Copy,
Node::Copy,
Node::Cmux(17, 3, 2),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(50, 1, 2),
Node::Cmux(50, 2, 0),
Node::Copy,
Node::Copy,
Node::Cmux(18, 3, 2),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(51, 2, 0),
Node::Cmux(51, 1, 2),
Node::Copy,
Node::Copy,
Node::Cmux(19, 2, 3),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(52, 1, 2),
Node::Cmux(52, 2, 0),
Node::Copy,
Node::Copy,
Node::None,
Node::Cmux(20, 3, 2),
Node::Copy,
Node::Copy,
Node::Cmux(53, 1, 3),
Node::Cmux(53, 3, 0),
Node::Copy,
Node::Copy,
Node::None,
Node::Cmux(21, 3, 2),
Node::Copy,
Node::Copy,
Node::Cmux(54, 1, 3),
Node::Cmux(54, 3, 0),
Node::Copy,
Node::Copy,
Node::None,
Node::Cmux(22, 3, 2),
Node::Copy,
Node::Copy,
Node::Cmux(55, 3, 0),
Node::Cmux(55, 1, 3),
Node::Copy,
Node::Copy,
Node::Cmux(23, 2, 3),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(56, 2, 0),
Node::Cmux(56, 1, 2),
Node::Copy,
Node::Copy,
Node::Cmux(24, 2, 3),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(57, 2, 0),
Node::Cmux(57, 1, 2),
Node::Copy,
Node::Copy,
Node::None,
Node::Cmux(25, 2, 3),
Node::Copy,
Node::Copy,
Node::Cmux(58, 1, 3),
Node::Cmux(58, 3, 0),
Node::Copy,
Node::Copy,
Node::Cmux(26, 3, 2),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(59, 1, 2),
Node::Cmux(59, 2, 0),
Node::Copy,
Node::Copy,
Node::None,
Node::Cmux(27, 3, 2),
Node::Copy,
Node::Copy,
Node::Cmux(60, 3, 0),
Node::Cmux(60, 1, 3),
Node::Copy,
Node::Copy,
Node::Cmux(28, 2, 3),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(61, 2, 0),
Node::Cmux(61, 1, 2),
Node::Copy,
Node::Copy,
Node::None,
Node::Cmux(29, 2, 3),
Node::Copy,
Node::Copy,
Node::Cmux(62, 1, 3),
Node::Cmux(62, 3, 0),
Node::Copy,
Node::Copy,
Node::None,
Node::Cmux(30, 3, 2),
Node::Cmux(63, 3, 1),
Node::None,
Node::None,
Node::Cmux(63, 0, 3),
Node::Cmux(31, 0, 3),
Node::None,
Node::None,
Node::None,
],
4,
))]);

View File

@@ -1,15 +1,11 @@
use crate::tfhe::bdd_arithmetic::{BitCircuit, BitCircuitInfo, Circuit, GetBitCircuitInfo, Node};
pub(crate) enum AnyBitCircuit {
B0(BitCircuit<219, 64>),
B0(BitCircuit<256>),
}
impl BitCircuitInfo for AnyBitCircuit {
fn info(&self) -> (&[Node], &[usize], usize) {
fn info(&self) -> (&[Node], usize) {
match self {
AnyBitCircuit::B0(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B0(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
}
}
}
@@ -21,237 +17,269 @@ impl GetBitCircuitInfo<u32> for Circuit<AnyBitCircuit, 1usize> {
fn output_size(&self) -> usize {
1
}
fn get_circuit(&self, bit: usize) -> (&[Node], &[usize], usize) {
fn get_circuit(&self, bit: usize) -> (&[Node], usize) {
self.0[bit].info()
}
}
pub(crate) static OUTPUT_CIRCUITS: Circuit<AnyBitCircuit, 1usize> = Circuit([AnyBitCircuit::B0(BitCircuit::new(
[
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(32, 1, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(0, 0, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(33, 2, 0),
Node::new(33, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(1, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(34, 2, 0),
Node::new(34, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(2, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(35, 1, 2),
Node::new(35, 2, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(3, 3, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(36, 2, 0),
Node::new(36, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(4, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(37, 2, 0),
Node::new(37, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(5, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(38, 1, 2),
Node::new(38, 2, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(6, 3, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(39, 2, 0),
Node::new(39, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(7, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(40, 1, 2),
Node::new(40, 2, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(8, 3, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(41, 1, 2),
Node::new(41, 2, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(9, 3, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(42, 1, 2),
Node::new(42, 2, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(10, 3, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(43, 2, 0),
Node::new(43, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(11, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(44, 1, 2),
Node::new(44, 2, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(12, 3, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(45, 2, 0),
Node::new(45, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(13, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(46, 1, 2),
Node::new(46, 2, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(14, 3, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(47, 2, 0),
Node::new(47, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(15, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(48, 2, 0),
Node::new(48, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(16, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(49, 1, 2),
Node::new(49, 2, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(17, 3, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(50, 1, 2),
Node::new(50, 2, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(18, 3, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(51, 1, 2),
Node::new(51, 2, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(19, 3, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(52, 2, 0),
Node::new(52, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(20, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(53, 2, 0),
Node::new(53, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(21, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(54, 2, 0),
Node::new(54, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(22, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(55, 1, 2),
Node::new(55, 2, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(23, 3, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(56, 2, 0),
Node::new(56, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(24, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(57, 1, 2),
Node::new(57, 2, 0),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(25, 3, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(58, 2, 0),
Node::new(58, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(26, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(59, 2, 0),
Node::new(59, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(27, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(60, 2, 0),
Node::new(60, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(28, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(61, 2, 0),
Node::new(61, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(29, 2, 3),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(62, 2, 0),
Node::new(62, 1, 2),
Node::new(0, 0, 0),
Node::new(0, 1, 1),
Node::new(30, 2, 3),
Node::new(63, 2, 0),
Node::new(63, 1, 2),
Node::new(31, 0, 1),
],
[
0, 3, 6, 10, 13, 17, 20, 24, 27, 31, 34, 38, 41, 45, 48, 52, 55, 59, 62, 66, 69, 73, 76, 80, 83, 87, 90, 94, 97, 101,
104, 108, 111, 115, 118, 122, 125, 129, 132, 136, 139, 143, 146, 150, 153, 157, 160, 164, 167, 171, 174, 178, 181, 185,
188, 192, 195, 199, 202, 206, 209, 213, 216, 218,
Node::Copy,
Node::Copy,
Node::None,
Node::Cmux(32, 1, 0),
Node::Copy,
Node::Copy,
Node::Cmux(0, 0, 3),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(33, 1, 2),
Node::Cmux(33, 2, 0),
Node::Copy,
Node::Copy,
Node::Cmux(1, 3, 2),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(34, 1, 2),
Node::Cmux(34, 2, 0),
Node::Copy,
Node::Copy,
Node::Cmux(2, 3, 2),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(35, 2, 0),
Node::Cmux(35, 1, 2),
Node::Copy,
Node::Copy,
Node::None,
Node::Cmux(3, 2, 3),
Node::Copy,
Node::Copy,
Node::Cmux(36, 3, 0),
Node::Cmux(36, 1, 3),
Node::Copy,
Node::Copy,
Node::Cmux(4, 2, 3),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(37, 1, 2),
Node::Cmux(37, 2, 0),
Node::Copy,
Node::Copy,
Node::Cmux(5, 3, 2),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(38, 2, 0),
Node::Cmux(38, 1, 2),
Node::Copy,
Node::Copy,
Node::Cmux(6, 2, 3),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(39, 1, 2),
Node::Cmux(39, 2, 0),
Node::Copy,
Node::Copy,
Node::Cmux(7, 3, 2),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(40, 1, 2),
Node::Cmux(40, 2, 0),
Node::Copy,
Node::Copy,
Node::None,
Node::Cmux(8, 3, 2),
Node::Copy,
Node::Copy,
Node::Cmux(41, 1, 3),
Node::Cmux(41, 3, 0),
Node::Copy,
Node::Copy,
Node::Cmux(9, 3, 2),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(42, 2, 0),
Node::Cmux(42, 1, 2),
Node::Copy,
Node::Copy,
Node::None,
Node::Cmux(10, 2, 3),
Node::Copy,
Node::Copy,
Node::Cmux(43, 1, 3),
Node::Cmux(43, 3, 0),
Node::Copy,
Node::Copy,
Node::None,
Node::Cmux(11, 3, 2),
Node::Copy,
Node::Copy,
Node::Cmux(44, 3, 0),
Node::Cmux(44, 1, 3),
Node::Copy,
Node::Copy,
Node::None,
Node::Cmux(12, 2, 3),
Node::Copy,
Node::Copy,
Node::Cmux(45, 3, 0),
Node::Cmux(45, 1, 3),
Node::Copy,
Node::Copy,
Node::Cmux(13, 2, 3),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(46, 2, 0),
Node::Cmux(46, 1, 2),
Node::Copy,
Node::Copy,
Node::Cmux(14, 2, 3),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(47, 2, 0),
Node::Cmux(47, 1, 2),
Node::Copy,
Node::Copy,
Node::Cmux(15, 2, 3),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(48, 1, 2),
Node::Cmux(48, 2, 0),
Node::Copy,
Node::Copy,
Node::Cmux(16, 3, 2),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(49, 2, 0),
Node::Cmux(49, 1, 2),
Node::Copy,
Node::Copy,
Node::Cmux(17, 2, 3),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(50, 1, 2),
Node::Cmux(50, 2, 0),
Node::Copy,
Node::Copy,
Node::Cmux(18, 3, 2),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(51, 2, 0),
Node::Cmux(51, 1, 2),
Node::Copy,
Node::Copy,
Node::None,
Node::Cmux(19, 2, 3),
Node::Copy,
Node::Copy,
Node::Cmux(52, 1, 3),
Node::Cmux(52, 3, 0),
Node::Copy,
Node::Copy,
Node::None,
Node::Cmux(20, 3, 2),
Node::Copy,
Node::Copy,
Node::Cmux(53, 3, 0),
Node::Cmux(53, 1, 3),
Node::Copy,
Node::Copy,
Node::Cmux(21, 2, 3),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(54, 2, 0),
Node::Cmux(54, 1, 2),
Node::Copy,
Node::Copy,
Node::None,
Node::Cmux(22, 2, 3),
Node::Copy,
Node::Copy,
Node::Cmux(55, 3, 0),
Node::Cmux(55, 1, 3),
Node::Copy,
Node::Copy,
Node::Cmux(23, 2, 3),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(56, 2, 0),
Node::Cmux(56, 1, 2),
Node::Copy,
Node::Copy,
Node::None,
Node::Cmux(24, 2, 3),
Node::Copy,
Node::Copy,
Node::Cmux(57, 3, 0),
Node::Cmux(57, 1, 3),
Node::Copy,
Node::Copy,
Node::None,
Node::Cmux(25, 2, 3),
Node::Copy,
Node::Copy,
Node::Cmux(58, 3, 0),
Node::Cmux(58, 1, 3),
Node::Copy,
Node::Copy,
Node::None,
Node::Cmux(26, 2, 3),
Node::Copy,
Node::Copy,
Node::Cmux(59, 1, 3),
Node::Cmux(59, 3, 0),
Node::Copy,
Node::Copy,
Node::Cmux(27, 3, 2),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(60, 1, 2),
Node::Cmux(60, 2, 0),
Node::Copy,
Node::Copy,
Node::Cmux(28, 3, 2),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(61, 1, 2),
Node::Cmux(61, 2, 0),
Node::Copy,
Node::Copy,
Node::Cmux(29, 3, 2),
Node::None,
Node::Copy,
Node::Copy,
Node::Cmux(62, 1, 2),
Node::Cmux(62, 2, 0),
Node::Copy,
Node::Copy,
Node::Cmux(30, 3, 2),
Node::None,
Node::Cmux(63, 2, 0),
Node::Cmux(63, 1, 2),
Node::None,
Node::None,
Node::Cmux(31, 0, 1),
Node::None,
Node::None,
Node::None,
],
4,
))]);

View File

@@ -1,201 +1,73 @@
use crate::tfhe::bdd_arithmetic::{BitCircuit, BitCircuitInfo, Circuit, GetBitCircuitInfo, Node};
pub(crate) enum AnyBitCircuit {
B0(BitCircuit<3, 2>),
B1(BitCircuit<3, 2>),
B2(BitCircuit<3, 2>),
B3(BitCircuit<3, 2>),
B4(BitCircuit<3, 2>),
B5(BitCircuit<3, 2>),
B6(BitCircuit<3, 2>),
B7(BitCircuit<3, 2>),
B8(BitCircuit<3, 2>),
B9(BitCircuit<3, 2>),
B10(BitCircuit<3, 2>),
B11(BitCircuit<3, 2>),
B12(BitCircuit<3, 2>),
B13(BitCircuit<3, 2>),
B14(BitCircuit<3, 2>),
B15(BitCircuit<3, 2>),
B16(BitCircuit<3, 2>),
B17(BitCircuit<3, 2>),
B18(BitCircuit<3, 2>),
B19(BitCircuit<3, 2>),
B20(BitCircuit<3, 2>),
B21(BitCircuit<3, 2>),
B22(BitCircuit<3, 2>),
B23(BitCircuit<3, 2>),
B24(BitCircuit<3, 2>),
B25(BitCircuit<3, 2>),
B26(BitCircuit<3, 2>),
B27(BitCircuit<3, 2>),
B28(BitCircuit<3, 2>),
B29(BitCircuit<3, 2>),
B30(BitCircuit<3, 2>),
B31(BitCircuit<3, 2>),
B0(BitCircuit<4>),
B1(BitCircuit<4>),
B2(BitCircuit<4>),
B3(BitCircuit<4>),
B4(BitCircuit<4>),
B5(BitCircuit<4>),
B6(BitCircuit<4>),
B7(BitCircuit<4>),
B8(BitCircuit<4>),
B9(BitCircuit<4>),
B10(BitCircuit<4>),
B11(BitCircuit<4>),
B12(BitCircuit<4>),
B13(BitCircuit<4>),
B14(BitCircuit<4>),
B15(BitCircuit<4>),
B16(BitCircuit<4>),
B17(BitCircuit<4>),
B18(BitCircuit<4>),
B19(BitCircuit<4>),
B20(BitCircuit<4>),
B21(BitCircuit<4>),
B22(BitCircuit<4>),
B23(BitCircuit<4>),
B24(BitCircuit<4>),
B25(BitCircuit<4>),
B26(BitCircuit<4>),
B27(BitCircuit<4>),
B28(BitCircuit<4>),
B29(BitCircuit<4>),
B30(BitCircuit<4>),
B31(BitCircuit<4>),
}
impl BitCircuitInfo for AnyBitCircuit {
fn info(&self) -> (&[Node], &[usize], usize) {
fn info(&self) -> (&[Node], usize) {
match self {
AnyBitCircuit::B0(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B1(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B2(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B3(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B4(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B5(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B6(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B7(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B8(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B9(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B10(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B11(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B12(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B13(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B14(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B15(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B16(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B17(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B18(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B19(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B20(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B21(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B22(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B23(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B24(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B25(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B26(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B27(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B28(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B29(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B30(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B31(bit_circuit) => (
bit_circuit.nodes.as_ref(),
bit_circuit.levels.as_ref(),
bit_circuit.max_inter_state,
),
AnyBitCircuit::B0(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B1(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B2(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B3(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B4(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B5(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B6(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B7(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B8(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B9(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B10(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B11(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B12(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B13(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B14(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B15(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B16(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B17(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B18(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B19(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B20(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B21(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B22(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B23(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B24(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B25(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B26(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B27(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B28(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B29(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B30(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
AnyBitCircuit::B31(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
}
}
}
@@ -207,258 +79,298 @@ impl GetBitCircuitInfo<u32> for Circuit<AnyBitCircuit, 32usize> {
fn output_size(&self) -> usize {
u32::BITS as usize
}
fn get_circuit(&self, bit: usize) -> (&[Node], &[usize], usize) {
fn get_circuit(&self, bit: usize) -> (&[Node], usize) {
self.0[bit].info()
}
}
pub(crate) static OUTPUT_CIRCUITS: Circuit<AnyBitCircuit, 32usize> = Circuit([
AnyBitCircuit::B0(BitCircuit::new(
[Node::new(32, 0, 1), Node::new(32, 1, 0), Node::new(0, 0, 1)],
[0, 2],
[
Node::Cmux(32, 0, 1),
Node::Cmux(32, 1, 0),
Node::Cmux(0, 0, 1),
Node::None,
],
2,
)),
AnyBitCircuit::B1(BitCircuit::new(
[Node::new(33, 0, 1), Node::new(33, 1, 0), Node::new(1, 0, 1)],
[0, 2],
[
Node::Cmux(33, 0, 1),
Node::Cmux(33, 1, 0),
Node::Cmux(1, 0, 1),
Node::None,
],
2,
)),
AnyBitCircuit::B2(BitCircuit::new(
[Node::new(34, 0, 1), Node::new(34, 1, 0), Node::new(2, 0, 1)],
[0, 2],
[
Node::Cmux(34, 1, 0),
Node::Cmux(34, 0, 1),
Node::Cmux(2, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B3(BitCircuit::new(
[Node::new(35, 1, 0), Node::new(35, 0, 1), Node::new(3, 1, 0)],
[0, 2],
[
Node::Cmux(35, 0, 1),
Node::Cmux(35, 1, 0),
Node::Cmux(3, 0, 1),
Node::None,
],
2,
)),
AnyBitCircuit::B4(BitCircuit::new(
[Node::new(36, 1, 0), Node::new(36, 0, 1), Node::new(4, 1, 0)],
[0, 2],
[
Node::Cmux(36, 0, 1),
Node::Cmux(36, 1, 0),
Node::Cmux(4, 0, 1),
Node::None,
],
2,
)),
AnyBitCircuit::B5(BitCircuit::new(
[Node::new(37, 0, 1), Node::new(37, 1, 0), Node::new(5, 0, 1)],
[0, 2],
[
Node::Cmux(37, 0, 1),
Node::Cmux(37, 1, 0),
Node::Cmux(5, 0, 1),
Node::None,
],
2,
)),
AnyBitCircuit::B6(BitCircuit::new(
[Node::new(38, 0, 1), Node::new(38, 1, 0), Node::new(6, 0, 1)],
[0, 2],
[
Node::Cmux(38, 1, 0),
Node::Cmux(38, 0, 1),
Node::Cmux(6, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B7(BitCircuit::new(
[Node::new(39, 0, 1), Node::new(39, 1, 0), Node::new(7, 0, 1)],
[0, 2],
[
Node::Cmux(39, 1, 0),
Node::Cmux(39, 0, 1),
Node::Cmux(7, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B8(BitCircuit::new(
[Node::new(40, 0, 1), Node::new(40, 1, 0), Node::new(8, 0, 1)],
[0, 2],
[
Node::Cmux(40, 0, 1),
Node::Cmux(40, 1, 0),
Node::Cmux(8, 0, 1),
Node::None,
],
2,
)),
AnyBitCircuit::B9(BitCircuit::new(
[Node::new(41, 1, 0), Node::new(41, 0, 1), Node::new(9, 1, 0)],
[0, 2],
[
Node::Cmux(41, 1, 0),
Node::Cmux(41, 0, 1),
Node::Cmux(9, 1, 0),
Node::None,
],
2,
)),
AnyBitCircuit::B10(BitCircuit::new(
[
Node::new(42, 0, 1),
Node::new(42, 1, 0),
Node::new(10, 0, 1),
Node::Cmux(42, 0, 1),
Node::Cmux(42, 1, 0),
Node::Cmux(10, 0, 1),
Node::None,
],
[0, 2],
2,
)),
AnyBitCircuit::B11(BitCircuit::new(
[
Node::new(43, 1, 0),
Node::new(43, 0, 1),
Node::new(11, 1, 0),
Node::Cmux(43, 0, 1),
Node::Cmux(43, 1, 0),
Node::Cmux(11, 0, 1),
Node::None,
],
[0, 2],
2,
)),
AnyBitCircuit::B12(BitCircuit::new(
[
Node::new(44, 0, 1),
Node::new(44, 1, 0),
Node::new(12, 0, 1),
Node::Cmux(44, 0, 1),
Node::Cmux(44, 1, 0),
Node::Cmux(12, 0, 1),
Node::None,
],
[0, 2],
2,
)),
AnyBitCircuit::B13(BitCircuit::new(
[
Node::new(45, 1, 0),
Node::new(45, 0, 1),
Node::new(13, 1, 0),
Node::Cmux(45, 1, 0),
Node::Cmux(45, 0, 1),
Node::Cmux(13, 1, 0),
Node::None,
],
[0, 2],
2,
)),
AnyBitCircuit::B14(BitCircuit::new(
[
Node::new(46, 0, 1),
Node::new(46, 1, 0),
Node::new(14, 0, 1),
Node::Cmux(46, 1, 0),
Node::Cmux(46, 0, 1),
Node::Cmux(14, 1, 0),
Node::None,
],
[0, 2],
2,
)),
AnyBitCircuit::B15(BitCircuit::new(
[
Node::new(47, 1, 0),
Node::new(47, 0, 1),
Node::new(15, 1, 0),
Node::Cmux(47, 1, 0),
Node::Cmux(47, 0, 1),
Node::Cmux(15, 1, 0),
Node::None,
],
[0, 2],
2,
)),
AnyBitCircuit::B16(BitCircuit::new(
[
Node::new(48, 0, 1),
Node::new(48, 1, 0),
Node::new(16, 0, 1),
Node::Cmux(48, 0, 1),
Node::Cmux(48, 1, 0),
Node::Cmux(16, 0, 1),
Node::None,
],
[0, 2],
2,
)),
AnyBitCircuit::B17(BitCircuit::new(
[
Node::new(49, 1, 0),
Node::new(49, 0, 1),
Node::new(17, 1, 0),
Node::Cmux(49, 0, 1),
Node::Cmux(49, 1, 0),
Node::Cmux(17, 0, 1),
Node::None,
],
[0, 2],
2,
)),
AnyBitCircuit::B18(BitCircuit::new(
[
Node::new(50, 1, 0),
Node::new(50, 0, 1),
Node::new(18, 1, 0),
Node::Cmux(50, 0, 1),
Node::Cmux(50, 1, 0),
Node::Cmux(18, 0, 1),
Node::None,
],
[0, 2],
2,
)),
AnyBitCircuit::B19(BitCircuit::new(
[
Node::new(51, 0, 1),
Node::new(51, 1, 0),
Node::new(19, 0, 1),
Node::Cmux(51, 1, 0),
Node::Cmux(51, 0, 1),
Node::Cmux(19, 1, 0),
Node::None,
],
[0, 2],
2,
)),
AnyBitCircuit::B20(BitCircuit::new(
[
Node::new(52, 1, 0),
Node::new(52, 0, 1),
Node::new(20, 1, 0),
Node::Cmux(52, 1, 0),
Node::Cmux(52, 0, 1),
Node::Cmux(20, 1, 0),
Node::None,
],
[0, 2],
2,
)),
AnyBitCircuit::B21(BitCircuit::new(
[
Node::new(53, 1, 0),
Node::new(53, 0, 1),
Node::new(21, 1, 0),
Node::Cmux(53, 0, 1),
Node::Cmux(53, 1, 0),
Node::Cmux(21, 0, 1),
Node::None,
],
[0, 2],
2,
)),
AnyBitCircuit::B22(BitCircuit::new(
[
Node::new(54, 1, 0),
Node::new(54, 0, 1),
Node::new(22, 1, 0),
Node::Cmux(54, 1, 0),
Node::Cmux(54, 0, 1),
Node::Cmux(22, 1, 0),
Node::None,
],
[0, 2],
2,
)),
AnyBitCircuit::B23(BitCircuit::new(
[
Node::new(55, 1, 0),
Node::new(55, 0, 1),
Node::new(23, 1, 0),
Node::Cmux(55, 1, 0),
Node::Cmux(55, 0, 1),
Node::Cmux(23, 1, 0),
Node::None,
],
[0, 2],
2,
)),
AnyBitCircuit::B24(BitCircuit::new(
[
Node::new(56, 1, 0),
Node::new(56, 0, 1),
Node::new(24, 1, 0),
Node::Cmux(56, 0, 1),
Node::Cmux(56, 1, 0),
Node::Cmux(24, 0, 1),
Node::None,
],
[0, 2],
2,
)),
AnyBitCircuit::B25(BitCircuit::new(
[
Node::new(57, 1, 0),
Node::new(57, 0, 1),
Node::new(25, 1, 0),
Node::Cmux(57, 0, 1),
Node::Cmux(57, 1, 0),
Node::Cmux(25, 0, 1),
Node::None,
],
[0, 2],
2,
)),
AnyBitCircuit::B26(BitCircuit::new(
[
Node::new(58, 1, 0),
Node::new(58, 0, 1),
Node::new(26, 1, 0),
Node::Cmux(58, 1, 0),
Node::Cmux(58, 0, 1),
Node::Cmux(26, 1, 0),
Node::None,
],
[0, 2],
2,
)),
AnyBitCircuit::B27(BitCircuit::new(
[
Node::new(59, 1, 0),
Node::new(59, 0, 1),
Node::new(27, 1, 0),
Node::Cmux(59, 0, 1),
Node::Cmux(59, 1, 0),
Node::Cmux(27, 0, 1),
Node::None,
],
[0, 2],
2,
)),
AnyBitCircuit::B28(BitCircuit::new(
[
Node::new(60, 1, 0),
Node::new(60, 0, 1),
Node::new(28, 1, 0),
Node::Cmux(60, 0, 1),
Node::Cmux(60, 1, 0),
Node::Cmux(28, 0, 1),
Node::None,
],
[0, 2],
2,
)),
AnyBitCircuit::B29(BitCircuit::new(
[
Node::new(61, 0, 1),
Node::new(61, 1, 0),
Node::new(29, 0, 1),
Node::Cmux(61, 0, 1),
Node::Cmux(61, 1, 0),
Node::Cmux(29, 0, 1),
Node::None,
],
[0, 2],
2,
)),
AnyBitCircuit::B30(BitCircuit::new(
[
Node::new(62, 1, 0),
Node::new(62, 0, 1),
Node::new(30, 1, 0),
Node::Cmux(62, 0, 1),
Node::Cmux(62, 1, 0),
Node::Cmux(30, 0, 1),
Node::None,
],
[0, 2],
2,
)),
AnyBitCircuit::B31(BitCircuit::new(
[
Node::new(63, 1, 0),
Node::new(63, 0, 1),
Node::new(31, 1, 0),
Node::Cmux(63, 1, 0),
Node::Cmux(63, 0, 1),
Node::Cmux(31, 1, 0),
Node::None,
],
[0, 2],
2,
)),
]);

View File

@@ -1,3 +1,5 @@
use core::panic;
use itertools::Itertools;
use poulpy_core::{
GLWEAdd, GLWECopy, GLWEExternalProduct, GLWESub, ScratchTakeCore,
@@ -11,18 +13,17 @@ use poulpy_hal::layouts::{Backend, DataMut, DataRef, Module, Scratch, ZnxZero};
use crate::tfhe::bdd_arithmetic::UnsignedInteger;
pub trait BitCircuitInfo {
fn info(&self) -> (&[Node], &[usize], usize);
fn info(&self) -> (&[Node], usize);
}
pub trait GetBitCircuitInfo<T: UnsignedInteger> {
fn input_size(&self) -> usize;
fn output_size(&self) -> usize;
fn get_circuit(&self, bit: usize) -> (&[Node], &[usize], usize);
fn get_circuit(&self, bit: usize) -> (&[Node], usize);
}
pub(crate) struct BitCircuit<const N: usize, const K: usize> {
pub(crate) struct BitCircuit<const N: usize> {
pub(crate) nodes: [Node; N],
pub(crate) levels: [usize; K],
pub(crate) max_inter_state: usize,
}
@@ -62,7 +63,9 @@ where
}
for (i, out_i) in out.iter_mut().enumerate().take(circuit.output_size()) {
let (nodes, levels, max_inter_state) = circuit.get_circuit(i);
let (nodes, max_inter_state) = circuit.get_circuit(i);
assert!(nodes.len().is_multiple_of(max_inter_state));
let (mut level, scratch_1) = scratch.take_glwe_slice(max_inter_state * 2, out_i);
@@ -76,40 +79,45 @@ where
let mut level_ref = level.iter_mut().collect_vec();
let (mut prev_level, mut next_level) = level_ref.split_at_mut(max_inter_state);
for i in 0..levels.len() - 1 {
let start: usize = levels[i];
let end: usize = levels[i + 1];
let nodes_lvl: &[Node] = &nodes[start..end];
let (all_but_last, last) = nodes.split_at(nodes.len() - max_inter_state);
for nodes_lvl in all_but_last.chunks_exact(max_inter_state) {
for (j, node) in nodes_lvl.iter().enumerate() {
if node.low_index == node.high_index {
self.glwe_copy(next_level[j], prev_level[node.low_index]);
} else {
match node {
Node::Cmux(in_idx, hi_idx, lo_idx) => {
self.cmux(
next_level[j],
prev_level[node.high_index],
prev_level[node.low_index],
&inputs[node.input_index].to_ref(),
prev_level[*hi_idx],
prev_level[*lo_idx],
&inputs[*in_idx].to_ref(),
scratch_1,
);
}
Node::Copy => self.glwe_copy(next_level[j], prev_level[j]), /* Update BDD circuits to order Cmux -> Copy -> None so that mem swap can be used */
Node::None => {}
}
}
(prev_level, next_level) = (next_level, prev_level);
}
// handle last output
// there's always only 1 node at last level
let node: &Node = nodes.last().unwrap();
// Last chunck of max_inter_state Nodes is always structured as
// [CMUX, NONE, NONE, ..., NONE]
match &last[0] {
Node::Cmux(in_idx, hi_idx, lo_idx) => {
self.cmux(
out_i,
prev_level[node.high_index],
prev_level[node.low_index],
&inputs[node.input_index].to_ref(),
prev_level[*hi_idx],
prev_level[*lo_idx],
&inputs[*in_idx].to_ref(),
scratch_1,
);
}
_ => {
panic!("invalid last node, should be CMUX")
}
}
}
for out_i in out.iter_mut().skip(circuit.output_size()) {
out_i.data_mut().zero();
@@ -117,40 +125,25 @@ where
}
}
impl<const N: usize, const K: usize> BitCircuit<N, K> {
pub(crate) const fn new(nodes: [Node; N], levels: [usize; K], max_inter_state: usize) -> Self {
impl<const N: usize> BitCircuit<N> {
pub(crate) const fn new(nodes: [Node; N], max_inter_state: usize) -> Self {
Self {
nodes,
levels,
max_inter_state,
}
}
}
impl<const N: usize, const K: usize> BitCircuitInfo for BitCircuit<N, K> {
fn info(&self) -> (&[Node], &[usize], usize) {
(
self.nodes.as_ref(),
self.levels.as_ref(),
self.max_inter_state,
)
impl<const N: usize> BitCircuitInfo for BitCircuit<N> {
fn info(&self) -> (&[Node], usize) {
(self.nodes.as_ref(), self.max_inter_state)
}
}
#[derive(Debug)]
pub struct Node {
input_index: usize,
high_index: usize,
low_index: usize,
}
impl Node {
pub(crate) const fn new(input_index: usize, high_index: usize, low_index: usize) -> Self {
Self {
input_index,
high_index,
low_index,
}
}
pub enum Node {
Cmux(usize, usize, usize),
Copy,
None,
}
pub trait Cmux<BE: Backend> {

View File

@@ -2,7 +2,7 @@ use std::time::Instant;
use poulpy_backend::FFT64Ref;
use poulpy_core::{
GGSWNoise, GLWEDecrypt, GLWENoise, ScratchTakeCore,
GGSWNoise, GLWEDecrypt, GLWEEncryptSk, GLWENoise, ScratchTakeCore,
layouts::{GGSWLayout, GLWELayout, GLWESecret, GLWESecretPreparedFactory, LWEInfos, LWESecret, prepared::GLWESecretPrepared},
};
use poulpy_hal::{
@@ -40,7 +40,8 @@ where
+ BDDKeyPreparedFactory<BRA, BE>
+ GGSWNoise<BE>
+ FheUintBlocksPrepare<BRA, u32, BE>
+ ExecuteBDDCircuit2WTo1W<u32, BE>,
+ ExecuteBDDCircuit2WTo1W<u32, BE>
+ GLWEEncryptSk<BE>,
BlindRotationKey<Vec<u8>, BRA>: BlindRotationKeyFactory<BRA>,
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
Scratch<BE>: ScratchTakeCore<BE>,
@@ -63,55 +64,12 @@ where
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
sk_glwe_prep.prepare(&module, &sk_glwe);
let a: u32 = source.next_u32();
let b: u32 = source.next_u32();
let a: u32 = 645139204;
let b: u32 = 0;
println!("a: {a}");
println!("b: {b}");
let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
let mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
let mut c_enc: FheUintBlocks<Vec<u8>, u32> = FheUintBlocks::<Vec<u8>, u32>::alloc(&module, &glwe_infos);
let mut c_enc_prep_debug: FheUintBlocksPreparedDebug<Vec<u8>, u32> =
FheUintBlocksPreparedDebug::<Vec<u8>, u32>::alloc(&module, &ggsw_infos);
let mut c_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
a_enc_prep.encrypt_sk(
&module,
a,
&sk_glwe_prep,
&mut source_xa,
&mut source_xe,
scratch.borrow(),
);
b_enc_prep.encrypt_sk(
&module,
b,
&sk_glwe_prep,
&mut source_xa,
&mut source_xe,
scratch.borrow(),
);
let start: Instant = Instant::now();
c_enc.sub(&module, &a_enc_prep, &b_enc_prep, scratch.borrow());
let duration: std::time::Duration = start.elapsed();
println!("add: {} ms", duration.as_millis());
println!(
"have: {}",
c_enc.decrypt(&module, &sk_glwe_prep, scratch.borrow())
);
println!("want: {}", a.wrapping_sub(b));
println!(
"noise: {:?}",
c_enc.noise(&module, &sk_glwe_prep, a.wrapping_sub(b), scratch.borrow())
);
let n_lwe: u32 = TEST_N_LWE;
let block_size: u32 = TEST_BLOCK_SIZE;
@@ -123,6 +81,8 @@ where
let mut bdd_key: BDDKey<Vec<u8>, BRA> = BDDKey::alloc_from_infos(&bdd_key_infos);
let now: Instant = Instant::now();
source.fill_bytes(&mut scratch.borrow().data);
scratch.borrow().data.fill(0);
bdd_key.encrypt_sk(
&module,
&sk_lwe,
@@ -132,37 +92,46 @@ where
scratch.borrow(),
);
let mut bdd_key_prepared: BDDKeyPrepared<Vec<u8>, BRA, BE> = BDDKeyPrepared::alloc_from_infos(&module, &bdd_key_infos);
source.fill_bytes(&mut scratch.borrow().data);
bdd_key_prepared.prepare(&module, &bdd_key, scratch.borrow());
println!("BDD-KGEN: {} ms", now.elapsed().as_millis());
let now: Instant = Instant::now();
c_enc_prep_debug.prepare(&module, &c_enc, &bdd_key_prepared, scratch.borrow());
println!("CBT: {} ms", now.elapsed().as_millis());
let mut sum_enc: FheUintBlocks<Vec<u8>, u32> = FheUintBlocks::<Vec<u8>, u32>::alloc(&module, &glwe_infos);
let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
let mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
c_enc_prep_debug.noise(&module, &sk_glwe_prep, a.wrapping_sub(b));
let now: Instant = Instant::now();
c_enc_prep.prepare(&module, &c_enc, &bdd_key_prepared, scratch.borrow());
println!("CBT: {} ms", now.elapsed().as_millis());
let start: Instant = Instant::now();
c_enc.add(&module, &c_enc_prep, &b_enc_prep, scratch.borrow());
let duration: std::time::Duration = start.elapsed();
println!("add: {} ms", duration.as_millis());
println!(
"have: {}",
c_enc.decrypt(&module, &sk_glwe_prep, scratch.borrow())
);
println!("want: {}", b.wrapping_add(a.wrapping_sub(b)));
println!(
"noise: {:?}",
c_enc.noise(
source.fill_bytes(&mut scratch.borrow().data);
a_enc_prep.encrypt_sk(
&module,
a,
&sk_glwe_prep,
b.wrapping_add(a.wrapping_sub(b)),
scratch.borrow()
)
&mut source_xa,
&mut source_xe,
scratch.borrow(),
);
source.fill_bytes(&mut scratch.borrow().data);
b_enc_prep.encrypt_sk(
&module,
b,
&sk_glwe_prep,
&mut source_xa,
&mut source_xe,
scratch.borrow(),
);
// d + a
sum_enc.add(&module, &a_enc_prep, &b_enc_prep, scratch.borrow());
println!(
"other have: {:032b}",
sum_enc.decrypt(&module, &sk_glwe_prep, scratch.borrow())
);
println!("other want: {:032b}", b.wrapping_add(a));
// print a, b, and d
println!("a: {a}");
println!("b: {b}");
}