prjunnamed_netlist/cell/
decision.rs

1use crate::{Const, Net, Value};
2
3/// If `enable` is asserted, output is one-hot priority match of `value` against `patterns`.
4/// Otherwise it is zero.
5#[derive(Debug, Clone, PartialEq, Eq, Hash)]
6pub struct MatchCell {
7    pub value: Value,
8    pub enable: Net,
9    /// Each pattern is a list of alternatives.
10    ///
11    /// Notice that `X` in a match pattern has different semantics than usual —
12    /// it signifies "match any bit", and not "replace with whatever is easier
13    /// to synthesize". This is fine, since the patterns are constants.
14    pub patterns: Vec<Vec<Const>>,
15}
16
17/// If `enable` is asserted, output is `value` where `value[offset..]` is replaced with `update`.
18/// Otherwise it is `value`.
19#[derive(Debug, Clone, PartialEq, Eq, Hash)]
20pub struct AssignCell {
21    pub value: Value,
22    pub enable: Net,
23    pub update: Value,
24    pub offset: usize,
25}
26
27impl MatchCell {
28    pub fn output_len(&self) -> usize {
29        self.patterns.len()
30    }
31
32    pub fn visit(&self, mut f: impl FnMut(Net)) {
33        self.value.visit(&mut f);
34        self.enable.visit(&mut f);
35    }
36
37    pub fn visit_mut(&mut self, mut f: impl FnMut(&mut Net)) {
38        self.value.visit_mut(&mut f);
39        self.enable.visit_mut(&mut f);
40    }
41}
42
43impl AssignCell {
44    pub fn output_len(&self) -> usize {
45        self.value.len()
46    }
47
48    pub fn visit(&self, mut f: impl FnMut(Net)) {
49        self.value.visit(&mut f);
50        self.enable.visit(&mut f);
51        self.update.visit(&mut f);
52    }
53
54    pub fn visit_mut(&mut self, mut f: impl FnMut(&mut Net)) {
55        self.value.visit_mut(&mut f);
56        self.enable.visit_mut(&mut f);
57        self.update.visit_mut(&mut f);
58    }
59}