arnaucube
arnaucube/poulpyPublic Self-hosted repository
poulpy/poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/and_codegen.rs
poulpy-schemes/src/tfhe/bdd_arithmetic/circuits/u32/and_codegen.rsRaw
  1use crate::tfhe::bdd_arithmetic::{BitCircuit, BitCircuitInfo, Circuit, GetBitCircuitInfo, Node};
  2pub(crate) enum AnyBitCircuit {
  3    B0(BitCircuit<3, 2>),
  4    B1(BitCircuit<3, 2>),
  5    B2(BitCircuit<3, 2>),
  6    B3(BitCircuit<3, 2>),
  7    B4(BitCircuit<3, 2>),
  8    B5(BitCircuit<3, 2>),
  9    B6(BitCircuit<3, 2>),
 10    B7(BitCircuit<3, 2>),
 11    B8(BitCircuit<3, 2>),
 12    B9(BitCircuit<3, 2>),
 13    B10(BitCircuit<3, 2>),
 14    B11(BitCircuit<3, 2>),
 15    B12(BitCircuit<3, 2>),
 16    B13(BitCircuit<3, 2>),
 17    B14(BitCircuit<3, 2>),
 18    B15(BitCircuit<3, 2>),
 19    B16(BitCircuit<3, 2>),
 20    B17(BitCircuit<3, 2>),
 21    B18(BitCircuit<3, 2>),
 22    B19(BitCircuit<3, 2>),
 23    B20(BitCircuit<3, 2>),
 24    B21(BitCircuit<3, 2>),
 25    B22(BitCircuit<3, 2>),
 26    B23(BitCircuit<3, 2>),
 27    B24(BitCircuit<3, 2>),
 28    B25(BitCircuit<3, 2>),
 29    B26(BitCircuit<3, 2>),
 30    B27(BitCircuit<3, 2>),
 31    B28(BitCircuit<3, 2>),
 32    B29(BitCircuit<3, 2>),
 33    B30(BitCircuit<3, 2>),
 34    B31(BitCircuit<3, 2>),
 35}
 36impl BitCircuitInfo for AnyBitCircuit {
 37    fn info(&self) -> (&[Node], &[usize], usize) {
 38        match self {
 39            AnyBitCircuit::B0(bit_circuit) => (
 40                bit_circuit.nodes.as_ref(),
 41                bit_circuit.levels.as_ref(),
 42                bit_circuit.max_inter_state,
 43            ),
 44            AnyBitCircuit::B1(bit_circuit) => (
 45                bit_circuit.nodes.as_ref(),
 46                bit_circuit.levels.as_ref(),
 47                bit_circuit.max_inter_state,
 48            ),
 49            AnyBitCircuit::B2(bit_circuit) => (
 50                bit_circuit.nodes.as_ref(),
 51                bit_circuit.levels.as_ref(),
 52                bit_circuit.max_inter_state,
 53            ),
 54            AnyBitCircuit::B3(bit_circuit) => (
 55                bit_circuit.nodes.as_ref(),
 56                bit_circuit.levels.as_ref(),
 57                bit_circuit.max_inter_state,
 58            ),
 59            AnyBitCircuit::B4(bit_circuit) => (
 60                bit_circuit.nodes.as_ref(),
 61                bit_circuit.levels.as_ref(),
 62                bit_circuit.max_inter_state,
 63            ),
 64            AnyBitCircuit::B5(bit_circuit) => (
 65                bit_circuit.nodes.as_ref(),
 66                bit_circuit.levels.as_ref(),
 67                bit_circuit.max_inter_state,
 68            ),
 69            AnyBitCircuit::B6(bit_circuit) => (
 70                bit_circuit.nodes.as_ref(),
 71                bit_circuit.levels.as_ref(),
 72                bit_circuit.max_inter_state,
 73            ),
 74            AnyBitCircuit::B7(bit_circuit) => (
 75                bit_circuit.nodes.as_ref(),
 76                bit_circuit.levels.as_ref(),
 77                bit_circuit.max_inter_state,
 78            ),
 79            AnyBitCircuit::B8(bit_circuit) => (
 80                bit_circuit.nodes.as_ref(),
 81                bit_circuit.levels.as_ref(),
 82                bit_circuit.max_inter_state,
 83            ),
 84            AnyBitCircuit::B9(bit_circuit) => (
 85                bit_circuit.nodes.as_ref(),
 86                bit_circuit.levels.as_ref(),
 87                bit_circuit.max_inter_state,
 88            ),
 89            AnyBitCircuit::B10(bit_circuit) => (
 90                bit_circuit.nodes.as_ref(),
 91                bit_circuit.levels.as_ref(),
 92                bit_circuit.max_inter_state,
 93            ),
 94            AnyBitCircuit::B11(bit_circuit) => (
 95                bit_circuit.nodes.as_ref(),
 96                bit_circuit.levels.as_ref(),
 97                bit_circuit.max_inter_state,
 98            ),
 99            AnyBitCircuit::B12(bit_circuit) => (
100                bit_circuit.nodes.as_ref(),
101                bit_circuit.levels.as_ref(),
102                bit_circuit.max_inter_state,
103            ),
104            AnyBitCircuit::B13(bit_circuit) => (
105                bit_circuit.nodes.as_ref(),
106                bit_circuit.levels.as_ref(),
107                bit_circuit.max_inter_state,
108            ),
109            AnyBitCircuit::B14(bit_circuit) => (
110                bit_circuit.nodes.as_ref(),
111                bit_circuit.levels.as_ref(),
112                bit_circuit.max_inter_state,
113            ),
114            AnyBitCircuit::B15(bit_circuit) => (
115                bit_circuit.nodes.as_ref(),
116                bit_circuit.levels.as_ref(),
117                bit_circuit.max_inter_state,
118            ),
119            AnyBitCircuit::B16(bit_circuit) => (
120                bit_circuit.nodes.as_ref(),
121                bit_circuit.levels.as_ref(),
122                bit_circuit.max_inter_state,
123            ),
124            AnyBitCircuit::B17(bit_circuit) => (
125                bit_circuit.nodes.as_ref(),
126                bit_circuit.levels.as_ref(),
127                bit_circuit.max_inter_state,
128            ),
129            AnyBitCircuit::B18(bit_circuit) => (
130                bit_circuit.nodes.as_ref(),
131                bit_circuit.levels.as_ref(),
132                bit_circuit.max_inter_state,
133            ),
134            AnyBitCircuit::B19(bit_circuit) => (
135                bit_circuit.nodes.as_ref(),
136                bit_circuit.levels.as_ref(),
137                bit_circuit.max_inter_state,
138            ),
139            AnyBitCircuit::B20(bit_circuit) => (
140                bit_circuit.nodes.as_ref(),
141                bit_circuit.levels.as_ref(),
142                bit_circuit.max_inter_state,
143            ),
144            AnyBitCircuit::B21(bit_circuit) => (
145                bit_circuit.nodes.as_ref(),
146                bit_circuit.levels.as_ref(),
147                bit_circuit.max_inter_state,
148            ),
149            AnyBitCircuit::B22(bit_circuit) => (
150                bit_circuit.nodes.as_ref(),
151                bit_circuit.levels.as_ref(),
152                bit_circuit.max_inter_state,
153            ),
154            AnyBitCircuit::B23(bit_circuit) => (
155                bit_circuit.nodes.as_ref(),
156                bit_circuit.levels.as_ref(),
157                bit_circuit.max_inter_state,
158            ),
159            AnyBitCircuit::B24(bit_circuit) => (
160                bit_circuit.nodes.as_ref(),
161                bit_circuit.levels.as_ref(),
162                bit_circuit.max_inter_state,
163            ),
164            AnyBitCircuit::B25(bit_circuit) => (
165                bit_circuit.nodes.as_ref(),
166                bit_circuit.levels.as_ref(),
167                bit_circuit.max_inter_state,
168            ),
169            AnyBitCircuit::B26(bit_circuit) => (
170                bit_circuit.nodes.as_ref(),
171                bit_circuit.levels.as_ref(),
172                bit_circuit.max_inter_state,
173            ),
174            AnyBitCircuit::B27(bit_circuit) => (
175                bit_circuit.nodes.as_ref(),
176                bit_circuit.levels.as_ref(),
177                bit_circuit.max_inter_state,
178            ),
179            AnyBitCircuit::B28(bit_circuit) => (
180                bit_circuit.nodes.as_ref(),
181                bit_circuit.levels.as_ref(),
182                bit_circuit.max_inter_state,
183            ),
184            AnyBitCircuit::B29(bit_circuit) => (
185                bit_circuit.nodes.as_ref(),
186                bit_circuit.levels.as_ref(),
187                bit_circuit.max_inter_state,
188            ),
189            AnyBitCircuit::B30(bit_circuit) => (
190                bit_circuit.nodes.as_ref(),
191                bit_circuit.levels.as_ref(),
192                bit_circuit.max_inter_state,
193            ),
194            AnyBitCircuit::B31(bit_circuit) => (
195                bit_circuit.nodes.as_ref(),
196                bit_circuit.levels.as_ref(),
197                bit_circuit.max_inter_state,
198            ),
199        }
200    }
201}
202
203impl GetBitCircuitInfo<u32> for Circuit<AnyBitCircuit, 32usize> {
204    fn input_size(&self) -> usize {
205        2 * u32::BITS as usize
206    }
207    fn output_size(&self) -> usize {
208        u32::BITS as usize
209    }
210    fn get_circuit(&self, bit: usize) -> (&[Node], &[usize], usize) {
211        self.0[bit].info()
212    }
213}
214
215pub(crate) static OUTPUT_CIRCUITS: Circuit<AnyBitCircuit, 32usize> = Circuit([
216    AnyBitCircuit::B0(BitCircuit::new(
217        [Node::new(0, 0, 0), Node::new(32, 1, 0), Node::new(0, 1, 0)],
218        [0, 2],
219        2,
220    )),
221    AnyBitCircuit::B1(BitCircuit::new(
222        [Node::new(0, 0, 0), Node::new(33, 1, 0), Node::new(1, 1, 0)],
223        [0, 2],
224        2,
225    )),
226    AnyBitCircuit::B2(BitCircuit::new(
227        [Node::new(0, 0, 0), Node::new(34, 1, 0), Node::new(2, 1, 0)],
228        [0, 2],
229        2,
230    )),
231    AnyBitCircuit::B3(BitCircuit::new(
232        [Node::new(0, 0, 0), Node::new(35, 1, 0), Node::new(3, 1, 0)],
233        [0, 2],
234        2,
235    )),
236    AnyBitCircuit::B4(BitCircuit::new(
237        [Node::new(0, 0, 0), Node::new(36, 1, 0), Node::new(4, 1, 0)],
238        [0, 2],
239        2,
240    )),
241    AnyBitCircuit::B5(BitCircuit::new(
242        [Node::new(0, 0, 0), Node::new(37, 1, 0), Node::new(5, 1, 0)],
243        [0, 2],
244        2,
245    )),
246    AnyBitCircuit::B6(BitCircuit::new(
247        [Node::new(0, 0, 0), Node::new(38, 1, 0), Node::new(6, 1, 0)],
248        [0, 2],
249        2,
250    )),
251    AnyBitCircuit::B7(BitCircuit::new(
252        [Node::new(0, 0, 0), Node::new(39, 1, 0), Node::new(7, 1, 0)],
253        [0, 2],
254        2,
255    )),
256    AnyBitCircuit::B8(BitCircuit::new(
257        [Node::new(0, 0, 0), Node::new(40, 1, 0), Node::new(8, 1, 0)],
258        [0, 2],
259        2,
260    )),
261    AnyBitCircuit::B9(BitCircuit::new(
262        [Node::new(0, 0, 0), Node::new(41, 1, 0), Node::new(9, 1, 0)],
263        [0, 2],
264        2,
265    )),
266    AnyBitCircuit::B10(BitCircuit::new(
267        [Node::new(0, 0, 0), Node::new(42, 1, 0), Node::new(10, 1, 0)],
268        [0, 2],
269        2,
270    )),
271    AnyBitCircuit::B11(BitCircuit::new(
272        [Node::new(0, 0, 0), Node::new(43, 1, 0), Node::new(11, 1, 0)],
273        [0, 2],
274        2,
275    )),
276    AnyBitCircuit::B12(BitCircuit::new(
277        [Node::new(0, 0, 0), Node::new(44, 1, 0), Node::new(12, 1, 0)],
278        [0, 2],
279        2,
280    )),
281    AnyBitCircuit::B13(BitCircuit::new(
282        [Node::new(0, 0, 0), Node::new(45, 1, 0), Node::new(13, 1, 0)],
283        [0, 2],
284        2,
285    )),
286    AnyBitCircuit::B14(BitCircuit::new(
287        [Node::new(0, 0, 0), Node::new(46, 1, 0), Node::new(14, 1, 0)],
288        [0, 2],
289        2,
290    )),
291    AnyBitCircuit::B15(BitCircuit::new(
292        [Node::new(0, 0, 0), Node::new(47, 1, 0), Node::new(15, 1, 0)],
293        [0, 2],
294        2,
295    )),
296    AnyBitCircuit::B16(BitCircuit::new(
297        [Node::new(0, 0, 0), Node::new(48, 1, 0), Node::new(16, 1, 0)],
298        [0, 2],
299        2,
300    )),
301    AnyBitCircuit::B17(BitCircuit::new(
302        [Node::new(0, 0, 0), Node::new(49, 1, 0), Node::new(17, 1, 0)],
303        [0, 2],
304        2,
305    )),
306    AnyBitCircuit::B18(BitCircuit::new(
307        [Node::new(0, 0, 0), Node::new(50, 1, 0), Node::new(18, 1, 0)],
308        [0, 2],
309        2,
310    )),
311    AnyBitCircuit::B19(BitCircuit::new(
312        [Node::new(0, 0, 0), Node::new(51, 1, 0), Node::new(19, 1, 0)],
313        [0, 2],
314        2,
315    )),
316    AnyBitCircuit::B20(BitCircuit::new(
317        [Node::new(0, 0, 0), Node::new(52, 1, 0), Node::new(20, 1, 0)],
318        [0, 2],
319        2,
320    )),
321    AnyBitCircuit::B21(BitCircuit::new(
322        [Node::new(0, 0, 0), Node::new(53, 1, 0), Node::new(21, 1, 0)],
323        [0, 2],
324        2,
325    )),
326    AnyBitCircuit::B22(BitCircuit::new(
327        [Node::new(0, 0, 0), Node::new(54, 1, 0), Node::new(22, 1, 0)],
328        [0, 2],
329        2,
330    )),
331    AnyBitCircuit::B23(BitCircuit::new(
332        [Node::new(0, 0, 0), Node::new(55, 1, 0), Node::new(23, 1, 0)],
333        [0, 2],
334        2,
335    )),
336    AnyBitCircuit::B24(BitCircuit::new(
337        [Node::new(0, 0, 0), Node::new(56, 1, 0), Node::new(24, 1, 0)],
338        [0, 2],
339        2,
340    )),
341    AnyBitCircuit::B25(BitCircuit::new(
342        [Node::new(0, 0, 0), Node::new(57, 1, 0), Node::new(25, 1, 0)],
343        [0, 2],
344        2,
345    )),
346    AnyBitCircuit::B26(BitCircuit::new(
347        [Node::new(0, 0, 0), Node::new(58, 1, 0), Node::new(26, 1, 0)],
348        [0, 2],
349        2,
350    )),
351    AnyBitCircuit::B27(BitCircuit::new(
352        [Node::new(0, 0, 0), Node::new(59, 1, 0), Node::new(27, 1, 0)],
353        [0, 2],
354        2,
355    )),
356    AnyBitCircuit::B28(BitCircuit::new(
357        [Node::new(0, 0, 0), Node::new(60, 1, 0), Node::new(28, 1, 0)],
358        [0, 2],
359        2,
360    )),
361    AnyBitCircuit::B29(BitCircuit::new(
362        [Node::new(0, 0, 0), Node::new(61, 1, 0), Node::new(29, 1, 0)],
363        [0, 2],
364        2,
365    )),
366    AnyBitCircuit::B30(BitCircuit::new(
367        [Node::new(0, 0, 0), Node::new(62, 1, 0), Node::new(30, 1, 0)],
368        [0, 2],
369        2,
370    )),
371    AnyBitCircuit::B31(BitCircuit::new(
372        [Node::new(0, 0, 0), Node::new(63, 1, 0), Node::new(31, 1, 0)],
373        [0, 2],
374        2,
375    )),
376]);