From 24b895778af0ce0cb872509be1d91229c3ba2bf6 Mon Sep 17 00:00:00 2001 From: Michael Nolan Date: Tue, 5 Jul 2022 15:15:54 -0400 Subject: Add support for GHDL modfloor operator --- backends/cxxrtl/cxxrtl.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'backends/cxxrtl/cxxrtl.h') 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 mod_ss(const value &a, const value &b) { return divmod_ss(a, b).second; } +template +CXXRTL_ALWAYS_INLINE +value modfloor_uu(const value &a, const value &b) { + return divmod_uu(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 +CXXRTL_ALWAYS_INLINE +value modfloor_ss(const value &a, const value &b) { + value r; + r = divmod_ss(a, b).second; + if((b.is_neg() != a.is_neg()) && !r.is_zero()) + return add_ss(b, r); + return r; +} + + // Memory helper struct memory_index { bool valid; -- cgit v1.2.3