arm_cmplx_dot_prod_f32.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_cmplx_dot_prod_f32.c
  4. * Description: Floating-point complex dot product
  5. *
  6. * $Date: 27. January 2017
  7. * $Revision: V.1.5.1
  8. *
  9. * Target Processor: Cortex-M cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2017 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 cmplx_dot_prod Complex Dot Product
  34. *
  35. * Computes the dot product of two complex vectors.
  36. * The vectors are multiplied element-by-element and then summed.
  37. *
  38. * The <code>pSrcA</code> points to the first complex input vector and
  39. * <code>pSrcB</code> points to the second complex input vector.
  40. * <code>numSamples</code> specifies the number of complex samples
  41. * and the data in each array is stored in an interleaved fashion
  42. * (real, imag, real, imag, ...).
  43. * Each array has a total of <code>2*numSamples</code> values.
  44. *
  45. * The underlying algorithm is used:
  46. * <pre>
  47. * realResult=0;
  48. * imagResult=0;
  49. * for(n=0; n<numSamples; n++) {
  50. * realResult += pSrcA[(2*n)+0]*pSrcB[(2*n)+0] - pSrcA[(2*n)+1]*pSrcB[(2*n)+1];
  51. * imagResult += pSrcA[(2*n)+0]*pSrcB[(2*n)+1] + pSrcA[(2*n)+1]*pSrcB[(2*n)+0];
  52. * }
  53. * </pre>
  54. *
  55. * There are separate functions for floating-point, Q15, and Q31 data types.
  56. */
  57. /**
  58. * @addtogroup cmplx_dot_prod
  59. * @{
  60. */
  61. /**
  62. * @brief Floating-point complex dot product
  63. * @param *pSrcA points to the first input vector
  64. * @param *pSrcB points to the second input vector
  65. * @param numSamples number of complex samples in each vector
  66. * @param *realResult real part of the result returned here
  67. * @param *imagResult imaginary part of the result returned here
  68. * @return none.
  69. */
  70. void arm_cmplx_dot_prod_f32(
  71. float32_t * pSrcA,
  72. float32_t * pSrcB,
  73. uint32_t numSamples,
  74. float32_t * realResult,
  75. float32_t * imagResult)
  76. {
  77. float32_t real_sum = 0.0f, imag_sum = 0.0f; /* Temporary result storage */
  78. float32_t a0,b0,c0,d0;
  79. #if defined (ARM_MATH_DSP)
  80. /* Run the below code for Cortex-M4 and Cortex-M3 */
  81. uint32_t blkCnt; /* loop counter */
  82. /*loop Unrolling */
  83. blkCnt = numSamples >> 2U;
  84. /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
  85. ** a second loop below computes the remaining 1 to 3 samples. */
  86. while (blkCnt > 0U)
  87. {
  88. a0 = *pSrcA++;
  89. b0 = *pSrcA++;
  90. c0 = *pSrcB++;
  91. d0 = *pSrcB++;
  92. real_sum += a0 * c0;
  93. imag_sum += a0 * d0;
  94. real_sum -= b0 * d0;
  95. imag_sum += b0 * c0;
  96. a0 = *pSrcA++;
  97. b0 = *pSrcA++;
  98. c0 = *pSrcB++;
  99. d0 = *pSrcB++;
  100. real_sum += a0 * c0;
  101. imag_sum += a0 * d0;
  102. real_sum -= b0 * d0;
  103. imag_sum += b0 * c0;
  104. a0 = *pSrcA++;
  105. b0 = *pSrcA++;
  106. c0 = *pSrcB++;
  107. d0 = *pSrcB++;
  108. real_sum += a0 * c0;
  109. imag_sum += a0 * d0;
  110. real_sum -= b0 * d0;
  111. imag_sum += b0 * c0;
  112. a0 = *pSrcA++;
  113. b0 = *pSrcA++;
  114. c0 = *pSrcB++;
  115. d0 = *pSrcB++;
  116. real_sum += a0 * c0;
  117. imag_sum += a0 * d0;
  118. real_sum -= b0 * d0;
  119. imag_sum += b0 * c0;
  120. /* Decrement the loop counter */
  121. blkCnt--;
  122. }
  123. /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
  124. ** No loop unrolling is used. */
  125. blkCnt = numSamples & 0x3U;
  126. while (blkCnt > 0U)
  127. {
  128. a0 = *pSrcA++;
  129. b0 = *pSrcA++;
  130. c0 = *pSrcB++;
  131. d0 = *pSrcB++;
  132. real_sum += a0 * c0;
  133. imag_sum += a0 * d0;
  134. real_sum -= b0 * d0;
  135. imag_sum += b0 * c0;
  136. /* Decrement the loop counter */
  137. blkCnt--;
  138. }
  139. #else
  140. /* Run the below code for Cortex-M0 */
  141. while (numSamples > 0U)
  142. {
  143. a0 = *pSrcA++;
  144. b0 = *pSrcA++;
  145. c0 = *pSrcB++;
  146. d0 = *pSrcB++;
  147. real_sum += a0 * c0;
  148. imag_sum += a0 * d0;
  149. real_sum -= b0 * d0;
  150. imag_sum += b0 * c0;
  151. /* Decrement the loop counter */
  152. numSamples--;
  153. }
  154. #endif /* #if defined (ARM_MATH_DSP) */
  155. /* Store the real and imaginary results in the destination buffers */
  156. *realResult = real_sum;
  157. *imagResult = imag_sum;
  158. }
  159. /**
  160. * @} end of cmplx_dot_prod group
  161. */