Jump to content

data type : sc_int v/s int


Recommended Posts

Hello ,


I have a confusion related to systemc data types particularly 

what is the difference between sc_int and int(c++) ....the difference

i found out was that sc_int is 64bit and int is 2byte or 4 byte depends on compiler....


could anyone elaborate any difference in above and which is preferred ???

does it have any effect on scheduler  ??

Link to post
Share on other sites



1.sc_int<w> , here 'w' can vary from 1 to 64 bits any number you can take,based on your requirement.default is 32 bits


2.int ,it is a c++ data type it takes by default 32 bits.


But simulation speed is fast when you use c++ data type compare to the systemC datatype..


so when you use 32 bits use C++ datatype(int) data type ...else use systemC datatype(sc_int)...

Link to post
Share on other sites

If you want to guarantee the # of bits, but want speed then you should include <cstdint> or stdint.h (which has become part of the C++11 standard, but has been available for many years). You only have access to multiples of 8-bits, but at least least it's fast. Of course to grab bit ranges you will need to do the standard software masking rather than the convenience of sc_int.


sc_int<W> should be used for situations where modeling the exact number of bits will make a difference in the results. For example, if the hardware implementation will have 13 bits and you do arithmetic (addition/subtraction), then sc_int<W> can catch overflow issues. Another example is synthesis of a register, where you need to control size of the hardware.


The difference in performance is dramatic. Consider the following code and timing results:


    using data_t = int32_t; //< replace this with sc_int<32>, sc_fixed<32,32>, float, etc...
    data_t result = 1;
    data_t A = 1103515245;
    data_t C = 12345;

    start_timer(); //< Calls a routine to get CPU time using C++11 constructs -- portable
    for (size_t loop=loop_count; loop!=0; --loop)
      result = A * result + C;
    cout << "result=" << result << endl; // Ensure compiler doesn't optimize loop out
    report_time(typeid(data_t).name); //< Calculates final time -- Be sure to filter with c++filt
I saw results for SystemC 2.3.0-ASI --- Jan  6 2014 07:20:27 (on 2.7GHz Intel i7) with no optimization using clang++ compiler:
loop_count = 1e8
int                     took  0.343008s
sc_dt::sc_int<32>       took  2.01204s
double                  took  0.755805s
sc_dt::sc_fixed<32, 32> took 41.3482s
With -O3 optimization:
loop_count = 1e8
int                     took  0.125028s
sc_dt::sc_int<32>       took  0.199671s
double                  took  0.364543s
sc_dt::sc_fixed<32, 32> took 25.6714s
So be careful what you select AND what compiler options you use.
You can view the source code at https://github.com/dcblack/scdataperf
Link to post
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...