Jump to content
amitk3553

Type casting and concatenation

Recommended Posts

Hello,

 

I faced problem in concatenation. I am able to concatenate sc_bv<8> type arguements, but not int type ??

 

a = (b,c); //where b and c are of sc_bv<8> type

 

 

I tried following also, compilation errors are there

cmd_opcode.write( concat(cmd_op_msb.read().range(7,0), cmd_op_lsb.read().range(7,0)) );  

cmd_opcode = concat(a, ab);

 

 

Next I tried to typecast sc_bv<8> into int type, i tried in following ways, but its not happening, showing compilation errors??

 

cmd_opcode = (int) cmd_opc; //where cmd_opc is of sc_bv type 

cmd_opcode.write(static_cast(cmd_opc.read()));

cmd_opcode.write(cmd_opc.read().to_int());

 

 

Please throw some light on these !!

 

Regards

cam

Share this post


Link to post
Share on other sites

sc_bv has member methods for explicit type conversion to integer types: 

 

int to_int() const;
unsigned int to_uint() const;
long to_long() const;
unsigned long to_ulong() const;
int64 to_int64() const;
uint64 to_uint64() const;

 

choose the one you want. 

 

Greetings 

Ralph

Share this post


Link to post
Share on other sites

Hello,

 

I faced problem in concatenation. I am able to concatenate sc_bv<8> type arguements, but not int type ??

 

a = (b,c); //where b and c are of sc_bv<8> type

 

 

I tried following also, compilation errors are there

cmd_opcode.write( concat(cmd_op_msb.read().range(7,0), cmd_op_lsb.read().range(7,0)) );  

cmd_opcode = concat(a, ab);

 

 

Next I tried to typecast sc_bv<8> into int type, i tried in following ways, but its not happening, showing compilation errors??

 

cmd_opcode = (int) cmd_opc; //where cmd_opc is of sc_bv type 

cmd_opcode.write(static_cast(cmd_opc.read()));

cmd_opcode.write(cmd_opc.read().to_int());

 

 

Please throw some light on these !!

 

Regards

cam

Hello Sir,

Thre are two points to be kept in mind.

1. Why would you need any type-casting at all ? If b, c in the statement a = (b,c) are of

type sc_bv<8> then very simply, then after concatenation the resulting bit vector would

be of type sc_bv, and size 8 + 8 = 16 bits. So if 'a' is decalred/defined to be a bit vector 

of size 16, then there would be not issues at all, both during compilation and runtime.

Why bother with needless type casting back and forth between various types, when a

clear, unambiguous method solves the problem ?

HTH.

Share this post


Link to post
Share on other sites

 

Hello Sir,

Thre are two points to be kept in mind.

1. Why would you need any type-casting at all ? If b, c in the statement a = (b,c) are of

type sc_bv<8> then very simply, then after concatenation the resulting bit vector would

be of type sc_bv, and size 8 + 8 = 16 bits. So if 'a' is decalred/defined to be a bit vector 

of size 16, then there would be not issues at all, both during compilation and runtime.

Why bother with needless type casting back and forth between various types, when a

clear, unambiguous method solves the problem ?

HTH.

Actually b,c were of int type and i required int datatype of a, so i was not able to concatenate, there was compilation error, then i assigned values of b and c in sc_bv<> type variable, in this case now concatenation was possible, then next motive was to convert a(sc_bv<> d) in to int  type, then i did it as int a = d.to_int().

Now its solved by the idea of Ralph. I learnt about concatenation and typecasting in systemC.

 

Thanks

cam

Share this post


Link to post
Share on other sites

Actually b,c were of int type and i required int datatype of a, so i was not able to concatenate, there was compilation error, then i assigned values of b and c in sc_bv<> type variable, in this case now concatenation was possible, then next motive was to convert a(sc_bv<> d) in to int  type, then i did it as int a = d.to_int().

Now its solved by the idea of Ralph. I learnt about concatenation and typecasting in systemC.

 

Thanks

cam

 

I am puzzled. Concatenation applies strictly to strings, never to integers. So, if b,c 

were integers, why would you need to concatenate them ?

Share this post


Link to post
Share on other sites

I am puzzled. Concatenation applies strictly to strings, never to integers. So, if b,c 

were integers, why would you need to concatenate them ?

i have 16 bit data, I had put lsb 8 bits in first location of fifo and 8 msb bits in 2nd location of fifo, Now i read fifo locations 1st and 2nd, now there was need to concatenate the lsb and msb retrieved from fifo locations to get 16 bit data again. and this 16 bit data was int and stored as int type on fifo locations(as fifo is of int type" sc_fifo(int) cmd_fifo;"), and retrieved  lsb and msb are also int type, i have to concatenate the retrieved lsb and msb, but as they were of int type, I was facing problem in concatenation.

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

×