Skip to content

Commit

Permalink
[Cider 2.0] Remaining comb prims and the seq mem implementation (#1967)
Browse files Browse the repository at this point in the history
* Get the low hanging combinational prims

* Remove the dead_code thingy

* all hail clippy

* revamp the shape construct

* seq mem support
  • Loading branch information
EclecticGriffin authored Mar 11, 2024
1 parent bdbddcb commit 23cd0a1
Show file tree
Hide file tree
Showing 15 changed files with 417 additions and 366 deletions.
4 changes: 4 additions & 0 deletions interp/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ pub enum InterpreterError {
//TODO Griffin: Make this more descriptive
#[error("Attempted to write an undefined memory address")]
UndefinedWriteAddr,

// TODO Griffin: Make this more descriptive
#[error("Attempted to read an undefined memory address")]
UndefinedReadAddr,
}

impl InterpreterError {
Expand Down
4 changes: 2 additions & 2 deletions interp/src/flatten/flat_ir/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl From<GlobalPortIdx> for GlobalPortRef {

impl GlobalPortRef {
#[must_use]
pub fn as_port(&self) -> Option<&GlobalPortIdx> {
pub fn _as_port(&self) -> Option<&GlobalPortIdx> {
if let Self::Port(v) = self {
Some(v)
} else {
Expand All @@ -181,7 +181,7 @@ impl GlobalPortRef {
}

#[must_use]
pub fn as_ref(&self) -> Option<&GlobalRefPortIdx> {
pub fn _as_ref(&self) -> Option<&GlobalRefPortIdx> {
if let Self::Ref(v) = self {
Some(v)
} else {
Expand Down
18 changes: 0 additions & 18 deletions interp/src/flatten/flat_ir/control/structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,21 +241,3 @@ pub(crate) enum ContainmentType {
/// A ref cell/port
Ref,
}

impl ContainmentType {
/// Returns `true` if the containment type is [`Local`].
///
/// [`Local`]: ContainmentType::Local
#[must_use]
pub(crate) fn is_local(&self) -> bool {
matches!(self, Self::Local)
}

/// Returns `true` if the containment type is [`Ref`].
///
/// [`Ref`]: ContainmentType::Ref
#[must_use]
pub(crate) fn is_ref(&self) -> bool {
matches!(self, Self::Ref)
}
}
1 change: 0 additions & 1 deletion interp/src/flatten/flat_ir/control/translator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ fn insert_cell(
pub struct Layout {
port_map: PortMapper,
cell_map: CellMapper,
component_map: ComponentMapper,
}

fn compute_local_layout(
Expand Down
88 changes: 70 additions & 18 deletions interp/src/flatten/primitives/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn build_primitive(
PrimType1::Le => Box::new(StdLe::new(base_port)),
PrimType1::Lsh => Box::new(StdLsh::new(base_port, *width)),
PrimType1::Rsh => Box::new(StdRsh::new(base_port, *width)),
PrimType1::Mux => Box::new(StdMux::new(base_port, *width)),
PrimType1::Mux => Box::new(StdMux::new(base_port)),
PrimType1::Wire => Box::new(StdWire::new(base_port)),
PrimType1::SignedAdd => Box::new(StdAdd::new(base_port)),
PrimType1::SignedSub => Box::new(StdSub::new(base_port)),
Expand Down Expand Up @@ -87,26 +87,38 @@ pub fn build_primitive(
frac_width: _,
} => todo!(),
CellPrototype::Slice {
in_width: _,
out_width: _,
} => todo!(),
in_width: _, // Not actually needed, should probably remove
out_width,
} => Box::new(StdSlice::new(base_port, *out_width)),
CellPrototype::Pad {
in_width: _,
out_width: _,
} => todo!(),
in_width: _, // Not actually needed, should probably remove
out_width,
} => Box::new(StdPad::new(base_port, *out_width)),
CellPrototype::Cat {
// Turns out under the assumption that the primitive is well formed,
// none of these parameter values are actually needed
left: _,
right: _,
out: _,
} => todo!(),
} => Box::new(StdCat::new(base_port)),
CellPrototype::MemD1 {
mem_type,
width,
size,
idx_size: _,
} => match mem_type {
MemType::Seq => todo!("SeqMem primitives are not currently defined in the flat interpreter"),
MemType::Std => Box::new(CombMemD1::new(base_port, *width, false, *size as usize))
MemType::Seq => Box::new(SeqMemD1::new(
base_port,
*width,
false,
*size as usize,
)),
MemType::Std => Box::new(CombMemD1::new(
base_port,
*width,
false,
*size as usize,
)),
},
CellPrototype::MemD2 {
mem_type,
Expand All @@ -116,8 +128,18 @@ pub fn build_primitive(
d0_idx_size: _,
d1_idx_size: _,
} => match mem_type {
MemType::Seq => todo!("SeqMem primitives are not currently defined in the flat interpreter"),
MemType::Std => Box::new(CombMemD2::new(base_port, *width, false, (*d0_size as usize, *d1_size as usize))),
MemType::Seq => Box::new(SeqMemD2::new(
base_port,
*width,
false,
(*d0_size as usize, *d1_size as usize),
)),
MemType::Std => Box::new(CombMemD2::new(
base_port,
*width,
false,
(*d0_size as usize, *d1_size as usize),
)),
},
CellPrototype::MemD3 {
mem_type,
Expand All @@ -128,9 +150,19 @@ pub fn build_primitive(
d0_idx_size: _,
d1_idx_size: _,
d2_idx_size: _,
} => match mem_type {
MemType::Seq => todo!("SeqMem primitives are not currently defined in the flat interpreter"),
MemType::Std => Box::new(CombMemD3::new(base_port, *width, false, (*d0_size as usize, *d1_size as usize, *d2_size as usize))),
} => match mem_type {
MemType::Seq => Box::new(SeqMemD3::new(
base_port,
*width,
false,
(*d0_size as usize, *d1_size as usize, *d2_size as usize),
)),
MemType::Std => Box::new(CombMemD3::new(
base_port,
*width,
false,
(*d0_size as usize, *d1_size as usize, *d2_size as usize),
)),
},
CellPrototype::MemD4 {
mem_type,
Expand All @@ -143,9 +175,29 @@ pub fn build_primitive(
d1_idx_size: _,
d2_idx_size: _,
d3_idx_size: _,
}=> match mem_type {
MemType::Seq => todo!("SeqMem primitives are not currently defined in the flat interpreter"),
MemType::Std => Box::new(CombMemD4::new(base_port, *width, false, (*d0_size as usize, *d1_size as usize, *d2_size as usize, *d3_size as usize))),
} => match mem_type {
MemType::Seq => Box::new(SeqMemD4::new(
base_port,
*width,
false,
(
*d0_size as usize,
*d1_size as usize,
*d2_size as usize,
*d3_size as usize,
),
)),
MemType::Std => Box::new(CombMemD4::new(
base_port,
*width,
false,
(
*d0_size as usize,
*d1_size as usize,
*d2_size as usize,
*d3_size as usize,
),
)),
},
CellPrototype::Unknown(_, _) => todo!(),
}
Expand Down
11 changes: 8 additions & 3 deletions interp/src/flatten/primitives/combinational.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,12 @@ impl Primitive for StdConst {

pub struct StdMux {
base: GlobalPortIdx,
width: u32,
}

impl StdMux {
declare_ports![ COND: 0, TRU: 1, FAL:2, OUT: 3];
pub fn new(base: GlobalPortIdx, width: u32) -> Self {
Self { base, width }
pub fn new(base: GlobalPortIdx) -> Self {
Self { base }
}
}

Expand Down Expand Up @@ -504,6 +503,12 @@ comb_primitive!(StdPad[OUT_WIDTH](input [0]) -> (out [1]) {
Ok( Some(input.ext(OUT_WIDTH as usize)))
});

comb_primitive!(StdCat(left [0], right [1]) -> (out [2]) {
all_defined!(left, right);

Ok(Some(Value::concat(left, right)))
});

// ===================== Unsynthesizeable Operations ======================
comb_primitive!(StdUnsynMult[WIDTH](left [0], right [1]) -> (out [2]) {
all_defined!(left, right);
Expand Down
2 changes: 1 addition & 1 deletion interp/src/flatten/primitives/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ macro_rules! make_getters {
$(
#[inline]
fn $port(&self) -> $crate::flatten::flat_ir::prelude::GlobalPortIdx {
($crate::flatten::structures::index_trait::IndexRef::index(&self.$base) + $offset).into()
($crate::flatten::structures::index_trait::IndexRef::index(&self.$base) + &self.addresser.non_address_base() + $offset).into()
}
)+

Expand Down
Loading

0 comments on commit 23cd0a1

Please sign in to comment.