SystemC has a number of predefined data types to support hardware designs spanning from the native C++ data types to specialized fractional fixed-point representations. Choosing a data type depends on the range of values to be represented, the required precision, and the required operations. The choice of a data type also affects the speed of simulation, synthesizability, and synthesis results. The data types used differ depending on the level of abstraction represented in your model
[1] Native Data Types
SystemC is a C++ class library, therefore, SystemC supports all the native C++ data types: bool, char, short, int, unsigned char, unsigned short int, unsigned int, long int, unsigned long int, double, float, …
Native C++ data types are the most efficient in terms of memory usage and execution speed of the simulator.
1 2 3 4 |
sc_in<unsigned long long> clock; sc_out<unsigned char> error; sc_signal<bool> rst_sig; ... |
[2] Arithmetic Data Types
SystemC provides two sets of numeric data types. One set models data with bit widths up to 64-bits; another set models data with bit widths larger than 64-bits.
[2.1] sc_int and sc_uint
1 2 |
sc_int<W> m_int; sc_uint<W> m_uint; |
The built-in sc_int and sc_uint (unsigned) numeric data types provide an efficient way to model data with specific widths from 1- to 64-bits wide.
Any data type that is not native to both the C++ language and the processor width will simulate slower than the native types. Thus, built-in C++ data types (eg: int, unsigned int, …) are faster than sc_int and sc_uint.
NOTE: Do not use sc_int unless or until prudent. One necessary condition for using sc_int is when using synthesis tools that require hardware representation
[2.2] sc_bigint and sc_biguint
1 2 |
sc_bigint<W> m_bigint; sc_biguint<W> m_biguint; |
Some hardware may be larger than the numbers supported by native C++ data types. SystemC provides sc_bigint and sc_biguint for this purpose
NOTE : Do not use sc_bigint for 64 or fewer bits. Doing so causes performance to suffer compared to using sc_int
[3] Boolean Data Types
[3.1] sc_bit and sc_bv
For ones and zeroes, SystemC provides the sc_bit, and for long bit-vectors SystemC provides sc_bv<> (bit vector) data types. These types do not support arithmetic data like the sc_int types, and these data types don’t execute as fast as bool and std::bitset types
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
sc_bit m_bit_1(SC_LOGIC_0); // m_val = false; sc_bit m_bit_2; // m_val = false; m_bit_2 = 1; // m_val = true; sc_bit m_bit_3(sc_dt::Log_1);// m_val = true; sc_bv<5> m_bit_vecto = "0111001"; //m_len = 5 (bits), m_data = 0x19 sc_bv<4> m_mask = "1100"; //m_len = 4 (bits), m_data = 0xC sc_bv<6> m_or = m_bit_vecto | m_mask;//m_len = 6 (bits), m_data = 0x1D sc_bv<6> m_and_reduce = m_bit_vecto.and_reduce(); //m_len = 6 (bits), m_data = 0x0 sc_bv<6> m_nand_reduce = m_bit_vecto.nand_reduce(); //m_len = 6 (bits), m_data = 0x1 sc_bv<6> m_or_reduce = m_bit_vecto.or_reduce(); //m_len = 6 (bits), m_data = 0x1 sc_bv<6> m_nor_reduce = m_bit_vecto.nor_reduce(); //m_len = 6 (bits), m_data = 0x0 sc_bv<6> m_xnor_reduce = m_bit_vecto.xnor_reduce(); //m_len = 6 (bits), m_data = 0x0 m_bit_vecto.range(3, 2) = "00"; //m_bit_vecto changed : m_len = 5 (bits), m_data = 0x11 m_bit_vecto[1] = "1"; //m_bit_vecto changed : m_len = 5 (bits), m_data = 0x13 |
[3.2] sc_logic and sc_lv
SystemC represents these with the sc_logic and sc_lv<> (logic vector) data types. These types are represented with SC_LOGIC_1, SC_LOGIC_0, SC_LOGIC_X, and SC_LOGIC_Z. For less typing, if using namespace sc_dt, then type Log_1, Log_0, Log_X, and Log_Z, or even type ‘1’, ‘0’, ‘X’ and ‘Z’
Because of the overhead, these data types are considerably slower than their sc_bit and sc_bv counterparts. For best performance, always use built-in types such as bool.
[4] Fixed-point Data Types
SystemC provides the following fixed-point data types: sc_fixed, sc_ufixed, sc_fix, sc_ufix, and the _fast variants of them
Integral data types do not satisfy all design types. In particular, DSP applications often need to represent numbers with fractional components. SystemC provides eight data types providing fixed-point numeric representation. While native float and double data types satisfy highlevel representations, realizable hardware has speed and area requirements. Also, integer-based DSP processors do not natively support floating point. Fixed-point numbers provide an efficient solution11 in both hardware and software.
I just want to mention I am just beginner to blogs and definitely enjoyed your blog. Likely I’m going to bookmark your blog . You definitely have good articles and reviews. With thanks for revealing your webpage.
I’m grateful for having you as a friend!
Asking questions are really good thing if you are not understanding anything fully, however this post offers pleasant understanding even.
I am just writing to make you be aware of what a brilliant discovery my cousin’s princess enjoyed reading yuor web blog. She even learned too many things, which included how it is like to possess a wonderful giving heart to let certain people with no trouble completely grasp specified tortuous matters. You truly exceeded our own expectations. Thank you for presenting these practical, healthy, edifying and even unique tips on that topic to Lizeth.