• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ----------------------------------------------------------------------
2  * Project:      CMSIS DSP Library
3  * Title:        arm_cmplx_mult_real_f32.c
4  * Description:  Floating-point complex by real multiplication
5  *
6  * $Date:        23 April 2021
7  * $Revision:    V1.9.0
8  *
9  * Target Processor: Cortex-M and Cortex-A cores
10  * -------------------------------------------------------------------- */
11 /*
12  * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
13  *
14  * SPDX-License-Identifier: Apache-2.0
15  *
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
19  *
20  * www.apache.org/licenses/LICENSE-2.0
21  *
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.
27  */
28 
29 #include "dsp/complex_math_functions.h"
30 
31 /**
32   @ingroup groupCmplxMath
33  */
34 
35 /**
36   @defgroup CmplxByRealMult Complex-by-Real Multiplication
37 
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.
45 
46   The underlying algorithm is used:
47 
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>
54 
55   There are separate functions for floating-point, Q15, and Q31 data types.
56  */
57 
58 /**
59   @addtogroup CmplxByRealMult
60   @{
61  */
62 
63 /**
64   @brief         Floating-point complex-by-real multiplication.
65   @param[in]     pSrcCmplx   points to complex input vector
66   @param[in]     pSrcReal    points to real input vector
67   @param[out]    pCmplxDst   points to complex output vector
68   @param[in]     numSamples  number of samples in each vector
69   @return        none
70  */
71 
72 #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
73 
arm_cmplx_mult_real_f32(const float32_t * pSrcCmplx,const float32_t * pSrcReal,float32_t * pCmplxDst,uint32_t numSamples)74 void arm_cmplx_mult_real_f32(
75   const float32_t * pSrcCmplx,
76   const float32_t * pSrcReal,
77         float32_t * pCmplxDst,
78         uint32_t numSamples)
79 {
80     static const uint32_t stride_cmplx_x_real_32[4] = { 0, 0, 1, 1 };
81 
82     uint32_t blockSizeC = numSamples * CMPLX_DIM;   /* loop counters */
83     uint32_t blkCnt;
84     f32x4_t rVec;
85     f32x4_t cmplxVec;
86     f32x4_t dstVec;
87     uint32x4_t strideVec;
88     float32_t in;
89 
90 
91     /* stride vector for pairs of real generation */
92     strideVec = vld1q(stride_cmplx_x_real_32);
93 
94     /* Compute 4 complex outputs at a time */
95     blkCnt = blockSizeC >> 2;
96     while (blkCnt > 0U)
97     {
98         cmplxVec = vld1q(pSrcCmplx);
99         rVec = vldrwq_gather_shifted_offset_f32(pSrcReal, strideVec);
100         dstVec = vmulq(cmplxVec, rVec);
101         vst1q(pCmplxDst, dstVec);
102 
103         pSrcReal += 2;
104         pSrcCmplx += 4;
105         pCmplxDst += 4;
106         blkCnt--;
107     }
108 
109     blkCnt = (blockSizeC & 3) >> 1;
110     while (blkCnt > 0U)
111     {
112       /* C[2 * i    ] = A[2 * i    ] * B[i]. */
113       /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */
114 
115       in = *pSrcReal++;
116       /* store result in destination buffer. */
117       *pCmplxDst++ = *pSrcCmplx++ * in;
118       *pCmplxDst++ = *pSrcCmplx++ * in;
119 
120       /* Decrement loop counter */
121       blkCnt--;
122     }
123 }
124 
125 #else
arm_cmplx_mult_real_f32(const float32_t * pSrcCmplx,const float32_t * pSrcReal,float32_t * pCmplxDst,uint32_t numSamples)126 void arm_cmplx_mult_real_f32(
127   const float32_t * pSrcCmplx,
128   const float32_t * pSrcReal,
129         float32_t * pCmplxDst,
130         uint32_t numSamples)
131 {
132         uint32_t blkCnt;                               /* Loop counter */
133         float32_t in;                                  /* Temporary variable */
134 
135 #if defined(ARM_MATH_NEON) && !defined(ARM_MATH_AUTOVECTORIZE)
136     float32x4_t r;
137     float32x4x2_t ab,outCplx;
138 
139     /* Compute 4 outputs at a time */
140     blkCnt = numSamples >> 2U;
141 
142     while (blkCnt > 0U)
143     {
144         ab = vld2q_f32(pSrcCmplx);  // load & separate real/imag pSrcA (de-interleave 2)
145         r = vld1q_f32(pSrcReal);  // load & separate real/imag pSrcB
146 
147 	/* Increment pointers */
148         pSrcCmplx += 8;
149         pSrcReal += 4;
150 
151         outCplx.val[0] = vmulq_f32(ab.val[0], r);
152         outCplx.val[1] = vmulq_f32(ab.val[1], r);
153 
154         vst2q_f32(pCmplxDst, outCplx);
155         pCmplxDst += 8;
156 
157         blkCnt--;
158     }
159 
160     /* Tail */
161     blkCnt = numSamples & 3;
162 #else
163 #if defined (ARM_MATH_LOOPUNROLL) && !defined(ARM_MATH_AUTOVECTORIZE)
164 
165   /* Loop unrolling: Compute 4 outputs at a time */
166   blkCnt = numSamples >> 2U;
167 
168   while (blkCnt > 0U)
169   {
170     /* C[2 * i    ] = A[2 * i    ] * B[i]. */
171     /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */
172 
173     in = *pSrcReal++;
174     /* store result in destination buffer. */
175     *pCmplxDst++ = *pSrcCmplx++ * in;
176     *pCmplxDst++ = *pSrcCmplx++ * in;
177 
178     in = *pSrcReal++;
179     *pCmplxDst++ = *pSrcCmplx++ * in;
180     *pCmplxDst++ = *pSrcCmplx++ * in;
181 
182     in = *pSrcReal++;
183     *pCmplxDst++ = *pSrcCmplx++ * in;
184     *pCmplxDst++ = *pSrcCmplx++ * in;
185 
186     in = *pSrcReal++;
187     *pCmplxDst++ = *pSrcCmplx++* in;
188     *pCmplxDst++ = *pSrcCmplx++ * in;
189 
190     /* Decrement loop counter */
191     blkCnt--;
192   }
193 
194   /* Loop unrolling: Compute remaining outputs */
195   blkCnt = numSamples % 0x4U;
196 
197 #else
198 
199   /* Initialize blkCnt with number of samples */
200   blkCnt = numSamples;
201 
202 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
203 #endif /* #if defined(ARM_MATH_NEON) */
204 
205   while (blkCnt > 0U)
206   {
207     /* C[2 * i    ] = A[2 * i    ] * B[i]. */
208     /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */
209 
210     in = *pSrcReal++;
211     /* store result in destination buffer. */
212     *pCmplxDst++ = *pSrcCmplx++ * in;
213     *pCmplxDst++ = *pSrcCmplx++ * in;
214 
215     /* Decrement loop counter */
216     blkCnt--;
217   }
218 
219 }
220 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
221 
222 /**
223   @} end of CmplxByRealMult group
224  */
225