Jump to content

Changing the width in sc_bv<W>


Karthik Rao

Recommended Posts

Hello Everyone,

In the existing code, the width of the WdwType is defined as shown below. Here WDW_SIZE is a macro.

typedef sc_bv<WDW_SIZE> WdwType;

But I want the width to be configurable. So I have declared a structure variable of datatype unsigned int and want to do the same. Can anybody please let me know how this can be done?

Thank you. 

Regards

Karthik.

 

Edited by Karthik Rao
Added Regards message.
Link to comment
Share on other sites

Hi Karthik,

you need to provide a constant expression as template argument so that it can be evaluated at compilation time. See http://en.cppreference.com/w/cpp/language/constant_expression. and http://en.cppreference.com/w/cpp/language/template_parameters#Template_non-type_arguments. So it would need to be written as:

const int WDW_SIZE = 2;

Best regards

-Eyck

Link to comment
Share on other sites

These questions have little to do with SystemC per se, and are really about C++. Templates are all about compile-time elaboration and template arguments must be compile-time computable. If you use C++11 or later, then various forms of constexpr functions may be available, but they are still compile-time issues. You could of course use sc_bv_base and its constructors, but keep in mind that modules, ports, and other "hardware" constructs are not allowed to be modified after end_of_elaboration.

KEY POINT: To be an effective SystemC designer, you MUST be proficient at C++. Minimal C++ is NOT enough. Knowledge of C (even expert knowledge) is totally inadequate and in some cases downright harmful. Furthermore, really good SystemC often requires excellent C++ skills. Therefore, before you even consider learning much in SystemC, you really should invest in a solid C++ course. Expert SystemC practitioners take time to continually update their C++ skills. If this does not sound like fun to you, then I would advise choosing a different discipline.

Link to comment
Share on other sites

  • 3 weeks later...

Hello Everyone,

Thank you for your insights. I looked up at the LRM later and found that it has to be a constant and also cannot be modified after end_of_elaboration. To achieve my task I later found another method which does not involve making the width configurable.

 

Best Regards

Karthik

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...