Skip to main content

prjunnamed_netlist/
cell.rs

1use std::{borrow::Cow, hash::Hash};
2
3use crate::{ControlNet, Design, ValueBit, TargetCellPurity, ConstBit, Value};
4
5mod decision;
6mod flip_flop;
7mod memory;
8mod io_buffer;
9mod target;
10mod instance;
11
12pub use decision::{MatchCell, AssignCell};
13pub use flip_flop::FlipFlop;
14pub use memory::{Memory, MemoryWritePort, MemoryReadPort, MemoryReadFlipFlop, MemoryPortRelation};
15pub use io_buffer::IoBuffer;
16pub use target::TargetCell;
17pub use instance::Instance;
18
19/// Compact, 16-byte representation for cells common in fine netlists.
20///
21/// This type is used internally within [`Design`]. Cells that can be
22/// represented with [`CellRepr`] get stored without a separate heap
23/// allocation. All others get represented as [`CellRepr::Coarse`].
24#[derive(Debug, Clone, PartialEq, Eq, Hash)]
25pub(crate) enum CellRepr {
26    /// Constant.  There are always exactly three constant cells in a design,
27    /// occupying the first three indices, corresponding to the three possible values:
28    /// 0, 1, X (in that order).
29    Const(ConstBit),
30
31    /// Reserved index. Can be created with [`Design::add_void`] for later
32    /// replacement with [`Design::replace_value`], or left over
33    /// after [`CellRef::unalive`].
34    ///
35    /// [`CellRef::unalive`]: crate::CellRef::unalive
36    Void,
37
38    /// Represents an index taken by a cell with more than one bit of
39    /// output. Stores the base index of the cell in question.
40    Skip(u32),
41
42    Buf(ValueBit),
43    Not(ValueBit),
44    And(ValueBit, ValueBit),
45    Or(ValueBit, ValueBit),
46    Xor(ValueBit, ValueBit),
47    Mux(ValueBit, [ValueBit; 2]), // b[a]
48    Adc(ValueBit, ValueBit, ValueBit), // a + b + ci
49    Aig(ValueBit, bool, ValueBit, bool),
50
51    Boxed(Box<Cell>),
52}
53
54/// A unit of logic.
55///
56/// Within a [`Design`], each cell is identified by a range of indices,
57/// with each index corresponding to one of the output bits of the cell.
58/// As such, the cell itself only contains information about its inputs,
59/// with the outputs being implicit.
60///
61/// (do note that cells without any outputs, such as [`output`][Cell::Output]
62/// or [`name`][Cell::Name], still get assigned an index)
63#[derive(Clone, Debug, PartialEq, Eq, Hash)]
64pub enum Cell {
65    Const(ConstBit),
66    Buf(Value),
67    Not(Value),
68    /// `a & b`.
69    ///
70    /// Has short-circuiting behavior for inputs containing `X` — if the other
71    /// bit is `0`, the output is `0` and the `X` doesn't propagate.
72    And(Value, Value),
73    /// `a | b`.
74    ///
75    /// Has short-circuiting behavior for inputs containing `X` — if the other
76    /// bit is `1`, the output is `1` and the `X` doesn't propagate.
77    Or(Value, Value),
78    Xor(Value, Value),
79    /// `b[a]`.
80    ///
81    /// Muxes are glitch free — if `a` is `X`, the bit positions that match
82    /// between `b[0]` and `b[1]` still have a defined value. The `X` propagates
83    /// only at the positions where `b[0]` and `b[1]` differ.
84    Mux(ValueBit, [Value; 2]),
85    /// `a + b + ci` — add with carry.
86    ///
87    /// Output is one bit wider than `a` and `b` — the most significant bit
88    /// is the carry-out.
89    ///
90    /// `X`s in the input propagate only to the more significant bits, and
91    /// do not affect the less significant bits.
92    Adc(Value, Value, ValueBit), // a + b + ci
93    /// `a & b`, single-bit wide, both inputs freely invertible.
94    ///
95    /// A variant of the `And` cell meant for fine logic optimization.
96    Aig(ControlNet, ControlNet),
97
98    Eq(Value, Value),
99    ULt(Value, Value),
100    SLt(Value, Value),
101
102    /// `a << (b * c)`. The bottom bits are filled with zeros.
103    ///
104    /// General notes for all shift cells:
105    /// - output is the same width as `a`. If you need wider output,
106    ///   zero-extend or sign-extend your input first, as appropriate.
107    /// - the shift count does not wrap. If you shift by more than
108    ///   `a.len() - 1`, you get the same result as if you made an equivalent
109    ///   sequence of 1-bit shifts (i.e. all zeros, all sign bits, or all `X`,
110    ///   as appropriate).
111    /// - shift cells are one of the few cells which *do not* expect their
112    ///   inputs to be of the same width. In fact, that is the expected case.
113    Shl(Value, Value, u32),
114    /// `a >> (b * c)`. The top bits are filled with zeros.
115    ///
116    /// See also [general notes above][Cell::Shl].
117    UShr(Value, Value, u32),
118    /// `a >> (b * c)`. The top bits are filled with copies of the top bit
119    /// of the input.
120    ///
121    /// `a` must be at least one bit wide (as otherwise there would be no sign
122    /// bit to propagate, and while there wouldn't be anywhere to propagate it
123    /// *to*, it's an edge-case it doesn't make sense to bother handling).
124    ///
125    /// See also [general notes above][Cell::Shl].
126    SShr(Value, Value, u32),
127    /// `a >> (b * c)`. The top bits are filled with `X`.
128    ///
129    /// See also [general notes above][Cell::Shl].
130    XShr(Value, Value, u32),
131
132    // future possibilities: popcnt, count leading/trailing zeros, powers
133    Mul(Value, Value),
134    UDiv(Value, Value),
135    UMod(Value, Value),
136    SDivTrunc(Value, Value),
137    SDivFloor(Value, Value),
138    SModTrunc(Value, Value),
139    SModFloor(Value, Value),
140
141    Match(MatchCell),
142    Assign(AssignCell),
143
144    Dff(FlipFlop),
145    Memory(Memory),
146    IoBuf(IoBuffer),
147    Target(TargetCell),
148    Other(Instance),
149
150    /// Design input of a given width.
151    ///
152    /// If synthesizing for a specified target, and not in out-of-context mode,
153    /// an input will be replaced with an [`IoBuffer`] and attached to a pin on
154    /// the target device.
155    Input(String, usize),
156    /// Design output. Attaches a name to a given value.
157    ///
158    /// If synthesizing for a specified target, and not in out-of-context mode,
159    /// an output will be replaced with an [`IoBuffer`] and attached to a pin on
160    /// the target device.
161    Output(String, Value),
162    /// Attaches a name to a given value for debugging.
163    ///
164    /// `Name` keeps a given value alive during optimization and makes it easily
165    /// available to be poked at during simulation.
166    ///
167    /// Do note that the [`unname` pass][unname], which runs during
168    /// target-dependent synthesis, replaces all `Name` cells with [`Debug`]
169    /// cells.
170    ///
171    /// [unname]: ../prjunnamed_generic/fn.unname.html
172    /// [`Debug`]: Cell::Debug
173    Name(String, Value),
174    /// Tentatively attaches a name to a given value.
175    ///
176    /// `Debug` gives a name to a particular value, without insisting on keeping
177    /// it alive during optimization. This helps correlate the output of
178    /// synthesis with the corresponding input logic.
179    ///
180    /// If at any point a value is being kept alive only by a `Debug` cell,
181    /// it will be optimized out and the input to the `Debug` cell will
182    /// be replaced with `X`.
183    ///
184    /// See also: [`Name`][Cell::Name].
185    Debug(String, Value),
186}
187
188impl Cell {
189    pub fn validate(&self, design: &Design) {
190        match self {
191            Cell::Const(_) => (),
192            Cell::Buf(_) => (),
193            Cell::Not(_) => (),
194            Cell::Aig(..) => (),
195            Cell::And(arg1, arg2)
196            | Cell::Or(arg1, arg2)
197            | Cell::Xor(arg1, arg2)
198            | Cell::Mux(_, [arg1, arg2])
199            | Cell::Adc(arg1, arg2, _)
200            | Cell::Eq(arg1, arg2)
201            | Cell::ULt(arg1, arg2)
202            | Cell::Mul(arg1, arg2)
203            | Cell::UDiv(arg1, arg2)
204            | Cell::UMod(arg1, arg2) => assert_eq!(arg1.len(), arg2.len()),
205            Cell::SLt(arg1, arg2)
206            | Cell::SDivTrunc(arg1, arg2)
207            | Cell::SDivFloor(arg1, arg2)
208            | Cell::SModTrunc(arg1, arg2)
209            | Cell::SModFloor(arg1, arg2) => {
210                assert_eq!(arg1.len(), arg2.len());
211                assert!(!arg1.is_empty());
212            }
213
214            Cell::Shl(..) => (),
215            Cell::UShr(..) => (),
216            Cell::SShr(arg1, _, _) => assert!(!arg1.is_empty()),
217            Cell::XShr(..) => (),
218
219            Cell::Match(match_cell) => {
220                for alternates in &match_cell.patterns {
221                    for pattern in alternates {
222                        assert_eq!(match_cell.value.len(), pattern.len());
223                    }
224                }
225            }
226            Cell::Assign(assign_cell) => {
227                assert!(assign_cell.value.len() >= assign_cell.update.len() + assign_cell.offset);
228            }
229
230            Cell::Dff(flip_flop) => {
231                assert_eq!(flip_flop.data.len(), flip_flop.init_value.len());
232                assert_eq!(flip_flop.data.len(), flip_flop.clear_value.len());
233                assert_eq!(flip_flop.data.len(), flip_flop.reset_value.len());
234            }
235            Cell::Memory(memory) => {
236                assert_eq!(memory.init_value.len(), memory.depth * memory.width);
237                for port in &memory.write_ports {
238                    assert_eq!(port.data.len(), port.mask.len());
239                    if memory.width == 0 {
240                        assert_eq!(port.data.len(), 0);
241                    } else {
242                        assert_eq!(port.data.len() % memory.width, 0);
243                        let wide_factor = port.data.len() / memory.width;
244                        assert!(wide_factor.is_power_of_two());
245                        assert_eq!(memory.depth % wide_factor, 0);
246                    }
247                }
248                for port in &memory.read_ports {
249                    if memory.width == 0 {
250                        assert_eq!(port.data_len, 0);
251                    } else {
252                        assert_eq!(port.data_len % memory.width, 0);
253                        let wide_factor = port.data_len / memory.width;
254                        assert!(wide_factor.is_power_of_two());
255                        assert_eq!(memory.depth % wide_factor, 0);
256                    }
257                    if let Some(ref flip_flop) = port.flip_flop {
258                        assert_eq!(flip_flop.clear_value.len(), port.data_len);
259                        assert_eq!(flip_flop.reset_value.len(), port.data_len);
260                        assert_eq!(flip_flop.init_value.len(), port.data_len);
261                        assert_eq!(flip_flop.relations.len(), memory.write_ports.len());
262                        for (write_port_index, &relation) in flip_flop.relations.iter().enumerate() {
263                            if relation != MemoryPortRelation::Undefined {
264                                assert_eq!(memory.write_ports[write_port_index].clock, flip_flop.clock);
265                            }
266                        }
267                    }
268                }
269            }
270            Cell::IoBuf(io_buffer) => {
271                assert_eq!(io_buffer.output.len(), io_buffer.io.len());
272            }
273            Cell::Target(target_cell) => {
274                let prototype = design.target_prototype(target_cell);
275                assert_eq!(target_cell.params.len(), prototype.params.len());
276                for (param, value) in prototype.params.iter().zip(target_cell.params.iter()) {
277                    assert!(param.kind.is_valid(value));
278                }
279                assert_eq!(target_cell.inputs.len(), prototype.input_len);
280                assert_eq!(target_cell.output_len, prototype.output_len);
281                assert_eq!(target_cell.ios.len(), prototype.io_len);
282                let target = design.target().unwrap();
283                target.validate(design, target_cell);
284            }
285            Cell::Other(_instance) => {
286                // TODO
287            }
288            Cell::Input(..) => (),
289            Cell::Output(..) => (),
290            Cell::Name(..) | Cell::Debug(..) => (),
291        }
292    }
293
294    /// If possible, return a cell that computes only a slice of the outputs
295    /// of this cell.
296    pub fn slice(&self, range: impl std::ops::RangeBounds<usize> + Clone) -> Option<Cell> {
297        match self {
298            Cell::Buf(arg) => Some(Cell::Buf(arg.slice(range))),
299            Cell::Not(arg) => Some(Cell::Not(arg.slice(range))),
300            Cell::And(arg1, arg2) => Some(Cell::And(arg1.slice(range.clone()), arg2.slice(range))),
301            Cell::Or(arg1, arg2) => Some(Cell::Or(arg1.slice(range.clone()), arg2.slice(range))),
302            Cell::Xor(arg1, arg2) => Some(Cell::Xor(arg1.slice(range.clone()), arg2.slice(range))),
303            Cell::Mux(sel, args) => Some(Cell::Mux(*sel, [args[0].slice(range.clone()), args[1].slice(range)])),
304            Cell::Dff(flip_flop) => Some(Cell::Dff(flip_flop.slice(range))),
305            Cell::IoBuf(io_buffer) => Some(Cell::IoBuf(io_buffer.slice(range))),
306            _ => None,
307        }
308    }
309}
310
311impl<'a> From<&'a Cell> for Cow<'a, Cell> {
312    fn from(value: &'a Cell) -> Self {
313        Cow::Borrowed(value)
314    }
315}
316
317impl From<Cell> for Cow<'_, Cell> {
318    fn from(value: Cell) -> Self {
319        Cow::Owned(value)
320    }
321}
322
323impl CellRepr {
324    pub fn get(&self) -> Cow<'_, Cell> {
325        match *self {
326            CellRepr::Void => unreachable!("void cell"),
327            CellRepr::Skip(_) => unreachable!("skip cell"),
328
329            CellRepr::Const(bit) => Cow::Owned(Cell::Const(bit)),
330            CellRepr::Buf(arg) => Cow::Owned(Cell::Buf(Value::from(arg))),
331            CellRepr::Not(arg) => Cow::Owned(Cell::Not(Value::from(arg))),
332            CellRepr::And(arg1, arg2) => Cow::Owned(Cell::And(Value::from(arg1), Value::from(arg2))),
333            CellRepr::Or(arg1, arg2) => Cow::Owned(Cell::Or(Value::from(arg1), Value::from(arg2))),
334            CellRepr::Xor(arg1, arg2) => Cow::Owned(Cell::Xor(Value::from(arg1), Value::from(arg2))),
335            CellRepr::Mux(sel, args) => Cow::Owned(Cell::Mux(sel, args.map(Value::from))),
336            CellRepr::Adc(arg1, arg2, arg3) => Cow::Owned(Cell::Adc(Value::from(arg1), Value::from(arg2), arg3)),
337            CellRepr::Aig(arg1, inv1, arg2, inv2) => {
338                Cow::Owned(Cell::Aig(ControlNet::from_net_invert(arg1, inv1), ControlNet::from_net_invert(arg2, inv2)))
339            }
340
341            CellRepr::Boxed(ref cell) => Cow::Borrowed(cell),
342        }
343    }
344}
345
346impl From<Cell> for CellRepr {
347    fn from(value: Cell) -> Self {
348        match value {
349            Cell::Buf(arg) if arg.len() == 1 => CellRepr::Buf(arg[0]),
350            Cell::Not(arg) if arg.len() == 1 => CellRepr::Not(arg[0]),
351            Cell::And(arg1, arg2) if arg1.len() == 1 && arg2.len() == 1 => CellRepr::And(arg1[0], arg2[0]),
352            Cell::Or(arg1, arg2) if arg1.len() == 1 && arg2.len() == 1 => CellRepr::Or(arg1[0], arg2[0]),
353            Cell::Xor(arg1, arg2) if arg1.len() == 1 && arg2.len() == 1 => CellRepr::Xor(arg1[0], arg2[0]),
354            Cell::Mux(sel, args) if args[0].len() == 1 && args[1].len() == 1 => {
355                CellRepr::Mux(sel, args.map(|arg| arg[0]))
356            }
357            Cell::Adc(arg1, arg2, arg3) if arg1.len() == 1 && arg2.len() == 1 => CellRepr::Adc(arg1[0], arg2[0], arg3),
358            Cell::Aig(arg1, arg2) => CellRepr::Aig(arg1.net(), arg1.is_negative(), arg2.net(), arg2.is_negative()),
359
360            cell => CellRepr::Boxed(Box::new(cell)),
361        }
362    }
363}
364
365impl CellRepr {
366    pub fn output_len(&self) -> usize {
367        match self {
368            CellRepr::Void => unreachable!("void cell"),
369            CellRepr::Skip(_) => unreachable!("skip cell"),
370
371            CellRepr::Const(_)
372            | CellRepr::Buf(..)
373            | CellRepr::Not(..)
374            | CellRepr::And(..)
375            | CellRepr::Or(..)
376            | CellRepr::Xor(..)
377            | CellRepr::Mux(..)
378            | CellRepr::Aig(..) => 1,
379            CellRepr::Adc(..) => 2,
380
381            CellRepr::Boxed(cell) => cell.output_len(),
382        }
383    }
384
385    pub(crate) fn visit(&self, mut f: impl FnMut(ValueBit)) {
386        match self {
387            CellRepr::Void => unreachable!("void cell"),
388            CellRepr::Skip(_) => unreachable!("skip cell"),
389
390            CellRepr::Const(_) => (),
391            CellRepr::Buf(arg) | CellRepr::Not(arg) => arg.visit(&mut f),
392            CellRepr::And(arg1, arg2)
393            | CellRepr::Or(arg1, arg2)
394            | CellRepr::Xor(arg1, arg2)
395            | CellRepr::Aig(arg1, _, arg2, _) => {
396                arg1.visit(&mut f);
397                arg2.visit(&mut f);
398            }
399            CellRepr::Mux(arg3, [arg1, arg2]) | CellRepr::Adc(arg1, arg2, arg3) => {
400                arg1.visit(&mut f);
401                arg2.visit(&mut f);
402                arg3.visit(&mut f);
403            }
404
405            CellRepr::Boxed(cell) => cell.visit(&mut f),
406        }
407    }
408
409    pub(crate) fn visit_mut(&mut self, mut f: impl FnMut(&mut ValueBit)) {
410        match self {
411            CellRepr::Void => unreachable!("void cell"),
412            CellRepr::Skip(_) => unreachable!("skip cell"),
413
414            CellRepr::Const(_) => (),
415            CellRepr::Buf(arg) | CellRepr::Not(arg) => arg.visit_mut(&mut f),
416            CellRepr::And(arg1, arg2)
417            | CellRepr::Or(arg1, arg2)
418            | CellRepr::Xor(arg1, arg2)
419            | CellRepr::Aig(arg1, _, arg2, _) => {
420                arg1.visit_mut(&mut f);
421                arg2.visit_mut(&mut f);
422            }
423            CellRepr::Mux(arg3, [arg1, arg2]) | CellRepr::Adc(arg1, arg2, arg3) => {
424                arg1.visit_mut(&mut f);
425                arg2.visit_mut(&mut f);
426                arg3.visit_mut(&mut f);
427            }
428
429            CellRepr::Boxed(cell) => cell.visit_mut(&mut f),
430        }
431    }
432}
433
434impl Cell {
435    pub fn output_len(&self) -> usize {
436        match self {
437            Cell::Const(_) => 1,
438            Cell::Buf(arg) | Cell::Not(arg) => arg.len(),
439            Cell::And(arg1, arg2) | Cell::Or(arg1, arg2) | Cell::Xor(arg1, arg2) | Cell::Mux(_, [arg1, arg2]) => {
440                debug_assert_eq!(arg1.len(), arg2.len());
441                arg1.len()
442            }
443            Cell::Adc(arg1, arg2, _) => {
444                debug_assert_eq!(arg1.len(), arg2.len());
445                arg1.len() + 1
446            }
447            Cell::Aig(..) => 1,
448
449            Cell::Eq(..) | Cell::ULt(..) | Cell::SLt(..) => 1,
450
451            Cell::Shl(arg1, _, _) | Cell::UShr(arg1, _, _) | Cell::SShr(arg1, _, _) | Cell::XShr(arg1, _, _) => {
452                arg1.len()
453            }
454
455            Cell::Mul(arg1, arg2)
456            | Cell::UDiv(arg1, arg2)
457            | Cell::UMod(arg1, arg2)
458            | Cell::SDivTrunc(arg1, arg2)
459            | Cell::SDivFloor(arg1, arg2)
460            | Cell::SModTrunc(arg1, arg2)
461            | Cell::SModFloor(arg1, arg2) => {
462                debug_assert_eq!(arg1.len(), arg2.len());
463                arg1.len()
464            }
465
466            Cell::Match(match_cell) => match_cell.output_len(),
467            Cell::Assign(assign_cell) => assign_cell.output_len(),
468
469            Cell::Dff(flip_flop) => flip_flop.output_len(),
470            Cell::Memory(memory) => memory.output_len(),
471            Cell::IoBuf(io_buffer) => io_buffer.output_len(),
472            Cell::Target(target_cell) => target_cell.output_len,
473            Cell::Other(instance) => instance.output_len(),
474
475            Cell::Input(_, width) => *width,
476            Cell::Output(..) => 0,
477            Cell::Name(..) | Cell::Debug(..) => 0,
478        }
479    }
480
481    pub fn has_effects(&self, design: &Design) -> bool {
482        match self {
483            Cell::IoBuf(_) | Cell::Other(_) | Cell::Input(..) | Cell::Output(..) | Cell::Name(..) => true,
484            Cell::Target(target_cell) => design.target_prototype(target_cell).purity == TargetCellPurity::HasEffects,
485            _ => false,
486        }
487    }
488
489    pub fn has_state(&self, design: &Design) -> bool {
490        match self {
491            Cell::IoBuf(_)
492            | Cell::Other(_)
493            | Cell::Input(..)
494            | Cell::Output(..)
495            | Cell::Name(..)
496            | Cell::Memory(..)
497            | Cell::Dff(..) => true,
498            Cell::Target(target_cell) => design.target_prototype(target_cell).purity != TargetCellPurity::Pure,
499            _ => false,
500        }
501    }
502
503    pub fn visit(&self, mut f: impl FnMut(ValueBit)) {
504        match self {
505            Cell::Const(_) => (),
506            Cell::Input(..) => (),
507            Cell::Buf(arg) | Cell::Not(arg) | Cell::Output(_, arg) | Cell::Name(_, arg) | Cell::Debug(_, arg) => {
508                arg.visit(&mut f)
509            }
510            Cell::And(arg1, arg2)
511            | Cell::Or(arg1, arg2)
512            | Cell::Xor(arg1, arg2)
513            | Cell::Mul(arg1, arg2)
514            | Cell::UDiv(arg1, arg2)
515            | Cell::UMod(arg1, arg2)
516            | Cell::SDivTrunc(arg1, arg2)
517            | Cell::SDivFloor(arg1, arg2)
518            | Cell::SModTrunc(arg1, arg2)
519            | Cell::SModFloor(arg1, arg2)
520            | Cell::Eq(arg1, arg2)
521            | Cell::ULt(arg1, arg2)
522            | Cell::SLt(arg1, arg2)
523            | Cell::Shl(arg1, arg2, _)
524            | Cell::UShr(arg1, arg2, _)
525            | Cell::SShr(arg1, arg2, _)
526            | Cell::XShr(arg1, arg2, _) => {
527                arg1.visit(&mut f);
528                arg2.visit(&mut f);
529            }
530            Cell::Aig(arg1, arg2) => {
531                arg1.visit(&mut f);
532                arg2.visit(&mut f);
533            }
534            Cell::Mux(net, [value1, value2]) | Cell::Adc(value1, value2, net) => {
535                value1.visit(&mut f);
536                value2.visit(&mut f);
537                net.visit(&mut f);
538            }
539            Cell::Match(match_cell) => match_cell.visit(&mut f),
540            Cell::Assign(assign_cell) => assign_cell.visit(&mut f),
541            Cell::Dff(flip_flop) => flip_flop.visit(&mut f),
542            Cell::Memory(memory) => memory.visit(&mut f),
543            Cell::IoBuf(io_buffer) => io_buffer.visit(&mut f),
544            Cell::Target(target_cell) => target_cell.visit(&mut f),
545            Cell::Other(instance) => instance.visit(&mut f),
546        }
547    }
548
549    pub fn visit_mut(&mut self, mut f: impl FnMut(&mut ValueBit)) {
550        match self {
551            Cell::Const(_) => (),
552            Cell::Input(..) => (),
553            Cell::Buf(arg) | Cell::Not(arg) | Cell::Output(_, arg) | Cell::Name(_, arg) | Cell::Debug(_, arg) => {
554                arg.visit_mut(&mut f)
555            }
556            Cell::And(arg1, arg2)
557            | Cell::Or(arg1, arg2)
558            | Cell::Xor(arg1, arg2)
559            | Cell::Mul(arg1, arg2)
560            | Cell::UDiv(arg1, arg2)
561            | Cell::UMod(arg1, arg2)
562            | Cell::SDivTrunc(arg1, arg2)
563            | Cell::SDivFloor(arg1, arg2)
564            | Cell::SModTrunc(arg1, arg2)
565            | Cell::SModFloor(arg1, arg2)
566            | Cell::Eq(arg1, arg2)
567            | Cell::ULt(arg1, arg2)
568            | Cell::SLt(arg1, arg2)
569            | Cell::Shl(arg1, arg2, _)
570            | Cell::UShr(arg1, arg2, _)
571            | Cell::SShr(arg1, arg2, _)
572            | Cell::XShr(arg1, arg2, _) => {
573                arg1.visit_mut(&mut f);
574                arg2.visit_mut(&mut f);
575            }
576            Cell::Aig(arg1, arg2) => {
577                arg1.visit_mut(&mut f);
578                arg2.visit_mut(&mut f);
579            }
580            Cell::Mux(net, [value1, value2]) | Cell::Adc(value1, value2, net) => {
581                value1.visit_mut(&mut f);
582                value2.visit_mut(&mut f);
583                net.visit_mut(&mut f);
584            }
585            Cell::Match(match_cell) => match_cell.visit_mut(&mut f),
586            Cell::Assign(assign_cell) => assign_cell.visit_mut(&mut f),
587            Cell::Dff(flip_flop) => flip_flop.visit_mut(&mut f),
588            Cell::Memory(memory) => memory.visit_mut(&mut f),
589            Cell::IoBuf(io_buffer) => io_buffer.visit_mut(&mut f),
590            Cell::Target(target_cell) => target_cell.visit_mut(&mut f),
591            Cell::Other(instance) => instance.visit_mut(&mut f),
592        }
593    }
594}
595
596#[cfg(test)]
597mod test {
598    use crate::cell::CellRepr;
599
600    #[test]
601    fn test_size() {
602        assert!(size_of::<CellRepr>() == 16);
603    }
604}