Merge branch 'jnosky/master'
[fw/stlink] / exampleF4 / CMSIS / DSP_Lib / Source / ComplexMathFunctions / arm_cmplx_mult_cmplx_f32.c
1 /* ----------------------------------------------------------------------   
2 * Copyright (C) 2010 ARM Limited. All rights reserved.   
3 *   
4 * $Date:        15. July 2011  
5 * $Revision:    V1.0.10  
6 *   
7 * Project:          CMSIS DSP Library   
8 * Title:            arm_cmplx_mult_cmplx_f32.c   
9 *   
10 * Description:  Floating-point complex-by-complex multiplication   
11 *   
12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
13 *  
14 * Version 1.0.10 2011/7/15 
15 *    Big Endian support added and Merged M0 and M3/M4 Source code.  
16 *   
17 * Version 1.0.3 2010/11/29  
18 *    Re-organized the CMSIS folders and updated documentation.   
19 *    
20 * Version 1.0.2 2010/11/11   
21 *    Documentation updated.    
22 *   
23 * Version 1.0.1 2010/10/05    
24 *    Production release and review comments incorporated.   
25 *   
26 * Version 1.0.0 2010/09/20    
27 *    Production release and review comments incorporated.   
28 * -------------------------------------------------------------------- */
29
30 #include "arm_math.h"
31
32 /**   
33  * @ingroup groupCmplxMath   
34  */
35
36 /**   
37  * @defgroup CmplxByCmplxMult Complex-by-Complex Multiplication   
38  *   
39  * Multiplies a complex vector by another complex vector and generates a complex result.   
40  * The data in the complex arrays is stored in an interleaved fashion   
41  * (real, imag, real, imag, ...).   
42  * The parameter <code>numSamples</code> represents the number of complex   
43  * samples processed.  The complex arrays have a total of <code>2*numSamples</code>   
44  * real values.   
45  *   
46  * The underlying algorithm is used:   
47  *   
48  * <pre>   
49  * for(n=0; n<numSamples; n++) {   
50  *     pDst[(2*n)+0] = pSrcA[(2*n)+0] * pSrcB[(2*n)+0] - pSrcA[(2*n)+1] * pSrcB[(2*n)+1];   
51  *     pDst[(2*n)+1] = pSrcA[(2*n)+0] * pSrcB[(2*n)+1] + pSrcA[(2*n)+1] * pSrcB[(2*n)+0];   
52  * }   
53  * </pre>   
54  *   
55  * There are separate functions for floating-point, Q15, and Q31 data types.   
56  */
57
58 /**   
59  * @addtogroup CmplxByCmplxMult   
60  * @{   
61  */
62
63
64 /**   
65  * @brief  Floating-point complex-by-complex multiplication   
66  * @param[in]  *pSrcA points to the first input vector   
67  * @param[in]  *pSrcB points to the second input vector   
68  * @param[out]  *pDst  points to the output vector   
69  * @param[in]  numSamples number of complex samples in each vector   
70  * @return none.   
71  */
72
73 void arm_cmplx_mult_cmplx_f32(
74   float32_t * pSrcA,
75   float32_t * pSrcB,
76   float32_t * pDst,
77   uint32_t numSamples)
78 {
79   float32_t a, b, c, d;                          /* Temporary variables to store real and imaginary values */
80
81 #ifndef ARM_MATH_CM0
82
83   /* Run the below code for Cortex-M4 and Cortex-M3 */
84   uint32_t blkCnt;                               /* loop counters */
85
86   /* loop Unrolling */
87   blkCnt = numSamples >> 2u;
88
89   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.   
90    ** a second loop below computes the remaining 1 to 3 samples. */
91   while(blkCnt > 0u)
92   {
93     /* C[2 * i] = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1].  */
94     /* C[2 * i + 1] = A[2 * i] * B[2 * i + 1] + A[2 * i + 1] * B[2 * i].  */
95     a = *pSrcA++;
96     b = *pSrcA++;
97     c = *pSrcB++;
98     d = *pSrcB++;
99
100     /* store the result in the destination buffer. */
101     *pDst++ = (a * c) - (b * d);
102     *pDst++ = (a * d) + (b * c);
103
104     a = *pSrcA++;
105     b = *pSrcA++;
106     c = *pSrcB++;
107     d = *pSrcB++;
108
109     *pDst++ = (a * c) - (b * d);
110     *pDst++ = (a * d) + (b * c);
111
112     a = *pSrcA++;
113     b = *pSrcA++;
114     c = *pSrcB++;
115     d = *pSrcB++;
116
117     *pDst++ = (a * c) - (b * d);
118     *pDst++ = (a * d) + (b * c);
119
120     a = *pSrcA++;
121     b = *pSrcA++;
122     c = *pSrcB++;
123     d = *pSrcB++;
124
125     *pDst++ = (a * c) - (b * d);
126     *pDst++ = (a * d) + (b * c);
127
128     /* Decrement the numSamples loop counter */
129     blkCnt--;
130   }
131
132   /* If the numSamples is not a multiple of 4, compute any remaining output samples here.   
133    ** No loop unrolling is used. */
134   blkCnt = numSamples % 0x4u;
135
136   while(blkCnt > 0u)
137   {
138     /* C[2 * i] = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1].  */
139     /* C[2 * i + 1] = A[2 * i] * B[2 * i + 1] + A[2 * i + 1] * B[2 * i].  */
140     a = *pSrcA++;
141     b = *pSrcA++;
142     c = *pSrcB++;
143     d = *pSrcB++;
144
145     /* store the result in the destination buffer. */
146     *pDst++ = (a * c) - (b * d);
147     *pDst++ = (a * d) + (b * c);
148
149     /* Decrement the numSamples loop counter */
150     blkCnt--;
151   }
152
153 #else
154
155   /* Run the below code for Cortex-M0 */
156
157   while(numSamples > 0u)
158   {
159     /* C[2 * i] = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1].  */
160     /* C[2 * i + 1] = A[2 * i] * B[2 * i + 1] + A[2 * i + 1] * B[2 * i].  */
161     a = *pSrcA++;
162     b = *pSrcA++;
163     c = *pSrcB++;
164     d = *pSrcB++;
165
166     /* store the result in the destination buffer. */
167     *pDst++ = (a * c) - (b * d);
168     *pDst++ = (a * d) + (b * c);
169
170     /* Decrement the numSamples loop counter */
171     numSamples--;
172   }
173
174 #endif /* #ifndef ARM_MATH_CM0 */
175
176 }
177
178 /**   
179  * @} end of CmplxByCmplxMult group   
180  */