Professional Documents
Culture Documents
SystemC Data Types 2pages
SystemC Data Types 2pages
Dr. Zhonghai Lu ()
School for ICT
KTH Royal Institute of Technology
C++ Basics
SystemC
Introduction
and Get
Started
Modules
and
Processes
Concurrency
and Time
Channels
and
Interfaces
Transaction
Level
Modeling
SystemC
Data Types
and
Debugging
SystemC
Summary
9/18/2013
Aim
Content
9/18/2013
SystemC
SystemC
supports
Types
Using
namespace sc_dt
5
sc_fix is the base class for sc_fixed. The size of an object of type
sc_fix is set when the object is created (i.e. by the constructor)
as opposed to sc_fixed where the size is set by the compiler
(using the template parameter).
Type
Description
sc_int<>
Integer types
sc_uint<>
sc_bigint<>
sc_biguint<>
sc_bv<>
sc_lv<>
sc_fixed<>
sc_ufixed<>
sc_fix
sc_ufix
9/18/2013
sc_int<n>, sc_uint<n>
n 64
Regardless of the bit width n given by the template
parameter, internally stored with 64 bits of precision
sc_bigint<n>, sc_biguint<n>
No max. for n (unbounded)
Internally stored with as many as necessary to hold the
result
sc_int<n>,
sc_lv<n>, sc_bv<n>
Operators
int
in C++
9/18/2013
sc_uint<4>
sc_int<>
c=14
sc_int<4>
Truncation!
d=30
Due
sc_int<16> a, b;
int d;
sc_int<8> a;
sc_bigint<64> B;
sc_int<8> s;
sc_uint<8> u;
d = a & b;
a = b + d;
B = a;
a = B;
s = -1;
u = s;
s = u;
u = 255
s = -1
10
9/18/2013
sc_logic
Bitwise
&
Assignment
&=
!=
^=
4 values: 0, 1, X, Z
Equality
==
Initial value is X
Similar to std_logic in VHDL.
Slower than bool
!=
sc_logic a, b;
a = 1;
b = Z;
b = a & b;
Vectors
Concatenation means composing two or more vectors endto-end to create a single longer vector.
Two ways of concatenation
1100
1101
11001101
c
12
9/18/2013
For sc_lv<>, sc_bv<>, if the first argument is less than the second, the
bits are read out of the vector in the reverse order.
sc_int<8> a;
bool b;
a.range(7,4) = a.range(3,0);
sc_lv<4> v = ZX10;
cout << v.range(0,3);
b = a[7]
a[6] = b;
10ZX
sc_lv<4> lv;
sc_bv<4> bv = lv;
sc_int<4> si = lv;
X Z cause warning
or run time error.
9/18/2013
sc_lv<8> lv = 0xff;
sc_bv<8> bv = 0xff;
sc_bigint<96> si = 0xff;
int i;
i = lv.to_int( ); // return -1
i = bv.to_uint( ); //return 255
i = bi.to_long(); //return 255
cout << bv.to_string(SC_DEC);
//return 0d255
To
SC_CTOR(Driver){
SC_THREAD(p1);
SC_THREAD(p2);
}
sc_signal<sc_logic> s;
void p1( ){
s.write(sc_logic(0));
//s = sc_logic(0);
}
void p2( ){
s.write(SC_LOGIC_0);
//s = SC_LOGIC_0;
}
}
16
9/18/2013
Due
to their compile-time overhead, fixedpoint types are omitted from the default
SystemC include file.
To enable fixed-point types, SC_INCLUDE_FX
must be defined prior to including the
#define SC_INCLUDE_FX
SystemC header file.
#include systemc.h
sc_fixed<5, 3>
}
Integer word length
Word length
value in [- 4, 3.75], precision 0.25
17
SC_CTOR(Driver){
SC_THREAD(p1);
SC_THREAD(p2);
}
sc_signal_resolved s;
void p1( ){
s.write(sc_logic(0));}
void p2( ){
s.write(SC_LOGIC_1);
wait(10, SC_NS);
s.write(SC_LOGIC_Z);}
}
Resolved
18
9/18/2013
sc_signal_resolved
is a specialized channel of
sc_signal<> for type sc_logic
class sc_signal_resolved : public sc_signal<sc_logic> { }
sc_signal_rv<>
channel.
template<int W>
class sc_signal_rv : public sc_signal< sc_lv<W> > { }
There
sc_in_resolved
sc_inout_resolved
sc_out_resolved
sc_in_rv< >
sc_inout_rv< >
sc_out_rv< >
19
What
20
10
9/18/2013
Type conversion
Implicit conversion
Use explicit type cast
21
Try
22
11
9/18/2013
www.systemc.org
www.doulos.com
SystemC:
23
12