View
222
Download
1
Category
Preview:
Citation preview
Winter-Spring 2001 Codesign of Embedded Syste
ms1
Fixed-Point Data Types inSystemC
Part ofHW/SW Codesign of
Embedded Systems Course (CE 40-226)
Winter-Spring 2001 Codesign of Embedded Syste
ms2
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 Syste
ms3
Fixed-Point Data Types inSystemC
Fast Fixed-Point Data Types
Winter-Spring 2001 Codesign of Embedded Syste
ms4
Fast Fixed-Point Data Types Arbitrary Precision vs. Simulation Speed Achieving Faster Speed
Use double as underlying data type Mantissa limited to 53 bits Range limited to that of double
Fast Fixed-Point Types 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 Syste
ms5
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 Syste
ms6
Fixed-Point Data Types inSystemC
Dynamic Fixed-Point Data Types
Winter-Spring 2001 Codesign of Embedded Syste
ms7
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 .wl() .iwl() .q_mode() .o_mode()
Winter-Spring 2001 Codesign of Embedded Syste
ms8
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 Syste
ms9
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 Context is activated when declared
Declaration without activating is supported 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 Syste
ms10
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 Syste
ms11
Context Concept:Complex Example
Winter-Spring 2001 Codesign of Embedded Syste
ms12
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;
c_2active
c_1active
c_3active
c_1active
c_2active
Winter-Spring 2001 Codesign of Embedded Syste
ms13
Fixed-Point Data Types inSystemC
Fixed-Point Operators
Winter-Spring 2001 Codesign of Embedded Syste
ms14
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 Syste
ms15
Operators on Fixed-Point Data Types Alignment is done before each binary
operation
&
Winter-Spring 2001 Codesign of Embedded Syste
ms16
Fixed-Point Data Types inSystemC
Complementary Notes onFixed-Point Classes
Winter-Spring 2001 Codesign of Embedded Syste
ms17
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 Syste
ms18
Conversion To String Conversion member function
to_string(number_representation, format) Available number representations
SC_DEC (is the default) SC_BIN SC_BIN_US SC_BIN_SM SC_OCT SC_OCT_US SC_OCT_SM SC_HEX SC_HEX_US SC_HEX_SM SC_CSD
Available formats SC_F Fixed Notation (is the default) SC_E Scientific Notation
sc_fixed<10,5> my_var;cout << my_var.to_string(SC_CSD);
Winter-Spring 2001 Codesign of Embedded Syste
ms19
Type Casting Done during initialization and/or assignment (if
required) Type casting operations
1. Quantization2. 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_OFFsc_ufixed<16,16> d(SC_OFF);
Winter-Spring 2001 Codesign of Embedded Syste
ms20
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 Syste
ms21
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 Syste
ms22
Example:17 Tap FIR Filter
Winter-Spring 2001 Codesign of Embedded Syste
ms23
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 Syste
ms24
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 Syste
ms25
Complementary Notes:Assignments Today is due date for all LATE
assignments. From now on, 5% penalty is re-
enabled
Recommended