Jump to content

systemC data type conversions


Recommended Posts

Hi all,

      I am newbie to system c and i am trying to work on system c data type's conversions.


I have a inport which a system c ufixed type and i need to change it to a bool type on the outport.


i tried the following code.



sc_in<sc_ufixed < 1, 1, SC_TRN, SC_SAT > > din;
sc_out<bool> dout;

bool i;

void conversion1() {

i = din.to_bool();

sensitive<< din;



Is the above code correct? do i need to use the process method to convert the inport type to a another datatype on the outport?


And Could you please refer me some good reference for system c data type conversions.



Thank you very much





Link to comment
Share on other sites



the code you have written won't compile, because:


- sc_ufixed does not provide a to_bool() member function as the sc_logic and bit select classes do.


- you should use the read() member function of the sc_in port to access the sc_ufixed() value.


However, your approach to use an SC_METHOD sensitive to the input port is correct. You will have to define a criteria, when your sc_ufixed value should be considered as true and when not. All fixed point data types provide is_neg() and is_zero() member functions, which might be suitable candidates for a conversion to bool depending on your truth criteria.


A one bit sc_ufixed value doesn't make really sense or did you mean an sc_uint value?


The SystemC datatypes are described in detail in chapter 7 of the IEEE Std 1666-2011, which you can download for free by following the link on www.accellera.org.





Link to comment
Share on other sites

Thank you for your reply Torsten.


I can understand .to_bool () member function cannot be used with fixed point types and fixed point types must be provided with the read member functions to read the value and also a criterion should be provided for outputting the boolean value (1 or 0) 


keeping the things on mind i tried to rewrite the code for an example. Please check the code and correct me if i am wrong.



#include "systemc.h"

SC_MODULE( convert)
sc_in<sc_ufixed < 12, 12, SC_TRN, SC_SAT > > count;
sc_out<bool > FIFO_we;

void function1(){
if ((count>= 1)&&(count<= 50))        // condition for the boolean
FIFO_we =count.read().is_zero();     // read() function and conversion to bool type
FIFO_we=1; // assign the boolean value
FIFO_we =count.read().is_zero();
FIFO_we = 0;
SC_CTOR(convert) {
sensitive << count;
} // End of Constructor



Link to comment
Share on other sites

Your solution is way too complicated and obfuscates your intent. Try instead the following implementation of function1:


void function1(){
  if ((count.read() >= 1) && (count.read() <= 50)) {


  } else {



Your decision criteria doesn't show why you would want to use sc_ufixed instead of a plain integer type or sc_int<N> / sc_uint<N>.
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.

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