prjunnamed_netlist/cell/
decision.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use crate::{Const, Net, Value};

/// If `enable` is asserted, output is one-hot priority match of `value` against `patterns`.
/// Otherwise it is zero.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct MatchCell {
    pub value: Value,
    pub enable: Net,
    /// Each pattern is a list of alternatives.
    ///
    /// Notice that `X` in a match pattern has different semantics than usual —
    /// it signifies "match any bit", and not "replace with whatever is easier
    /// to synthesize". This is fine, since the patterns are constants.
    pub patterns: Vec<Vec<Const>>,
}

/// If `enable` is asserted, output is `value` where `value[offset..]` is replaced with `update`.
/// Otherwise it is `value`.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct AssignCell {
    pub value: Value,
    pub enable: Net,
    pub update: Value,
    pub offset: usize,
}

impl MatchCell {
    pub fn output_len(&self) -> usize {
        self.patterns.len()
    }

    pub fn visit(&self, mut f: impl FnMut(Net)) {
        self.value.visit(&mut f);
        self.enable.visit(&mut f);
    }

    pub fn visit_mut(&mut self, mut f: impl FnMut(&mut Net)) {
        self.value.visit_mut(&mut f);
        self.enable.visit_mut(&mut f);
    }
}

impl AssignCell {
    pub fn output_len(&self) -> usize {
        self.value.len()
    }

    pub fn visit(&self, mut f: impl FnMut(Net)) {
        self.value.visit(&mut f);
        self.enable.visit(&mut f);
        self.update.visit(&mut f);
    }

    pub fn visit_mut(&mut self, mut f: impl FnMut(&mut Net)) {
        self.value.visit_mut(&mut f);
        self.enable.visit_mut(&mut f);
        self.update.visit_mut(&mut f);
    }
}