mark.johnstone Posted September 22, 2014 Report Share Posted September 22, 2014 Hello all, I am writing some template code which manipulates some SystemC values, and I came across a place where I am having problems deducing the bit-width of an sc_uint. In looking over the source code for sc_uint (and sc_uint_base), I see that while the width must be specified as a template parameter, it is stored in a (non-const) member variable of every instance. I was wondering why the length is implemented this way, and not as a static method which returns the template parameter? I can't find any place where the width can be changed dynamically. If the length were implemented as a reference to the template parameter, template code would be easier to write, and every object would be smaller. Thanks, --Mark Quote Link to comment Share on other sites More sharing options...
sumit_tuwien Posted September 22, 2014 Report Share Posted September 22, 2014 Very interesting! I would be interested in knowing the use case of this. Can you please elaborate ? Regards, Sumit Quote Link to comment Share on other sites More sharing options...
Philipp A Hartmann Posted September 22, 2014 Report Share Posted September 22, 2014 The templated SystemC datatypes all build upon a "dynamic bitwidth" implementation (e.g. sc_uint_base) that has its bitwidth set upon construction. The templates themselves only provide constructors (initializing the length of the base class), assignment operators, and related functions. It would of course be possible to add a static member to the sc_(big)(u)int templates to provide direct access to the template argument: template< int W > class sc_int : public sc_int_base { static const int static_length = W; // or some other name // ... }; For these classes, an external helper can be defined easily as well: template< typename T > struct number_traits; // undefined by default // specialization for SystemC integer datatypes template< int W > struct number_traits< sc_dt::sc_int<W> > { static const int length = W; }; // same for sc_uint, sc_bigint, ... But for true generic programming, the concatenation and range classes would require additional meta programming to make this fully usable. Secondly, as the base classes should provide access to the length() of the instances as well, this function would require to be declared virtual (as the base classes are non-templated). This would increase the size (and eventually the runtime cost) again. That said, if you're interested in bit true datatypes implemented with fully deduced widths etc., you might want to use the Mentor/Calypto "Algorithmic C datatypes", see http://calypto.com/en/products/catapult/overview/. Greetings from Oldenburg, Philipp maehne 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.