SystemC_6-1.ppt

advertisement
Fixed-Point Data Types in
SystemC
Part of
HW/SW Codesign of Embedded
Systems Course (CE 40-226)
Winter-Spring 2001
Codesign of Embedded Systems
1
Topics


Fast Fixed-Point Types
Dynamic Fixed-Point Types



Context concept and its usage
Defined Operators on Fixed-Point Types
Complementary Notes on Fixed-Point Class



Some other member functions of Fixed-Point class
Type casting
Arrays of Fixed-Point Data
Winter-Spring 2001
Codesign of Embedded Systems
2
Fixed-Point Data Types in
SystemC
Fast Fixed-Point Data Types
Winter-Spring 2001
Codesign of Embedded Systems
3
Fast Fixed-Point Data Types


Arbitrary Precision vs. Simulation Speed
Achieving Faster Speed




Fast Fixed-Point Types




Use double as underlying data type
Mantissa limited to 53 bits
Range limited to that of double
sc_fixed_fast, sc_ufixed_fast
sc_fix_fast, sc_ufix_fast
Exactly the same declaration format and usage as
before
All fixed-point data types, can be mixed freely
Winter-Spring 2001
Codesign of Embedded Systems
4
Fast Fixed-Point Data Types:
Simple Example
#include “systemc.h”
float adder(float a, float b)
{
sc_fixed_fast<4,2,SC_RND, SC_WRAP> Inputa = a;
sc_fixed_fast<6,3, SC_RND, SC_WRAP> Inputb = b;
sc_fixed_fast<7,4,SC_RND, SC_WRAP> Output;
Output = (Inputa + Inputb);
return (Output);
}
Winter-Spring 2001
Codesign of Embedded Systems
5
Fixed-Point Data Types in
SystemC
Dynamic Fixed-Point Data Types
Winter-Spring 2001
Codesign of Embedded Systems
6
Dynamic
Fixed-Point Data Types

Parameters passing

sc_fxtype_params Type

data members







wl: word length
iwl: integer word length
q_mode: quantization mode
o_mode: overflow mode
n_bits: saturated bits
some others
Reading/writing individual data members

Winter-Spring 2001
.wl()
.iwl()
.q_mode()
Codesign of Embedded Systems
.o_mode()
7
Dynamic Fixed-Point Data
Types (cont’d)

Example
sc_fxtype_params my_fx_type(8,4,SC_RND,SC_SAT);
sc_fix my_fx(my_fx_type);
my_fx = 10.2;
my_fx_type.wl(15);
cout<<my_fx_type.wl();
Winter-Spring 2001
Codesign of Embedded Systems
8
Context Concept


Specifies default values for (dynamic) fixed-point
variables. Built-in defaults: <32,32,SC_TRN,SC_WRAP>
Declaration syntax


sc_fxtype_context obj_name(<sc_fxtype_params>)
Scope

C/C++ scopes for variables/objects


Declaration without activating is supported


Context is activated when declared
sc_fxtype_context
obj_name(<sc_fxtype_params>, SC_LATER)
Selective enabling/disabling of Contexts is supported

.begin() and .end() member functions
Winter-Spring 2001
Codesign of Embedded Systems
9
Context Concept:
Simple Example
sc_fxtype_params myparams(SC_RND, SC_SAT);
sc_fxtype_context mycontext(myparams);
sc_fix_fast adder(sc_fix_fast a, sc_fix_fast b)
{
sc_fix_fast Output(a.wl() +1, a.iwl() +1);
Output = a + b;
return(Output);
}
Winter-Spring 2001
Codesign of Embedded Systems
10
Context Concept:
Complex Example
Winter-Spring 2001
Codesign of Embedded Systems
11
c_2
active
c_1
active
c_3
active
c_1
active
c_2
active
sc_fxtype_params param1(12,3);
sc_fxtype_params param2(32,3,SC_RND,SC_SAT);
sc_fxtype_params param3(16,16,SC_TRN,SC_SAT_ZERO);
.............
sc_fxtype_context c_1(param1,SC_LATER);
sc_fxtype_context c_2(param2);
sc_fxtype_context c_3(param3, SC_LATER);
sc_fix a;
c_1.begin();
sc_fix b;
c_3.begin();
sc_fix c;
sc_fixed<13,5> zz;
c_3.end();
sc_fix d;
c_1.end();
sc_fix e;
c_2.end();
sc_fix f;
Winter-Spring 2001
Codesign of Embedded Systems
12
Fixed-Point Data Types in
SystemC
Fixed-Point Operators
Winter-Spring 2001
Codesign of Embedded Systems
13
Operators
on Fixed-Point Data Types









