aboutsummaryrefslogtreecommitdiffstats
path: root/backends/cxxrtl/cxxrtl.h
diff options
context:
space:
mode:
authorMiodrag Milanović <mmicko@gmail.com>2022-07-06 10:04:12 +0200
committerGitHub <noreply@github.com>2022-07-06 10:04:12 +0200
commit4c5152bf2687ee31ebc572803a88689d0267f54a (patch)
tree94cdb68900d26288fbea90caa604f8e336d507e8 /backends/cxxrtl/cxxrtl.h
parent86a4ba17580ec203a5b299c75a4c3f7098ecfdaa (diff)
parent24b895778af0ce0cb872509be1d91229c3ba2bf6 (diff)
downloadyosys-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.h21
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;