Presentation is loading. Please wait.

Presentation is loading. Please wait.

Winter-Spring 2001Codesign of Embedded Systems1 Fixed-Point Data Types in SystemC Part of HW/SW Codesign of Embedded Systems Course (CE 40-226)

Similar presentations


Presentation on theme: "Winter-Spring 2001Codesign of Embedded Systems1 Fixed-Point Data Types in SystemC Part of HW/SW Codesign of Embedded Systems Course (CE 40-226)"— Presentation transcript:

1 Winter-Spring 2001Codesign of Embedded Systems1 Fixed-Point Data Types in SystemC Part of HW/SW Codesign of Embedded Systems Course (CE 40-226)

2 Winter-Spring 2001Codesign of Embedded Systems2 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

3 Winter-Spring 2001Codesign of Embedded Systems3 Fixed-Point Data Types in SystemC Fast Fixed-Point Data Types

4 Winter-Spring 2001Codesign of Embedded Systems4 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

5 Winter-Spring 2001Codesign of Embedded Systems5 Fast Fixed-Point Data Types: Simple Example #include “systemc.h” float adder(float a, float b) { sc_fixed_fast Inputa = a; sc_fixed_fast Inputb = b; sc_fixed_fast Output; Output = (Inputa + Inputb); return (Output); }

6 Winter-Spring 2001Codesign of Embedded Systems6 Fixed-Point Data Types in SystemC Dynamic Fixed-Point Data Types

7 Winter-Spring 2001Codesign of Embedded Systems7 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()

8 Winter-Spring 2001Codesign of Embedded Systems8 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();

9 Winter-Spring 2001Codesign of Embedded Systems9 Context Concept Specifies default values for (dynamic) fixed-point variables. Built-in defaults: Declaration syntax sc_fxtype_context obj_name( ) Scope C/C++ scopes for variables/objects Context is activated when declared Declaration without activating is supported sc_fxtype_context obj_name(, SC_LATER) Selective enabling/disabling of Contexts is supported.begin() and.end() member functions

10 Winter-Spring 2001Codesign of Embedded Systems10 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); }

11 Winter-Spring 2001Codesign of Embedded Systems11 Context Concept: Complex Example

12 Winter-Spring 2001Codesign of Embedded Systems12 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 zz; c_3.end(); sc_fix d; c_1.end(); sc_fix e; c_2.end(); sc_fix f; c_2 active c_1 active c_3 active c_1 active c_2 active

13 Winter-Spring 2001Codesign of Embedded Systems13 Fixed-Point Data Types in SystemC Fixed-Point Operators

14 Winter-Spring 2001Codesign of Embedded Systems14 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

15 Winter-Spring 2001Codesign of Embedded Systems15 Operators on Fixed-Point Data Types Alignment is done before each binary operation &

16 Winter-Spring 2001Codesign of Embedded Systems16 Fixed-Point Data Types in SystemC Complementary Notes on Fixed-Point Classes

17 Winter-Spring 2001Codesign of Embedded Systems17 Useful State Information Status member functions is_neg() is_zero() overflow_flag() quantization_flag() sc_fixed my_var; if (my_var.is_zero())...

18 Winter-Spring 2001Codesign of Embedded Systems18 Conversion To String Conversion member function to_string(number_representation, format) Available number representations SC_DEC (is the default) SC_BINSC_BIN_USSC_BIN_SM SC_OCTSC_OCT_USSC_OCT_SM SC_HEXSC_HEX_USSC_HEX_SM SC_CSD Available formats SC_FFixed Notation (is the default) SC_EScientific Notation sc_fixed my_var; cout << my_var.to_string(SC_CSD);

19 Winter-Spring 2001Codesign of Embedded Systems19 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 d(SC_OFF);

20 Winter-Spring 2001Codesign of Embedded Systems20 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

21 Winter-Spring 2001Codesign of Embedded Systems21 Arrays of Fixed-Point Data Static fixed-point data types sc_fixed 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

22 Winter-Spring 2001Codesign of Embedded Systems22 Example: 17 Tap FIR Filter

23 Winter-Spring 2001Codesign of Embedded Systems23 sc_fixed fir_fx(sc_fixed Input) { const int NumberOfCoefficients = 17; static sc_fixed state[16]; static sc_fixed coeff[17] = { 1.05162989348173e-02, …}; sc_fixed * pstate; sc_fixed * pcoeff; sc_fixed 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); }

24 Winter-Spring 2001Codesign of Embedded Systems24 What we learned today Fix-point data types Faster versions Dynamic versions Default behaviors Operators Arrays Other complementary notes

25 Winter-Spring 2001Codesign of Embedded Systems25 Complementary Notes: Assignments Today is due date for all LATE assignments. From now on, 5% penalty is re-enabled


Download ppt "Winter-Spring 2001Codesign of Embedded Systems1 Fixed-Point Data Types in SystemC Part of HW/SW Codesign of Embedded Systems Course (CE 40-226)"

Similar presentations


Ads by Google