Bitwise:
Arithmetic:
&
*
<<
Equality:
==
Relational:
<
Assignment: =
-=
Bit Selection:
Part Selection
|
^
/
+
>>
!=
<=
>
&=
|=
*=
/=
[]
.range(,)
~
-
++
>=
^=
<<=
+=
>>=
--
Bit selection return type: like sc_bit
Part selection return type: like sc_bv
Winter-Spring 2001
Codesign of Embedded Systems
14
Operators
on Fixed-Point Data Types

Alignment is done before each binary
operation
&
Winter-Spring 2001
Codesign of Embedded Systems
15
Fixed-Point Data Types in
SystemC
Complementary Notes on
Fixed-Point Classes
Winter-Spring 2001
Codesign of Embedded Systems
16
Useful State Information

Status member functions




is_neg()
is_zero()
overflow_flag()
quantization_flag()
sc_fixed<10,2> my_var;
if (my_var.is_zero())
...
Winter-Spring 2001
Codesign of Embedded Systems
17
Conversion To String

Conversion member function


Available number representations






to_string(number_representation, format)
SC_DEC
SC_BIN
SC_OCT
SC_HEX
SC_CSD
(is the default)
SC_BIN_US
SC_OCT_US
SC_HEX_US
SC_BIN_SM
SC_OCT_SM
SC_HEX_SM
Available formats


SC_F
SC_E
Fixed Notation (is the default)
Scientific Notation
sc_fixed<10,5> my_var;
cout << my_var.to_string(SC_CSD);
Winter-Spring 2001
Codesign of Embedded Systems
18
Type Casting


Done during initialization and/or assignment (if
required)
Type casting operations
1. Quantization
2. Overflow handling
(sign-extension and/or zero filling is done wherever necessary)

Can be turned ON or OFF, using


Current Context
Parameter during fix-point data declaration
SC_ON, SC_OFF
sc_ufixed<16,16> d(SC_OFF);

Winter-Spring 2001
Codesign of Embedded Systems
19
Type Casting (cont’d)

Turning Casting off will turn off fixed-point
handling of the operand


It will be treated as a large float
Bit-accurate behavior of the operand will not be
available
Winter-Spring 2001
Codesign of Embedded Systems
20
Arrays of Fixed-Point Data

Static fixed-point data types


sc_fixed<10,5> a[8];
Only CAST Switch is determined by current
Context


The same for all Static fixed-point types
Dynamic fixed-point data types



sc_fix a[8];
Default constructor is called.
Default values are taken from current context
Winter-Spring 2001
Codesign of Embedded Systems
21
Example:
17 Tap FIR Filter
Winter-Spring 2001
Codesign of Embedded Systems
22
sc_fixed<32,3,SC_RND, SC_WRAP>
fir_fx(sc_fixed<4,2,SC_RND, SC_WRAP> Input)
{
const int NumberOfCoefficients = 17;
static sc_fixed<4,2,SC_RND, SC_WRAP> state[16];
static sc_fixed<32,0,SC_RND, SC_WRAP> coeff[17] = {
1.05162989348173e-02, …};
sc_fixed< 4,2,SC_RND, SC_WRAP> * pstate;
sc_fixed<32,0,SC_RND, SC_WRAP> * pcoeff;
sc_fixed<32,3,SC_RND, SC_WRAP> sum;
int i;
/* FIR filter output */
pcoeff = &coeff[0];
pstate = &state[0];
sum = ((*pcoeff++ ) * (Input));
for (i = 0; i<16; i++)
sum = (sum + ((*pcoeff++ ) * (*pstate++ )));
/* shift state */
pstate = &state[15];
pcoeff = (pstate - 1);
for (i = 0; i < 15; i++)
*pstate-- = *pcoeff-- ;
*pstate = Input;
return(Sum);
}
Winter-Spring 2001
Codesign of Embedded Systems
23
What we learned today

Fix-point data types






Faster versions
Dynamic versions
Default behaviors
Operators
Arrays
Other complementary notes
Winter-Spring 2001
Codesign of Embedded Systems
24
Complementary Notes:
Assignments

Today is due date for all LATE
assignments.

From now on, 5% penalty is re-enabled
Winter-Spring 2001
Codesign of Embedded Systems
25
Download