simplify getting IMM_WIDTH for LogicalFlagsMOpImm
This commit is contained in:
parent
0824b63d31
commit
2ad469e331
1 changed files with 13 additions and 12 deletions
|
|
@ -156,6 +156,13 @@ pub trait CommonMOpTrait: MOpTrait {
|
|||
) -> Expr<Self::Mapped<NewDestReg, NewSrcRegWidth>>;
|
||||
}
|
||||
|
||||
pub type CommonMOpFor<T> = CommonMOp<
|
||||
<T as CommonMOpTrait>::PrefixPad,
|
||||
<T as CommonMOpTrait>::CommonMOpTraitDestReg,
|
||||
<T as CommonMOpTrait>::CommonMOpTraitSrcRegWidth,
|
||||
<T as CommonMOpTrait>::SrcCount,
|
||||
>;
|
||||
|
||||
impl<T: CommonMOpTrait> MOpTrait for T {
|
||||
type Mapped<NewDestReg: Type, NewSrcRegWidth: Size> =
|
||||
T::CommonMOpTraitMapped<NewDestReg, NewSrcRegWidth>;
|
||||
|
|
@ -984,8 +991,8 @@ pub struct LogicalFlagsMOpImm {
|
|||
#[test]
|
||||
fn test_logical_flags_mop_imm_fits() {
|
||||
let needed_width = LogicalFlagsMOpImm.canonical().bit_width();
|
||||
type TheMOpCommon = LogicalFlagsMOpCommon<MOpDestReg, ConstUsize<{ MOpRegNum::WIDTH }>>;
|
||||
let imm_width = TheMOpCommon::IMM_WIDTH;
|
||||
let imm_width =
|
||||
CommonMOpFor::<LogicalFlagsMOp<MOpDestReg, ConstUsize<{ MOpRegNum::WIDTH }>>>::IMM_WIDTH;
|
||||
assert!(
|
||||
needed_width <= imm_width,
|
||||
"needed_width={needed_width} imm_width={imm_width}",
|
||||
|
|
@ -1083,7 +1090,7 @@ impl LogicalFlagsMOpImm {
|
|||
#[track_caller]
|
||||
pub fn from_imm(imm: impl ToExpr<Type = SInt>) -> Expr<Self> {
|
||||
let imm_ty =
|
||||
LogicalFlagsMOpCommon::<MOpDestReg, ConstUsize<{ MOpRegNum::WIDTH }>>::imm_ty();
|
||||
CommonMOpFor::<LogicalFlagsMOp<MOpDestReg, ConstUsize<{ MOpRegNum::WIDTH }>>>::imm_ty();
|
||||
let imm = imm.to_expr();
|
||||
assert_eq!(imm_ty, imm.ty(), "imm must have the correct width");
|
||||
imm.cast_to(UInt[LogicalFlagsMOpImm.canonical().bit_width()])
|
||||
|
|
@ -1091,7 +1098,7 @@ impl LogicalFlagsMOpImm {
|
|||
}
|
||||
pub fn to_imm(this: impl ToExpr<Type = Self>) -> Expr<SInt> {
|
||||
let imm_ty =
|
||||
LogicalFlagsMOpCommon::<MOpDestReg, ConstUsize<{ MOpRegNum::WIDTH }>>::imm_ty();
|
||||
CommonMOpFor::<LogicalFlagsMOp<MOpDestReg, ConstUsize<{ MOpRegNum::WIDTH }>>>::imm_ty();
|
||||
this.to_expr().cast_to_bits().cast_to(imm_ty)
|
||||
}
|
||||
fn flags_operation_impl<Flags, I, IU, C, CU, Lut, U, B, AF>(
|
||||
|
|
@ -1384,10 +1391,6 @@ impl LogicalFlagsMOpImm {
|
|||
}
|
||||
}
|
||||
|
||||
#[hdl]
|
||||
type LogicalFlagsMOpCommon<DestReg: Type, SrcRegWidth: Size> =
|
||||
CommonMOp<ConstUsize<0>, DestReg, SrcRegWidth, ConstUsize<3>>;
|
||||
|
||||
common_mop_struct! {
|
||||
#[mapped(<NewDestReg, NewSrcRegWidth> LogicalFlagsMOp<NewDestReg, NewSrcRegWidth>)]
|
||||
#[hdl(cmp_eq)]
|
||||
|
|
@ -1461,7 +1464,7 @@ common_mop_struct! {
|
|||
/// ```
|
||||
pub struct LogicalFlagsMOp<DestReg: Type, SrcRegWidth: Size> {
|
||||
#[common]
|
||||
pub common: LogicalFlagsMOpCommon<DestReg, SrcRegWidth>,
|
||||
pub common: CommonMOp<ConstUsize<0>, DestReg, SrcRegWidth, ConstUsize<3>>,
|
||||
pub lut: Lut4,
|
||||
}
|
||||
}
|
||||
|
|
@ -1511,9 +1514,7 @@ impl<DestReg: Type, SrcRegWidth: Size> LogicalFlagsMOp<DestReg, SrcRegWidth> {
|
|||
}
|
||||
#[hdl]
|
||||
pub fn imm(this: impl ToExpr<Type = Self>) -> Expr<LogicalFlagsMOpImm> {
|
||||
LogicalFlagsMOpImm::from_imm(LogicalFlagsMOpCommon::<DestReg, SrcRegWidth>::imm(
|
||||
this.to_expr().common,
|
||||
))
|
||||
LogicalFlagsMOpImm::from_imm(CommonMOpFor::<Self>::imm(this.to_expr().common))
|
||||
}
|
||||
#[hdl]
|
||||
pub fn logical_flags<Target: MOpTrait>(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue