Jump to content
katang

Left shift with zero results in

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?

 

Share this post


Link to post
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

Share this post


Link to post
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>

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×