arm_cmplx_mult_cmplx_f32.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_cmplx_mult_cmplx_f32.c
  4. * Description: Floating-point complex-by-complex 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 CmplxByCmplxMult Complex-by-Complex Multiplication
  34. Multiplies a complex vector by another complex 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.
  40. The underlying algorithm is used:
  41. <pre>
  42. for (n = 0; n < numSamples; n++) {
  43. pDst[(2*n)+0] = pSrcA[(2*n)+0] * pSrcB[(2*n)+0] - pSrcA[(2*n)+1] * pSrcB[(2*n)+1];
  44. pDst[(2*n)+1] = pSrcA[(2*n)+0] * pSrcB[(2*n)+1] + pSrcA[(2*n)+1] * pSrcB[(2*n)+0];
  45. }
  46. </pre>
  47. There are separate functions for floating-point, Q15, and Q31 data types.
  48. */
  49. /**
  50. @addtogroup CmplxByCmplxMult
  51. @{
  52. */
  53. /**
  54. @brief Floating-point complex-by-complex multiplication.
  55. @param[in] pSrcA points to first input vector
  56. @param[in] pSrcB points to second input vector
  57. @param[out] pDst points to output vector
  58. @param[in] numSamples number of samples in each vector
  59. @return none
  60. */
  61. void arm_cmplx_mult_cmplx_f32(
  62. const float32_t * pSrcA,
  63. const float32_t * pSrcB,
  64. float32_t * pDst,
  65. uint32_t numSamples)
  66. {
  67. uint32_t blkCnt; /* Loop counter */
  68. float32_t a, b, c, d; /* Temporary variables to store real and imaginary values */
  69. #if defined(ARM_MATH_NEON)
  70. float32x4x2_t va, vb;
  71. float32x4_t real, imag;
  72. float32x4x2_t outCplx;
  73. /* Compute 4 outputs at a time */
  74. blkCnt = numSamples >> 2U;
  75. while (blkCnt > 0U)
  76. {
  77. va = vld2q_f32(pSrcA); // load & separate real/imag pSrcA (de-interleave 2)
  78. vb = vld2q_f32(pSrcB); // load & separate real/imag pSrcB
  79. /* Increment pointers */
  80. pSrcA += 8;
  81. pSrcB += 8;
  82. /* Re{C} = Re{A}*Re{B} - Im{A}*Im{B} */
  83. outCplx.val[0] = vmulq_f32(va.val[0], vb.val[0]);
  84. outCplx.val[0] = vmlsq_f32(outCplx.val[0], va.val[1], vb.val[1]);
  85. /* Im{C} = Re{A}*Im{B} + Im{A}*Re{B} */
  86. outCplx.val[1] = vmulq_f32(va.val[0], vb.val[1]);
  87. outCplx.val[1] = vmlaq_f32(outCplx.val[1], va.val[1], vb.val[0]);
  88. vst2q_f32(pDst, outCplx);
  89. /* Increment pointer */
  90. pDst += 8;
  91. /* Decrement the loop counter */
  92. blkCnt--;
  93. }
  94. /* Tail */
  95. blkCnt = numSamples & 3;
  96. #else
  97. #if defined (ARM_MATH_LOOPUNROLL)
  98. /* Loop unrolling: Compute 4 outputs at a time */
  99. blkCnt = numSamples >> 2U;
  100. while (blkCnt > 0U)
  101. {
  102. /* C[2 * i ] = A[2 * i] * B[2 * i ] - A[2 * i + 1] * B[2 * i + 1]. */
  103. /* C[2 * i + 1] = A[2 * i] * B[2 * i + 1] + A[2 * i + 1] * B[2 * i ]. */
  104. a = *pSrcA++;
  105. b = *pSrcA++;
  106. c = *pSrcB++;
  107. d = *pSrcB++;
  108. /* store result in destination buffer. */
  109. *pDst++ = (a * c) - (b * d);
  110. *pDst++ = (a * d) + (b * c);
  111. a = *pSrcA++;
  112. b = *pSrcA++;
  113. c = *pSrcB++;
  114. d = *pSrcB++;
  115. *pDst++ = (a * c) - (b * d);
  116. *pDst++ = (a * d) + (b * c);
  117. a = *pSrcA++;
  118. b = *pSrcA++;
  119. c = *pSrcB++;
  120. d = *pSrcB++;
  121. *pDst++ = (a * c) - (b * d);
  122. *pDst++ = (a * d) + (b * c);
  123. a = *pSrcA++;
  124. b = *pSrcA++;
  125. c = *pSrcB++;
  126. d = *pSrcB++;
  127. *pDst++ = (a * c) - (b * d);
  128. *pDst++ = (a * d) + (b * c);
  129. /* Decrement loop counter */
  130. blkCnt--;
  131. }
  132. /* Loop unrolling: Compute remaining outputs */
  133. blkCnt = numSamples % 0x4U;
  134. #else
  135. /* Initialize blkCnt with number of samples */
  136. blkCnt = numSamples;
  137. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  138. #endif /* #if defined(ARM_MATH_NEON) */
  139. while (blkCnt > 0U)
  140. {
  141. /* C[2 * i ] = A[2 * i] * B[2 * i ] - A[2 * i + 1] * B[2 * i + 1]. */
  142. /* C[2 * i + 1] = A[2 * i] * B[2 * i + 1] + A[2 * i + 1] * B[2 * i ]. */
  143. a = *pSrcA++;
  144. b = *pSrcA++;
  145. c = *pSrcB++;
  146. d = *pSrcB++;
  147. /* store result in destination buffer. */
  148. *pDst++ = (a * c) - (b * d);
  149. *pDst++ = (a * d) + (b * c);
  150. /* Decrement loop counter */
  151. blkCnt--;
  152. }
  153. }
  154. /**
  155. @} end of CmplxByCmplxMult group
  156. */