forked from libre-chip/cpu
WIP
This commit is contained in:
parent
cfd04469ce
commit
6a4881ca25
3 changed files with 1779 additions and 650 deletions
|
|
@ -163,3 +163,15 @@ pub type CpuConfigFetchWidthInBytes<C: PhantomConstGet<CpuConfig>> = DynSize;
|
||||||
|
|
||||||
#[hdl(get(|c| c.rob_size.get()))]
|
#[hdl(get(|c| c.rob_size.get()))]
|
||||||
pub type CpuConfigRobSize<C: PhantomConstGet<CpuConfig>> = DynSize;
|
pub type CpuConfigRobSize<C: PhantomConstGet<CpuConfig>> = DynSize;
|
||||||
|
|
||||||
|
pub trait PhantomConstCpuConfig:
|
||||||
|
PhantomConstGet<CpuConfig>
|
||||||
|
+ Into<PhantomConst<CpuConfig>>
|
||||||
|
+ From<PhantomConst<CpuConfig>>
|
||||||
|
+ Type
|
||||||
|
+ ToSimValue<Type = Self>
|
||||||
|
+ ToExpr<Type = Self>
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PhantomConstCpuConfig for PhantomConst<CpuConfig> {}
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -190,6 +190,35 @@ impl<T: Type, N: Size> ArrayVec<T, N> {
|
||||||
mapped_array_vec
|
mapped_array_vec
|
||||||
}
|
}
|
||||||
#[hdl]
|
#[hdl]
|
||||||
|
pub fn map_sim<U: Type>(
|
||||||
|
this: impl ToSimValue<Type = Self>,
|
||||||
|
uninit_element: impl ToSimValue<Type = U>,
|
||||||
|
mut f: impl FnMut(usize, SimValue<T>) -> SimValue<U>,
|
||||||
|
) -> SimValue<ArrayVec<U, N>> {
|
||||||
|
let this = this.into_sim_value();
|
||||||
|
let uninit_element = uninit_element.into_sim_value();
|
||||||
|
let ty = this.ty().mapped_ty(uninit_element.ty());
|
||||||
|
#[hdl(sim)]
|
||||||
|
let Self { elements, len } = this;
|
||||||
|
#[hdl(sim)]
|
||||||
|
ArrayVec::<_, _> {
|
||||||
|
elements: SimValue::from_array_elements(
|
||||||
|
ty.elements,
|
||||||
|
SimValue::into_value(elements)
|
||||||
|
.into_iter()
|
||||||
|
.enumerate()
|
||||||
|
.map(|(index, element)| {
|
||||||
|
if index < *len {
|
||||||
|
f(index, element)
|
||||||
|
} else {
|
||||||
|
uninit_element.clone()
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
len,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[hdl]
|
||||||
pub fn as_array_of_options(this: impl ToExpr<Type = Self>) -> Expr<ArrayType<HdlOption<T>, N>> {
|
pub fn as_array_of_options(this: impl ToExpr<Type = Self>) -> Expr<ArrayType<HdlOption<T>, N>> {
|
||||||
let this = this.to_expr();
|
let this = this.to_expr();
|
||||||
#[hdl]
|
#[hdl]
|
||||||
|
|
@ -217,3 +246,34 @@ where
|
||||||
<ArrayType<T, N> as ExprIndex<Idx>>::expr_index(&this.elements, index)
|
<ArrayType<T, N> as ExprIndex<Idx>>::expr_index(&this.elements, index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: Type> ArrayVec<T, ConstUsize<1>> {
|
||||||
|
#[hdl]
|
||||||
|
pub fn from_opt_sim(
|
||||||
|
opt: impl ToSimValue<Type = HdlOption<T>>,
|
||||||
|
uninit_element: impl ToSimValueWithType<T>,
|
||||||
|
) -> SimValue<Self> {
|
||||||
|
let opt = opt.into_sim_value();
|
||||||
|
let ty = ArrayVec[opt.ty().HdlSome][ConstUsize];
|
||||||
|
#[hdl(sim)]
|
||||||
|
match opt {
|
||||||
|
HdlSome(v) => ty.new_full_sim([v]),
|
||||||
|
HdlNone => ty.new_sim(uninit_element),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[hdl]
|
||||||
|
pub fn into_opt_sim(this: impl ToSimValue<Type = Self>) -> SimValue<HdlOption<T>> {
|
||||||
|
let this = this.into_sim_value();
|
||||||
|
#[hdl(sim)]
|
||||||
|
let Self { elements, len } = this;
|
||||||
|
let [element] = SimValue::into_value(elements);
|
||||||
|
let ty = HdlOption[element.ty()];
|
||||||
|
if *len == 0 {
|
||||||
|
#[hdl(sim)]
|
||||||
|
ty.HdlNone()
|
||||||
|
} else {
|
||||||
|
#[hdl(sim)]
|
||||||
|
ty.HdlSome(element)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue