Freescale Semiconductor DSP56800E User Manual

Mlib
Hide thumbs Also See for DSP56800E:
Table of Contents

Advertisement

Quick Links

MLIB User's Guide
DSP56800E
Document Number: DSP56800EMLIBUG
Rev. 2, 10/2015

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the DSP56800E and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

Summary of Contents for Freescale Semiconductor DSP56800E

  • Page 1 MLIB User's Guide DSP56800E Document Number: DSP56800EMLIBUG Rev. 2, 10/2015...
  • Page 2 MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 3: Table Of Contents

    MLIB_Abs..................................23 2.1.1 Available versions............................. 23 2.1.2 Declaration.................................23 2.1.3 Function use...............................24 MLIB_AbsSat.................................24 2.2.1 Available versions............................. 24 2.2.2 Declaration.................................25 2.2.3 Function use...............................25 MLIB_Add..................................25 2.3.1 Available versions............................. 25 2.3.2 Declaration.................................26 2.3.3 Function use...............................26 MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 4 Available versions............................. 32 2.8.2 Declaration.................................32 2.8.3 Function use...............................32 MLIB_Div..................................33 2.9.1 Available versions............................. 33 2.9.2 Declaration.................................34 2.9.3 Function use...............................34 2.10 MLIB_DivSat................................. 34 2.10.1 Available versions............................. 35 2.10.2 Declaration.................................35 2.10.3 Function use...............................36 MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 5 2.15.1 Available versions............................. 42 2.15.2 Declaration.................................43 2.15.3 Function use...............................43 2.16 MLIB_MacRnd................................44 2.16.1 Available versions............................. 44 2.16.2 Declaration.................................45 2.16.3 Function use...............................45 2.17 MLIB_MacRndSat................................. 45 2.17.1 Available versions............................. 45 2.17.2 Declaration.................................46 2.17.3 Function use...............................46 MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 6 2.22.1 Available versions............................. 52 2.22.2 Declaration.................................53 2.22.3 Function use...............................53 2.23 MLIB_MsuSat................................54 2.23.1 Available versions............................. 54 2.23.2 Declaration.................................54 2.23.3 Function use...............................55 2.24 MLIB_MsuRnd................................55 2.24.1 Available versions............................. 55 2.24.2 Declaration.................................56 2.24.3 Function use...............................56 MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 7 2.29.1 Available versions............................. 62 2.29.2 Declaration.................................63 2.29.3 Function use...............................63 2.30 MLIB_Mul..................................64 2.30.1 Available versions............................. 64 2.30.2 Declaration.................................65 2.30.3 Function use...............................65 2.31 MLIB_MulSat................................65 2.31.1 Available versions............................. 65 2.31.2 Declaration.................................66 2.31.3 Function use...............................66 MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 8 2.36.1 Available versions............................. 74 2.36.2 Declaration.................................74 2.36.3 Function use...............................74 2.37 MLIB_NegSat................................75 2.37.1 Available versions............................. 75 2.37.2 Declaration.................................75 2.37.3 Function use...............................75 2.38 MLIB_Rcp..................................76 2.38.1 Available versions............................. 76 2.38.2 Declaration.................................77 2.38.3 Function use...............................77 MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 9 2.43.1 Available versions............................. 82 2.43.2 Declaration.................................82 2.43.3 Function use...............................82 2.44 MLIB_Sh1LSat................................83 2.44.1 Available versions............................. 83 2.44.2 Declaration.................................83 2.44.3 Function use...............................83 2.45 MLIB_Sh1R................................... 84 2.45.1 Available versions............................. 84 2.45.2 Declaration.................................84 2.45.3 Function use...............................85 MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 10 2.50.1 Available versions............................. 91 2.50.2 Declaration.................................91 2.50.3 Function use...............................91 2.51 MLIB_ShRBi................................. 92 2.51.1 Available versions............................. 92 2.51.2 Declaration.................................92 2.51.3 Function use...............................93 2.52 MLIB_ShRBiSat................................93 2.52.1 Available versions............................. 93 2.52.2 Declaration.................................94 2.52.3 Function use...............................94 MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 11 2.55.1 Available versions............................. 97 2.55.2 Declaration.................................98 2.55.3 Function use...............................98 2.56 MLIB_Sub4..................................98 2.56.1 Available versions............................. 99 2.56.2 Declaration.................................99 2.56.3 Function use...............................99 2.57 MLIB_Sub4Sat................................100 2.57.1 Available versions............................. 100 2.57.2 Declaration.................................100 2.57.3 Function use...............................100 MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 12 MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 13: Introduction

    Library 1.1 Introduction 1.1.1 Overview This user's guide describes the Math Library (MLIB) for the family of DSP56800E core- based digital signal controllers. This library contains optimized functions. 1.1.2 Data types MLIB supports several data types: (un)signed integer, fractional, and accumulator. The integer data types are useful for general-purpose computation;...
  • Page 14: Api Definition

    1.1.4 Supported compilers MLIB for the DSP56800E core is written in assembly language with C-callable interface. The library is built and tested using the following compilers: • CodeWarrior™ Development Studio For the CodeWarrior™ Development Studio, the library is delivered in the mlib.lib file.
  • Page 15: Special Issues

    1. Launch CodeWarrior™ Development Studio. 2. Choose File > New > Bareboard Project, so that the "New Bareboard Project" dialog appears. 3. Type a name of the project, for example, MyProject01. MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 16 6. Now select the connection that will be used to download and debug the application. In this case, select the option P&E USB MultiLink Universal[FX] / USB MultiLink and Freescale USB TAP, and click Next. See Figure 1-3. MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 17: Library Path Variable

    To make the library integration easier, create a variable that will hold the information about the library path. 1. Right-click the MyProject01 node in the left-hand part and click Properties, or select Project > Properties from the menu. The project properties dialog appears. MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 18 FSLESL_LOC 5. Select the library parent folder by clicking 'Folder…' or just typing the following path into the Location box: C:\Freescale\FSLESL\DSP56800E_FSLESL_4.2_CW and click OK. 6. Click OK in the previous dialog. MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 19: Library Folder Addition

    4. Click Variables…, and select the FSLESL_LOC variable in the dialog that appears, click OK, and/or type the variable name into the box. See Figure 1-8. 5. Click Finish, and you will see the library folder linked in the project. See Figure 1-9 MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 20: Library Path Setup

    3. In the right-hand tree, expand the DSC Linker node, and click Input. See Figure 1-11. 4. In the third dialog Additional Libraries, click the 'Add…' icon, and a dialog appears. MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 21 6. Tick the box Relative To, and select FSLESL_LOC next to the box. See Figure 1-9. Click OK. 7. Now, you will see the library added in the box. See Figure 1-11. Figure 1-10. Library file inclusion Figure 1-11. Linker setting MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 22 After the main.c file opens up, include the following line into the #include section: #include "mlib.h" When you click the Build icon (hammer), the project will be compiled without errors. MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 23: Algorithms In Detail

    Absolute value of a 32-bit fractional value. The output is within the range <-1 ; 1). 2.1.2 Declaration The available MLIB_Abs functions have the following declarations: frac16_t MLIB_Abs_F16(frac16_t f16Val) frac32_t MLIB_Abs_F32(frac32_t f32Val) MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 24: Function Use

    Absolute value of a 16-bit fractional value. The output is within the range <0 ; 1). MLIB_AbsSat_F32 frac32_t frac32_t Absolute value of a 32-bit fractional value. The output is within the range <0 ; 1). MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 25: Mlib_Abssat

    This function is available in the following versions: • Fractional output - the output is the fractional portion of the result; the result is within the range <-1 ; 1). The result may overflow. MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 26: Function Use

    = FRAC16(-0.8); /* f16Add1 = -0.8 */ f16Add2 = FRAC16(-0.5); /* f16Add2 = -0.5 */ /* a32Result = f16Add1 + f16Add2 */ a32Result = MLIB_Add_A32ss(f16Add1, f16Add2); MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 27: Mlib_Addsat

    MLIB_AddSat functions have the following declarations: frac16_t MLIB_Add_F16(frac16_t f16Add1, frac16_t f16Add2) frac32_t MLIB_Add_F32(frac32_t f32Add1, frac32_t f32Add2) 2.4.3 Function use The use of the MLIB_AddSat function is shown in the following example: MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 28: Mlib_Add4

    MLIB_Add4_F32 frac32_t frac32_t frac32_t frac32_t frac32_t Addition of four 32-bit fractional addends. The output is within the range <-1 ; 1). 2.5.2 Declaration The available MLIB_Add4 functions have the following declarations: MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 29: Function Use

    This function is available in the following versions: • Fractional output - the output is the fractional portion of the result; the result is within the range <-1 ; 1). The result may saturate. MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 30: Declaration

    = MLIB_Add4Sat_F16(f16Add1, f16Add2, f16Add3, f16Add4); 2.7 MLIB_Clb MLIB_Clb functions return the number of leading bits of the input. If the input is 0, it returns the size of the type minus one. MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 31: Available Versions

    #include "mlib.h" static uint16_t u16Result; static frac32_t f32Val; void main(void) f32Val = FRAC32(0.00000452); /* f32Val = 0.00000452 */ /* u16Result = clb(f32Val) */ u16Result = MLIB_Clb_U16l(f32Val); 2.8 MLIB_Conv MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 32: Available Versions

    #include "mlib.h" static frac32_t f32Result; static frac16_t f16Val; void main(void) f16Val = FRAC16(-0.354); /* f16Val = -0.354 */ /* f32Result = (frac32_t)f16Val << 16 */ f32Result = MLIB_Conv_F32s(f16Val); MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 33: Available Versions

    Division of a 16-bit fractional numerator and denominator; the output is a 32-bit accumulator result. The output may be out of the range <-1 ; 1). Table continues on the next page... MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 34: Declaration

    = FRAC32(0.2); /* f32Num = 0.2 */ f16Denom = FRAC16(-0.495); /* f16Denom = -0.495 */ /* f32Result = f32Num / f16Denom */ f32Result = MLIB_Div_F32ls(f32Num, f16Denom); 2.10 MLIB_DivSat MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 35: Declaration

    Division of a 32-bit accumulator numerator by a 16-bit fractional denominator; the output is a 32-bit accumulator result. The output may be out of the range <-1 ; 1). 2.10.2 Declaration The available MLIB_DivSat functions have the following declarations: MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 36: Function Use

    The function returns undefined results out of this condition. • Accumulator output - the output is the accumulator type, where the result is greater than or equal to 0. MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 37: Declaration

    MLIB_Div1Q_F32ls(frac32_t f32Num, frac16_t f16Denom) frac32_t MLIB_Div1Q_F32(frac32_t f32Num, frac32_t f32Denom) acc32_t MLIB_Div1Q_A32ss(frac16_t f16Num, frac16_t f16Denom) acc32_t MLIB_Div1Q_A32ls(frac32_t f32Num, frac16_t f16Denom) acc32_t MLIB_Div1Q_A32ll(frac32_t f32Num, frac32_t f32Denom) acc32_t MLIB_Div1Q_A32as(acc32_t a32Num, frac16_t f16Denom) MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 38: Function Use

    Num. Denom. MLIB_Div1QSat_F16 frac16_t frac16_t frac16_t Division of a non-negative 16-bit fractional numerator and denominator. The output is within the range <0 ; 1). Table continues on the next page... MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 39: Declaration

    = FRAC32(0.02); /* f32Num = 0.02 */ f16Denom = FRAC16(0.4); /* f16Denom = 0.4 */ /* f32Result = f32Num / f16Denom */ f32Result = MLIB_Div1QSat_F32ls(f32Num, f16Denom); MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 40: Mlib_Log2

    2.13.3 Function use The use of the MLIB_Log2 function is shown in the following example: #include "mlib.h" static uint16_t u16Result, u16Val; void main(void) u16Val = 5; /* u16Val = 5 */ MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 41: Mlib_Mac

    The upper 16-bit portion [16..31] of the fractional product (of two 16-bit fractional multiplicands) is added to a 32-bit accumulator. The output may be out of the range <-1 ; 1). MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 42: Declaration

    The function saturates the output. See the following equation: Equation 13. Algorithm formula 2.15.1 Available versions This function is available in the following versions: MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 43: Declaration

    /* f32Accum = -0.7 */ f16Mult1 = FRAC16(-1.0); /* f16Mult1 = -1.0 */ f16Mult2 = FRAC16(0.8); /* f16Mult2 = 0.8 */ /* f32Result = sat(f32Accum + f16Mult1 * f16Mult2) */ f32Result = MLIB_MacSat_F32lss(f32Accum, f16Mult1, f16Mult2); MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 44: Mlib_Macrnd

    The fractional product (of two 16-bit fractional multiplicands), rounded to the upper 16 bits [16..31], is added to a 32-bit accumulator. The output may be out of the range <-1 ; 1). MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 45: Declaration

    The round method is the round to nearest. The function saturates the output. See the following equation: Equation 15. Algorithm formula 2.17.1 Available versions This function is available in the following versions: MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 46: Declaration

    = FRAC32(-0.7); /* f32Accum = -0.7 */ f32Mult1 = FRAC32(-1.0); /* f32Mult1 = -1.0 */ f32Mult2 = FRAC32(0.8); /* f32Mult2 = 0.8 */ /* f32Result = sat(round(f32Accum + f32Mult1 * f32Mult2)) */ MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 47: Mlib_Mac4

    The available MLIB_Mac4 functions have the following declarations: frac32_t MLIB_Mac4_F32ssss(frac16_t f16Add1Mult1, frac16_t f16Add1Mult2, frac16_t f16Add2Mult1, frac16_t f16Add2Mult2) 2.18.3 Function use The use of the MLIB_Mac4 function is shown in the following example: MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 48: Mlib_Mac4Sat

    Mult. 2 Mult. 1 Mult. 2 MLIB_Mac4Sat_F32ssss frac16_t frac16_t frac16_t frac16_t frac32_t Addition of two 32-bit fractional products (of two 16-bit fractional multiplicands). The output is within the range <-1 ; 1). MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 49: Declaration

    This function is available in the following versions: • Fractional output - the output is the fractional portion of the result; the result is within the range <-1 ; 1). The result may overflow. MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 50: Declaration

    /* f16Add2Mult1 = 0.365 */ f16Add2Mult2 = FRAC16(-0.25); /* f16Add2Mult2 = -0.25 */ /* f16Result = round(f16Add1Mult1 * f16Add1Mult2 + f16Add2Mult1 * f16Add2Mult2) */ f16Result = MLIB_Mac4Rnd_F16(f16Add1Mult1, f16Add1Mult2, f16Add2Mult1, f16Add2Mult2); 2.21 MLIB_Mac4RndSat MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 51: Mlib_Mac4Rndsat

    <-1 ; 1). 2.21.2 Declaration The available MLIB_Mac4RndSat functions have the following declarations: frac16_t MLIB_Mac4RndSat_F16(frac16_t f16Add1Mult1, frac16_t f16Add1Mult2, frac16_t f16Add2Mult1, frac16_t f16Add2Mult2) frac32_t MLIB_Mac4RndSat_F32(frac32_t f32Add1Mult1, frac32_t f32Add1Mult2, frac32_t f32Add2Mult1, frac32_t f32Add2Mult2) MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 52: Mlib_Msu

    • Accumulator output with mixed inputs - the output is the accumulator type, where the result can be out of the range <-1 ; 1). The accumulator is the accumulator type, the multiplicands are the fractional types. The result may overflow. MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 53: Declaration

    /* a32Accum = 2.3 */ f16Mult1 = FRAC16(0.1); /* f16Mult1 = 0.1 */ f16Mult2 = FRAC16(-0.2); /* f16Mult2 = -0.2 */ /* a32Result = a32Accum - f16Mult1 * f16Mult2 */ a32Result = MLIB_Msu_A32ass(a32Accum, f16Mult1, f16Mult2); MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 54: Declaration

    (of two 32-bit fractional multiplicands) is subracted from a 32-bit fractional accumulator. The output is within the range <-1 ; 1). 2.23.2 Declaration The available MLIB_MsuSat functions have the following declarations: MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 55: Function Use

    • Accumulator output with mixed inputs - the output is the accumulator type, where the result can be out of the range <-1 ; 1). The accumulator is the accumulator type, the multiplicands are the fractional types. The result may overflow. MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 56: Declaration

    = FRAC16(0.3); /* f16Accum = 0.3 */ f16Mult1 = FRAC16(0.1); /* f16Mult1 = 0.1 */ f16Mult2 = FRAC16(-0.2); /* f16Mult2 = -0.2 */ /* f16Result = round(f16Accum - f16Mult1 * f16Mult2) */ MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 57 The fractional product (of two 32-bit fractional multiplicands), rounded to the upper 32 bits [32..63], is subtracted from a 32-bit fractional accumulator. The output is within the range <-1 ; 1). MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 58: Mlib_Msu4

    The function is available in the following versions: • Fractional output - the output is the fractional portion of the result; the result is within the range <-1 ; 1). The result may overflow. MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 59: Mlib_Msu4Sat

    /* f32Result = f16MinMult1 * f16MinMult2 - f16SubMult1 * f16SubMult2 */ f32Result = MLIB_Msu4_F32ssss(f16MinMult1, f16MinMult2, f16SubMult1, f16SubMult2); 2.27 MLIB_Msu4Sat MLIB_Msu4Sat functions return the subtraction of the products of two multiplicands. The function saturates the output. See the following equation: MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 60: Available Versions

    #include "mlib.h" static frac32_t f32Result; static frac16_t f16MinMult1, f16MinMult2, f16SubMult1, f16SubMult2; void main(void) f16MinMult1 = FRAC16(0.8); /* f16MinMult1 = 0.8 */ f16MinMult2 = FRAC16(-0.9); /* f16MinMult2 = -0.9 */ MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 61: Declaration

    (of two 32-bit fractional multiplicands), rounded to the upper 32 bits. The output is within the range <-1 ; 1). 2.28.2 Declaration The available MLIB_Msu4Rnd functions have the following declarations: MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 62: Mlib_Msu4Rndsat

    This function is available in the following versions: • Fractional output - the output is the fractional portion of the result; the result is within the range <-1 ; 1). The result may saturate. MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 63: Declaration

    = FRAC16(0.7); /* f16SubMult1 = 0.7 */ f16SubMult2 = FRAC16(0.9); /* f16SubMult2 = 0.9 */ /* f16Result = sat(round(f16MinMult1 * f16MinMult2 - f16SubMult1 * f16SubMult2)) */ f16Result = MLIB_Msu4RndSat_F16(f16MinMult1, f16MinMult2, f16SubMult1, f16SubMult2); MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 64: Mlib_Mul

    Product of two 32-bit accumulator multiplicands; the output is a 32- bit accumulator, which has the upper mid bits of the result [16..47]. The output is within the range <-65536.0 ; 65536.0). MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 65: Declaration

    The function saturates the output. See the following equation: Equation 29. Algorithm formula 2.31.1 Available versions This function is available in the following versions: MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 66: Declaration

    MLIB_MulSat_F32ss(frac16_t f16Mult1, frac16_t f16Mult2) frac32_t MLIB_MulSat_F32(frac32_t f32Mult1, frac32_t f32Mult2) acc32_t MLIB_MulSat_A32(acc32_t a32Mult1, acc32_t a32Mult1) 2.31.3 Function use The use of the MLIB_MulSat function is shown in the following example: MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 67: Mlib_Mulneg

    16-bit fractional value, which has the upper 16 bits of the fractional portion of the result [16..31]. The output is within the range <-1 ; 1). Table continues on the next page... MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 68: Declaration

    = FRAC16(0.5); /* f16Mult1 = 0.5 */ f16Mult2 = FRAC16(-0.3); /* f16Mult2 = -0.3 */ /* f32Result = f16Mult1 * (-f16Mult2) */ f32Result = MLIB_MulNeg_F32ss(f16Mult1, f16Mult2); 2.33 MLIB_MulRnd MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 69: Available Versions

    MLIB_MulRnd_A32 acc32_t acc32_t acc32_t Product of two 32-bit accumulator multiplicands; the output is rounded to the middle bits of the result [16..47]. The output is within the range <-65536.0 ; 65536.0). MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 70: Declaration

    • Fractional output with fractional inputs - the output is the fractional portion of the result; the result is within the range <-1 ; 1). The inputs are the fractional values only. The result may saturate. MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 71: Declaration

    MLIB_MulRndSat_F32ls(frac32_t f32Mult1, frac16_t f16Mult2) frac32_t MLIB_MulRndSat_F32(frac32_t f32Mult1, frac32_t f32Mult2) acc32_t MLIB_MulRndSat_A32(acc32_t a32Mult1, acc32_t a32Mult1) 2.34.3 Function use The use of the MLIB_MulRndSat function is shown in the following example: MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 72: Mlib_Mulnegrnd

    Negative product of two 16-bit fractional multiplicands; the output is rounded to the upper 16 bits of the results [16..31]. The output is within the range <-1 ; 1). Table continues on the next page... MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 73: Declaration

    = FRAC32(0.3); /* f32Mult1 = 0.3 */ f32Mult2 = FRAC32(-0.5); /* f32Mult2 = -0.5 */ /* f32Result = round(f32Mult1 * (-f32Mult2)) */ f32Result = MLIB_MulNegRnd_F32(f32Mult1, f32Mult2); MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 74: Declaration

    MLIB_Neg_F16(frac16_t f16Val) frac32_t MLIB_Neg_F32(frac32_t f32Val) 2.36.3 Function use The use of the MLIB_Neg function is shown in the following example: #include "mlib.h" static frac32_t f32Val, f32Result; MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 75: Declaration

    Negative value of a 32-bit value. The output is within the range <-1 ; 2.37.2 Declaration The available MLIB_NegSat functions have the following declarations: frac16_t MLIB_NegSat_F16(frac16_t f16Val) frac32_t MLIB_NegSat_F32(frac32_t f32Val) MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 76: Function Use

    Reciprocal for a 16-bit fractional value; the output is a 32-bit accumulator value. The absolute value of the output is greater than or equal to 1. Faster version, where the division is performed with 16-bit accuracy. MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 77: Declaration

    • Accumulator output with fractional input - the output is the accumulator type, where the result is greater than or equal to 1. The function is not defined for negative inputs. The input is the fractional type. MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 78: Declaration

    2.40 MLIB_Rnd MLIB_Rnd functions round the input to the nearest value to meet the return type's size. The function does not saturate the output. See the following equation: Equation 38. Algorithm formula MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 79: Declaration

    /* f16Result = round(f32Val)*/ f16Result = MLIB_Rnd_F16l(f32Val); 2.41 MLIB_RndSat MLIB_RndSat functions round the input to the nearest value to meet the return type's size. The function saturates the output. See the following equation: MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 80: Declaration

    #include "mlib.h" static frac32_t f32Val; static frac16_t f16Result; void main(void) f32Val = FRAC32(0.9997996); /* f32Val = 0.9997996 */ /* f16Result = sat(round(f32Val)) */ f16Result = MLIB_RndSat_F16l(f32Val); 2.42 MLIB_Sat MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 81: Declaration

    #include "mlib.h" static acc32_t a32Accum; static frac16_t f16Result; void main(void) a32Accum = ACC32(5.6); /* a32Accum = 5.6 */ /* f16Result = sat(a32Accum) */ f16Result = MLIB_Sat_F16a(a32Accum); MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 82: Mlib_Sh1L

    MLIB_Sh1L_F16(frac16_t f16Val) frac32_t MLIB_Sh1L_F32(frac32_t f32Val) 2.43.3 Function use The use of the MLIB_Sh1L function is shown in the following example: #include "mlib.h" static frac32_t f32Result, f32Val; MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 83: Mlib_Sh1Lsat

    Shift of a 32-bit fractional value by one time to the left. The output is within the range <-1 ; 1). 2.44.2 Declaration The available MLIB_Sh1LSat functions have the following declarations: frac16_t MLIB_Sh1LSat_F16(frac16_t f16Val) frac32_t MLIB_Sh1LSat_F32(frac32_t f32Val) MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 84: Function Use

    Shift of a 16-bit fractional value by one time to the right. The output is within the range <-0.5 ; 0.5). MLIB_Sh1R_F32 frac32_t frac32_t Shift of a 32-bit fractional value by one time to the right. The output is within the range <-0.5 ; 0.5). MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 85: Declaration

    This function is available in the following versions: • Fractional output - the output is the fractional portion of the result; the result is within the range <-1 ; 1). The result may overflow. MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 86: Declaration

    << u16Sh */ f16Result = MLIB_ShL_F16(f16Val, u16Sh); 2.47 MLIB_ShLSat MLIB_ShLSat functions return the arithmetically shifted value to the left a specified number of times. The function saturates the output. See the following equation: MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 87: Available Versions

    MLIB_ShLSat_F32(frac32_t f32Val, uint16_t u16Sh) 2.47.3 Function use The use of the MLIB_ShLSat function is shown in the following example: #include "mlib.h" static frac16_t f16Result, f16Val; static uint16_t u16Sh; void main(void) MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 88: Mlib_Shr

    <0 ; 31>. The output is within the range <-1 ; 1). 2.48.2 Declaration The available MLIB_ShR functions have the following declarations: frac16_t MLIB_ShR_F16(frac16_t f16Val, uint16_t u16Sh) frac32_t MLIB_ShR_F32(frac32_t f32Val, uint16_t u16Sh) MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 89: Function Use

    The shift is allowed within the range <-15 ; 15>. The output is within the range <-1 ; 1). Table continues on the next page... MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 90: Declaration

    If the number of shifts is positive, the shift is performed to the left; if negative, to the right. The function saturates the output. See the following equation: MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 91: Available Versions

    MLIB_ShLBiSat_F16(frac16_t f16Val, int16_t i16Sh) frac32_t MLIB_ShLBiSat_F32(frac32_t f32Val, int16_t i16Sh) 2.50.3 Function use The use of the MLIB_ShLBiSat function is shown in the following example: #include "mlib.h" static frac16_t f16Result, f16Val; MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 92: Mlib_Shrbi

    The shift is allowed within the range <-31 ; 31>. The output is within the range <-1 ; 1). MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 93: Declaration

    This function is available in the following versions: • Fractional output - the output is the fractional portion of the result; the result is within the range <-1 ; 1). The result may saturate. MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 94: Declaration

    = 13; /* i16Sh = 13 */ /* f32Result = sat(f32Val >> i16Sh) */ f32Result = MLIB_ShRBiSat_F32(f32Val, i16Sh); 2.53 MLIB_Sign MLIB_Sign functions return the sign of the input. See the following equation: MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 95: Available Versions

    MLIB_Sign function is shown in the following example: #include "mlib.h" static frac32_t f32In, f32Result; void main(void) f32In = FRAC32(-0.95); /* f32In = -0.95 */ /* f32Result = sign(f32In)*/ f32Result = MLIB_Sign_F32(f32In); MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 96: Mlib_Sub

    Subtraction of a 16-bit fractional subtrahend from a 32-bit accumulator. The output may be out of the range <-1 ; 1). 2.54.2 Declaration The available MLIB_Sub functions have the following declarations: MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 97: Mlib_Subsat

    This function is available in the following versions: • Fractional output - the output is the fractional portion of the result; the result is within the range <-1 ; 1). The result may saturate. MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 98: Declaration

    = MLIB_SubSat_F32(f32Min,f32Sub); 2.56 MLIB_Sub4 MLIB_Sub4 functions return the subtraction of three subtrahends from the minuend. The function does not saturate the output. See the following equation: Equation 54. Algorithm formula MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 99: Mlib_Sub4

    = FRAC16(-0.5); /* f16Sub2 = -0.5 */ f16Sub3 = FRAC16(0.2); /* f16Sub3 = 0.2 */ /* f16Result = sat(f16Min - f16Sub1 - f16Sub2 - f16Sub3) */ f16Result = MLIB_Sub4_F16(f16Min, f16Sub1, f16Sub2, f16Sub3); MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 100: Mlib_Sub4Sat

    <-1 ; 1). 2.57.2 Declaration The available MLIB_Sub4Sat functions have the following declarations: frac16_t MLIB_Sub4Sat_F16(frac16_t f16Min, frac16_t f16Sub1, frac16_t f16Sub2, frac16_t f16Sub3) frac32_t MLIB_Sub4Sat_F32(frac32_t f32Min, frac32_t f32Sub1, frac32_t f32Sub2, frac32_t f32Sub3) MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 101: Function Use

    = FRAC32(-0.1); /* f32Sub2 = -0.1 */ f32Sub3 = FRAC32(0.7); /* f32Sub3 = 0.7 */ /* f32Result = sat(f32Min - f32Sub1 - f32Sub2 - f32Sub3) */ f32Result = MLIB_Sub4Sat_F32(f32Min, f32Sub1, f32Sub2, f32Sub3); MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 102 MLIB_Sub4Sat MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 103 8-bit integer type. It is able to store the variables within the range <0 ; 255>. Its definition is as follows: typedef unsigned char int8_t; The following figure shows the way in which the data is stored by this type: MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 104 <0 ; 65535>. Its definition is as follows: typedef unsigned short uint16_t; The following figure shows the way in which the data is stored by this type: Table A-3. Data storage Value Integer 65535 15518 40768 A.4 uint32_t MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 105 <-128 ; 127>. Its definition is as follows: typedef char int8_t; The following figure shows the way in which the data is stored by this type: Table A-5. Data storage Value Sign Integer -128 MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 106 The following figure shows the way in which the data is stored by this type: Table A-7. Data storage 24 23 16 15 Value Integer 2147483647 -2147483648 55977296 -843915468 MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 107 The following figure shows the way in which the data is stored by this type: Table A-9. Data storage Value Sign Fractional 0.99997 -1.0 Table continues on the next page... MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 108 16-bit fractional type. It is able to store the variables within the range <-256 ; 256). Its definition is as follows: typedef short acc16_t; The following figure shows the way in which the data is stored by this type: MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 109 The following figure shows the way in which the data is stored by this type: Table A-12. Data storage 24 23 16 15 Value Integer Fractional 65535.999969 -65536.0 -1.0 23.789734 -1171.306793 To store a real number as acc32_t, use the ACC32 macro. MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 110 #define FRAC8(x) ((frac8_t)((x) < 0.9921875 ? ((x) >= -1 ? (x)*0x80 : 0x80) : 0x7F)) The input is multiplied by 128 (=2 ). The output is limited to the range <0x80 ; 0x7F>, which corresponds to <-1.0 ; 1.0-2 >. MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 111 ). The output is limited to the range <0x80000000 ; 0x7FFFFFFF>, which corresponds to <-1.0 ; 1.0-2 >. #include "mlib.h" static frac32_t f32Val; void main(void) f32Val = FRAC32(-0.1735667); /* f32Val = -0.1735667 */ MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 112 ). The output is limited to the range <0x80000000 ; 0x7FFFFFFF>, which corresponds to <-65536.0 ; 65536.0-2 >. #include "mlib.h" static acc32_t a32Val; void main(void) a32Val = ACC32(-13.654437); /* a32Val = -13.654437 */ MLIB User's Guide, Rev. 2, 10/2015 Freescale Semiconductor, Inc.
  • Page 113 Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © 2015 Freescale Semiconductor, Inc. Document Number DSP56800EMLIBUG Revision 2, 10/2015...

Table of Contents