arm_cmplx_mult_real_f32.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. #include "dsp/complex_math_functions.h"
  29. /**
  30. @ingroup groupCmplxMath
  31. */
  32. /**
  33. @defgroup CmplxByRealMult Complex-by-Real Multiplication
  34. Multiplies a complex vector by a real vector and generates a complex result.
  35. The data in the complex arrays is stored in an interleaved fashion
  36. (real, imag, real, imag, ...).
  37. The parameter <code>numSamples</code> represents the number of complex
  38. samples processed. The complex arrays have a total of <code>2*numSamples</code>
  39. real values while the real array has a total of <code>numSamples</code>
  40. real values.
  41. The underlying algorithm is used:
  42. <pre>
  43. for (n = 0; n < numSamples; n++) {
  44. pCmplxDst[(2*n)+0] = pSrcCmplx[(2*n)+0] * pSrcReal[n];
  45. pCmplxDst[(2*n)+1] = pSrcCmplx[(2*n)+1] * pSrcReal[n];
  46. }
  47. </pre>
  48. There are separate functions for floating-point, Q15, and Q31 data types.
  49. */
  50. /**
  51. @addtogroup CmplxByRealMult
  52. @{
  53. */
  54. /**
  55. @brief Floating-point complex-by-real multiplication.
  56. @param[in] pSrcCmplx points to complex input vector
  57. @param[in] pSrcReal points to real input vector
  58. @param[out] pCmplxDst points to complex output vector
  59. @param[in] numSamples number of samples in each vector
  60. @return none
  61. */
  62. #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
  63. void arm_cmplx_mult_real_f32(
  64. const float32_t * pSrcCmplx,
  65. const float32_t * pSrcReal,
  66. float32_t * pCmplxDst,
  67. uint32_t numSamples)
  68. {
  69. static const uint32_t stride_cmplx_x_real_32[4] = { 0, 0, 1, 1 };
  70. uint32_t blockSizeC = numSamples * CMPLX_DIM; /* loop counters */
  71. uint32_t blkCnt;
  72. f32x4_t rVec;
  73. f32x4_t cmplxVec;
  74. f32x4_t dstVec;
  75. uint32x4_t strideVec;
  76. float32_t in;
  77. /* stride vector for pairs of real generation */
  78. strideVec = vld1q(stride_cmplx_x_real_32);
  79. /* Compute 4 complex outputs at a time */
  80. blkCnt = blockSizeC >> 2;
  81. while (blkCnt > 0U)
  82. {
  83. cmplxVec = vld1q(pSrcCmplx);
  84. rVec = vldrwq_gather_shifted_offset_f32(pSrcReal, strideVec);
  85. dstVec = vmulq(cmplxVec, rVec);
  86. vst1q(pCmplxDst, dstVec);
  87. pSrcReal += 2;
  88. pSrcCmplx += 4;
  89. pCmplxDst += 4;
  90. blkCnt--;
  91. }
  92. blkCnt = (blockSizeC & 3) >> 1;
  93. while (blkCnt > 0U)
  94. {
  95. /* C[2 * i ] = A[2 * i ] * B[i]. */
  96. /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */
  97. in = *pSrcReal++;
  98. /* store result in destination buffer. */
  99. *pCmplxDst++ = *pSrcCmplx++ * in;
  100. *pCmplxDst++ = *pSrcCmplx++ * in;
  101. /* Decrement loop counter */
  102. blkCnt--;
  103. }
  104. }
  105. #else
  106. void arm_cmplx_mult_real_f32(
  107. const float32_t * pSrcCmplx,
  108. const float32_t * pSrcReal,
  109. float32_t * pCmplxDst,
  110. uint32_t numSamples)
  111. {
  112. uint32_t blkCnt; /* Loop counter */
  113. float32_t in; /* Temporary variable */
  114. #if defined(ARM_MATH_NEON) && !defined(ARM_MATH_AUTOVECTORIZE)
  115. float32x4_t r;
  116. float32x4x2_t ab,outCplx;
  117. /* Compute 4 outputs at a time */
  118. blkCnt = numSamples >> 2U;
  119. while (blkCnt > 0U)
  120. {
  121. ab = vld2q_f32(pSrcCmplx); // load & separate real/imag pSrcA (de-interleave 2)
  122. r = vld1q_f32(pSrcReal); // load & separate real/imag pSrcB
  123. /* Increment pointers */
  124. pSrcCmplx += 8;
  125. pSrcReal += 4;
  126. outCplx.val[0] = vmulq_f32(ab.val[0], r);
  127. outCplx.val[1] = vmulq_f32(ab.val[1], r);
  128. vst2q_f32(pCmplxDst, outCplx);
  129. pCmplxDst += 8;
  130. blkCnt--;
  131. }
  132. /* Tail */
  133. blkCnt = numSamples & 3;
  134. #else
  135. #if defined (ARM_MATH_LOOPUNROLL) && !defined(ARM_MATH_AUTOVECTORIZE)
  136. /* Loop unrolling: Compute 4 outputs at a time */
  137. blkCnt = numSamples >> 2U;
  138. while (blkCnt > 0U)
  139. {
  140. /* C[2 * i ] = A[2 * i ] * B[i]. */
  141. /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */
  142. in = *pSrcReal++;
  143. /* store result in destination buffer. */
  144. *pCmplxDst++ = *pSrcCmplx++ * in;
  145. *pCmplxDst++ = *pSrcCmplx++ * in;
  146. in = *pSrcReal++;
  147. *pCmplxDst++ = *pSrcCmplx++ * in;
  148. *pCmplxDst++ = *pSrcCmplx++ * in;
  149. in = *pSrcReal++;
  150. *pCmplxDst++ = *pSrcCmplx++ * in;
  151. *pCmplxDst++ = *pSrcCmplx++ * in;
  152. in = *pSrcReal++;
  153. *pCmplxDst++ = *pSrcCmplx++* in;
  154. *pCmplxDst++ = *pSrcCmplx++ * in;
  155. /* Decrement loop counter */
  156. blkCnt--;
  157. }
  158. /* Loop unrolling: Compute remaining outputs */
  159. blkCnt = numSamples % 0x4U;
  160. #else
  161. /* Initialize blkCnt with number of samples */
  162. blkCnt = numSamples;
  163. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  164. #endif /* #if defined(ARM_MATH_NEON) */
  165. while (blkCnt > 0U)
  166. {
  167. /* C[2 * i ] = A[2 * i ] * B[i]. */
  168. /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */
  169. in = *pSrcReal++;
  170. /* store result in destination buffer. */
  171. *pCmplxDst++ = *pSrcCmplx++ * in;
  172. *pCmplxDst++ = *pSrcCmplx++ * in;
  173. /* Decrement loop counter */
  174. blkCnt--;
  175. }
  176. }
  177. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  178. /**
  179. @} end of CmplxByRealMult group
  180. */