arm_cmplx_mult_real_f32.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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: 18. March 2019
  7. * $Revision: V1.6.0
  8. *
  9. * Target Processor: Cortex-M cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2019 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 "arm_math.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. void arm_cmplx_mult_real_f32(
  63. const float32_t * pSrcCmplx,
  64. const float32_t * pSrcReal,
  65. float32_t * pCmplxDst,
  66. uint32_t numSamples)
  67. {
  68. uint32_t blkCnt; /* Loop counter */
  69. float32_t in; /* Temporary variable */
  70. #if defined(ARM_MATH_NEON)
  71. float32x4_t r;
  72. float32x4x2_t ab,outCplx;
  73. /* Compute 4 outputs at a time */
  74. blkCnt = numSamples >> 2U;
  75. while (blkCnt > 0U)
  76. {
  77. ab = vld2q_f32(pSrcCmplx); // load & separate real/imag pSrcA (de-interleave 2)
  78. r = vld1q_f32(pSrcReal); // load & separate real/imag pSrcB
  79. /* Increment pointers */
  80. pSrcCmplx += 8;
  81. pSrcReal += 4;
  82. outCplx.val[0] = vmulq_f32(ab.val[0], r);
  83. outCplx.val[1] = vmulq_f32(ab.val[1], r);
  84. vst2q_f32(pCmplxDst, outCplx);
  85. pCmplxDst += 8;
  86. blkCnt--;
  87. }
  88. /* Tail */
  89. blkCnt = numSamples & 3;
  90. #else
  91. #if defined (ARM_MATH_LOOPUNROLL)
  92. /* Loop unrolling: Compute 4 outputs at a time */
  93. blkCnt = numSamples >> 2U;
  94. while (blkCnt > 0U)
  95. {
  96. /* C[2 * i ] = A[2 * i ] * B[i]. */
  97. /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */
  98. in = *pSrcReal++;
  99. /* store result in destination buffer. */
  100. *pCmplxDst++ = *pSrcCmplx++ * in;
  101. *pCmplxDst++ = *pSrcCmplx++ * in;
  102. in = *pSrcReal++;
  103. *pCmplxDst++ = *pSrcCmplx++ * in;
  104. *pCmplxDst++ = *pSrcCmplx++ * in;
  105. in = *pSrcReal++;
  106. *pCmplxDst++ = *pSrcCmplx++ * in;
  107. *pCmplxDst++ = *pSrcCmplx++ * in;
  108. in = *pSrcReal++;
  109. *pCmplxDst++ = *pSrcCmplx++* in;
  110. *pCmplxDst++ = *pSrcCmplx++ * in;
  111. /* Decrement loop counter */
  112. blkCnt--;
  113. }
  114. /* Loop unrolling: Compute remaining outputs */
  115. blkCnt = numSamples % 0x4U;
  116. #else
  117. /* Initialize blkCnt with number of samples */
  118. blkCnt = numSamples;
  119. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  120. #endif /* #if defined(ARM_MATH_NEON) */
  121. while (blkCnt > 0U)
  122. {
  123. /* C[2 * i ] = A[2 * i ] * B[i]. */
  124. /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */
  125. in = *pSrcReal++;
  126. /* store result in destination buffer. */
  127. *pCmplxDst++ = *pSrcCmplx++ * in;
  128. *pCmplxDst++ = *pSrcCmplx++ * in;
  129. /* Decrement loop counter */
  130. blkCnt--;
  131. }
  132. }
  133. /**
  134. @} end of CmplxByRealMult group
  135. */