amitk3553 Posted November 15, 2013 Report Share Posted November 15, 2013 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 Annossyenudge 1 Quote Link to comment Share on other sites More sharing options...
ralph.goergen Posted November 15, 2013 Report Share Posted November 15, 2013 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 Quote Link to comment Share on other sites More sharing options...
dakupoto Posted November 16, 2013 Report Share Posted November 16, 2013 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. Quote Link to comment Share on other sites More sharing options...
amitk3553 Posted November 16, 2013 Author Report Share Posted November 16, 2013 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 Quote Link to comment Share on other sites More sharing options...
dakupoto Posted November 17, 2013 Report Share Posted November 17, 2013 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 ? Quote Link to comment Share on other sites More sharing options...
amitk3553 Posted November 19, 2013 Author Report Share Posted November 19, 2013 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. Quote Link to comment Share on other sites More sharing options...
ralph.goergen Posted November 19, 2013 Report Share Posted November 19, 2013 How about: int16_t result; int8_t lsb; int8_t msb; result = msb; result = result << 8; result += lsb; Greetings Ralph amitk3553 1 Quote Link to comment Share on other sites More sharing options...
sumit_tuwien Posted November 19, 2013 Report Share Posted November 19, 2013 Ralph, how about: int8_t lsb; int16_t msb_16 = msb ; int16_t result = ( msb_16 << 8) | lsb; Greetings Sumit amitk3553 1 Quote Link to comment Share on other sites More sharing options...
acc_sysC Posted July 18, 2022 Report Share Posted July 18, 2022 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 ? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.