Jump to content

Type casting and concatenation


amitk3553

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

Link to comment
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.

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

Link to comment
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 ?

Link to comment
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.

Link to comment
Share on other sites

  • 8 years later...
On 11/15/2013 at 10:07 PM, dakupoto said:

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.

Can b and c be ports ?

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