ST SPC56xx DSP function library 1 Reference Manual
Iklan
Iklan
RM0019
Reference manual
SPC56xx DSP function library 1
Introduction
The SPC56xx DSP function library 1 contains optimized functions for SPC56xx family of processors with Signal Processing Engine (SPE APU).
September 2013 Rev 2 1/29 www.st.com
Contents
Contents
RM0019
How to use the library in a project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Reduced lookup table for 16-bit CRC . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Standard lookup table for 16-bit CRC . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
256-point complex FFT, float data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
22 TAP real FIR filter with symmetrical impulse response . . . . . . . . . . . . 17
32 TAP real FIR Filter with symmetrical impulse response . . . . . . . . . . . 18
64 TAP real FIR filter with symmetrical impulse response . . . . . . . . . . . . 19
2/29
RM0019
List of tables
List of tables
3/29
RM0019
●
●
●
●
●
●
●
●
●
●
●
The library contains the following functions: conv_enc_mux - rate 1/2 constraint length 9 convolutional encoder corr_mn crc_calc dct fft256 fir20 fir22sym fir32sym fir64sym
- cross-correlation
- 16-bit cyclic redundancy code
- 2-D 8x8 DCT
- 256-point complex FFT, single precision floating point
- real 20TAP FIR filter
- real 22TAP FIR filter with symmetrical impulse response
- real 32TAP FIR filter with symmetrical impulse response
- real 64TAP FIR filter with symmetrical impulse response iir_2nd_o - direct form 2nd order IIR filter lu_decomp - LU decomposition
Library functions
4/29
Supported compilers
●
●
●
The library was built and tested using the following compilers:
CodeWarrior for PowerPC V1.5 beta2
Green Hills MULTI for PowerPC v4.2.1
Wind River Compiler Version 5.2.1.0
RM0019
5/29
RM0019 Directory structure
●
●
●
●
●
●
● doc - contains library user's manual include - contains library header file libdsp1.h
lib - contains library files (.a), _cw for CodeWarrior, _ghs for Green Hills, _wr for Wind
River project - contains project and make files to rebuild the library src - contains library source files for CodeWarrior and Green Hills compilers src\src_WR - contains library source files for Wind River compiler test - contains test projects (optional)
6/29
How to use the library in a project
4 How to use the library in a project
RM0019
Comments:
●
●
CodeWarrior
– add libdsp1_cw.a into your project window
– add path to library include file libdsp1.h to “Target Settings (Alt-F7)->Access
Paths->User Paths”
– include file libdsp1.h to your source file
Green Hills
– use -l and -L linker options -llibdsp1_ghs.a -L{path to libdsp1_ghs.a}
– use -I compiler option -I{path to libdsp1.h},
– include file libdsp1.h to your source file
The -l, -L and -I options can be set in MULTI Project Builder menu “Edit->Set Options...-
>Basic Options->Project”
● Wind River
– use -l and -L linker options -llibdsp1_wr.a -L{path to libdsp1_wr.a}
– use -I compiler option -I{path to libdsp1.h}
– include file libdsp1.h to your source file
Code example:
#include "libdsp1.h"
#define N 4
#define M 4
/* vec_x and vec_y must be double-word aligned */ int vec_x[N] = {1073741824,-429496729,1288490188,1717986918}; int vec_y[N] = {-1073741824,1073741824,1503238553,1717986918}; int vec_out[M]; void main(void)
{ corr_mn(N, M, vec_x, vec_y, vec_out);
}
7/29
RM0019
5 How to rebuild the library
How to rebuild the library
●
●
●
The project files needed to rebuild the library are stored in the “project” directory.
CodeWarrior , open project libdsp1.mcp in the CodeWarrior IDE and press F7
Green Hills
Wind River
, open project libdsp1.gpj in the MULTI Project Builder and press Ctrl+F7
, open command prompt window, change current directory to {libdsp1 folder}\project and run dmake.exe
8/29
Function API RM0019
Function call:
Arguments: void conv_enc_mux(int n, unsigned short *message_ptr, unsigned long *out_ptr); n out_ptr
Table 1.
message_ptr in conv_enc_mux arguments size of input message in half-words, must be multiple of 2 in out pointer to input sequence of bits, each half-word contains bits b(15) b(14) ... b(0), must be half-word aligned memory layout: message_ptr(0) message_ptr(1) ... message_ptr(n-1) pointer to output sequence of bits, each word contains bits b(31) b(30)
... b(0), must be word aligned memory layout: out_ptr(0) out_ptr(1) ... out_ptr(n-1)
Description: Computes rate 1/2 constraint length 9 convolutional encoder. Input sequence of bits is stored in message_ptr. Output sequence of bits is written to out_ptr.
Algorithm:
Generator polynomials are fixed: g_0 = 561 (octal), g_1 = 753 (octal). These are the polynomials given in the 3G specification.
Encoder output sequences G_0 and G_1 are given by:
Equation 1 G_0 k = x k
– 2
– 3
– 4
– 8
Equation 2 = – 1
– 2
– 3
– 5
– 7
Output bit sequence is obtained by interleaving bit sequences G_0 and G_1.
– for each k = 0, 1, ..., 16n-1 where x 0
bits). Note that x 1 x
... x 16n
– 15
x
–
–
14
1
is the input message (i.e., input sequence of
... x
– 1
are zero for 3G.
8
Performance: See
Example1: conv_enc_mux
#define K 8 unsigned short message[K]; unsigned long out[K]; conv_enc_mux(K, message, out);
9/29
RM0019 Function API
6.2 Cross-correlation
Function call:
Arguments: void corr_mn(int N, int M, int *x_ptr, int *y_ptr, int *out_ptr);
N
M x_ptr y_ptr out_ptr
Table 2.
in corr_mn arguments length of the input vectors x_ptr and y_ptr, must be multiple of 4 in in in out length of the output sequence out_ptr, must be <= N, must be multiple of 4 pointer to the first input vector of length N, data type of each vector item is signed 32-bit fractional in range -1 to 1-2
-31
, vector must be double word aligned memory layout: x_ptr(0) x_ptr(1) ... x_ptr(N-1) pointer to the second input vector of length N, data type of each vector item is signed 32-bit fractional in range -1 to 1-2
-31
, vector must be double word aligned memory layout: y_ptr(0) y_ptr(1) ... y_ptr(N-1) pointer to the output vector of length M, data type of each vector item is signed 32-bit fractional in range -1 to 1-2
-31
, vector must be word aligned, memory layout: out_ptr(0) out_ptr(1) ... out_ptr(M-1)
Description: Computes cross-correlation of input vectors x_ptr and y_ptr. The result is written to vector out_ptr. All data types signed 32-bit fractional in range -1 to 1-2
-31
.
Algorithm:
Correlation:
Equation 3 out j = x j for each j = 0, 1, ..., M-1 y 0 + + 1
y 1 + ...
+ – 1
– j – 1
Note: The input data must be appropriately scaled to prevent overflow.
Performance: See
Example 2. corr_mn
#define N 4
#define M 4 int vector_x[N] = {1073741824,-429496729,1288490188,1717986918}; int vector_y[N] = {-1073741824,1073741824,1503238553,1717986918}; int result[M]; corr_mn(N, M, vector_x, vector_y, result);
10/29
Function API RM0019
6.3 Reduced lookup table for 16-bit CRC
Function call:
Arguments: void crc_rdc_table(unsigned short gen_poly, unsigned short *rdc_table_ptr);
Table 3.
crc_rdc_table arguments bits g0, g1, ..., g15 of generator polynomial where g x = x
16
+
15
+
14
+ ...
+ 1
+ g0 gen_poly in
For example, gen_poly = 0xa001 corresponds to rdc_table_ptr out g x = x
16
+
15
+ 2
+ g0 pointer to reduced lookup table of length 16 memory layout: rdc_table_ptr(0) rdc_table_ptr(1) ... rdc_table_ptr(15)
Description: Creates a reduced lookup table for 16-bit CRC computation (for a reference see T. V.
Ramabadran and S. S. Gaitonde, A Tutorial on CRC Computations , IEEE Micro, Vol.
8, Issue 4, August 1988, pp. 62-75).
Algorithm:
Let g(x) be a 16-bit CRC generator polynomial.
We have
Equation 4 g x = x
16
+
15
+
14
+ ...
+ g1 x
1
+ 1 , where coefficients g15, g14,..., g0 are equal to 0 or 1.
The 16-entry reduced lookup table is created as follows: divide x i + 16
by g(x) and let s_i(x) to be the remainder. Set table entry i equal to s_i(x).
The values s_i(x) are determined using the standard feedback shift register for polynomial division.
Performance: See
Example 3. crc_rdc_table
#define GEN_POLY 0xa001 unsigned short rdc_table[16]; crc_rdc_table(GEN_POLY, rdc_table);
11/29
RM0019 Function API
6.4 Standard lookup table for 16-bit CRC
Function call:
Arguments: void crc_table(unsigned short *rdc_table_ptr, unsigned short *table_ptr);
Table 4.
rdc_table_ptr table_ptr in crc_table arguments pointer to reduced lookup table of length 16 created by the crc_rdc_table function, must be half-word aligned memory layout: rdc_table_ptr(0) rdc_table_ptr(1) ... rdc_table_ptr(15) out pointer to standard lookup table of length 256, must be word aligned, memory layout: table_ptr(0) table_ptr(1) ... table_ptr(255)
Description: Creates a standard 256-entry lookup table for byte-wise 16-bit CRC computation (for a reference see T. V. Ramabadran and S. S. Gaitonde, A Tutorial on CRC
Computations , IEEE Micro, Vol. 8, Issue 4, August 1988, pp. 62-75).
Algorithm:
For any message byte (t0, t1, ..., t7), table entry corresponds to byte's 16-bit CRC value, i.e. divide x
16
(t0 + t1x + ... + t7x
7
) by generator polynomial g(x) and set remainder equal to CRC. Table has 256 16-bit entries.
The standard table is created from the first 8-entries of reduced lookup table as follows:
For each input byte (t0, t1, ..., t7) determine it's CRC by XORing the entries of the reduced lookup table corresponding to the nonzero bits of (t0, t1, ..., t7). For example, if message byte is (t0, t1, ..., t7) = (0, 0, 0, 0, 1, 0, 0, 1) = 0x9, then t4 and t7 are nonzero. So XOR reduced table entries rdc_table_ptr(4) and rdc_table_ptr(7) to obtain CRC.
Performance: See
Example 4. crc_table unsigned short rdc_table[16]; unsigned short table[256]; crc_table(rdc_table, table);
Function call:
Arguments: unsigned short crc_calc(int K, unsigned short *table_ptr, unsigned char *message_ptr);
12/29
Function API RM0019
K
Table 5.
table_ptr message_ptr in crc_calc arguments message size in bytes, must be a multiple of 4 in in pointer to standard lookup table created by the crc_table function, must be word aligned memory layout: table_ptr(0) table_ptr(1) ... table_ptr(255) pointer to input message bytes, must be word aligned memory layout: message_ptr(0) message_ptr(1) ... message_ptr(K-1)
Description: Function returns 16-bit CRC (Cyclic Redundancy Code) computed for input message using the standard table lookup algorithm (for a reference see T. V. Ramabadran and
S. S. Gaitonde, A Tutorial on CRC Computations , IEEE Micro, Vol. 8, Issue 4, August
1988, pp. 62-75).
Algorithm:
2. For input byte (b0, b1, ..., b7) compute vector t:
(t0, t1, ..., t7) = (b0, b1, ..., b7) XOR (s8, s9, ..., s15).
3. Right shift CRC register eight bits.
4. Table lookup: Look up value corresponding to (t0, t1, ..., t7) and XOR with CRC register.
5. Repeat steps 2.-4. for each message byte.
Performance: See
Example 5. crc_calc
#define GEN_POLY 0xa001
#define K 8 unsigned short rdc_table[16]; unsigned short table[256]; unsigned char message[K]; unsigned short crc16; crc_rdc_table(GEN_POLY, rdc_table); crc_table(rdc_table, table); crc16 = crc_calc(K, table, message);
6.6 2-D 8x8 DCT
Function call: void dct(short *in_matrix_ptr, short *constant_ptr, short *out_matrix_ptr);
13/29
RM0019 Function API
Arguments:
Table 6.
in_matrix_ptr constant_ptr out_matrix_ptr in dct arguments pointer to the 8x8 input matrix, data type of each matrix item is 8-bit unsigned integer in range 0 to 255 stored as 16-bit value, matrix must be word aligned in out pointer to the constant array, array must be word aligned, use dct_const array which is defined inside the library and its extern definition is in the libdsp1.h header file
The library defines the dct_const as follows: const short dct_const[10] = {
6269, /* sqrt(2)[sin(3pi/8) - cos(3pi/8)]2^13 */
-15137, /* sqrt(2)[sin(3pi/8) + cos(3pi/8)]2^13 */
4434, /* sqrt(2)[cos(3pi/8)]2^13 */
11585, /* sqrt(2)2^13 */
6811, /* [cos(3pi/16)]2^13 */
8035, /* [cos(pi/16)]2^13 */
-2260, /* [sin(3pi/16) - cos(3pi/16)]2^13 */
-6436, /* [sin(pi/16) - cos(pi/16)]2^13 */
-11363, /* [-sin(3pi/16) - cos(3pi/16)]2^13 */
-9633, /* [-sin(pi/16) - cos(pi/16)]2^13 */
}; pointer to the 8x8 output matrix, data type of each matrix item is signed
16-bit integer, matrix must be word aligned
Description: This code performs a 1-D DCT (discrete cosine transform) on each row of an 8x8 input matrix. The result of each row operation is stored in the corresponding column of an 8x8 output matrix. The 1-D DCT is implemented using the method described in
C. Loeffler, A. Lightenberf, and G. Moschytzi, Practical Fast 1-D DCT Algorithms with
11 Multiplications , Proceedings International Conference on Acoustics, Speech, and
Signal Processing, 1989, pp. 988-991.
To compute 2-D 8x8 DCT, two subsequent calls of the dct function are needed. The first call computes a 1-D DCT on the rows of the input matrix. The results of the 1-D
DCT row operations are written column-wise to an output matrix. The output matrix is used as input to the second call of the dct function. The second call to the dct function performs a 1-D DCT on the rows of the output matrix. The results are written columnwise over the input matrix.
Algorithm:
1-D DCT definition (there is added multiplication by 8 against the true 1-D DCT):
Equation 5
Equation 6
= 8 w
N – 1
n = 0
=
N
for k = 0
cos
N
+ ---
2
for each n from 0 to N-1
14/29
Function API RM0019
Equation 7 = for 1
N – 1
N where N is the length of input sequence.
Note: The final results of the 2-D 8x8 DCT are 8 times larger than the true 2-D DCT results.
Performance: See
Example 6. dct short x[8][8]; short temp[8][8];
/* calculate 2-D 8x8 DCT on input matrix x, results stored to x */ dct(&x[0][0], dct_const, &temp[0][0]); dct(&temp[0][0], dct_const, &x[0][0]);
6.7 256-point complex FFT, float data
Function call:
Arguments: void fft256(float *io_buffer1, float *io_buffer2, float
*w_table_ptr);
Description:
Table 7.
io_buffer1 io_buffer2 w_table_ptr fft256 arguments in/out pointer to the input/output vector of length 512, vector must be double word aligned memory layout: x_Re(0) x_Im(0) x_Re(1) x_Im(1) ... x_Re(255) x_Im(255)
(Re - real part, Im - imaginary part) in in pointer to a vector of length 512, the vector is used by the routine as a temporary buffer during computations, vector must be double word aligned pointer to the vector of twiddle factors of length 256, vector must be double word aligned memory layout: w_Re(0) w_Im(0) w_Re(1) w_Im(1) ... w_Re(127) w_Im(127)
Use w_table256 array which is defined inside the library and its extern definition is in the libdsp1.h header file.
The w_table256 is computed according to this formula: w_Re k
+ = w k
N
for k = 0, 1, ..., 127
Computes the 256-point complex fast fourier transform (FFT), single precision floating point data types. Input data are stored in io_buffer1, output data are written over the input data into io_buffer1.
Algorithm:
Equation 8 =
N – 1
k = 0 x k
w
N for each n from 0 to N-1
15/29
RM0019 Function API e
–
2
i
N
Equation 9 w
N
= where i is the imaginary unit with the property that: i
2
= – 1 , N = 256.
Note: There must be at least 16 bytes of readable memory before vector io_buffer1.
Performance: See
Example 7. fft256 float io_buffer_1[512]; float io_buffer_2[512]; fft256(io_buffer_1, io_buffer_2, w_table256);
6.8 20 TAP real FIR filter
Function call:
Arguments: void fir20(int N, short int *x_ptr, short int *y_ptr, short int
*h_ptr);
N x_ptr y_ptr h_ptr
Table 8.
in fir20 arguments length of the output vector, must be multiple of 2 in out in pointer to input vector of length N + M - 1, data type of each sample is signed 16 bit fractional, range -1 to 1-2
-15
, vector must be word aligned memory layout: x(-M+1) x(-M+2) ... x(0) x(1) ... x(N-1) pointer to output vector of length N, data type of each sample is signed
16 bit fractional, range -1 to 1-1-2
-15
, vector must be word aligned memory layout: y(0) y(1) ... y(N-1) pointer to vector of FIR coefficients of length M, data type of each coefficient is signed 16 bit fractional, range -1 to 1-2
-15
, vector must be half-word aligned memory layout: h(0) h(1) h(2) ... h(M-1)
Description: Computes 20 TAP real FIR filter (M = 20). The coefficients of the filter are stored in vector h. Input samples are stored in vector x, output samples in vector y. 16-bit fractional data types with saturation.
Algorithm:
Equation 10 =
M – 1
k = 0 h k
– k
for each n from 0 to N-1, M = 20
16/29
Function API RM0019
Note: The coefficients stored in vector h must be scaled by user in order to prevent saturation, i.e. the sum of the absolute values of all coefficients must be lower than 1:
Equation 11
M – 1
k = 0
1
Performance: See
Example 8. fir20
#define N 256
#define M 20 short int xvec[N + M - 1]; short int yvec[N]; short int hvec[M]; fir20(N, xvec, yvec, hvec);
6.9 22 TAP real FIR filter with symmetrical impulse response
Function call:
Arguments: void fir22sym(int N, short *x, int *y, short *h);
N x y h
Table 9.
in fir22sym arguments length of the output vector, must be multiple of 2 in pointer to input vector of length N + M - 1, data type of each sample is signed 16 bit integer, range -32768 to 32767, vector must be word aligned memory layout: x(-M+1) x(-M+2) ... x(0) x(1) ... x(N-1) out in pointer to output vector of length N, data type of each sample is signed
32 bit integer, range -2
31
to 2
31
-1, vector must be word aligned memory layout: y(0) y(1) ... y(N-1) pointer to vector of FIR coefficients of length M/2, data type of each coefficient is signed 16 bit integer, range -32768 to 32767, vector must be word aligned memory layout: h(0) h(1) h(2) ... h(M/2-1)
Description: Computes 22 TAP real FIR filter with symmetrical impulse response (i.e. coefficients of the filter are symmetrical), M = 22. Half of the filter coefficients are stored in vector h. Input samples are stored in vector x, output samples in vector y.
17/29
RM0019 Function API
Algorithm:
Equation 12 =
M – 1
k = 0 h k
– k
for each n from 0 to N-1, M = 22
Note: The coefficients stored in vector h must be scaled by user in order to prevent overflow, i.e. the sum of the absolute values of all coefficients must be lower than 2
15
:
Equation 13
M – 1
k = 0
2
15
The filter must have symmetrical coefficients:
Equation 14 h n = h
M n
2
–
for each n from M/2 to M-1
Performance: See
Example 9. fir22sym
#define N 256
#define M 22 short x[N + M - 1]; int y[N]; short h[M/2]; fir22sym(N, x, y, h);
6.10 32 TAP real FIR Filter with symmetrical impulse response
Function call:
Arguments: void fir32sym(int N, short *x, int *y, short *h);
N x
Table 10.
fir32sym arguments in length of the output vector, must be multiple of 2 in pointer to input vector of length N + M - 1, data type of each sample is signed 16 bit integer, range -32768 to 32767, vector must be word aligned memory layout: x(-M+1) x(-M+2) ... x(0) x(1) ... x(N-1)
18/29
Function API RM0019 y h
Table 10.
fir32sym arguments (continued) out pointer to output vector of length N, data type of each sample is signed
32 bit integer, range -2
31
to 2
31
-1, vector must be word aligned memory layout: y(0) y(1) ... y(N-1) in pointer to vector of FIR coefficients of length M/2, data type of each coefficient is signed 16 bit integer, range -32768 to 32767, vector must be word aligned memory layout: h(0) h(1) h(2) ... h(M/2-1)
Description: Computes 32 TAP real FIR filter with symmetrical impulse response (i.e. the coefficients of the filter are symmetrical), M = 32. Half of the filter coefficients are stored in vector h. Input samples are stored in vector x, output samples in vector y.
Algorithm:
Equation 15 =
M – 1
k = 0 h k
– k
for each n from 0 to N-1, M = 32
Note: The coefficients stored in vector h must be scaled by user in order to prevent overflow, i.e. the sum of the absolute values of all coefficients must be lower than 2
15
:
Equation 16
M – 1
k = 0
2
15
The filter must have symmetrical coefficients:
Equation 17 h n = h
M n
2
–
for each n from M/2 to M-1
Performance: See
Example 10. fir32sym
#define N 256
#define M 32 short x[N + M - 1]; int y[N]; short h[M/2]; fir32sym(N, x, y, h);
6.11 64 TAP real FIR filter with symmetrical impulse response
Function call: void fir64sym(int N, short *x, int *y, short *h);
19/29
RM0019 Function API
Arguments:
N x y h
Table 11.
fir64sym arguments in length of the output vector, must be multiple of 2 in pointer to input vector of length N + M - 1, data type of each sample is signed 16 bit integer, range -32768 to 32767, vector must be word aligned memory layout: x(-M+1) x(-M+2) ... x(0) x(1) ... x(N-1) out in pointer to output vector of length N, data type of each sample is signed
32 bit integer, range -2
31
to 2
31
-1, vector must be word aligned memory layout: y(0) y(1) ... y(N-1) pointer to vector of FIR coefficients of length M/2, data type of each coefficient is signed 16 bit integer, range -32768 to 32767, vector must be word aligned memory layout: h(0) h(1) h(2) ... h(M/2-1)
Description: Computes 64 TAP real FIR filter with symmetrical impulse response (i.e. the coefficients of the filter are symmetrical), M = 64. Half of the filter coefficients are stored in vector h. Input samples are stored in vector x, output samples in vector y.
Algorithm:
Equation 18 =
M – 1
k = 0 h k
– k
for each n from 0 to N-1, M = 64
Note: The coefficients stored in vector h must be scaled by user in order to prevent overflow, i.e. the sum of the absolute values of all coefficients must be lower than 2
15
:
Equation 19
M – 1
k = 0
2
15
The filter must have symmetrical coefficients:
Equation 20 h n = h
M n
2
–
for each n from M/2 to M-1
Performance: See
Example 11. fir64sym
#define N 256
#define M 64 short x[N + M - 1]; int y[N]; short h[M/2]; fir64sym(N, x, y, h);
20/29
Function API RM0019
6.12 2nd-order filter
Function call:
Arguments: void iir_2nd_o(int N, short int *coeff_ptr, short int *x_ptr, short int *y_ptr);
N x_ptr y_ptr
Table 12.
iir_2nd_o arguments in length of the input and output vector, must be >= 8, must be multiple of
4 coeff_ptr in out in pointer to input vector of length N, data type of each sample is signed
16 bit integer, range -32768 to 32767, vector must be word aligned memory layout: x(0) x(1) ... x(N-1) pointer to output vector of length N, data type of each sample is signed
16 bit integer, range -32768 to 32767, vector must be word aligned memory layout: y(0) y(1) ... y(N-1) pointer to vector of filter coefficients, data type of each coefficient is signed 16 bit integer, range -32768 to 32767, vector must be half-word aligned coefficients must be stored in this order: b(0) b(1) b(2) a(1) a(2)
Description: Computes direct form second-order IIR filter (M = 2). The coefficients of the filter are stored in vector coeff_ptr. Input samples are stored in vector x_ptr, output samples in vector y_ptr. Signed 16-bit integer data computation with saturation.
Algorithm:
Equation 21 =
M
k = 0 b k
– k
–
M
k = 1 a k
– k
for each n from 0 to N-1, M = 2
Note: Initial conditions are assumed to be zero, i.e. x n = = 0
Performance: See
for each n < 0.
Example 12. iir_2nd_o
#define N 256 short int coeff[5]; short int vec_x[N]; short int vec_y[N]; iir_2nd_o(N, coeff, vec_x, vec_y);
21/29
RM0019 Function API
Function call:
Arguments: void lu_decomp(int n, float *matrix_ptr, int *row_perm_ptr, int *d, float *row_scale_ptr); n
Table 13.
lu_decomp arguments in dimension of input/output square matrix, must be >= 6, must be multiple of 2 matrix_ptr row_perm_ptr in/out out pointer to the input/output matrix of size nxn, data type of each matrix element is float, matrix must be double word aligned pointer to the permutation vector of length n, vector must be word aligned, to understand the meaning of this argument see Chapter 2.3 of
“Numerical Recipes in C” d row_scale_ptr out out pointer to integer variable, there is returned value +/-1 in this variable indicating that an even/odd number of row interchanges were performed pointer to the row scale vector of length n, vector must be double word aligned, to understand the meaning of this argument see Chapter 2.3 of
“Numerical Recipes in C”
Description: Computes LU decomposition. The input matrix is stored in matrix_ptr. The output matrix is written over the input matrix matrix_ptr. The method used for the LU decomposition is described in Chapter 2.3 of “Numerical Recipes in C”, which can be downloaded from http://www.library.cornell.edu/nr/bookcpdf.html.
Algorithm:
For input matrix X, the code finds matrices L and U such that
Equation 22 PX = LU where L is a lower triangular matrix, U is an upper triangular matrix and P is a permutation matrix, i.e. a matrix of zeros and ones that has exactly one entry 1 in each row and column.
The output matrix contains the L and U matrices:
Equation 23 u
11 l n1 u
12 l n2 u
13 l n3
u
1n l
21 l
31 u l
22
32 u u
23
33
u
2n
u
3n
u nn
To get L from the output matrix - set the lower elements of L to the same values as the lower elements of the output matrix. Set the diagonal elements of L equal to one. The upper elements of L are all zero.
22/29
Function API RM0019
Equation 24 L = l l
1 0 0
0
21
1 0
0
31 l
32
1
0 l
n1 l n2 l n3
1
To get U from the output matrix - set the upper elements of U to the same values as the upper elements of the output matrix. Set the diagonal elements of U to the same values as the diagonal elements of the output matrix. Set the lower elements of U to zero.
Equation 25 U = u
11 u
12 u
13
u
1n
0 u
22 u
23
0 0 u
33
u
2n
u
3n
0 0 0
u nn
Performance: See
Example 13. lu_decomp
#define N 8 float matrix[N][N]; int d; int row_perm[N]; float row_scale[N]; lu_decomp(N, &matrix[0][0], row_perm, &d, row_scale);
23/29
RM0019
7 Performance
Performance
●
●
●
●
This section shows the code size and clock cycles for each function. The clock cycles were measured for the following conditions:
Code Memory (Internal Flash) - cache on
Data Memory (Internal RAM) - cache on
Stack Memory - locked in cache
Data acquired on the MPC5554
The “Improvement to C function” column shows performance increase comparing the assembly code to a respective C function, the value is calculated as a ratio of the number_of_clock_cycles_of_C_ function/number_of_clock_cycles_of_optimized_library_function. The number of clock cycles are taken for the third function call.
The IPC column shows instructions per cycle.
Table 14.
Code size
Function conv_enc_mux corr_mn crc_calc crc_rdc_table crc_table dct fft256 fir20 fir22sym fir32sym fir64sym iir_2nd_o lu_decomp
Code size [bytes]
436
348
500
984
404
1300
444
580
168
312
240
412
1112
Table 15.
Clock cycles
Function
First function call [clock cycles] crc_rdc_table
(1)
170 crc_table dct
(2) fft256
(3)
6342
696
13259
1.
gen_poly = 0xA001
Second function call [clock cycles]
89
6296
589
12494
Third function call [clock cycles]
Improvement to
C function [-]
89
6296
589
12465
1.9
-
3.2
5.2
IPC
[-]
0.87
0.96
0.92
0.95
24/29
Performance
2.
dct_const in Internal Flash
3.
w_table256 in Internal Flash
Table 16.
conv_enc_mux function n
(1)
First function call [clock cycles]
Second function call [clock cycles]
Third function call [clock cycles]
Improvement to
C function [-]
8
32
256
2
4
6
182
279
379
475
1657
12677
1.
Size of input message in half-words
Table 17.
corr_mn function
N
(1)
M
First function call [clock cycles]
126
223
323
420
1595
12573
Second
Function call
[clock cycles]
4
8
12
16
32
256
4
8
12
16
32
256
159
290
436
615
1710
84317
95
184
317
495
1583
84070
1.
N - length of the input vectors, M - length of the output vector
95
184
317
490
1583
84070
126
223
323
420
1595
12573
4.5
6.7
7.2
7.7
8.1
8.3
6.3
7.0
7.2
7.4
7.7
7.8
Third function call [clock cycles]
Improvement to
C function [-]
Table 18.
crc_calc function
K
(1)
First function call [clock cycles]
Second function call [clock cycles]
4
8
12
32
256
1.
Message size in bytes
107
143
178
362
2393
64
100
136
318
2335
Third function call [clock cycles]
Improvement to
C function [-]
64
100
136
318
2333
11.1
13.9
15.3
17.3
18.8
RM0019
IPC
[-]
0.66
0.71
0.74
0.77
0.80
IPC
[-]
0.88
0.93
0.94
0.95
0.97
0.98
IPC
[-]
0.60
0.79
0.84
0.86
0.88
0.86
25/29
RM0019
Table 19.
fir20 function
N
(1)
First function call [clock cycles]
Second function call [clock cycles]
8
32
256
2
4
6
1.
Length of the output vector
261
313
366
417
1044
6896
160
214
264
316
941
6764
Table 20.
fir22sym function
N
(1)
First function call [clock cycles]
Second function call [clock cycles]
2
4
6
8
32
256
1.
Length of the output vector
211
256
309
360
1000
6972
124
174
227
280
917
6852
Third function call [clock cycles]
Improvement to
C function [-]
160
214
264
316
941
6764
11.3
16.8
20.4
22.7
30.3
33.7
Third function call [clock cycles]
Improvement to
C function [-]
124
174
227
280
917
6852
7.9
11.1
12.7
13.7
16.6
17.7
Table 21.
fir32sym function
N
(1)
First function call [clock cycles]
Second function call [clock cycles]
2
4
6
8
32
256
1.
Length of the output vector
286
380
445
524
1396
9613
177
252
322
395
1271
9447
Third function call [clock cycles]
Improvement to
C function [-]
173
246
322
395
1271
9447
8.1
11.2
12.8
13.9
17.2
18.5
Performance
IPC
[-]
0.73
0.80
0.84
0.86
0.92
0.94
IPC
[-]
0.74
0.80
0.83
0.86
0.93
0.95
IPC
[-]
0.68
0.74
0.77
0.80
0.88
0.92
26/29
Performance
Table 22.
fir64sym function
N
(1)
First function call [clock cycles]
Second function call [clock cycles]
8
32
256
2
4
6
1.
Length of the output vector
508
682
862
1038
3168
23014
300
480
657
833
2958
22782
Table 23.
iir_2nd_o function
N
(1)
First function call [clock cycles]
Second function call [clock cycles]
8
12
16
100
256
1.
Length of the output vector
220
259
291
1055
2482
142
178
212
968
2371
Table 24.
lu_decomp function n
(1)
First function call [clock cycles]
Second function call [clock cycles]
10
20
6
8
2278
4428
7664
48343
1.
Dimension of input/output square matrix
2070
4159
7439
47928
Third function call [clock cycles]
Improvement to
C function [-]
300
480
657
833
2958
22782
9.1
11.4
12.4
13.1
14.7
15.2
Third function call [clock cycles]
Improvement to
C function [-]
142
178
212
968
2371
1.8
2.2
2.5
3.5
3.7
Third function call [clock cycles]
Improvement to
C function [-]
2070
4159
7439
47928
10.8
8.6
7.1
4.3
RM0019
IPC
[-]
0.82
0.87
0.90
0.92
0.96
0.98
IPC
[-]
0.71
0.73
0.75
0.79
0.80
IPC
[-]
0.71
0.72
-
-
27/29
RM0019
Table 25.
Document revision history
Date Revision
29-May-2008
24-Sep-2013
1
2
Initial release
Updated Disclaimer.
Changes
Revision history
28/29
RM0019
Please Read Carefully:
Information in this document is provided solely in connection with ST products. STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, modifications or improvements, to this document, and the products and services described herein at any time, without notice.
All ST products are sold pursuant to ST’s terms and conditions of sale.
Purchasers are solely responsible for the choice, selection and use of the ST products and services described herein, and ST assumes no liability whatsoever relating to the choice, selection or use of the ST products and services described herein.
No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. If any part of this document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such third party products or services or any intellectual property contained therein.
UNLESS OTHERWISE SET FORTH IN ST’S TERMS AND CONDITIONS OF SALE ST DISCLAIMS ANY EXPRESS OR IMPLIED
WARRANTY WITH RESPECT TO THE USE AND/OR SALE OF ST PRODUCTS INCLUDING WITHOUT LIMITATION IMPLIED
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE (AND THEIR EQUIVALENTS UNDER THE LAWS
OF ANY JURISDICTION), OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT.
ST PRODUCTS ARE NOT DESIGNED OR AUTHORIZED FOR USE IN: (A) SAFETY CRITICAL APPLICATIONS SUCH AS LIFE
SUPPORTING, ACTIVE IMPLANTED DEVICES OR SYSTEMS WITH PRODUCT FUNCTIONAL SAFETY REQUIREMENTS; (B)
AERONAUTIC APPLICATIONS; (C) AUTOMOTIVE APPLICATIONS OR ENVIRONMENTS, AND/OR (D) AEROSPACE APPLICATIONS
OR ENVIRONMENTS. WHERE ST PRODUCTS ARE NOT DESIGNED FOR SUCH USE, THE PURCHASER SHALL USE PRODUCTS AT
PURCHASER’S SOLE RISK, EVEN IF ST HAS BEEN INFORMED IN WRITING OF SUCH USAGE, UNLESS A PRODUCT IS
EXPRESSLY DESIGNATED BY ST AS BEING INTENDED FOR “AUTOMOTIVE, AUTOMOTIVE SAFETY OR MEDICAL” INDUSTRY
DOMAINS ACCORDING TO ST PRODUCT DESIGN SPECIFICATIONS. PRODUCTS FORMALLY ESCC, QML OR JAN QUALIFIED ARE
DEEMED SUITABLE FOR USE IN AEROSPACE BY THE CORRESPONDING GOVERNMENTAL AGENCY.
Resale of ST products with provisions different from the statements and/or technical features set forth in this document shall immediately void any warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever, any liability of ST.
ST and the ST logo are trademarks or registered trademarks of ST in various countries.
Information in this document supersedes and replaces all information previously supplied.
The ST logo is a registered trademark of STMicroelectronics. All other names are the property of their respective owners.
© 2013 STMicroelectronics - All rights reserved
STMicroelectronics group of companies
Australia - Belgium - Brazil - Canada - China - Czech Republic - Finland - France - Germany - Hong Kong - India - Israel - Italy - Japan -
Malaysia - Malta - Morocco - Philippines - Singapore - Spain - Sweden - Switzerland - United Kingdom - United States of America www.st.com
29/29
Unduh
Iklan