mirror of
https://github.com/YosysHQ/yosys
synced 2025-04-06 01:24:10 +00:00
cxxrtl: add $divfloor
.
This commit is contained in:
parent
911a76affa
commit
eb397592f0
|
@ -1595,6 +1595,25 @@ value<BitsY> modfloor_ss(const value<BitsA> &a, const value<BitsB> &b) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<size_t BitsY, size_t BitsA, size_t BitsB>
|
||||||
|
CXXRTL_ALWAYS_INLINE
|
||||||
|
value<BitsY> divfloor_uu(const value<BitsA> &a, const value<BitsB> &b) {
|
||||||
|
return divmod_uu<BitsY>(a, b).first;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Divfloor. Similar to above: returns q=a//b, where q has the sign of a*b and a=b*q+N.
|
||||||
|
// In other words, returns (truncating) a/b, except if a and b have different signs
|
||||||
|
// and there's non-zero remainder, subtract one more towards floor.
|
||||||
|
template<size_t BitsY, size_t BitsA, size_t BitsB>
|
||||||
|
CXXRTL_ALWAYS_INLINE
|
||||||
|
value<BitsY> divfloor_ss(const value<BitsA> &a, const value<BitsB> &b) {
|
||||||
|
value<BitsY> q, r;
|
||||||
|
std::tie(q, r) = divmod_ss<BitsY>(a, b);
|
||||||
|
if ((b.is_neg() != a.is_neg()) && !r.is_zero())
|
||||||
|
return sub_uu<BitsY>(q, value<1> { 1u });
|
||||||
|
return q;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Memory helper
|
// Memory helper
|
||||||
struct memory_index {
|
struct memory_index {
|
||||||
|
|
|
@ -185,7 +185,7 @@ bool is_binary_cell(RTLIL::IdString type)
|
||||||
ID($and), ID($or), ID($xor), ID($xnor), ID($logic_and), ID($logic_or),
|
ID($and), ID($or), ID($xor), ID($xnor), ID($logic_and), ID($logic_or),
|
||||||
ID($shl), ID($sshl), ID($shr), ID($sshr), ID($shift), ID($shiftx),
|
ID($shl), ID($sshl), ID($shr), ID($sshr), ID($shift), ID($shiftx),
|
||||||
ID($eq), ID($ne), ID($eqx), ID($nex), ID($gt), ID($ge), ID($lt), ID($le),
|
ID($eq), ID($ne), ID($eqx), ID($nex), ID($gt), ID($ge), ID($lt), ID($le),
|
||||||
ID($add), ID($sub), ID($mul), ID($div), ID($mod), ID($modfloor));
|
ID($add), ID($sub), ID($mul), ID($div), ID($mod), ID($modfloor), ID($divfloor));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_extending_cell(RTLIL::IdString type)
|
bool is_extending_cell(RTLIL::IdString type)
|
||||||
|
|
Loading…
Reference in a new issue