Merge pull request #11270 from haslinghuis/rename_attr
[betaflight.git] / lib / main / CMSIS / DSP / Source / ComplexMathFunctions / arm_cmplx_mult_real_f32.c
blob8c7ca313b373d85c6dd6d844738161ff9975596b
1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_cmplx_mult_real_f32.c
4 * Description: Floating-point complex by real multiplication
6 * $Date: 27. January 2017
7 * $Revision: V.1.5.1
9 * Target Processor: Cortex-M cores
10 * -------------------------------------------------------------------- */
12 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
14 * SPDX-License-Identifier: Apache-2.0
16 * Licensed under the Apache License, Version 2.0 (the License); you may
17 * not use this file except in compliance with the License.
18 * You may obtain a copy of the License at
20 * www.apache.org/licenses/LICENSE-2.0
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
29 #include "arm_math.h"
31 /**
32 * @ingroup groupCmplxMath
35 /**
36 * @defgroup CmplxByRealMult Complex-by-Real Multiplication
38 * Multiplies a complex vector by a real vector and generates a complex result.
39 * The data in the complex arrays is stored in an interleaved fashion
40 * (real, imag, real, imag, ...).
41 * The parameter <code>numSamples</code> represents the number of complex
42 * samples processed. The complex arrays have a total of <code>2*numSamples</code>
43 * real values while the real array has a total of <code>numSamples</code>
44 * real values.
46 * The underlying algorithm is used:
48 * <pre>
49 * for(n=0; n<numSamples; n++) {
50 * pCmplxDst[(2*n)+0] = pSrcCmplx[(2*n)+0] * pSrcReal[n];
51 * pCmplxDst[(2*n)+1] = pSrcCmplx[(2*n)+1] * pSrcReal[n];
52 * }
53 * </pre>
55 * There are separate functions for floating-point, Q15, and Q31 data types.
58 /**
59 * @addtogroup CmplxByRealMult
60 * @{
64 /**
65 * @brief Floating-point complex-by-real multiplication
66 * @param[in] *pSrcCmplx points to the complex input vector
67 * @param[in] *pSrcReal points to the real input vector
68 * @param[out] *pCmplxDst points to the complex output vector
69 * @param[in] numSamples number of samples in each vector
70 * @return none.
73 void arm_cmplx_mult_real_f32(
74 float32_t * pSrcCmplx,
75 float32_t * pSrcReal,
76 float32_t * pCmplxDst,
77 uint32_t numSamples)
79 float32_t in; /* Temporary variable to store input value */
80 uint32_t blkCnt; /* loop counters */
82 #if defined (ARM_MATH_DSP)
84 /* Run the below code for Cortex-M4 and Cortex-M3 */
85 float32_t inA1, inA2, inA3, inA4; /* Temporary variables to hold input data */
86 float32_t inA5, inA6, inA7, inA8; /* Temporary variables to hold input data */
87 float32_t inB1, inB2, inB3, inB4; /* Temporary variables to hold input data */
88 float32_t out1, out2, out3, out4; /* Temporary variables to hold output data */
89 float32_t out5, out6, out7, out8; /* Temporary variables to hold output data */
91 /* loop Unrolling */
92 blkCnt = numSamples >> 2U;
94 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
95 ** a second loop below computes the remaining 1 to 3 samples. */
96 while (blkCnt > 0U)
98 /* C[2 * i] = A[2 * i] * B[i]. */
99 /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */
100 /* read input from complex input buffer */
101 inA1 = pSrcCmplx[0];
102 inA2 = pSrcCmplx[1];
103 /* read input from real input buffer */
104 inB1 = pSrcReal[0];
106 /* read input from complex input buffer */
107 inA3 = pSrcCmplx[2];
109 /* multiply complex buffer real input with real buffer input */
110 out1 = inA1 * inB1;
112 /* read input from complex input buffer */
113 inA4 = pSrcCmplx[3];
115 /* multiply complex buffer imaginary input with real buffer input */
116 out2 = inA2 * inB1;
118 /* read input from real input buffer */
119 inB2 = pSrcReal[1];
120 /* read input from complex input buffer */
121 inA5 = pSrcCmplx[4];
123 /* multiply complex buffer real input with real buffer input */
124 out3 = inA3 * inB2;
126 /* read input from complex input buffer */
127 inA6 = pSrcCmplx[5];
128 /* read input from real input buffer */
129 inB3 = pSrcReal[2];
131 /* multiply complex buffer imaginary input with real buffer input */
132 out4 = inA4 * inB2;
134 /* read input from complex input buffer */
135 inA7 = pSrcCmplx[6];
137 /* multiply complex buffer real input with real buffer input */
138 out5 = inA5 * inB3;
140 /* read input from complex input buffer */
141 inA8 = pSrcCmplx[7];
143 /* multiply complex buffer imaginary input with real buffer input */
144 out6 = inA6 * inB3;
146 /* read input from real input buffer */
147 inB4 = pSrcReal[3];
149 /* store result to destination bufer */
150 pCmplxDst[0] = out1;
152 /* multiply complex buffer real input with real buffer input */
153 out7 = inA7 * inB4;
155 /* store result to destination bufer */
156 pCmplxDst[1] = out2;
158 /* multiply complex buffer imaginary input with real buffer input */
159 out8 = inA8 * inB4;
161 /* store result to destination bufer */
162 pCmplxDst[2] = out3;
163 pCmplxDst[3] = out4;
164 pCmplxDst[4] = out5;
166 /* incremnet complex input buffer by 8 to process next samples */
167 pSrcCmplx += 8U;
169 /* store result to destination bufer */
170 pCmplxDst[5] = out6;
172 /* increment real input buffer by 4 to process next samples */
173 pSrcReal += 4U;
175 /* store result to destination bufer */
176 pCmplxDst[6] = out7;
177 pCmplxDst[7] = out8;
179 /* increment destination buffer by 8 to process next sampels */
180 pCmplxDst += 8U;
182 /* Decrement the numSamples loop counter */
183 blkCnt--;
186 /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
187 ** No loop unrolling is used. */
188 blkCnt = numSamples % 0x4U;
190 #else
192 /* Run the below code for Cortex-M0 */
193 blkCnt = numSamples;
195 #endif /* #if defined (ARM_MATH_DSP) */
197 while (blkCnt > 0U)
199 /* C[2 * i] = A[2 * i] * B[i]. */
200 /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */
201 in = *pSrcReal++;
202 /* store the result in the destination buffer. */
203 *pCmplxDst++ = (*pSrcCmplx++) * (in);
204 *pCmplxDst++ = (*pSrcCmplx++) * (in);
206 /* Decrement the numSamples loop counter */
207 blkCnt--;
212 * @} end of CmplxByRealMult group