Comments (5)
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 operator BinOp (T const &, Typename<N> const &)
from being instantiated for any T
which is itself a crave::randv<U>
, because in that case the same function is already defined as operator BinOp (randv<Typename<N>> const &, V const &)
. The expression SFINAE is required to prevent the function being instantiated if the BinOp operation doesn't exist for the given types.
Note that I kept the return type as sc_dt::int64
. Ideally I would use e.g. decltype(i BinOp static_cast<Typename<N>>(r))
to auto deduce what it should be, but I'm not quite sure how that would be implemented pre-C++11 (something along the lines of std::result_of
I guess).
Also note that I replaced the C-style casts with C++ ones.
from crave.
LGTM, thanks! Can you create a PR which also includes the example from your first comment as an unittest? The unittest should be in tests/core/test_SystemC_Data.cpp
. We already have crave::is_crave_variable<T>
in src/crave/frontend/bitsize_traits.hpp
which you can use instead of is_randv_type<T>
. A C++11 compiler is now required to build CRAVE, so please feel free to use C++11 stuffs as much as you can.
from crave.
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?
from crave.
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?
from crave.
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.
from crave.
Related Issues (11)
- Vector randomization & constraints don't work correctly. HOT 2
- Vector Constraint with if_then_else not working when if statement is about a separate random variable
- interclass constraints not working
- randv (and related classes) don't use RAII HOT 2
- __rand_vec and __rand_vec_base have reserved names HOT 1
- Randomization of SystemC types > 64 bit not supported HOT 4
- How to know what seed was used?
- Constraint specified using multiplication operator gives wrong values HOT 3
- Thread safety
- Sudoku Examples Stalling? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crave.