mirror of
https://github.com/YosysHQ/yosys
synced 2025-06-06 14:13:23 +00:00
cxxrtl: add $divfloor
.
This commit is contained in:
parent
911a76affa
commit
eb397592f0
2 changed files with 20 additions and 1 deletions
|
@ -1595,6 +1595,25 @@ value<BitsY> modfloor_ss(const value<BitsA> &a, const value<BitsB> &b) {
|
|||
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
|
||||
struct memory_index {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue