add helper functions for creating instructions
This commit is contained in:
parent
5b15f4a6b4
commit
4ff75313e7
3 changed files with 188 additions and 94 deletions
|
|
@ -10,6 +10,20 @@ use std::{fmt, marker::PhantomData, ops::Range};
|
|||
|
||||
pub mod power_isa;
|
||||
|
||||
pub trait MOpInto<Target: MOpTrait>: MOpTrait {
|
||||
fn mop_into_ty(self) -> Target;
|
||||
fn mop_into(this: Expr<Self>) -> Expr<Target>;
|
||||
}
|
||||
|
||||
impl<T: MOpTrait> MOpInto<T> for T {
|
||||
fn mop_into_ty(self) -> T {
|
||||
self
|
||||
}
|
||||
fn mop_into(this: Expr<Self>) -> Expr<T> {
|
||||
this
|
||||
}
|
||||
}
|
||||
|
||||
pub trait MOpTrait: Type {
|
||||
type Mapped<NewDestReg: Type, NewSrcRegWidth: Size>: MOpTrait;
|
||||
type DestReg: Type;
|
||||
|
|
@ -424,6 +438,30 @@ 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))
|
||||
}
|
||||
}
|
||||
|
||||
$(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>;
|
||||
type DestReg = $DestReg;
|
||||
|
|
@ -517,6 +555,70 @@ common_mop_struct! {
|
|||
}
|
||||
}
|
||||
|
||||
impl<DestReg: Type, SrcRegWidth: Size> AddSubMOp<DestReg, SrcRegWidth, ConstUsize<3>> {
|
||||
#[hdl]
|
||||
pub fn add_sub<Target: MOpTrait>(
|
||||
dest: impl ToExpr<Type = DestReg>,
|
||||
src: impl ToExpr<Type = Array<UIntType<SrcRegWidth>, 3>>,
|
||||
imm: impl ToExpr<Type = SInt<{ COMMON_MOP_3_IMM_WIDTH }>>,
|
||||
output_integer_mode: impl ToExpr<Type = OutputIntegerMode>,
|
||||
invert_src0: impl ToExpr<Type = Bool>,
|
||||
src1_is_carry_in: impl ToExpr<Type = Bool>,
|
||||
invert_carry_in: impl ToExpr<Type = Bool>,
|
||||
add_pc: impl ToExpr<Type = Bool>,
|
||||
) -> Expr<Target>
|
||||
where
|
||||
Self: MOpInto<Target>,
|
||||
{
|
||||
MOpInto::mop_into(
|
||||
#[hdl]
|
||||
AddSubMOp {
|
||||
alu_common: #[hdl]
|
||||
AluCommonMOp {
|
||||
common: CommonMOp::new(0_hdl_u0, dest, src, Expr::as_dyn_int(imm.to_expr())),
|
||||
output_integer_mode,
|
||||
},
|
||||
invert_src0,
|
||||
src1_is_carry_in,
|
||||
invert_carry_in,
|
||||
add_pc,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<DestReg: Type, SrcRegWidth: Size> AddSubMOp<DestReg, SrcRegWidth, ConstUsize<2>> {
|
||||
#[hdl]
|
||||
pub fn add_sub_i<Target: MOpTrait>(
|
||||
dest: impl ToExpr<Type = DestReg>,
|
||||
src: impl ToExpr<Type = Array<UIntType<SrcRegWidth>, 2>>,
|
||||
imm: impl ToExpr<Type = SInt<{ COMMON_MOP_2_IMM_WIDTH }>>,
|
||||
output_integer_mode: impl ToExpr<Type = OutputIntegerMode>,
|
||||
invert_src0: impl ToExpr<Type = Bool>,
|
||||
src1_is_carry_in: impl ToExpr<Type = Bool>,
|
||||
invert_carry_in: impl ToExpr<Type = Bool>,
|
||||
add_pc: impl ToExpr<Type = Bool>,
|
||||
) -> Expr<Target>
|
||||
where
|
||||
Self: MOpInto<Target>,
|
||||
{
|
||||
MOpInto::mop_into(
|
||||
#[hdl]
|
||||
AddSubMOp {
|
||||
alu_common: #[hdl]
|
||||
AluCommonMOp {
|
||||
common: CommonMOp::new(0_hdl_u0, dest, src, Expr::as_dyn_int(imm.to_expr())),
|
||||
output_integer_mode,
|
||||
},
|
||||
invert_src0,
|
||||
src1_is_carry_in,
|
||||
invert_carry_in,
|
||||
add_pc,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
common_mop_struct! {
|
||||
#[mapped(<NewDestReg, NewSrcRegWidth> LogicalMOp<NewDestReg, NewSrcRegWidth>)]
|
||||
#[hdl(cmp_eq)]
|
||||
|
|
@ -527,6 +629,32 @@ common_mop_struct! {
|
|||
}
|
||||
}
|
||||
|
||||
impl<DestReg: Type, SrcRegWidth: Size> LogicalMOp<DestReg, SrcRegWidth> {
|
||||
#[hdl]
|
||||
pub fn logical<Target: MOpTrait>(
|
||||
dest: impl ToExpr<Type = DestReg>,
|
||||
src: impl ToExpr<Type = Array<UIntType<SrcRegWidth>, 2>>,
|
||||
imm: impl ToExpr<Type = SInt<{ COMMON_MOP_2_IMM_WIDTH }>>,
|
||||
output_integer_mode: impl ToExpr<Type = OutputIntegerMode>,
|
||||
lut: impl ToExpr<Type = UInt<4>>,
|
||||
) -> Expr<Target>
|
||||
where
|
||||
Self: MOpInto<Target>,
|
||||
{
|
||||
MOpInto::mop_into(
|
||||
#[hdl]
|
||||
LogicalMOp {
|
||||
alu_common: #[hdl]
|
||||
AluCommonMOp {
|
||||
common: CommonMOp::new(0_hdl_u0, dest, src, Expr::as_dyn_int(imm.to_expr())),
|
||||
output_integer_mode,
|
||||
},
|
||||
lut,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
common_mop_struct! {
|
||||
#[mapped(<NewDestReg, NewSrcRegWidth> BranchMOp<NewDestReg, NewSrcRegWidth>)]
|
||||
#[hdl(cmp_eq)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue