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