UnitMOp now has L2RegisterFileMOp after renaming and instead has MoveRegMOp before renaming
This commit is contained in:
parent
6c91d1b0b0
commit
518284685f
6 changed files with 33960 additions and 32521 deletions
|
|
@ -25,7 +25,10 @@ impl<T: MOpTrait> MOpInto<T> for T {
|
|||
}
|
||||
|
||||
pub trait MOpTrait: Type {
|
||||
type Mapped<NewDestReg: Type, NewSrcRegWidth: Size>: MOpTrait;
|
||||
type Mapped<NewDestReg: Type, NewSrcRegWidth: Size>: MOpTrait<
|
||||
DestReg = NewDestReg,
|
||||
SrcRegWidth = NewSrcRegWidth,
|
||||
>;
|
||||
type DestReg: Type;
|
||||
type SrcRegWidth: Size;
|
||||
fn dest_reg_ty(self) -> Self::DestReg;
|
||||
|
|
@ -69,7 +72,12 @@ pub trait MOpTrait: Type {
|
|||
pub trait CommonMOpTrait: MOpTrait {
|
||||
type PrefixPad: KnownSize;
|
||||
type SrcCount: KnownSize;
|
||||
type CommonMOpTraitMapped<NewDestReg: Type, NewSrcRegWidth: Size>: CommonMOpTrait;
|
||||
type CommonMOpTraitMapped<NewDestReg: Type, NewSrcRegWidth: Size>: CommonMOpTrait<
|
||||
DestReg = NewDestReg,
|
||||
SrcRegWidth = NewSrcRegWidth,
|
||||
PrefixPad = Self::PrefixPad,
|
||||
SrcCount = Self::SrcCount,
|
||||
>;
|
||||
type CommonMOpTraitDestReg: Type;
|
||||
type CommonMOpTraitSrcRegWidth: Size;
|
||||
fn common_mop_ty(
|
||||
|
|
@ -418,9 +426,15 @@ macro_rules! common_mop_struct {
|
|||
|
||||
macro_rules! mop_enum {
|
||||
(
|
||||
#[impl_mop_into = $impl_mop_into:tt]
|
||||
$(#[$enum_meta:meta])*
|
||||
$vis:vis enum $MOp:ident<$DestReg:ident: Type, $SrcRegWidth:ident: Size> {
|
||||
$(#[$first_variant_meta:meta])*
|
||||
$vis:vis enum $MOp:ident<
|
||||
$DestReg:ident: Type,
|
||||
$SrcRegWidth:ident: Size
|
||||
$(, #[MOp(get_ty = $mop_types_get_ty:expr)] $MOpTypes:ident: Type)*
|
||||
$(, #[Size(get_size = $sizes_get_size:expr)] $Sizes:ident: Size)*
|
||||
> {
|
||||
$(#[$($first_variant_meta:tt)*])*
|
||||
$FirstVariant:ident($first_ty:ty),
|
||||
$(
|
||||
$(#[$variant_meta:meta])*
|
||||
|
|
@ -429,7 +443,7 @@ macro_rules! mop_enum {
|
|||
}
|
||||
) => {
|
||||
$(#[$enum_meta])*
|
||||
$vis enum $MOp<$DestReg: Type, $SrcRegWidth: Size> {
|
||||
$vis enum $MOp<$DestReg: Type, $SrcRegWidth: Size $(, $MOpTypes: Type)* $(, $Sizes: Size)*> {
|
||||
$(#[$first_variant_meta])*
|
||||
$FirstVariant($first_ty),
|
||||
$(
|
||||
|
|
@ -438,32 +452,37 @@ macro_rules! mop_enum {
|
|||
)*
|
||||
}
|
||||
|
||||
impl<$DestReg: Type, $SrcRegWidth: Size, Target: MOpTrait> MOpInto<Target> for $first_ty
|
||||
where
|
||||
$MOp<$DestReg, $SrcRegWidth>: MOpInto<Target>
|
||||
{
|
||||
fn mop_into_ty(self) -> Target {
|
||||
MOpInto::mop_into_ty($MOp[MOpTrait::dest_reg_ty(self)][MOpTrait::src_reg_width(self)])
|
||||
}
|
||||
fn mop_into(this: Expr<Self>) -> Expr<Target> {
|
||||
MOpInto::mop_into(MOpInto::<$MOp<$DestReg, $SrcRegWidth>>::mop_into_ty(Expr::ty(this)).$FirstVariant(this))
|
||||
mop_enum! {
|
||||
@impl_variants
|
||||
#[impl_mop_into = $impl_mop_into]
|
||||
enum $MOp [
|
||||
$DestReg: Type,
|
||||
$SrcRegWidth: Size
|
||||
$(, #[MOp(get_ty = $mop_types_get_ty)] $MOpTypes: Type)*
|
||||
$(, #[Size(get_size = $sizes_get_size)] $Sizes: Size)*
|
||||
] {
|
||||
$FirstVariant($first_ty),
|
||||
$($Variant($ty),)*
|
||||
}
|
||||
}
|
||||
|
||||
$(impl<$DestReg: Type, $SrcRegWidth: Size, Target: MOpTrait> MOpInto<Target> for $ty
|
||||
where
|
||||
$MOp<$DestReg, $SrcRegWidth>: MOpInto<Target>
|
||||
{
|
||||
fn mop_into_ty(self) -> Target {
|
||||
MOpInto::mop_into_ty($MOp[MOpTrait::dest_reg_ty(self)][MOpTrait::src_reg_width(self)])
|
||||
}
|
||||
fn mop_into(this: Expr<Self>) -> Expr<Target> {
|
||||
MOpInto::mop_into(MOpInto::<$MOp<$DestReg, $SrcRegWidth>>::mop_into_ty(Expr::ty(this)).$Variant(this))
|
||||
}
|
||||
})*
|
||||
|
||||
impl<$DestReg: Type, $SrcRegWidth: Size> MOpTrait for $MOp<$DestReg, $SrcRegWidth> {
|
||||
type Mapped<NewDestReg: Type, NewSrcRegWidth: Size> = $MOp<NewDestReg, NewSrcRegWidth>;
|
||||
impl<
|
||||
$DestReg: Type,
|
||||
$SrcRegWidth: Size,
|
||||
$($MOpTypes: Type + MOpTrait<DestReg = $DestReg, SrcRegWidth = $SrcRegWidth>,)*
|
||||
$($Sizes: Size,)*
|
||||
> MOpTrait for $MOp<
|
||||
$DestReg,
|
||||
$SrcRegWidth,
|
||||
$($MOpTypes,)*
|
||||
$($Sizes,)*
|
||||
> {
|
||||
type Mapped<NewDestReg: Type, NewSrcRegWidth: Size> = $MOp<
|
||||
NewDestReg,
|
||||
NewSrcRegWidth,
|
||||
$(<$MOpTypes as MOpTrait>::Mapped<NewDestReg, NewSrcRegWidth>,)*
|
||||
$($Sizes,)*
|
||||
>;
|
||||
type DestReg = $DestReg;
|
||||
type SrcRegWidth = $SrcRegWidth;
|
||||
fn dest_reg_ty(self) -> Self::DestReg {
|
||||
|
|
@ -476,8 +495,8 @@ macro_rules! mop_enum {
|
|||
let dest_reg = wire(Expr::ty(input).dest_reg_ty());
|
||||
#[hdl]
|
||||
match input {
|
||||
$MOp::<_, _>::$FirstVariant(v) => connect(dest_reg, MOpTrait::dest_reg(v)),
|
||||
$($MOp::<_, _>::$Variant(v) => connect(dest_reg, MOpTrait::dest_reg(v)),)*
|
||||
Self::$FirstVariant(v) => connect(dest_reg, <$first_ty as MOpTrait>::dest_reg(v)),
|
||||
$(Self::$Variant(v) => connect(dest_reg, <$ty as MOpTrait>::dest_reg(v)),)*
|
||||
}
|
||||
dest_reg
|
||||
}
|
||||
|
|
@ -491,8 +510,8 @@ macro_rules! mop_enum {
|
|||
) {
|
||||
#[hdl]
|
||||
match input {
|
||||
$MOp::<_, _>::$FirstVariant(v) => MOpTrait::for_each_src_reg(v, f),
|
||||
$($MOp::<_, _>::$Variant(v) => MOpTrait::for_each_src_reg(v, f),)*
|
||||
Self::$FirstVariant(v) => MOpTrait::for_each_src_reg(v, f),
|
||||
$(Self::$Variant(v) => MOpTrait::for_each_src_reg(v, f),)*
|
||||
}
|
||||
}
|
||||
fn mapped_ty<NewDestReg: Type, NewSrcRegWidth: Size>(
|
||||
|
|
@ -500,7 +519,7 @@ macro_rules! mop_enum {
|
|||
new_dest_reg: NewDestReg,
|
||||
new_src_reg_width: NewSrcRegWidth::SizeType,
|
||||
) -> Self::Mapped<NewDestReg, NewSrcRegWidth> {
|
||||
$MOp[new_dest_reg][new_src_reg_width]
|
||||
$MOp[new_dest_reg][new_src_reg_width]$([$mop_types_get_ty(self, new_dest_reg, new_src_reg_width)])*$([$sizes_get_size(self)])*
|
||||
}
|
||||
#[hdl]
|
||||
fn map_regs<NewDestReg: Type, NewSrcRegWidth: Size>(
|
||||
|
|
@ -519,13 +538,52 @@ macro_rules! mop_enum {
|
|||
let mapped_regs = wire(mapped_ty);
|
||||
#[hdl]
|
||||
match input {
|
||||
$MOp::<_, _>::$FirstVariant(v) => connect(mapped_regs, mapped_ty.$FirstVariant(MOpTrait::map_regs(v, new_dest, new_src_reg_width, map_src))),
|
||||
$($MOp::<_, _>::$Variant(v) => connect(mapped_regs, mapped_ty.$Variant(MOpTrait::map_regs(v, new_dest, new_src_reg_width, map_src))),)*
|
||||
Self::$FirstVariant(v) => connect(mapped_regs, mapped_ty.$FirstVariant(MOpTrait::map_regs(v, new_dest, new_src_reg_width, map_src))),
|
||||
$(Self::$Variant(v) => connect(mapped_regs, mapped_ty.$Variant(MOpTrait::map_regs(v, new_dest, new_src_reg_width, map_src))),)*
|
||||
}
|
||||
mapped_regs
|
||||
}
|
||||
}
|
||||
};
|
||||
(
|
||||
@impl_variants
|
||||
#[impl_mop_into = true]
|
||||
enum $MOp:ident $generics:tt {
|
||||
$($Variant:ident($ty:ty),)+
|
||||
}
|
||||
) => {
|
||||
$(mop_enum! {
|
||||
@impl_variant
|
||||
enum $MOp $generics {
|
||||
$Variant($ty),
|
||||
}
|
||||
})+
|
||||
};
|
||||
(
|
||||
@impl_variants
|
||||
#[impl_mop_into = false]
|
||||
enum $MOp:ident $generics:tt {
|
||||
$($Variant:ident($ty:ty),)+
|
||||
}
|
||||
) => {};
|
||||
(
|
||||
@impl_variant
|
||||
enum $MOp:ident[$DestReg:ident: Type, $SrcRegWidth:ident: Size $(, #[Size(get_size = $sizes_get_size:expr)] $Sizes:ident: Size)*] {
|
||||
$Variant:ident($ty:ty),
|
||||
}
|
||||
) => {
|
||||
impl<$DestReg: Type, $SrcRegWidth: Size, Target: MOpTrait, $($Sizes: Size,)*> MOpInto<Target> for $ty
|
||||
where
|
||||
$MOp<$DestReg, $SrcRegWidth, $($Sizes,)*>: MOpInto<Target>
|
||||
{
|
||||
fn mop_into_ty(self) -> Target {
|
||||
MOpInto::mop_into_ty($MOp[MOpTrait::dest_reg_ty(self)][MOpTrait::src_reg_width(self)]$([$sizes_get_size(self)])*)
|
||||
}
|
||||
fn mop_into(this: Expr<Self>) -> Expr<Target> {
|
||||
MOpInto::mop_into(MOpInto::<$MOp<$DestReg, $SrcRegWidth, $($Sizes,)*>>::mop_into_ty(Expr::ty(this)).$Variant(this))
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub(crate) use mop_enum;
|
||||
|
|
@ -666,6 +724,7 @@ common_mop_struct! {
|
|||
}
|
||||
|
||||
mop_enum! {
|
||||
#[impl_mop_into = true]
|
||||
#[hdl]
|
||||
pub enum AluBranchMOp<DestReg: Type, SrcRegWidth: Size> {
|
||||
AddSub(AddSubMOp<DestReg, SrcRegWidth, ConstUsize<3>>),
|
||||
|
|
@ -693,6 +752,7 @@ common_mop_struct! {
|
|||
}
|
||||
|
||||
mop_enum! {
|
||||
#[impl_mop_into = true]
|
||||
#[hdl]
|
||||
pub enum L2RegisterFileMOp<DestReg: Type, SrcRegWidth: Size> {
|
||||
ReadL2Reg(ReadL2RegMOp<DestReg, SrcRegWidth>),
|
||||
|
|
@ -728,6 +788,7 @@ common_mop_struct! {
|
|||
}
|
||||
|
||||
mop_enum! {
|
||||
#[impl_mop_into = true]
|
||||
#[hdl]
|
||||
pub enum LoadStoreMOp<DestReg: Type, SrcRegWidth: Size> {
|
||||
Load(CommonMOp<ConstUsize<1>, DestReg, SrcRegWidth, ConstUsize<0>>),
|
||||
|
|
@ -735,6 +796,15 @@ mop_enum! {
|
|||
}
|
||||
}
|
||||
|
||||
common_mop_struct! {
|
||||
#[mapped(<NewDestReg, NewSrcRegWidth> MoveRegMOp<NewDestReg, NewSrcRegWidth>)]
|
||||
#[hdl(cmp_eq)]
|
||||
pub struct MoveRegMOp<DestReg: Type, SrcRegWidth: Size> {
|
||||
#[common]
|
||||
pub common: CommonMOp<ConstUsize<2>, DestReg, SrcRegWidth, ConstUsize<1>>,
|
||||
}
|
||||
}
|
||||
|
||||
#[hdl(cmp_eq)]
|
||||
/// 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
|
||||
|
|
@ -1014,4 +1084,12 @@ impl MOpDestReg {
|
|||
}
|
||||
|
||||
#[hdl]
|
||||
pub type MOp = UnitMOp<MOpDestReg, ConstUsize<{ MOpRegNum::WIDTH }>>;
|
||||
pub type MOp = UnitMOp<
|
||||
MOpDestReg,
|
||||
ConstUsize<{ MOpRegNum::WIDTH }>,
|
||||
MoveRegMOp<MOpDestReg, ConstUsize<{ MOpRegNum::WIDTH }>>,
|
||||
>;
|
||||
|
||||
#[hdl]
|
||||
pub type RenamedMOp<DestReg: Type, SrcRegWidth: Size> =
|
||||
UnitMOp<DestReg, SrcRegWidth, L2RegisterFileMOp<DestReg, SrcRegWidth>>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue