-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(In)equality operators don't always behave symmetrical #5
Comments
The code below does the trick. Implementing it without C++11 (i.e. without expression SFINAE) will require some extra code (see e.g. https://stackoverflow.com/questions/257288). // These changes go in frontend/SystemC.hpp, starting at line 47.
// For C++98 compatibility and e.g. QuestaSim, Boost needs to be used instead of C++11 std.
namespace detail {
template <class T> struct is_randv_type : std::false_type { };
template <class T> struct is_randv_type<::crave::randv<T>> : std::true_type { };
} // ns detail
#define RANDV_SCDT_BINARY_OPERATOR(Typename, BinOp) \
template <int N, typename T> \
sc_dt::int64 operator BinOp(randv<Typename<N> > const& r, T const& i) { \
return static_cast<Typename<N>>(r) BinOp i; \
} \
template <int N, typename T, \
typename std::enable_if<!detail::is_randv_type<T>::value, int>::type = 0> \
auto operator BinOp(T const & i, randv<Typename<N>> const & r) \
-> decltype(i BinOp static_cast<Typename<N>>(r), sc_dt::int64()) { \
return i BinOp static_cast<Typename<N>>(r); \
} The general idea is to prevent Note that I kept the return type as Also note that I replaced the C-style casts with C++ ones. |
LGTM, thanks! Can you create a PR which also includes the example from your first comment as an unittest? The unittest should be in |
Sure, I'll put something together. BTW, when you say "use C++11 stuffs as much as you can", you mean the language extensions, right? Because as far as I know the C++11 additions to the STL aren't even supported by the latest QuestaSim versions (e.g. 10.5b, which still uses GCC 4.7.4). Or is there some extra trick I'm unaware of to make those work as well? |
I actually meant full C++11 support as we do not explicitly try to be compatible with any particular EDA simulator. It has been a while since the last time we compiled CRAVE with QuestaSim, does it still work out of the box? |
Honestly, I haven't tried yet. I'll try to give it a go soon. I've never been able to get any C++11 STL additions to compile in QuestaSim 10.5b/10.6 though. Edit: Just noticed that GCC 5.3.0 is bundled with QuestaSim 10.6 and newer. Maybe that'll do it. |
The (in)equality operators defined for
crave::randv<sc_dt::sc_bv<W>>
behave asymmetrical once W > 64. Try for example the following code:The cause seems to be the promotion of
c_IntOnes
tosc_dt::int64
when callingoperator== (sc_dt::int64 const, randv<Typename<N>> const &)
. I tried my hand at fixing theRANDV_SCDT_BINARY_OPERATOR
macro, but so far haven't been able to come up with the proper SFINAE to make it work/compile in all cases.Also note that these (in)equality operators all return
sc_dt::int64
instead ofbool
.The text was updated successfully, but these errors were encountered: