SystemC_5-1.ppt

advertisement
Data Types in
SystemC
Part of
HW/SW Codesign of Embedded
Systems Course (CE 40-226)
Winter-Spring 2001
Codesign of Embedded Systems
1
Today programme

SystemC Data Types

User-Defined Data Types
Winter-Spring 2001
Codesign of Embedded Systems
2
Data Types in
SystemC
Data Types
Winter-Spring 2001
Codesign of Embedded Systems
3
Data Types

Single-bit Types


Integer Types


sc_int, sc_uint, sc_bigint, sc_biguint
Bit-Vector Types


sc_bit, sc_logic
sc_bv, sc_lv
Fixed-Point Types

sc_fixed, sc_ufixed, sc_fix, sc_ufix
Winter-Spring 2001
Codesign of Embedded Systems
4
Single-bit Types

sc_bit


Two-valued logic: ‘0’ , ‘1’ (character literal)
Defined operators



Bitwise:
&(and) |(or)
Assignment: =
&=
Equality:
==
!=
Winter-Spring 2001
^(xor) ~(not)
|=
^=
Codesign of Embedded Systems
5
Single-bit Types (cont’d)

sc_logic

Four-valued logic: ‘0’, ‘1’,‘X’,‘x’,‘Z’,‘z’ (char. literal)



‘x’ means unknown or indeterminate value
‘z’ means high impedance or floating value
Defined operators



Bitwise:
&(and) |(or)
Assignment: =
&=
Equality:
==
!=
Winter-Spring 2001
^(xor) ~(not)
|=
^=
Codesign of Embedded Systems
6
Single-bit Types (cont’d)

Any mixture of sc_bit, sc_logic, and bool
types in comparison and assignments is
possible, except:
sc_logic l;
sc_bit b;
l = ‘z’;
b = l;
Winter-Spring 2001
//
//
//
//
or bool b
or l = ‘x’
Result is undefined.
Run-time warning is issued
Codesign of Embedded Systems
7
Integer Types:
Fixed Precision

Fixed Precision Unsigned and Signed Integers





Integer variables with fixed width (number of bits)
sc_int<n>, sc_uint<n>
Signed representation uses 2’s complement
SystemC provides 1-64 bit integer types
Underlying implementation: 64 bit integer


-D_32BIT_ compiler directive
Can freely be mixed with C++ integers (int, short,
long)
Winter-Spring 2001
Codesign of Embedded Systems
8
Fixed Precision Integers
(cont’d)

Defined operators









Bitwise ~
Arithemtic
Assignment
Equality
Relational
Auto-inc/dec
Bit Select
Part Select
Concatenation
Winter-Spring 2001
&
|
+
+=
-=
&=
|=
==
!=
<
<=
++
-[]
.range(,)
(,)
^
*
*=
^=
>>
/
/=
=
>
>=
Codesign of Embedded Systems
<<
%
%=
9
Fixed Precision Integers
(cont’d)
sc_logic mybit;
sc_uint<8> myuint;
mybit = myuint[7];
sc_uint<4> myrange;
myrange = myuint.range(5,2);
sc_uint<12> my12int;
my12int = (myuint, myrange);
Winter-Spring 2001
Codesign of Embedded Systems
10
Fixed Precision Integers
(cont’d)
sc_uint<8> u1, u2;
sc_int<16> i1, i2;
u1 = i1;
// convert int to uint
i2 = u2;
// convert uint to int
// BUG! in SystemC 1.1 User’s Guide
Winter-Spring 2001
Codesign of Embedded Systems
11
Integer Types:
Arbitrary Precision Integers

Integers with (virtually) no width limit





MAX_NBITS defined in sc_constants.h
sc_bigint<n>, sc_biguint<n>
Signed representation uses 2’s complement
Operators are the same as sc_int, sc_uint
Can be intermixed with sc_int, sc_uint,
C++ integer types
Winter-Spring 2001
Codesign of Embedded Systems
12
Bit-Vector Types:
Arbitrary Length Bit Vector

Arbitrary Length Bit Vector




Vector of 2-valued bits
No arithmetic operation
Assignment: String of ‘0’ and ‘1’ chars
Reduction operations
and_reduce(), nand, or, nor, xor, xnor
sc_bv<6> databus;
databus = “100100”;
sc_logic result;
result =databus.or_reduce();
Winter-Spring 2001
Codesign of Embedded Systems
13
Arbitrary Length Bit Vector
(cont’d)

Defined operators







Bitwise ~
Assignment
Equality
Bit Select
Part Select
Concatenation
Reduction
Winter-Spring 2001
&
|
=
&=
==
!=
[]
.range(,)
(,)
and_reduce()
xor_reduce()
^
|=
>>
^=
<<
or_reduce()
Codesign of Embedded Systems
14
Bit-Vector Types:
Arbitrary Length Logic Vector

Arbitrary Length Logic Vector


Vector of 4-valued bits
No arithmetic operation



Any ‘x’ or ‘z’ in rhs: runtime warning +
undefined result
Assignment: String of ‘0’, ‘1’, ‘x’, ‘z’ chars
Operators are the same as sc_bv
Winter-Spring 2001
Codesign of Embedded Systems
15
Arbitrary Length Logic Vector
(cont’d)
sc_lv<8> bus1;
if(enable)
bus1 = “01xz10xx”;
else
bus1 = “zzzzzzzz”;
cout<< “bus = “<<bus1.to_string();
Winter-Spring 2001
Codesign of Embedded Systems
16
Fixed-Point Types

Usage

HW implementation of Floating-point
arithmetic
Floating point representation
S
Mantissa
Exponent
Fixed point representation
(2’s complement) binary value
Winter-Spring 2001
Codesign of Embedded Systems
17
Fixed-Point Types (cont’d)

Advantages



Disadvantages



Narrower representable range of numbers
Uniform resolution over entire range
Problems to be addressed



Less area
More speed
Overflow
Quantization
To Be Discussed in Next Session
Winter-Spring 2001
Codesign of Embedded Systems
18
Data Types in
SystemC
Complementary Issues
Winter-Spring 2001
Codesign of Embedded Systems
19
Complementary Issues


Simulation Speed Issues
User Defined Type Issues


Equality-check Operator
Tracing a User-Defined Type
Winter-Spring 2001
Codesign of Embedded Systems
20
Speed Issues:
Integer Types
sc_bigint
sc_biguint
with
MAX_NBITS
not defined
sc_int
sc_uint
sc_int
sc_uint
with -D_32BIT_
C++
Types
with
MAX_NBITS
defined
Winter-Spring 2001
Codesign of Embedded Systems
21
Speed Issues:
Bit and Logic Types
sc_logic
sc_bit
sc_lv
sc_bv
Winter-Spring 2001
Codesign of Embedded Systems
22
User-Defined Type Issues
write()

new_val==old_val
Equality-Check Operator

Required for every type used as sc_signal
inline bool operator == (const packet_type& rhs) const
{
return (rhs.info == info && rhs.seq == seq &&
rhs.retry == retry);
}
Winter-Spring 2001
Codesign of Embedded Systems
23
Tracing a User-Defined Type

Need to define a special trace function
void sc_trace(sc_trace_file *tf, const packet_type& v,
const sc_string& NAME) {
sc_trace(tf,v.info, NAME + ".info");
sc_trace(tf,v.seq, NAME + ".seq");
sc_trace(tf,v.retry, NAME + ".retry");
}
Winter-Spring 2001
Codesign of Embedded Systems
24
What we learned today

SystemC-provided Data Types

User-Defined Data Types


Required operator
Tracing Issues
Winter-Spring 2001
Codesign of Embedded Systems
25
Download