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;...
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
= 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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
• 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.
(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.
• 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 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.
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.
/* 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.
(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.
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.
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.
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.
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.
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.
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.
• 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.
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.
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.
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.
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.
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.
• 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.
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.
/* 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.
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.
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.
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.
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.
<< 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.
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.
<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.
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.
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.
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.
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.
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.
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.
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.
= 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 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.
Need help?
Do you have a question about the DSP56800E and is the answer not in the manual?
Questions and answers