Texas Instruments Incorporated and its subsidiaries (TI) reserve the right to make corrections,
modifications, enhancements, improvements, and other changes to its products and services at
any time and to discontinue any product or service without notice. Customers should obtain the
latest relevant information before placing orders and should verify that such information is current
and complete. All products are sold subject to TI’s terms and conditions of sale supplied at the
time of order acknowledgment.
TI warrants performance of its hardware products to the specifications applicable at the time of
sale in accordance with TI’s standard warranty. Testing and other quality control techniques are
used to the extent TI deems necessary to support this warranty. Except where mandated by
government requirements, testing of all parameters of each product is not necessarily performed.
TI assumes no liability for applications assistance or customer product design. Customers are
responsible for their products and applications using TI components. To minimize the risks
associated with customer products and applications, customers should provide adequate design
and operating safeguards.
TI does not warrant or represent that any license, either express or implied, is granted under any
TI patent right, copyright, mask work right, or other TI intellectual property right relating to any
combination, machine, or process in which TI products or services are used. Information
published by TI regarding third party products or services does not constitute a license from TI
to use such products or services or a warranty or endorsement thereof. Use of such information
may require a license from a third party under the patents or other intellectual property of that third
party , or a license from TI under the patents or other intellectual property of TI.
Reproduction of information in TI data books or data sheets is permissible only if reproduction
is without alteration and is accompanied by all associated warranties, conditions, limitations, and
notices. Reproduction of this information with alteration is an unfair and deceptive business
practice. TI is not responsible or liable for such altered documentation.
Resale of TI products or services with statements dif ferent from or beyond the parameters stated
by TI for that product or service voids all express and any implied warranties for the associated
TI product or service and is an unfair and deceptive business practice. TI is not responsible or
liable for any such statements.
Mailing Address:
Texas Instruments
Post Office Box 655303
Dallas, Texas 75265
Copyright 2003, Texas Instruments Incorporated
Page 3
About This Manual
Preface
Read This First
Welcome to the TMS320C67x digital signal processor (DSP) Library or
DSPLIB, for short. The DSPLIB is a collection of 36 high-level optimized DSP
functions for the TMS320C67x device. This source code library includes Ccallable functions (ANSI-C language compatible) for general signal processing math and vector functions.
This document contains a reference for the DSPLIB functions and is organized
as follows:
- Overview - an introduction to the TI C67x DSPLIB
- Installation - information on how to install and rebuild DSPLIB
- DSPLIB Functions - a quick reference table listing of routines in the library
- DSPLIB Reference - a description of all DSPLIB functions complete with
- Information about performance, fractional Q format and customer support
How to Use This Manual
The information in this document describes the contents of the TMS320C67x
DSPLIB in several different ways.
- Chapter 1 provides a brief introduction to the TI C67x DSPLIB, shows the
- Chapter 2 provides information on how to install, use, and rebuild the TI
- Chapter 3 provides a quick overview of all DSPLIB functions in table for-
calling convention, algorithm details, special requirements and implementation notes
organization of the routines contained in the library, and lists the features
and benefits of the DSPLIB.
C67x DSPLIB
mat for easy reference. The information shown for each function includes
the syntax, a brief description, and a page reference for obtaining more
detailed information.
iiiRead This First
Page 4
Notational Conventions
-
- Appendix A describes performance considerations related to the C67x
- Appendix B provides information about software updates and customer
Notational Conventions
This document uses the following conventions:
- Program listings, program examples, and interactive displays are shown
- In syntax descriptions, the function or macro appears in a bold typeface
Chapter 4 provides a list of the routines within the DSPLIB organized into
functional categories. The functions within each category are listed in alphabetical order and include arguments, descriptions, algorithms, benchmarks, and special requirements.
DSPLIB and provides information about the Q format used by DSPLIB
functions.
support.
in a special typeface.
and the parameters appear in plainface within parentheses. Portions of a
syntax that are in bold should be entered as shown; portions of syntax that
are within parentheses describe the type of information that should be entered.
- Macro names are written in uppercase text; function names are written in
lowercase.
- The TMS320C67x is also referred to in this reference guide as the C67x.
Related Documentation From Texas Instruments
The following books describe the TMS320C6x devices and related support
tools. To obtain a copy of any of these TI documents, call the Texas Instruments Literature Response Center at (800) 477-8924. When ordering, please
identify the book by its title and literature number. Many of these documents
can be found on the Internet at http://www.ti.com.
TMS320C62x/C67x Technical Brief (literature number SPRU197) gives an
introduction to the ’C62x/C67x digital signal processors, development tools,
and third-party support.
TMS320C6000 CPU and Instruction Set Reference Guide (literature number SPRU189) describes the C6000 CPU architecture, instruction set, pipeline, and interrupts for these digital signal processors.
iv
Page 5
Trademarks
TMS320C6000 Peripherals Reference Guide (literature number SPRU190)
describes common peripherals available on the TMS320C6000 digital signal
processors. This book includes information on the internal data and program
memories, the external memory interface (EMIF), the host port interface (HPI),
multichannel buffered serial ports (McBSPs), direct memory access (DMA),
enhanced DMA (EDMA), expansion bus, clocking and phase-locked loop
(PLL), and the power-down modes.
TMS320C6000 Programmer’s Guide (literature number SPRU198) describes ways to optimize C and assembly code for the TMS320C6000 DSPs
and includes application program examples.
TMS320C6000 Assembly Language Tools User’s Guide (literature number
SPRU186) describes the assembly language tools (assembler, linker, and other tools used to develop assembly language code), assembler directives,
macros, common object file format, and symbolic debugging directives for the
C6000 generation of devices.
TMS320C6000 Optimizing C Compiler User’s Guide (literature number
SPRU187) describes the C6000 C compiler and the assembly optimizer. Th is
C compiler accepts ANSI standard C source code and produces assembly language source code for the C6000 generation of devices. The assembly optimizer helps you optimize your assembly code.
Trademarks
TMS320C6000 Chip Support Library (literature number SPRU401) de-
scribes the application programming interfaces (APIs) used to configure and
control all on-chip peripherals.
TMS320C62x Image/Video Processing Library (literature number
SPRU400) describes the optimized image/video processing functions including many C-callable, assembly-optimized, general-purpose image/video
processing routines.
TMS320C6000, TMS320C62x, TMS320C67x, and Code Composer Studio
are trademarks of Texas Instruments.
Other trademarks are the property of their respective owners.
Provides a brief introduction to the TI C67x DSPLIB, shows the organization of the routines contained in the library, and lists the features and benefits of the DSPLIB.
This chapter provides a brief introduction to the TI C67x DSP Library
(DSPLIB), shows the organization of the routines contained in the library, and
lists the features and benefits of the DSPLIB.
The TI C67x DSPLIB is an optimized DSP Function Library for C programmers
using TMS320C67x devices. It includes C-callable, assembly-optimized general-purpose signal-processing routines. These routines are typically used in
computationally intensive real-time applications where optimal execution
speed is critical. By using these routines, you can achieve execution speeds
considerably faster than equivalent code written in standard ANSI C language.
In addition, by providing ready-to-use DSP functions, TI DSPLIB can significantly shorten your DSP application development time.
The TI DSPLIB includes commonly used DSP routines. Source code is provided that allows you to modify functions to match your specific needs.
The routines contained in the library are organized into the following seven different functional categories:
Directory containing the following document files:
PDF document of API - this document
2-2
Page 15
2.2How to Install the DSP Library
To install the DSP libary, follow these steps:
Step 1: Open the file, C67xDSPLIB.exe.
Step 2: Click Yes to install the library.
Step 3: Click Next to continue with the Install Shield Wizard.
Step 4: Read the Software Licenses, and choose either “I accept” or “I don’t
accept.”
Step 5: Click Next to continue.
If you selected “I accept,” the installation will continue.
If you selected “I don’t accept,” the installation cancels.
Step 6: Choose the location where you would like to install the library. The
wizard will install the library into the c6700 sub-directory of the directory you choose.
The default location is c:\ti.
How to Install the DSP Library
Step 7: Click Next.
Step 8: If the library has already been installed, you will be prompted to de-
cide whether to replace the files or not. Click Yes to update the library .
Step 9: The Install Shield will complete the installation. When the installation
is complete, click Finish.
2-3Installing and Using DSPLIB
Page 16
Using DSPLIB
2.3Using DSPLIB
2.3.1DSPLIB Arguments and Data Types
DSPLIB Types
Table 2-1 shows the data types handled by the DSPLIB.
Unless specifically noted, DSPLIB operates on single-precision IEEE float
data type elements.
DSPLIB Arguments
TI DSPLIB functions typically operate over vector operands for greater efficiency. Even though these routines can be used to process smaller arrays, or
even scalars (unless a minimum size requirement is noted), they will be slower
for these cases.
- Vector stride is always equal to 1: Vector operands are composed of vector
elements held in consecutive memory locations (vector stride equal to 1).
- Complex elements are assumed to be stored in consecutive memory loca-
tions with Real data followed by Imaginary data.
- In-place computation is not allowed, unless specifically noted: Source and
destination arrays should not overlap.
2-4
Page 17
2.3.2Calling a DSPLIB Function From C
In addition to correctly installing the DSPLIB software, you must follow these
steps to include a DSPLIB function in your code:
- Include the function header file corresponding to the DSPLIB function
- Link your code with dsp67x.lib
- Use a correct linker command file for the platform you use. Remember
most functions in dsp67x.lib are written assuming little-endian mode of operation.
For example, if you want to call the Autocorrelation DSPLIB function, you
would add:
Assuming your C_DIR environment is correctly set up (as mentioned in
section 2.2), you would have to add DSPLIB under the Code Composer Studio
environment by choosing dsp67x.lib from the menu Project → Add Files toProject. Also, you should make sure that you link with the run-time support library, rts6700.lib.
2.3.3Calling a DSP Function From Assembly
The C67x DSPLIB functions were written to be used from C. Calling the functions from assembly language source code is possible as long as the calling
function conforms to the Texas Instruments C6x C compiler calling conventions. Here, the corresponding .h67 header files located in the ‘include’ directory must be included using the ‘.include’ directive. For more information, refer to
section 8 (Runtime Environment) of the TMS320C6000 Optimizing C Compil-er User’s Guide (SPRU187).
2.3.4How DSPLIB is Tested - Allowable Error
DSPLIB is tested under the Code Composer Studio environment against a reference C implementation. Because of floating point calculation order change
for these two implementations, they differ in the results with an allowable tolerance for that particular kernel. Thus every kernel’s test routine (in the driver
file) has error tolerance variable defined that gives the maximum value that is
acceptable as the error difference.
2-5Installing and Using DSPLIB
Page 18
How to Rebuild DSPLIB
For example:
#define R_TOL (1e-05)
Here, the maximum difference allowed between the output reference array
from the C implementation and all other implementations (linear asm, hand
asm) is 1e-05 (0.00001).
The error tolerance is therefore different for different functions.
2.3.5How DSPLIB Deals With Overflow and Scaling Issues
The DSPLIB functions implement the same functionality of the reference C
code. The user is expected to conform to the range requirements specified in
the API function, and in addition, take care to restrict the input range in such a
way that the outputs do not overflow.
2.3.6Interrupt Behavior of DSPLIB Functions
Most DSPLIB functions are interrupt-tolerant but not interruptible. The cycle
count formula provided for each function can be used to estimate the number
of cycles during which interrupts cannot be taken.
2.4How to Rebuild DSPLIB
If you would like to rebuild DSPLIB (for example, because you modified the
source file contained in the archive), you will have to use the mk6x utility as
follows:
mk6x dsp67x.src -mv6700 -l dsp67x.lib
2-6
Page 19
Chapter 3
DSPLIB Function Tables
This chapter provides tables containing all DSPLIB functions, a brief description of each, and a page reference for more detailed information.
The following convention has been followed when describing the arguments
for each individual function:
Table 3-1. Argument Conventions
ArgumentDescription
x,yArgument reflecting input data vector
rArgument reflecting output data vector
nx,ny,nrArguments reflecting the size of vectors x,y, and r, respectively. For
functions in the case nx = ny = nr, only nx has been used across.
hArgument reflecting filter coefficient vector (filter routines only)
nhArgument reflecting the size of vector h
w
float DSPF_sp_dotprod (float*x, float*y, int nx)Vector dot product4-53
void DSPF_sp_dotp_cplx (float *x, float *y, int n, float *re,
float *im)
float DSPF_sp_maxval (float *x, int nx)Maximum value of a vector4-56
int DSPF_sp_maxidx (float *x, int nx)Index of the maximum element of
float DSPF_sp_minval (float *x, int nx)Minimum value of a vector4-58
void DSPF_sp_vecrecip (float *x, float *r, int n)Vector reciprocal4-59
float DSPF_sp_vecsum_sq (float *x, int n)Sum of squares4-60
void DSPF_sp_w_vec (float *x, float *y, float m, float *r, int
void DSPF_sp_mat_mul (float *x, int r1, int c1, float *y, int
c2, float *r)
void DSPF_sp_mat_trans (float *x, int rows, int cols,
float *r)
void DSPF_sp_mat_mul_cplx (float *x, int r1, int c1, float
*y, int c2, float *r)
3-6
Matrix multiplication4-64
Matrix transpose4-65
Complex matrix multiplication4-66
Page 25
DSPLIB Function Tables
Table 3-8. Miscellaneous
FunctionsDescriptionPage
void DSPF_sp_blk_move (float*x, float*r, int nx)Move a block of memory4-69
void DSPF_blk_eswap16 (void *x, void *r, int nx)Endianswap a block of 16-bit
values
void DSPF_blk_eswap32 (void *x, void *r, int nx)Endian-swap a block of 32-bit
values
void DSPF_blk_eswap64 (void *x, void *r, int nx)Endian-swap a block of 64-bit
values
void DSPF_fltoq15 (float *x, short *r, int nx)Float to Q15 conversion4-75
float DSPF_sp_minerr (float *GSP0_TABLE,float
*errCoefs, int *max_index)
void DSPF_q15tofl (short *x, float *r, int nx)
Minimum energy error search4-76
Q15 to float conversion4-78
4-70
4-71
4-73
3-7DSPLIB Function Tables
Page 26
Chapter 4
DSPLIB Reference
This chapter provides a list of the functions within the DSP library (DSPLIB)
organized into functional categories. The functions within each category are
listed in alphabetical order and include arguments, descriptions, algorithms,
benchmarks, and special requirements.
xPointer to input samples
hPointer to the coefficient array
desiredPointer to the desired output array
rPointer to filtered output array
adaptrateAdaptation rate
errorInitial error
nhNumber of coefficients
nrNumber of output samples
DescriptionThe DSPF_sp_lms implements an LMS adaptive filter. Given an actual input
signal and a desired input signal, the filter produces an output signal, the final
coefficient values, and returns the final output error signal.
AlgorithmThis is the C equivalent of the assembly code without restrictions. Note that
the assembly code is hand optimized and restrictions may apply.
- The inner loop counter must be a multiple of 6 and ≥6.
- Little endianness is assumed.
- Extraneous loads are allowed in the program.
- The coefficient array is assumed to be in reverse order; i.e., h(nh-1),
h(nh-2), ..., h(0) will hold coefficients h0, h1, ..., hnh-1, repectively.
- The inner loop is unrolled six times to allow update of six coefficients in the
kernel.
- The outer loop has been unrolled twice to enable use of LDDW for loading
the input coefficients.
Benchmarks
- LDDW instruction is used to load the coefficients.
- Register sharing is used to make optimal use of available registers.
- The outer loop instructions are scheduled in parallel with epilog and prolog
wherever possible.
- The error term needs to be computed in the outer loop before a new itera-
tion of the inner loop can start. As a result the prolog cannot be placed in
parallel with epilog (after the loop kernel).
- Pushing and popping variables from the stack does not really add any
overhead except increase stack size. This is because the pops and
pushes are done in the delay slots of the outer loop instructions.
- Endianess: This code is little endian.
- Interruptibility: This code is interrupt-tolerant but not interruptible.
Cycles(nh + 35) nr + 21
eg. for nh = 36 and nr = 64
cycles = 4565
Code size
1376
(in bytes)
4-3 DSPLIB Reference
Page 29
DSPF_sp_autocor
4.2Correlation
DSPF_sp_autocor
Single-precision autocorrelation
Function void DSPF_sp_autocor (float * restrict r, const float * restrict x, int nx, int nr)
Arguments
rPointer to output array of autocorrelation of length nr
xPointer to input array of length nx+nr. Input data must be
padded with nr consecutive zeros at the beginning.
nxLength of autocorrelation vector
nrLength of lags
DescriptionThis routine performs the autocorrelation of the input array x. It is assumed that
the length of the input array, x, is a multiple of 2 and the length of the output
array, r, is a multiple of 4. The assembly routine computes 4 output samples
at a time. It is assumed that input vector x is padded with nr no of zeros in the
beginning.
AlgorithmThis is the C equivalent of the assembly code. Note that the assembly code
int nx, int nr)
{
int i,k;
float sum;
for (i = 0; i < nr; i++)
{
sum = 0;
for (k = nr; k < nx+nr; k++)
sum += x[k] * x[k-i];
r[i] = sum ;
}
}
Special Requirements
- nx is a multiple of 2 and greater than or equal to 4.
4-4
- nr is a multiple of 4 and greater than or equal to 4.
- nx is greater than or equal to nr
- x is double-word aligned.
Page 30
Implementation Notes
Benchmarks
DSPF_sp_autocor
- The inner loop is unrolled twice and the outer loop is unrolled four times.
- Endianess: This code is little endian.
- Interruptibility: This code is interrupt-tolerant but not interruptible.
Cycles(nx/2) * nr + (nr/2) * 5 + 10 - (nr * nr)/4 + nr
For nx=64 and nr=64, cycles=1258
For nx=60 and nr=32, cycles=890
Code size
(in bytes)
512
4-5 DSPLIB Reference
Page 31
DSPF_sp_bitrev_cplx
4.3FFT
DSPF_sp_bitrev_cplx
Bit reversal for single-precision complex numbers
Function void DSPF_sp_bitrev_cplx (double *x, short *index, int nx)
Arguments
xComplex input array to be bit reversed. Contains 2*nx floats.
indexArray of size ~sqrt(nx) created by the routine bitrev_index to
allow the fast implementation of the bit reversal.
nxNumber of elements in array x[]. Must be power of 2.
DescriptionThis routine performs the bit-reversal of the input array x[], where x[] is a float
array of length 2*nx containing single-precision floating-point complex pairs of
data. This routine requires the index array provided by the program below . This
index should be generated at compile time, not by the DSP. TI retains all rights,
title and interest in this code and only authorizes the use of the bit-reversal
code and related table generation code with TMS320 family DSPs manufactured by TI.
/* -------------------------------------------------------- */
/* This routine calculates the index for bit reversal of */
/* an array of length nx. The length of the index table is */
/* 2^(2*ceil(k/2)) where nx = 2^k. */
/* */
/* In other words, the length of the index table is: */
/* - for even power of radix: sqrt(nx) */
/* - for odd power of radix: sqrt(2*nx) */
/* -------------------------------------------------------- */
void bitrev_index(short *index, int nx)
{
int i, j, k, radix = 2;
short nbits, nbot, ntop, ndiff, n2, raddiv2;
nbits = 0;
i = nx;
while (i > 1)
{
i = i >> 1;
nbits++;
}
raddiv2 = radix >> 1;
nbot = nbits >> raddiv2;
nbot = nbot << raddiv2 - 1;
ndiff = nbits & raddiv2;
ntop = nbot + ndiff;
n2 = 1 << ntop;
index[0] = 0;
4-6
Page 32
DSPF_sp_bitrev_cplx
for ( i = 1, j = n2/radix + 1; i < n2 - 1; i++)
{
index[i] = j - 1;
for (k = n2/radix; k*(radix-1) < j; k /= radix)
j -= k*(radix-1);
j += k;
}
index[n2 - 1] = n2 - 1;
}
AlgorithmThis is the C equivalent for the assembly code. Note that the assembly code
is hand optimized and restrictions may apply.
void DSPF_sp_bitrev_cplx(double* x, short* index, int nx)
{
int i;
short i0, i1, i2, i3;
short j0, j1, j2, j3;
double xi0, xi1, xi2, xi3;
double xj0, xj1, xj2, xj3;
short t;
int a, b, ia, ib, ibs;
int mask;
int nbits, nbot, ntop, ndiff, n2, halfn;
nbits = 0;
i = nx;
while (i > 1)
{
i = i >> 1;
nbits++;
}
nbot = nbits >> 1;
ndiff = nbits & 1;
ntop = nbot + ndiff;
n2 = 1 << ntop;
mask = n2 - 1;
halfn = nx >> 1;
for (i0 = 0; i0 < halfn; i0 += 2)
{
b = i0 & mask;
- The array x is actually an array of 2*nx floats. It is assumed to be double-
word aligned.
Page 34
Implementation Notes
Benchmarks
DSPF_sp_cfftr4_dif
- LDDW is used to load in one complex number at a time (both the real and
the imaginary parts).
- There are 12 stores in 10 cycles but all of them are to locations already
loaded. No use of the write buffer is made.
- If nx ≤ 4K one can use the char (8-bit) data type for the index variable. This
would require changing the LDH when loading index values in the assembly routine to LDB. This would further reduce the size of the index table by
half its size.
- Endianess: Little endian configuration used.
- Interruptibility: This code is interrupt-tolerant, but not interruptible.
Cycles(5/2)nx + 26
e.g., nx = 256, cycles = 666
Code size
608
(in bytes)
DSPF_sp_cfftr4_dif
Single-precision floating-point decimation in frequency radix-4 FFT
with complex input
Function void DSPF_sp_cfftr4_dif (float* x, float* w, short n)
Arguments
xPointer to an array holding the input and output floating-point
array which contains ‘n’ complex points.
wPointer to an array holding the coefficient floating-point array
which contains 3*n/4 complex numbers.
nNumber of complex points in x.
DescriptionThis routine implements the DIF (decimation in frequency) complex radix 4
FFT with digit-reversed output and normal order input. The number of points,
‘n’, must be a power of 4 {4, 16, 64, 256, 1024, ...}. This routine is an in-place
routine in the sense that the output is written over the input. It is not an in-place
routine in the sense that the input is in normal order and the output is in digit-reversed order.
There must be n complex points (2*n values), and 3*n/4 complex coefficients
(3*n/2 values).
4-9 DSPLIB Reference
Page 35
DSPF_sp_cfftr4_dif
Each real and imaginary input value is interleaved in the ‘x’ array {rx0, ix0, rx1,
ix2, ...} and the complex numbers are in normal order . Each real and imaginary
output value is interleaved in the ‘x’ array and the complex numbers are in digit-
reversed order {rx0, ix0, ...}. The real and imaginary values of the coefficients
are interleaved in the ‘w’ array {rw0, -iw0, rw1, -iw1, ...} and the complex numbers are in normal order.
Note that the imaginary coefficients are negated {cos(d*0), sin(d*0), cos(d*1),
sin(d*1), ...} rather than {cos(d*0), -sin(d*0), cos(d*1), -sin(d*1), ...} where d =
2*PI/n. The value of w(n,k) is usually written w(n,k) = e^-j(2*PI*k/n) =
cos(2*PI*k/n) - sin(2*PI*k/n). The routine can be used to implement an inverse
FFT by performing the complex conjugate on the input complex numbers (negating the imaginary value), and dividing the result by n. Another method to
use the FFT to perform an inverse FFT, is to swap the real and imaginary values of the input and the result, and divide the result by n. In either case, the
input is still in normal order and the output is still in digit-reversed order. Note
that you can not make the radix 4 FFT into an inverse FFT by using the complex conjugate of the coefficients as you can do with the complex radix 2 FFT.
If you label the input locations from 0 to (n-1) (normal order), the digit-reversed
locations can be calculated by reversing the order of the bit pairs of the labels.
For example, for a 1024 point FFT, the digit-reversed location for
- d = 1001101001b = 10 01 10 10 01 is
- d = 0110100110b = 01 10 10 01 10 and visa versa.
The twiddle factor array w can be generated by the gen_twiddle function provided in support\fft\tw_r4fft.c. The .exe file for this function, bin\tw_r4fft.exe,
can be used to dump the twiddle factor array into a file.
The function bit_rev in support\fft\bit_rev.c can be used to bit reverse the output array in order to convert it to normal order.
AlgorithmThis is the C equivalent for the assembly code. Note that the assembly code
Special Requirements There are no special alignment requirements.
Implementation Notes
- The two inner loops are executed as one loop with conditional instructions.
The variable ‘wcntr’ is used to determine when the load pointers and coefficient offsets need to be reset.
- The first 8 cycles of the inner loop prolog are conditionally scheduled in
parallel with the outer loop. This increases the code size by 12 words, but
improves the cycle time.
- A load counter, lcntr, is used so that extraneous loads are not performed.
- If more registers were available, the inner loop could probably be as small
as 11 cycles (22 ADDSP/SUBSP instructions). The inner loop was extended to 14 cycles to allow more variables to share registers and thus
only need 32 registers.
- The store variable, scntr, is used to determine when the store pointer
needs to be reset.
- The variable, n2b, is used as the outer loop counter. We are finished when
n2b = 0.
- LDDW instructions are not used so that the real and imaginary values can
be loaded to separate register files and so that the load and store pointers
can use the same offset, n2.
- The outer loop resets the inner loop count to ‘n’ by multiplying ‘ie’ by ‘n2b’
which is equivalent to ‘ie’ multiplied by ‘n2’ which is always ‘n’. The product
is always the same since the outer loop shifts ‘n2’ to the right by 2 and shifts
‘ie’ to the left by 2.
4-12
Page 38
Benchmarks
DSPF_sp_cfftr2_dit
-
Endianess: This code is endian neutral.
- Interruptibility: This code is interrupt-tolerant but not interruptible.
Cycles(14*n/4 + 23)*log4(n) + 20
e.g., if n = 256, cycles = 3696.
Code size
1184
(in bytes)
DSPF_sp_cfftr2_dit
Single-precision floating-point radix-2 FFT with complex input
Function void DSPF_sp_cfftr2_dit (float * x, float * w, short n)
Arguments
xPointer to complex data input.
wPointer to complex twiddle factor in bit-reverse order.
nLength of FFT in complex samples, power of 2 such that n ≥
32.
DescriptionThis routine performs the decimation-in-time (DIT) radix-2 FFT of the input
array x. x has N complex floating-point numbers arranged as successive real
and imaginary number pairs. Input array x contains N complex points (N*2 elements). The coefficients for the FFT are passed to the function in array w which
contains N/2 complex numbers (N elements) as successive real and imaginary number pairs. The FFT coefficients w are in N/2 bit-reversed order The
elements of input array x are in normal order The assembly routine performs
4 output samples (2 real and 2 imaginary) for a pass through inner loop.
How to Use
void main(void)
{
gen_w_r2(w, N); // Generate coefficient table
bit_rev(w, N>>1); // Bit-reverse coefficient table
DSPF_sp_cfftr2_dit(x, w, N);
// input in normal order, output in
// order bit-reversed
// coefficient table in bit-reversed
// order
}
Note that (bit-reversed) coefficients for higher order FFT (1024 point) can be
used unchanged as coefficients for a lower order FFT (512, 256, 128 ... ,2) The
4-13 DSPLIB Reference
Page 39
DSPF_sp_cfftr2_dit
routine can be used to implement inverse FFT by any one of the following
methods:
1) Inputs (x) are replaced by their complex-conjugate values.
Output values are divided by N.
2) FFT coefficients (w) are replaced by their complex conjugates.
Output values are divided by N.
3) Swap real and imaginary values of input.
4) Swap real and imaginary values of output.
AlgorithmThis is the C equivalent of the assembly code. Note that the assembly code
is hand optimized and restrictions may apply.
void DSPF_sp_cfftr2_dit(float* x, float* w, short n)
{
short n2, ie, ia, i, j, k, m;
float rtemp, itemp, c, s;
n2 = n;
ie = 1;
for(k=n; k > 1; k >>= 1)
{
n2 >>= 1;
ia = 0;
for(j=0; j < ie; j++)
{
c = w[2*j];
s = w[2*j+1];
for(i=0; i < n2; i++)
{
m = ia + n2;
rtemp = c * x[2*m] + s * x[2*m+1];
itemp = c * x[2*m+1] - s * x[2*m];
x[2*m] = x[2*ia] - rtemp;
x[2*m+1] = x[2*ia+1] - itemp;
x[2*ia] = x[2*ia] + rtemp;
x[2*ia+1] = x[2*ia+1] + itemp;
ia++;
4-14
Page 40
Special Requirements
Implementation Notes
DSPF_sp_cfftr2_dit
}
ia += n2;
}
ie <<= 1;
}
}
- n is a integral power of 2 and ≥32.
- The FFT Coefficients w are in bit-reversed order
- The elements of input array x are in normal order
- The imaginary coefficients of w are negated as {cos(d*0), sin(d*0),
cos(d*1), sin(d*1) ...} as opposed to the normal sequence of {cos(d*0),
-sin(d*0), cos(d*1), -sin(d*1) ...} where d = 2*PI/n.
- x and w are double-word aligned.
- The inner two loops are combined into one inner loop whose loop count
is n/2.
Benchmarks
- The prolog has been completely merged with the epilog. But this gives rise
to a problem which has not been overcome. The problem is that the minimum trip count is 32. The safe trip count is atleast 16 bound by the size
of the epilog. In addition because of merging the prolog and the epilog a
data dependency via memory is caused which forces n to be at least 32.
- Endianess: This code is little endian.
- Interruptibility: This code is interrupt-tolerant but not interruptible.
Cycles(2 * n * log(base-2) n) + 42
For n = 64, Cycles = 810
Code size
1248
(in bytes)
4-15 DSPLIB Reference
Page 41
DSPF_sp_fftSPxSP
DSPF_sp_fftSPxSP
Single-precision floating-point mixed radix forwards FFT with
complex input
Function void DSPF_sp_fftSPxSP (int N, float * ptr_x, float * ptr_w, float * ptr_y,
unsigned char * brev, int n_min, int offset, int n_max)
Arguments
NLength of fft in complex samples, power of 2 such that N ≥ 8
and N ≤ 16384.
ptr_xPointer to complex data input.
ptr_wPointer to complex twiddle factor (see below).
ptr_yPointer to complex output data.
brevPointer to bit reverse table containing 64 entries.
n_minSmallest fft butterfly used in computation used for
decomposing fft into subffts, see notes.
offsetIndex in complex samples of sub-fft from start of main fft.
n_maxSize of main fft in complex samples.
DescriptionThe benchmark performs a mixed radix forwards fft using a special sequece
This redundant set of twiddle factors is size 2*N float samples. The function
is accurate to about 130dB of signal to noise ratio to the DFT function below:
The function takes the table and input data and calculates the fft producing the
frequency domain data in the Y array. As the fft allows every input point to effect
every output point in a cache based system such as the c6711, this causes
cache thrashing. This is mitigated by allowing the main fft of size N to be divided into several steps, allowing as much data reuse as possible. For example
the following function:
Notice how the first fft function is called on the entire 1K data set it covers the
first pass of the fft until the butterfly size is 256. The following 4 ffts do 256 pt
4-17 DSPLIB Reference
Page 43
DSPF_sp_fftSPxSP
ffts 25% of the size. These continue down to the end when the buttefly is of size
4. They use an index to the main twiddle factor array of 0.75*2*N. This is because the twiddle factor array is composed of successively decimated versions of the main array. N not equal to a power of 4 can be used, i.e. 512. In
this case to decompose the fft the following would be needed :
The twiddle factor array is composed of log4(N) sets of twiddle factors, (3/4)*N,
(3/16)*N, (3/64)*N, etc. The index into this array for each stage of the fft is calculated by summing these indices up appropriately. For multiple ffts they can
share the same table by calling the small ffts from further down in the twiddle
factor array. In the same way as the decomposition works for more data reuse.
Thus, the above decomposition can be summarized for a general N, radix “rad”
as follows:
As discussed previously, N can be either a power of 4 or 2. If N is a power of
4, then rad = 4, and if N is a power of 2 and not a power of 4, then rad = 2. “rad”
is used to control how many stages of decomposition are performed. It is also
used to determine whether a radix-4 or radix-2 decomposition should be performed at the last stage. Hence when “rad” is set to “N/4” the first stage of the
transform alone is performed and the code exits. To complete the FFT, four
other calls are required to perform N/4 size FFTs.In fact, the ordering of these
4 FFTs amongst themselves does not matter and hence from a cache perspective, it helps to go through the remaining 4 FFTs in exactly the opposite order
to the first. This is illustrated as follows:
- N must be a power of 2 and N ≥ 8 N ≤ 16384 points.
- Complex time data x and twiddle facotrs w are aligned on double-word
boundares. Real values are stored in even word positions and imaginary
values in odd positions.
- All data is in single-precision floating-point format. The complex frequency
data will be returned in linear order.
Implementation Notes
- A special sequence of coeffs. used as generated above produces the fft.
This collapses the inner 2 loops in the taditional Burrus and Parks implementation Fortran code.
- The revised FFT uses a redundant sequence of twiddle factors to allow a
linear access through the data. This linear access enables data and instruction level parallelism.
- The data produced by the fftSPxSP fft is in normal form, the whole data
array is written into a new output buffer.
- The fftSPxSP butterfly is bit reversed, i.e. the inner 2 points of the butterfly
are corssed over, this has the effect of making the data come out in bit reversed rather than fftSPxSP digit reversed order. This simplifies the last
pass of the loop. ia simple table is used to do the bit reversal out of place.
Single-precision floating-point mixed radix inverse FFT with
1440
complex input
Function void DSPF_sp_ifftSPxSP (int n, float * ptr_x, float * ptr_w, float * ptr_y,
unsigned char * brev, int n_min, int offset, int n_max)
Arguments
nLength of ifft in complex samples, power of 2 such that n ≥ 8
and n ≤ 16384.
ptr_xPointer to complex data input (normal order).
ptr_wPointer to complex twiddle factor (see below).
ptr_yPointer to complex output data (normal order).
brevPointer to bit reverse table containing 64 entries.
n_minSmallest ifft butterfly used in computation used for
decomposing ifft into subiffts, see notes.
4-24
offsetIndex in complex samples of sub-ifft from start of main ifft.
n_maxSize of main ifft in complex samples.
Page 50
DSPF_sp_ifftSPxSP
DescriptionThe benchmark performs a mixed radix forwards ifft using a special sequece
This redundant set of twiddle factors is size 2*N float samples. The function
is accurate to about 130dB of signal to noise ratio to the IDFT function below:
The function takes the table and input data and calculates the ifft producing the
frequency domain data in the Y array. the output is scaled by a scaling factor
of 1/N. As the ifft allows every input point to effect every output point in a cache
based system such as the c6711, this causes cache thrashing. This is mitigated by allowing the main ifft of size N to be divided into several steps, allowing as much data reuse as possible. For example the following function:
Notice how the first ifft function is called on the entire 1K data set it covers the
first pass of the ifft until the butterfly size is 256. The following 4 iffts do 256 pt
iffts 25% of the size. These continue down to the end when the buttefly is of
size 4. They use an index to the main twiddle factor array of 0.75*2*N. This is
because the twiddle factor array is composed of successively decimated versions of the main array. N not equal to a power of 4 can be used, i.e. 512. In
this case to decompose the ifft the following would be needed :
The twiddle factor array is composed of log4(N) sets of twiddle factors, (3/4)*N,
(3/16)*N, (3/64)*N, etc. The index into this array for each stage of the ifft is calculated by summing these indices up appropriately. For multiple iffts they can
share the same table by calling the small iffts from further down in the twiddle
factor array. In the same way as the decomposition works for more data reuse.
Thus, the above decomposition can be summarized for a general N radix “rad”
as follows:
As discussed previously, N can be either a power of 4 or 2. If N is a power of
4, then rad = 4, and if N is a power of 2 and not a power of 4, then rad = 2. “rad”
is used to control how many stages of decomposition are performed. It is also
used to determine whether a radix-4 or radix-2 decomposition should be performed at the last stage. Hence when “rad” is set to “N/4” the first stage of the
transform alone is performed and the code exits. To complete the FFT, four
other calls are required to perform N/4 size FFTs.In fact, the ordering of these
4 FFTs amongst themselves does not matter and hence from a cache perspective, it helps to go through the remaining 4 FFTs in exactly the opposite order
to the first. This is illustrated as follows:
- N must be a power of 2 and N ≥ 8, N ≤ 16384 points.
- Complex time data x and twiddle facotrs w are aligned on double-word
boundares. Real values are stored in even word positions and imaginary
values in odd positions.
- All data is in single-precision floating-point format. The complex frequency
data will be returned in linear order.
- x must be padded with 16 words at the end.
- A special sequence of coeffs. used as generated above produces the ifft.
This collapses the inner 2 loops in the traditional Burrus and Parks implementation Fortran code.
- The revised FFT uses a redundant sequence of twiddle factors to allow a
linear access through the data. This linear access enables data and instruction level parallelism.
4-31 DSPLIB Reference
Page 57
DSPF_sp_ifftSPxSP
The data produced by the DSPF_sp_ifftSPxSP ifft is in normal form, the
-
whole data array is written into a new output buffer.
- The DSPF_sp_ifftSPxSP butterfly is bit reversed, i.e., the inner 2 points
of the butterfly are crossed over, this has the effect of making the data
come out in bit reversed rather than DSPF_sp_ifftSPxSP digit reversed order. This simplifies the last pass of the loop. ia simple table is used to do
the bit reversal out of place.
Function void DSPF_sp_icfftr2_dif (float* x, float* w, short n)
Arguments
xInput and output sequences (dim-n) (input/output) x has n
complex numbers (2*n SP values). The real and imaginary
values are interleaved in memory. The input is in bit-reversed
order nad output is in normal order.
wFFT coefficients (dim-n/2) (input) w has n/2 complex
numbers (n SP values). FFT coeficients must be in
bit-reversed order. The real and imaginary values are
interleaved in memory.
nFFT size (input).
DescriptionThis routine is used to compute the inverse, complex, radix-2, decimation-in-
frequency Fast Fourier Transform of a single-precision complex sequence of
size n, and a power of 2. The routine requires bit-reversed input and bit-reversed coefficents (twiddle factors) and produces results that are in normal order.
Final scaling by 1/N is not done in this function.
How To Use
void main(void)
{
gen_w_r2(w, N); // Generate coefficient table
bit_rev(w, N>>1); // Bit-reverse coefficient table
DSPF_sp_cfftr2_dit(x, w, N);
// radix-2 DIT forward FFT
// input in normal order, output in
// order bit-reversed
// coefficient table in bit-reversed
// order
DSPF_sp_icfftr2_dif(x, w, N);
// Inverse radix 2 FFT
// input in bit-reversed order,
// order output in normal
// coefficient table in bit-reversed
// order
divide(x, N); // scale inverse FFT output
// result is the same as original
// input
}
4-33 DSPLIB Reference
Page 59
DSPF_sp_icfftr2_dif
AlgorithmThis is the C equivalent of the assembly code without restrictions. Note that
the assembly code is hand optimized and restrictions may apply.
void DSPF_sp_icfftr2_dif(float* x, float* w, short n)
{
short n2, ie, ia, i, j, k, m;
float rtemp, itemp, c, s;
n2 = 1;
ie = n;
for(k=n; k > 1; k >>= 1)
{
ie >>= 1;
ia = 0;
for(j=0; j < ie; j++)
{
c = w[2*j];
s = w[2*j+1];
for(i=0; i < n2; i++)
{
m = ia + n2;
rtemp = x[2*ia] - x[2*m];
x[2*ia] = x[2*ia] + x[2*m];
itemp = x[2*ia+1] - x[2*m+1];
x[2*ia+1] = x[2*ia+1] + x[2*m+1];
x[2*m] = c*rtemp - s*itemp;
x[2*m+1] = c*itemp + s*rtemp;
ia++;
}
ia += n2;
}
n2 <<= 1;
}
}
4-34
The follwoing C code is used to generate the coefficient table (non-bit reversed):
#include <math.h>
Page 60
DSPF_sp_icfftr2_dif
/* generate real and imaginary twiddle
table of size n/2 complex numbers */
gen_w_r2(float* w, int n)
{
int i;
float pi = 4.0*atan(1.0);
float e = pi*2.0/n;
for(i=0; i < ( n>>1 ); i++)
{
w[2*i] = cos(i*e);
w[2*i+1] = sin(i*e);
}
}
The follwoing C code is used to bit-reverse the coefficents:
bit_rev(float* x, int n)
{
int i, j, k;
float rtemp, itemp;
j = 0;
for(i=1; i < (n-1); i++)
{
k = n >> 1;
while(k <= j)
{
j -= k;
k >>= 1;
}
j += k;
if(i < j)
{
rtemp = x[j*2];
x[j*2] = x[i*2];
x[i*2] = rtemp;
itemp = x[j*2+1];
x[j*2+1] = x[i*2+1];
4-35 DSPLIB Reference
Page 61
DSPF_sp_icfftr2_dif
x[i*2+1] = itemp;
}
}
}
The follwoing C code is used to perform the final scaling of the IFFT:
/* divide each element of x by n */
divide(float* x, int n)
{
int i;
float inv = 1.0 / n;
for(i=0; i < n; i++)
{
x[2*i] = inv * x[2*i];
x[2*i+1] = inv * x[2*i+1];
}
}
Special Requirements
Implementation Notes
- Both input x and coef ficient w should be aligned on double-word boundary.
- x should be padded with 4 words.
- n should be greater than 8.
- Loading input x as well as coefficient w in double word.
- MPY was used to perform an MV. EX. mpy x, 1, y <=> mv x, y
- Because the data loads are 1 iteration ahead of the coefficent loads,
counter i was copied so that the actual count could live longer for the coefficent loads.
- 2 inner loops are callapsed into one loop.
- Prolog and epilog are done in parallel with the outermost loop.
- Since the twiddle table is in bit-reversed order, it turns out that the same
twiddle table will also work for smaller IFFTs.This means that if you need
to do both 512 and 1024 point IFFTs in the same application, you only need
to have the 1024 point twiddle table. The 512 point FFT will use the first
half of the 1024 point twiddle table.
4-36
Page 62
Benchmarks
DSPF_sp_icfftr2_dif
-
The bit-reversed twiddle factor array w can be generated by using the
gen_twiddle function provided in the support\fft directory or by running
tw_r2fft.exe provided in bin\. The twiddle factor array can also be generated using the gen_w_r2 and bit_rev algorithms, as described above.
- Endianess: This code is little endian.
- Interruptibility: This code is interrupt-tolerant but not interruptible.
Cycles2*n*log2(n) + 37
e.g., IF n = 64, cycles = 805
e.g., IF n = 128, cycles = 1829
x[2*(nr+nh-1)]Pointer to complex input array. The input data pointer x
must point to the (nh)th complex element; i.e., element
2*(nh-1).
h[2*nh]Pointer to complex coefficient array (in normal order).
r[2*nr]Pointer to complex output array.
nhNumber of complex coefficients in vector h.
nrNumber of complex output samples to calculate.
DescriptionThis function implements the FIR filter for complex input data. The filter has
nr output samples and nh coefficients. Each array consists of an even and odd
term with even terms representing the real part and the odd terms the imaginary part of the element. The coefficients are expected in normal order.
AlgorithmThis is the C equivalent of the assembly code. Note that the assembly code
is hand optimized and restrictions may apply.
void DSPF_sp_fir_cplx(const float * x, const float * h,
float * restrict r, int nh, int nr)
{
int i,j;
float imag, real;
for (i = 0; i < 2*nr; i += 2)
{
imag = 0;
real = 0;
for (j = 0; j < 2*nh; j += 2)
{
real += h[j] * x[i-j] - h[j+1] * x[i+1-j];
imag += h[j] * x[i+1-j] + h[j+1] * x[i-j];
}
r[i] = real;
r[i+1] = imag;
}
}
4-38
Page 64
Special Requirements
Implementation Notes
Benchmarks
DSPF_sp_fir_gen
- nr is a multiple of 2 and greater than or equal to 2.
- nh is greater than or equal to 5.
- x and h are double-word aligned.
- x points to 2*(nh-1)th input element.
- The outer loop is unrolled twice.
- Outer loop instructions are executed in parallel with inner loop.
- Endianess: This code is little endian.
- Interruptibility: This code is interrupt-tolerant but not interruptible.
Cycles2 * nh * nr + 33
For nh=24 and nr=64, cycles=3105
For nx=32 and nr=64, cycles=4129
Code size
640
(in bytes)
DSPF_sp_fir_gen
Single-precision generic FIR filter
Function void DSPF_sp_fir_gen (const float *x, const float *h, float * restrict r, int nh,
int nr)
Arguments
xPointer to array holding the input floating-point array.
hPointer to array holding the coefficient floating-point array.
rPointer to output array
nhNumber of coefficents.
nrNumber of output values.
DescriptionThis routine implements a block FIR filter. There are “nh” filter coefficients, “nr”
output samples, and “nh+nr-1” input samples. The coefficients need to be
placed in the “h” array in reverse order {h(nh-1), ... , h(1), h(0)} and the array“x” starts at x(-nh+1) and ends at x(nr-1). The routine calculates y(0) through
y(nr-1) using the following formula:
y(n) = h(0)*x(n) + h(1)*x(n-1) + ... + h(nh-1)*x(n-nh+1)
where n = {0, 1, ... , nr-1}.
4-39 DSPLIB Reference
Page 65
DSPF_sp_fir_gen
AlgorithmThis is the C equivalent for the assembly code. Note that the assembly code
int nh, int nr)
{
int i, j;
float sum;
for(j=0; j < nh; j++)
{
sum = 0;
for(i=0; i < nr; i++)
{
sum += x[i+j] * h[i];
}
r[j] = sum;
}
}
Special Requirements
Implementation Notes
- Little Endian is assumed for LDDW instructions.
- The number of coefficients must be greater than or equal to 4.
- The number of outputs must be greater than or equal to 4
- LDDW instructions are used to load two SP floating-point values simulta-
neously for the x and h arrays.
- The outer loop is unrolled 4 times.
- The inner loop is unrolled 2 times and software pipelined.
- The variables prod1, prod3, prod5, and prod7 share A9.
The variables prod0, prod2, prod4, and prod6 share B6.
The variables sum1, sum3, sum5, and sum7 share A7.
The variables sum0, sum2, sum4, and sum6 share B7.
This multiple assignment is possible since the variables are always read
just once on the first cycle that they are availble.
- The first 8 cycles of the inner loop prolog are conditionally scheduled in
parallel with the outer loop. This increases the code size by 14 words, but
improves the cycle time.
4-40
Page 66
Benchmarks
DSPF_sp_fir_r2
-
A load counter is used so that an epilog is not needed. No extraneous
loads are performed.
- Endianess: This code is little endian.
- Interruptibility: This code is interrupt-tolerant but not interruptible.
x[nr+nh-1]Pointer to input array of size nr+nh-1.
h[nh]Pointer to coefficient array of size nh (in reverse order).
r[nr]Pointer to output array of size nr.
nhNumber of coefficients.
nrNumber of output samples.
DescriptionComputes a real FIR filter (direct-form) using coefficients stored in vector h[].
The real data input is stored in vector x[]. The filter output result is stored in
vector r[]. The filter calculates nr output samples using nh coefficients. The coefficients are expected to be in reverse order.
AlgorithmThis is the C equivalent of the assembly code. Note that the assembly code
is hand optimized and restrictions may apply.
void DSPF_sp_fir_r2(const float * x, const float * h,
float *restrict r, int nh, int nr)
{
int i, j;
float sum;
for (j = 0; j < nr; j++)
4-41 DSPLIB Reference
Page 67
DSPF_sp_fircirc
Special Requirements
Implementation Notes
{
sum = 0;
for (i = 0; i < nh; i++)
sum += x[i + j] * h[i];
r[j] = sum;
}
}
- nr is a multiple of 2 and greater than or equal to 2.
- nh is a multiple of 2 and greater than or equal to 8.
- x and h are double-word aligned.
- Coefficients in array h are expected to be in reverse order.
- x and h should be padded with 4 words at the end.
- The outer loop is unrolled four times and inner loop is unrolled twice.
- Outer loop instructions are executed in parallel with inner loop.
- Endianess: This code is little endian.
- Interruptibility: This code is interrupt-tolerant but not interruptible.
Benchmarks
Cycles(nh * nr)/2 + 34, if nr multiple of 4
(nh * nr)/2 + 45, if nr not multiple of 4
For nh=24 and nr=64, cycles=802
For nh=30 and nr=50, cycles=795
Code size
960
(in bytes)
DSPF_sp_fircirc
Single-precision circular FIR algorithm
Function void DSPF_sp_fircirc (float *x, float *h, float *r, int index, int csize, int nh,
int nr)
Arguments
x[]Input array (circular buffer of 2^(csize+1) bytes). Must be
aligned at 2^(csize+1) byte boundary.
h[nh]Filter coefficients array. Must be double-word aligned.
4-42
Page 68
DSPF_sp_fircirc
r[nr]Output array
indexOffset by which to start reading from the input array. Must be
multiple of 2.
csizeSize of circular buffer x[] is 2^(csize+1) bytes. Must be 2 ≤
csize ≤ 31.
nhNumber of filter coefficients. Must be multiple of 2 and ≥ 4.
nrSize of output array. Must be multiple of 4.
DescriptionThis routine implements a circularly addressed FIR filter. ‘nh’ is the number of
filter coefficients. ‘nr’ is the number of the output samples.
AlgorithmThis is the C equivalent for the assembly code. Note that the assembly code
is hand optimized and restrictions may apply.
void DSPF_sp_fircirc (float x[], float h[], float r[], int
index, int csize,
int nh, int nr)
{
int i, j;
//Circular Buffer block size = ((2^(csize + 1)) / 4)
//floating point numbers
int mod = (1 << (csize - 1));
float r0;
for (i = 0; i < nr; i++)
{
r0 = 0;
for (j = 0; j < nh; j++)
{
//Operation ”% mod” is equivalent to ”& (mod -1)”
//r0 += x[(i + j + index) % mod] * h[j];
r0 += x[(i + j + index) & (mod - 1)] * h[j];
}
r[i] = r0;
}
}
Special Requirements
- The circular input buffer x[] must be aligned at a 2^(csize+1) byte bound-
ary. csize must lie in the range 2 ≤ csize ≤ 31.
- The number of coefficients (nh) must be a multiple of 2 and greater than
or equal to 4.
4-43 DSPLIB Reference
Page 69
DSPF_sp_biquad
Implementation Notes
The number of outputs (nr) must be a multiple of 4 and greater than or
-
equal to 4.
- The ‘index’ (offset to start reading input array) must be mutiple of 2 and
less than or equal to (2^(csize-1) - 6).
- The coefficient array is assured to be in reverse order; i.e., h(nh-1) to h(0)
hold coefficients h0, h1, h2, etc.
- LDDW instructions are used to load two SP floating-point values simulta-
neously for the x and h arrays.
- The outer loop is unrolled 4 times.
- The inner loop is unrolled 2 times.
- The variables prod1, prod3, prod5 and prod7 share A9.
The variables prod0, prod2, prod4 and prod6 share B6.
The variables sum1, sum3, sum5 and sum7 share A7.
The variables sum0, sum2, sum4 and sum6 share B8.
This multiple assignment is possible since the variables are always read
just once on the first cycle that they are avaliable.
- A load counter is used so that an epilog is not needed. No extraneous
loads are performed.
- Endianess: This code is LITLLE ENDIAN.
- Interruptibility: This code is interrupt-tolerant but not interruptible.
Benchmarks
Cycles(2*nh + 10) nr/4 + 18
For nh = 30 & nr=100, cycles = 1768
Code size
512
(in bytes)
DSPF_sp_biquad
Single-precision 2nd order IIR (biquad) filter
Function void DSPF_sp_biquad (float *x, float *b, float *a, float *delay, float *r, int
nx)
Arguments
xPointer to input samples.
bPointer to Nr coefs b0, b1, b2.
4-44
Page 70
DSPF_sp_biquad
aPointer to Dr coefs a1, a2.
delayPointer to filter delays.
rPointer to output samples.
nxNumber of input/output samples.
DescriptionThis routine implements a DF 2 transposed structure of the biquad filter. The
r1[nr+4]Delay element values (i/p and o/p).
x[nr]Pointer to the input array.
r2[nr+4]Pointer to the output array.
h2[5]Auto-regressive filter coefficients.
h1[5]Moving average filter coefficients.
nrNumber of output samples.
DescriptionThe IIR performs an auto-regressive moving-average (ARMA) filter with 4
auto-regressive filter coefficients and 5 moving-average filter coefficients for
nr output samples. The output vector is stored in two locations. This routine
is used as a high pass filter in the VSELP vocoder. The 4 values in the r1 vector
store the initial values of the delays.
4-46
Page 72
DSPF_sp_iir
AlgorithmThis is the C equivalent of the Assembly Code without restrictions. Note that
the assembly code is hand optimized and restrictions may apply.
void DSPF_sp_iir (float* restrict r1,
const float* x,
float* restrict r2,
const float* h2,
const float* h1,
int nr
)
{
int i, j;
float sum;
for (i = 0; i < nr; i++)
{
sum = h2[0] * x[4+i];
for (j = 1; j <= 4; j++)
sum += h2[j] * x[4+i-j] - h1[j] * r1[4+i-j];
r1[4+i] = sum;
r2[i] = r1[4+i];
}
}
Special Requirements
Implementation Notes
- The value of ‘nr’ must be a multiple of 2.
- Extraneous loads are allowed in the program.
- Due to unrolling modulus(h1[1]) < 1 must be true.
- The inner loop is completely unrolled so that two loops become one loop.
- The outer loop is unrolled twice to break the dependency bound of 8
cycles.
- The values of the r1 array are not loaded each time to calculate the value
of the ‘sum’ variable. Instead, the 4 values of the r1 array required are
maintained in registers so that memory operations are significantly reduced.
- Unrolling by 2 implies calculation of constants before the start of the loop.
Due to shortage of registers these constants are stored in the stack and
later retrieved each time they are required.
4-47 DSPLIB Reference
Page 73
DSPF_sp_iirlat
Benchmarks
The stack must be placed in L2 to reduce overhead due to external
-
memory access stalls.
- Endianess: The code is little endian.
- Interruptibility: This code is interrupt-tolerant but not interruptible.
Cycles6 * nr + 59
e.g., for nr = 64, cycles = 443
Code size
1152
(in bytes)
DSPF_sp_iirlat
Single-precision all-pole IIR lattice filter
Function void DSPF_sp_iirlat (float *x, int nx, const float * restrict k, int nk, float *
restrict b, float * r)
Arguments
x[nx]Input vector.
nxLength of input vector.
k[nk]Reflection coefficients.
nkNumber of reflection coefficients/lattice stages. Must be
multiple of 2 and ≥ 6.
b[nk+1]Delay line elements from previous call. Should be initialized
to all zeros prior to the first call.
r[nx]Output vector
DescriptionThis routine implements a real all-pole IIR filter in lattice structure (AR lattice).
The filter consists of nk lattice stages. Each stage requires one reflection coefficient k and one delay element b. The routine takes an input vector x[] and returns the filter output in r[]. Prior to the first call of the routine the delay elements
in b[] should be set to zero. The input data may have to be pre-scaled to avoid
overflow or achieve better SNR. The reflections coefficients lie in the range
-1.0 < k < 1.0. The order of the coefficients is such that k[nk-1] corresponds
to the first lattice stage after the input and k[0] corresponds to the last stage.
4-48
Page 74
Algorithm
DSPF_sp_iirlat
void DSPF_sp_iirlat(float * x, int nx, const float * restrict
k, int nk,
float * restrict b, float * r)
{
float rt; // output //
int i, j;
for (j = 0; j < nx; j++)
{
rt = x[j];
for (i = nk - 1; i >= 0; i--)
{
rt = rt - b[i] * k[i];
b[i + 1] = b[i] + rt * k[i];
}
b[0] = rt;
r[j] = rt;
}
}
Special Requirements
Implementation Notes
Benchmarks
- nk is a multiple of 2 and ≥ 6.
- Extraneous loads are allowed (80 bytes) before the start of array.
- The arrays k and b are double-word aligned.
- The loop has been unrolled by 4 times.
- Register sharing has been used to optimize on the use of registers.
- Endianess: This code is little endian.
- Interruptibility: This code is interrupt-tolerant but not interruptible.
Cycles(6*floor((nk+1)/4) + 29)* nx + 25
For nk = 10, nx = 100 cycles = 4125
Code size
1024
(in bytes)
4-49 DSPLIB Reference
Page 75
DSPF_sp_convol
DSPF_sp_convol
Single-precision convolution
Function void DSPF_sp_convol (float *x, float *h, float *r, int nh, int nr)
Arguments
xPointer to real input vector of size = nr+nh-1 a typically
contains input data (x) padded with consecutive nh - 1 zeros
at the beginning and end.
hpointer to real input vector of size nh in forward order. h
typically contains the filter coefs.
rPointer to real output vector of size nr.
nhNumber of elements in vector b. Note: nh ≤ nr nh is typically
noted as m in convol formulas. nh must be a multiple of 2.
nrNumber of elements in vector r. nr must be a multiple of 4.
DescriptionThis funct ion calculates the full-length convolution of real vectors x and h using
time-domain techniques. The result is placed in real vector r. It is assumed that
input vector x is padded with nh-1 no of zeros in the beginning and end. It is
assumed that the length of the input vector h, nh, is a multiple of 2 and the
length of the output vector r, nr, is a multiple of 4. nh is greater thanor equal
to 4 and nr is greater than or equal to nh. The routine computes 4 output samples at a time. x and h are assumed to be aligned on a double word boundary .
AlgorithmThis is the C equivalent of the assembly code. Note that the assembly code
is hand optimized and restrictions may apply.
void DSPF_sp_convol(float *x, float *h, float *r, short nh,
short nr)
- nh is a multiple of 2 and greater than or equal to 4.
- nr is a multiple of 4.
- x and h are assumed to be aligned on a double-word boundary.
- The inner loop is unrolled twice and the outer loop is unrolled four times.
- Endianess: This code is little endian.
- Interruptibility: This code is interrupt-tolerant but not interruptible.
Cycles(nh/2)*nr + (nr/2)*5 + 9
For nh=24 and nr=64, cycles=937
For nh=20 and nr=32, cycles=409
Code size
(in bytes)
480
4-51 DSPLIB Reference
Page 77
DSPF_sp_dotp_sqr
4.5Math
DSPF_sp_dotp_sqr
Single-precision dot product and sum of square
Function float DSPF_sp_dotp_sqr (float G, const float * x, const float * y, float * restrict
r, int nx)
Arguments
GSum of y-squared initial value.
x[nx]Pointer to first input array.
y[nx]Pointer to second input array.
rPointer to output for accumulation of x[]*y[].
nxLength of input vectors.
DescriptionThis routine computes the dot product of x[] and y[] arrays,adding it to the value
in the location pointed to by r. Additionally , it computes the sum of the squares
of the terms in the y array, adding it to the argument G. The final value of G is
given as the return value of the function.
AlgorithmThis is the C equivalent of the assembly code. Note that the assembly code
float *restrict r, int nx)
{
int i;
for (i = 0; i < nx; i++)
{
*r += x[i] * y[i]; /* Compute Dot Product */
G += y[i] * y[i]; /* Compute Square */
}
return G;
}
Special Requirements There are no special alignment requirements.
Implementation Notes
- Multiple assignment was used to reduce loop carry path.
- Endianess: This code is endian neutral.
- Interruptibility: This code is interrupt-tolerant but not interruptible.
4-52
Page 78
Benchmarks
DSPF_sp_dotprod
Cyclesnx + 23
For nx=64, cycles=87.
For nx=30, cycles=53
Code size
288
(in bytes)
DSPF_sp_dotprod
Dot product of 2 single-precision float vectors
Function float DSPF_sp_dotprod (const float *x, const float *y, const int nx)
Arguments
xPointer to array holding the first floating-point vector.
yPointer to array holding the second floating-point vector.
nxNumber of values in the x and y vectors.
DescriptionThis routine calculates the dot product of 2 single-precision float vectors.
AlgorithmThis is the C equivalent for the assembly code. Note that the assembly code
is hand optimized and restrictions may apply.
float DSPF_sp_dotprod(const float *x, const float *y, const
int nx)
{
int i;
float sum = 0;
for (i=0; i < nx; i++)
{
sum += x[i] * y[i];
}
return sum;
}
Special Requirements
- The x and y arrays must be double-word aligned.
- A memory pad of 4 bytes is required at the end of each array if the number
of inputs is odd.
- The value of nx must be > 0.
4-53 DSPLIB Reference
Page 79
DSPF_sp_dotp_cplx
Implementation Notes
- LDDW instructions are used to load two SP floating-point values at a time
for the x and y arrays.
- The loop is unrolled once and software pipelined. However, by condition-
ally adding to the dot product odd numbered array sizes are also permitted.
- Since the ADDSP and MPYSP instructions take 4 cycles, A8, B8, A0, and
B0 multiplex different variables to save on register usage. This multiple assignment is possible since the variables are always read just once on the
first cycle that they are available.
- The loop is primed to reduce the prolog by 4 cycles (14 words) with no in-
crease in cycle time.
- The load counter is used as the loop counter which requires a 3-cycle
(6 word) epilog to finish the calculations. This does not increase the cycle
time.
- Endianess: This code is little endian.
- Interruptibility: This code is interrupt-tolerant but not interruptible.
Function void DSPF_sp_dotp_cplx (const float *x, const float *y, int n, float *restrict
re, float * restrict im)
Arguments
xPointer to array holding the first floating-point vector.
yPointer to array holding the second floating-point vector.
nNumber of values in the x and y vectors.
rePointer to the location storing the real part of the result.
imPointer to the location storing the imaginary part of the
result.
4-54
Page 80
DSPF_sp_dotp_cplx
DescriptionThis routine calculates the dot product of 2 single-precision complex float vec-
tors. The even numbered locations hold the real parts of the complex numbers
while the odd numbered locations contain the imaginary portions.
AlgorithmThis is the C equivalent for the assembly code. Note that the assembly code
is hand optimized and restrictions may apply.
void DSPF_sp_dotp_cplx(const float* x, const float* y, int n,
float* restrict re, float* restrict im)
{
float real=0, imag=0;
int i=0;
for(i=0; i<n; i++)
{
real+=(x[2*i]*y[2*i] - x[2*i+1]*y[2*i+1]);
imag+=(x[2*i]*y[2*i+1] + x[2*i+1]*y[2*i]);
}
*re=real;
*im=imag;
}
Special Requirements
Implementation Notes
Benchmarks
- Since single assignment of registers is not used, interrupts should be dis-
abled before this function is called.
- Loop counter must be even and > 0.
- The x and y arrays must be double-word aligned.
- LDDW instructions are used to load two SP floating-point values at a time
for the x and y arrays.
- A load counter avoids all extraneous loads.
- Endianess: This code is little endian.
- Interruptibility: This code is interrupt-tolerant but not interruptible.
Cycles2*N + 22
e.g., for N = 512, cycles = 1046
Code size
384
(in bytes)
4-55 DSPLIB Reference
Page 81
DSPF_sp_maxval
DSPF_sp_maxval
Maximum element of single-precision vector
Function float DSPF_sp_maxval (const float* x, int nx)
Arguments
xPointer to input array.
nxNumber of inputs in the input array.
DescriptionThis routine finds out the maximum number in the input array. This code re-
turns the maximum value in the array.
AlgorithmThis is the C equivalent of the assembly code. Note that the assembly code
is hand optimized and restrictions may apply.
float DSPF_sp_maxval(const float* x, int nx)
{
int i,index;
float max;
*((int *)&max) = 0xff800000;
for (i = 0; i < nx; i++)
if (x[i] > max)
{
max = x[i];
index = i;
}
return max;
}
Special Requirements
Implementation Notes
4-56
- nx should be multiple of 2 and ≥ 2.
- x should be double-word aligned.
- The loop is unrolled six times.
- Six maximums are maintained in each iteration.
- One of the maximums is calculated using SUBSP in place of CMPGTSP.
- NAN (not a number in single-precision format) in the input are disre-
garded.
Page 82
Benchmarks
DSPF_sp_maxidx
-
Endianess: This code is little endian.
- Interruptibility: This code is interrupt-tolerant but not interruptible.
Cycles3*ceil(nx/6) + 35
For nx=60, cycles=65
For nx=34, cycles=53
Code size
448
(in bytes)
DSPF_sp_maxidx
Index of maximum element of single-precision vector
Function int DSPF_sp_maxidx (const float* x, int nx)
Arguments
xPointer to input array.
nxNumber of inputs in the input array.
DescriptionThis routine finds out the index of maximum number in the input array. This
function returns the index of the greatest value.
Algorithm
int DSPF_sp_maxidx(const float* x, int nx)
{
int index, i;
float max;
*((int *)&max) = 0xff800000;
for (i = 0; i < nx; i++)
if (x[i] > max)
{
max = x[i];
index = i;
}
return index;
}
Special Requirements
- nx is a multiple of 3.
- nx ≥ 3, and nx ≤ 2^16-1.
4-57 DSPLIB Reference
Page 83
DSPF_sp_minval
Implementation Notes
Benchmarks
- The loop is unrolled three times.
- Three maximums are maintained in each iteration.
- MPY instructions are used for move.
- Endianess: This code is endian neutral.
- Interruptibility: This code is interrupt-tolerant butnot interruptible.
Cycles2*nx/3 + 13
For nx=60, cycles=53
For nx=30, cycles=33
Code size
256
(in bytes)
DSPF_sp_minval
Minimum element of single-precision vector
Function float DSPF_sp_minval (const float* x, int nx)
Arguments
xPointer to input array.
nxNumber of inputs in the input array.
DescriptionThis routine finds out and returns the minimum number in the input array.
Algorithm
float DSPF_sp_minval(const float* x, int nx)
{
int i,index;
float min;
*((int *)&min) = 0x7f800000;
for (i = 0; i < nx; i++)
if (x[i] < min)
{
min = x[i];
index = i;
}
return min;
}
4-58
Page 84
Special Requirements
Implementation Notes
Benchmarks
DSPF_sp_vecrecip
- nx should be multiple of 2 and ≥ 2.
- x should be double-word aligned.
- The loop is unrolled six times.
- Six minimums are maintained in each iteration. One of the minimums is
calculated using SUBSP in place of CMPGTSP
- NAN (not a number in single-precision format) in the input are disre-
garded.
- Endianess: This code is little endian.
- Interruptibility: This code is interrupt-tolerant but not interruptible.
Cycles3*ceil(nx/6) + 35
For nx=60 cycles=65
For nx=34 cycles=53
Code size
448
(in bytes)
DSPF_sp_vecrecip
Single-precision vector reciprocal
Function void DSPF_sp_vecrecip (const float *x, float * restrict r, int n)
Arguments
xPointer to input array.
rPointer to output array.
nNumber of elements in array.
DescriptionThe sp_vecrecip module calculates the reciprocal of each element in the array
x and returns the output in array r. It uses 2 iterations of the Newton-Raphson
method to improve the accuracy of the output generated by the RCPSP instruction of the C67x. Each iteration doubles the accuracy. The initial output
generated by RCPSP is 8 bits. So after the first iteration it is 16 bits and after
the second it is the full 23 bits. The formula used is:
r[n+1] = r[n](2 - v*r[n])
where v = the number whose reciprocal is to be found.
x[0], the seed value for the algorithm, is given by RCPSP.
4-59 DSPLIB Reference
Page 85
DSPF_sp_vecsum_sq
AlgorithmThis is the C equivalent of the Assembly Code without restrictions.
void DSPF_sp_vecrecip(const float* x, float* restrict r, int
n)
{
int i;
for(i = 0; i < n; i++)
r[i] = 1 / x[i];
}
Special Requirements There are no alignment requirements.
Implementation Notes
- The inner loop is unrolled four times to allow calculation of four reciprocals
in the kernel. However the stores are executed conditionally to allow ‘n’ to
be any number > 0.
- Register sharing is used to make optimal use of available registers.
- No extraneous loads occur except for the case when n ≤ 4 where a pad
of 16 bytes is required.
- Endianess: This code is little endian.
- Interruptibility: This code is interrupt-tolerant but not interruptible.
Benchmarks
Cycles8*floor((n-1)/4) + 53
e.g., for n = 100, cycles = 245
Code size
512
(in bytes)
DSPF_sp_vecsum_sq
Single-precision sum of squares
Function float DSPF_sp_vecsum_sq (const float *x, int n)
Arguments
xPointer to first input array.
nNumber of elements in arrays.
DescriptionThis routine performs a sum of squares of the elements of the array x and re-
turns the sum.
4-60
Page 86
DSPF_sp_w_vec
AlgorithmThis is the C equivalent of the Assembly Code without restrictions. Note that
the assembly code is hand optimized and restrictions may apply.
float DSPF_sp_vecsum_sq(const float *x,int n)
{
int i;
float sum=0;
for(i = 0; i < n; i++ )
sum += x[i]*x[i];
return sum;
}
Special Requirements
- The x array must be double-word aligned.
- Since loads of 8 floats beyond the array occur, a pad must be provided.
Implementation Notes
- The inner loop is unrolled twice. Hence, 2 registers are used to hold the
sum of squares. ADDSPs are staggered.
- Endianess: This code is endian neutral.
- Interruptibility: This code is interrupt-tolerant but not interruptible.
Benchmarks
Cyclesfloor((n-1)/2) + 26
eg. for n = 200, cycles = 125
Code size
384
(in bytes)
DSPF_sp_w_vec
Single-precision weighted sum of vectors
Function void DSPF_sp_w_vec (const float* x, const float * y, float m, float * restrict
r, int nr)
Arguments
xPointer to first input array.
yPointer to second input array.
mWeight factor.
4-61 DSPLIB Reference
Page 87
DSPF_sp_vecmul
rOutput array pointer.
nrNumber of elements in arrays.
DescriptionThis routine is used to obtain the weighted vector sum. Both the inputs and out-
put are single-precision floating-point numbers.
AlgorithmThis is the C equivalent of the Assembly Code without restrictions.
void DSPF_sp_w_vec( const float * x,const float * y, float m,
float * restrict r,int nr)
{
int i;
for (i = 0; i < nr; i++)
r[i] = (m * x[i]) + y[i];
}
Special Requirements
- The x and y arrays must be double-word aligned.
- The value of nr must be > 0.
Implementation Notes
- The inner loop is unrolled twice.
- No extraneous loads occur except for odd values of n.
- Write buffer fulls occur unless the array ‘r’ is in cache.
- Endianess: This code is little endian.
- Interruptibility: This code is interrupt-tolerant but not interruptible.
Benchmarks
Cycles2*floor((n-1)/2) + 19
e.g., for n = 200, cycles = 219
Code size
384
(in bytes)
DSPF_sp_vecmul
Single-precision vector multiplication
Function void DSPF_sp_vecmul (const float *x, const float *y, float * restrict r, int n)
Arguments
xPointer to first input array.
yPointer to second input array.
4-62
Page 88
DSPF_sp_vecmul
rPointer to output array.
nNumber of elements in arrays.
DescriptionThis routine performs an element by element floating-point multiply of the vec-
tors x[] and y[] and returns the values in r[].
AlgorithmThis is the C equivalent of the Assembly Code without restrictions.
void DSPF_sp_vecmul(const float * x, const float * y,
float * restrict r, int n)
{
int i;
for(i = 0; i < n; i++)
r[i] = x[i] * y[i];
}
Special Requirements The x and y arrays must be double-word aligned.
Implementation Notes
- The inner loop is unrolled twice to allow calculation of 2 outputs in the ker-
nel. However the stores are executed conditionally to allow ‘n’ to be any
number > 0.
Benchmarks
- No extraneous loads occur except for the case when n is odd where a pad
of 4 bytes is required.
- Endianess: This code is little endian.
- Interruptibility: The code is interrupt-tolerant but not interruptible.
Cycles2*floor((n-1)/2) + 18
e.g., for n = 200, cycles = 216
Code size
192
(in bytes)
4-63 DSPLIB Reference
Page 89
DSPF_sp_mat_mul
4.6Matrix
DSPF_sp_mat_mul
Single-precision matrix multiplication
Function void DSPF_sp_mat_mul (float *x, int r1, int c1, float *y, int c2, float *r)
Arguments
xPointer to r1 by c1 input matrix.
r1Number of rows in x.
c1Number of columns in x. Also number of rows in y.
yPointer to c1 by c2 input matrix.
c2Number of columns in y.
rPointer to r1 by c2 output matrix.
DescriptionThis function computes the expression “r = x * y” for the matrices x and y. The
column dimension of x must match the row dimension o f y . The resulting matrix
has the same number of rows as x and the same number of columns as y. The
values stored in the matrices are assumed to be single-precision floating-point
values. This code is suitable for dense matrices. No optimizations are made
for sparse matrices.
Algorithm
void DSPF_sp_mat_mul(float *x, int r1, int c1, float *y, int
c2, float *r)
{
int i, j, k;
float sum;
// Multiply each row in x by each column in y.
// The product of row m in x and column n in y is placed
// in position (m,n) in the result.
for (i = 0; i < r1; i++)
for (j = 0; j < c2; j++)
{
sum = 0;
for (k = 0; k < c1; k++)
sum += x[k + i*c1] * y[j + k*c2];
r[j + i*c2] = sum;
}
}
4-64
Page 90
Special Requirements
Implementation Notes
DSPF_sp_mat_trans
- The arrays ‘x’, ‘y’, and ‘r’ are stored in distinct arrays. That is, in-place proc-
essing is not allowed.
- All r1, c1, c2 are assumed to be > 1
- 5 Floats are always loaded extra from the locations:
where
r1’ = r1 + (r1&1)
c2’ = c2 + (c2&1)
For r1 = 12, c1 = 14 and c2 = 18, cycles = 2890
Code size
992
(in bytes)
DSPF_sp_mat_trans
Single-precision matrix transpose
Function void DSPF_sp_mat_trans (const float *restrict x, int rows, int cols, float
*restrict r)
Arguments
x[r1*c1]Input matrix containing r1*c1 floating-point numbers having
r1 rows and c1 columns.
rowsNumber of rows in matrix x. Also number of columns in ma-
trix r.
4-65 DSPLIB Reference
Page 91
DSPF_sp_mat_mul_cplx
colsNumber of columns in matrix x. Also number of rows in ma-
trix r.
r[c1*r1]Output matrix containing c1*r1 floating-point numbers having
c1 rows and r1 columns.
DescriptionThis function transposes the input matrix x[] and writes the result to matrix r[].
AlgorithmThis is the C equivalent of the assembly code. Note that the assembly code
numbers.
c2Number of columns in matrix y.
r[2*r1*c2]Output matrix of c1*c2 complex floating-point numbers
having c1 rows and c2 columns of complex numbers.
Complex numbers are stored consecutively with real values
are stored in even word positions and imaginary values in
odd positions.
DescriptionThis function computes the expression “r = x * y” for the matrices x and y. The
columnar dimension of x must match the row dimension of y. The resulting matrix has the same number of rows as x and the same number of columns as
y. Each element of Matrices are assumed to be complex numbers with real values are stored in even word positions and imaginary values in odd positions.
AlgorithmThis is the C equivalent of the assembly code. Note that the assembly code
is hand optimized and restrictions may apply.
void DSPF_sp_mat_mul_cplx(const float* x, int r1, int c1,
const float* y, int c2, float* restrict r)
{
float real, imag;
int i, j, k;
for(i = 0; i < r1; i++)
{
for(j = 0; j < c2; j++)
{
real=0;
imag=0;
for(k = 0; k < c1; k++)
{
real += (x[i*2*c1 + 2*k]*y[k*2*c2 + 2*j]
- Outermost loop is executed in parallel with innner loops.
- Real values are stored in even word positions and imaginary values in odd
positions.
Benchmarks
- Endianess: This code is little endian.
- Interruptibility: This code is interrupt tolerant but not interruptible.
Cycles2*r1*c1*c2’ + 33 WHERE c2’=2*ceil(c2/2)
When r1=3, c1=4, c2=4, cycles = 129
When r1=4, c1=4, c2=5, cycles = 225
Code size
800
(in bytes)
4-68
Page 94
4.7Miscellaneous
DSPF_sp_blk_move
DSPF_sp_blk_move
Single-precision block move
Function void DSPF_sp_blk_move (const float * x, float *restrict r, int nx)
Arguments
x[nx]Pointer to source data to be moved.
r[nx]Pointer to destination array.
nxNumber of floats to move.
DescriptionThis routine moves nx floats from one memory location pointed to by x to
another pointed to by r.
AlgorithmThis is the C equivalent of the assembly code. Note that the assembly code
is hand optimized and restrictions may apply.
void DSPF_sp_blk_move(const float * x, float *restrict r, int
nx)
{
int i;
for (i = 0 ; i < nx; i++)
r[i] = x[i];
}
Special Requirements
- nx is greater than 0.
Implementation Notes
Benchmarks
- If nx is odd then x and r should be padded with 1 word.
- x and r are double-word aligned.
- The loop is unrolled twice.
- Cache touching is used to remove the Write Buffer Full problem.
- Endianess: This implementation is little endian.
- Interruptibility: This code is interrupt-tolerant but not interruptible.
Cycles2*ceil(nx/2)+7
For nx=64, cycles=71
For nx=25, cycles=33
Code size
128
(in bytes)
4-69 DSPLIB Reference
Page 95
DSPF_blk_eswap16
DSPF_blk_eswap16
Endian swap a block of 16-bit values
Function void DSPF_blk_eswap16 (void *restrict x, void *restrict r, int nx)
Arguments
x[nx]Pointer to source data.
r[nx]Pointer to destination array.
nxNumber of shorts (16-bit values) to swap.
DescriptionThe data in the x[] array is endian swapped, meaning that the byte-order of the
bytes within each half-word of the r[] array is reversed. This is meant to facilitate moving big-endian data to a little-endian system or vice versa. When the
r pointer is non-NULL, the endian swap occurs out-of-place, similar to a block
move. When the r pointer is NULL, the endian swap occurs in place, allowing
the swap to occur without using any additional storage.
AlgorithmThis is the C equivalent of the assembly code. Note that the assembly code
is hand optimized and restrictions may apply.
void DSPF_blk_eswap16(void *restrict x, void *restrict r, int
nx)
- Input array x and output array r do not overlap, except in the special case
“r==NULL” so that the operation occurs in place.
- The loop is unrolled eight times.
- Endianess: This implementation is ENDIAN NEUTRAL.
- Interruptibility: This code is interrupt-tolerant but not interruptible.
Cycles0.625 * nx + 12
For nx=64, cycles=52
For nx=32, cycles=32
Code size
256
(in bytes)
DSPF_blk_eswap32
Endian swap a block of 32-bit values
Function void DSPF_blk_eswap32 (void *restrict x, void *restrict r, int nx)
Arguments
x[nx]Pointer to source data.
r[nx]Pointer to destination array.
nxNumber of floats (32-bit values) to swap.
DescriptionThe data in the x[] array is endian swapped, meaning that the byte-order of the
bytes within each word of the r[] array is reversed. This is meant to facilitate
moving big-endian data to a little-endian system or vice versa. When the r
pointer is non-NULL, the endian swap occurs out-of-place, similar to a block
move. When the r pointer is NULL, the endian swap occurs in place, allowing
the swap to occur without using any additional storage.
4-71 DSPLIB Reference
Page 97
DSPF_blk_eswap32
AlgorithmThis is the C equivalent of the assembly code. Note that the assembly code
is hand optimized and restrictions may apply.
void DSPF_blk_eswap32(void *restrict x, void *restrict r, int
nx)
- Input array x and Output array r do not overlap, except in the special case
“r==NULL” so that the operation occurs in place.
Page 98
Implementation Notes
Benchmarks
DSPF_blk_eswap64
- The loop is unrolled twice.
- Multiply instructions are used for shifting left and right.
- Endianess: This implementation is endian neutral.
- Interruptibility: This code is interrupt-tolerant but not interruptible.
Cycles1.5 * nx + 14
For nx=64 cycles=110
For nx=32 cycles=62
Code size
224
(in bytes)
DSPF_blk_eswap64
Endian swap a block of 64-bit values
Function void DSPF_blk_eswap64 (void *restrict x, void *restrict r, int nx)
Arguments
x[nx]Pointer to source data.
r[nx]Pointer to destination array.
nxNumber of doubles (64-bit values) to swap.
DescriptionThe data in the x[] array is endian swapped, meaning that the byte-order of the
bytes within each double word of the r[] array is reversed. This is meant to facilitate moving big-endian data to a little-endian system or vice versa. When the
r pointer is non-NULL, the endian swap occurs out-of-place, similar to a block
move. When the r pointer is NULL, the endian swap occurs in place, allowing
the swap to occur without using any additional storage.
AlgorithmThis is the C equivalent of the assembly code. Note that the assembly code
is hand optimized and restrictions may apply.
void DSPF_blk_eswap64(void *restrict x, void *restrict r, int
nx)
- Input array x and Output array r do not overlap, except in the special case
“r==NULL” so that the operation occurs in place.
Page 100
Implementation Notes
Benchmarks
DSPF_fltoq15
- Multiply instructions are used for shifting left and right.
- Endianess: This implementation is endian neutral.
- Interruptibility: This code is interrupt-tolerant but not interruptible.
Cycles3 * nx + 14
For nx=64, cycles=206
For nx=32, cycles=110
Code size
224
(in bytes)
DSPF_fltoq15
IEEE single-precision floating point-to-Q15 format
Function void DSPF_fltoq15 (const float* restrict x, short* restrict r, int nx)
Arguments
x[nx]Input array contaning values of type float.
r[nx]Output array contains Q15 equivalents of x[nx].
nxNumber of elements in both arrays.
DescriptionConvert the IEEE floating-point numbers stored in vector x[] into Q.15 format
numbers stored in vector r[]. Results will be rounded towards negative infinity.
All values that exceed the size limit will be saturated to 0x7fff if value is positive
and 0x8000 if value is negative.
AlgorithmThis is the C equivalent of the assembly code. Note that the assembly code
is hand optimized and restrictions may apply.
void DSPF_fltoq15
(
const float* restrict x,
short* restrict r,
int nx
)
{
int i, a;
for(i = 0; i < nx; i++)
4-75 DSPLIB Reference
Loading...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.