This commit is contained in:
parent
d0aa86e335
commit
cb5855589f
9 changed files with 570 additions and 100 deletions
|
|
@ -1,102 +1,11 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
// See Notices.txt for copyright information
|
||||
use crate::config::CpuConfig;
|
||||
use crate::unit::UnitMOp;
|
||||
use fayalite::prelude::*;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
pub mod power_isa;
|
||||
|
||||
macro_rules! all_units {
|
||||
(
|
||||
#[hdl_unit_kind = $HdlUnitKind:ident]
|
||||
#[unit_kind = $UnitKind:ident]
|
||||
#[hdl]
|
||||
$(#[$enum_meta:meta])*
|
||||
$vis:vis enum $UnitMOpEnum:ident<$RegWidth:ident: Size> {
|
||||
$(
|
||||
$(#[$variant_meta:meta])*
|
||||
$Unit:ident($Op:ty),
|
||||
)*
|
||||
}
|
||||
) => {
|
||||
$(#[$enum_meta])*
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
|
||||
$vis enum $UnitKind {
|
||||
$(
|
||||
$(#[$variant_meta])*
|
||||
$Unit,
|
||||
)*
|
||||
}
|
||||
|
||||
impl ToExpr for $UnitKind {
|
||||
type Type = $HdlUnitKind;
|
||||
|
||||
fn to_expr(&self) -> Expr<Self::Type> {
|
||||
match self {
|
||||
$($UnitKind::$Unit => $HdlUnitKind.$Unit(),)*
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[hdl]
|
||||
$(#[$enum_meta])*
|
||||
$vis enum $HdlUnitKind {
|
||||
$(
|
||||
$(#[$variant_meta])*
|
||||
$Unit,
|
||||
)*
|
||||
}
|
||||
|
||||
#[hdl]
|
||||
$(#[$enum_meta])*
|
||||
$vis enum $UnitMOpEnum<$RegWidth: Size> {
|
||||
$(
|
||||
$(#[$variant_meta])*
|
||||
$Unit($Op),
|
||||
)*
|
||||
}
|
||||
|
||||
impl<$RegWidth: Size> $UnitMOpEnum<$RegWidth> {
|
||||
#[hdl]
|
||||
$vis fn kind(expr: impl ToExpr<Type = Self>) -> Expr<$HdlUnitKind> {
|
||||
#[hdl]
|
||||
let unit_kind = wire();
|
||||
#[hdl]
|
||||
match expr {
|
||||
$($UnitMOpEnum::<$RegWidth>::$Unit(_) => connect(unit_kind, $HdlUnitKind.$Unit()),)*
|
||||
}
|
||||
unit_kind
|
||||
}
|
||||
}
|
||||
|
||||
impl CpuConfig {
|
||||
#[hdl]
|
||||
pub fn available_units_for_kind(&self, unit_kind: impl ToExpr<Type = $HdlUnitKind>) -> Expr<Array<Bool>> {
|
||||
#[hdl]
|
||||
let available_units_for_kind = wire(Array[Bool][self.units.len()]);
|
||||
#[hdl]
|
||||
match unit_kind {
|
||||
$($HdlUnitKind::$Unit => for (index, &unit) in self.units.iter().enumerate() {
|
||||
connect(available_units_for_kind[index], unit == $UnitKind::$Unit);
|
||||
})*
|
||||
}
|
||||
available_units_for_kind
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
all_units! {
|
||||
#[hdl_unit_kind = HdlUnitKind]
|
||||
#[unit_kind = UnitKind]
|
||||
#[hdl]
|
||||
pub enum UnitMOp<RegWidth: Size> {
|
||||
AluBranch(AluBranchMOp<RegWidth>),
|
||||
L2RegisterFile(L2RegisterFileMOp<RegWidth>),
|
||||
LoadStore(LoadStoreMOp<RegWidth>),
|
||||
}
|
||||
}
|
||||
|
||||
#[hdl]
|
||||
pub enum OutputIntegerMode {
|
||||
Full64,
|
||||
|
|
@ -239,11 +148,14 @@ pub enum LoadStoreMOp<RegWidth: Size> {
|
|||
}
|
||||
|
||||
#[hdl]
|
||||
/// there may be more than one unit of a given kind, so UnitNum is not the same as UnitKind
|
||||
/// there may be more than one unit of a given kind, so UnitNum is not the same as UnitKind.
|
||||
/// zero is used for built-in constants, such as the zero register
|
||||
pub struct UnitNum<Width: Size> {
|
||||
pub value: UIntType<Width>,
|
||||
}
|
||||
|
||||
pub const CONST_ZERO_UNIT_NUM: usize = 0;
|
||||
|
||||
#[hdl]
|
||||
pub struct UnitOutRegNum<Width: Size> {
|
||||
pub value: UIntType<Width>,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue