Jump to content

Left shift with zero results in


katang

Recommended Posts

In my program, I have a member variable

    sc_dt::sc_uint<MASK_WIDTH>
  mymask; ///< One-hot bitmask corresponding to ID 

In my constructor, I can initialize that variable like

  mymask(ID ? 1 << ID : 1)

because using only

mymask(1 << ID )

SC library results in

 

Error: (E5) out of bounds: sc_uint[_base] initialization: length = -2147483648 violates 1 <= length <= 64

In file: ../../../../src/sysc/datatypes/int/sc_uint_base.cpp:342

 I see nothing against shifting a value by zero position. Is there any deeper reason?

 

Link to comment
Share on other sites

Shifting by zero should of course be supported. Can you provide a self-contained example demonstrating the problem?

Instead, the error message indicates, that you try to create an sc_uint<-2147483648> (or rather an sc_uint_base with the dynamic width of this value, e.g.), which is not allowed.

  • What's the definition of MASK_WIDTH?
  • What's the definition of ID?

Hope that helps,
  Philipp

Link to comment
Share on other sites

In a config file, I have

#define CORE_BUS_WIDTH 5

In my SC_MODULE I have

//    sc_dt::sc_uint<CORE_BUS_WIDTH>
    int
  mID; ///< internal ID (sequence number) of the core

Changing the data type from int to sc_unit provokes the error message, with all others unchanged.

Works also with line

sc_dt::sc_uint<5>

 

Link to comment
Share on other sites

Can you please post a complete, self-contained example to demonstrate the issue?  Reading your post, I still cannot infer what actual values, types, ... are involved and not even where you changed the "line" to sc_uint<5>.

The following code works for me:

#include <systemc>

int sc_main (int, char *[]) {

   using namespace sc_dt;

   #define CORE_BUS_WIDTH 5
   #define MASK_WIDTH 32
   {
     sc_uint<CORE_BUS_WIDTH> id;
     sc_uint<MASK_WIDTH>     mask(1 << id);
     std::cout << "id=" << id << "\t- mask=" << mask.to_string(SC_BIN) << std::endl;
   }
   {
     sc_uint<CORE_BUS_WIDTH> id(-1);
     sc_uint<MASK_WIDTH>     mask(1 << id);
     std::cout << "id=" << id << "\t- mask=" << mask.to_string(SC_BIN) << std::endl;
   }
   return 0;
}

From your original error message, it looks more like an issue with MASK_WIDTH or CORE_BUS_WIDTH to me.

Do you see any compiler warnings?

Hope that helps,
 Philipp

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...