diff options
author | Miodrag Milanović <mmicko@gmail.com> | 2022-07-06 10:04:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-06 10:04:12 +0200 |
commit | 4c5152bf2687ee31ebc572803a88689d0267f54a (patch) | |
tree | 94cdb68900d26288fbea90caa604f8e336d507e8 /backends/cxxrtl/cxxrtl.h | |
parent | 86a4ba17580ec203a5b299c75a4c3f7098ecfdaa (diff) | |
parent | 24b895778af0ce0cb872509be1d91229c3ba2bf6 (diff) | |
download | yosys-4c5152bf2687ee31ebc572803a88689d0267f54a.tar.gz yosys-4c5152bf2687ee31ebc572803a88689d0267f54a.tar.bz2 yosys-4c5152bf2687ee31ebc572803a88689d0267f54a.zip |
Merge pull request #3402 from C-Elegans/modfloor_support
Add support for GHDL modfloor operator to cxxrtl backend
Diffstat (limited to 'backends/cxxrtl/cxxrtl.h')
-rw-r--r-- | backends/cxxrtl/cxxrtl.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/backends/cxxrtl/cxxrtl.h b/backends/cxxrtl/cxxrtl.h index b4ffa87cd..073921cc4 100644 --- a/backends/cxxrtl/cxxrtl.h +++ b/backends/cxxrtl/cxxrtl.h @@ -1575,6 +1575,27 @@ value<BitsY> mod_ss(const value<BitsA> &a, const value<BitsB> &b) { return divmod_ss<BitsY>(a, b).second; } +template<size_t BitsY, size_t BitsA, size_t BitsB> +CXXRTL_ALWAYS_INLINE +value<BitsY> modfloor_uu(const value<BitsA> &a, const value<BitsB> &b) { + return divmod_uu<BitsY>(a, b).second; +} + +// GHDL Modfloor operator. Returns r=a mod b, such that r has the same sign as b and +// a=b*N+r where N is some integer +// In practical terms, when a and b have different signs and the remainder returned by divmod_ss is not 0 +// then return the remainder + b +template<size_t BitsY, size_t BitsA, size_t BitsB> +CXXRTL_ALWAYS_INLINE +value<BitsY> modfloor_ss(const value<BitsA> &a, const value<BitsB> &b) { + value<BitsY> r; + r = divmod_ss<BitsY>(a, b).second; + if((b.is_neg() != a.is_neg()) && !r.is_zero()) + return add_ss<BitsY>(b, r); + return r; +} + + // Memory helper struct memory_index { bool valid; |