arm_cmplx_dot_prod_q15.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_cmplx_dot_prod_q15.c
  4. * Description: Processing function for the Q15 Complex Dot product
  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. @addtogroup cmplx_dot_prod
  34. @{
  35. */
  36. /**
  37. @brief Q15 complex dot product.
  38. @param[in] pSrcA points to the first input vector
  39. @param[in] pSrcB points to the second input vector
  40. @param[in] numSamples number of samples in each vector
  41. @param[out] realResult real part of the result returned here
  42. @param[out] imagResult imaginary part of the result returned her
  43. @return none
  44. @par Scaling and Overflow Behavior
  45. The function is implemented using an internal 64-bit accumulator.
  46. The intermediate 1.15 by 1.15 multiplications are performed with full precision and yield a 2.30 result.
  47. These are accumulated in a 64-bit accumulator with 34.30 precision.
  48. As a final step, the accumulators are converted to 8.24 format.
  49. The return results <code>realResult</code> and <code>imagResult</code> are in 8.24 format.
  50. */
  51. #if defined(ARM_MATH_MVEI)
  52. void arm_cmplx_dot_prod_q15(
  53. const q15_t * pSrcA,
  54. const q15_t * pSrcB,
  55. uint32_t numSamples,
  56. q31_t * realResult,
  57. q31_t * imagResult)
  58. {
  59. uint32_t blockSize = numSamples * CMPLX_DIM; /* loop counters */
  60. uint32_t blkCnt;
  61. q15_t a0,b0,c0,d0;
  62. q63_t accReal = 0LL; q63_t accImag = 0LL;
  63. q15x8_t vecSrcA, vecSrcB;
  64. /* should give more freedom to generate stall free code */
  65. vecSrcA = vld1q(pSrcA);
  66. vecSrcB = vld1q(pSrcB);
  67. pSrcA += 8;
  68. pSrcB += 8;
  69. /* Compute 4 complex samples at a time */
  70. blkCnt = blockSize >> 3;
  71. while (blkCnt > 0U)
  72. {
  73. q15x8_t vecSrcC, vecSrcD;
  74. accReal = vmlsldavaq(accReal, vecSrcA, vecSrcB);
  75. vecSrcC = vld1q(pSrcA);
  76. pSrcA += 8;
  77. accImag = vmlaldavaxq(accImag, vecSrcA, vecSrcB);
  78. vecSrcD = vld1q(pSrcB);
  79. pSrcB += 8;
  80. accReal = vmlsldavaq(accReal, vecSrcC, vecSrcD);
  81. vecSrcA = vld1q(pSrcA);
  82. pSrcA += 8;
  83. accImag = vmlaldavaxq(accImag, vecSrcC, vecSrcD);
  84. vecSrcB = vld1q(pSrcB);
  85. pSrcB += 8;
  86. /*
  87. * Decrement the blockSize loop counter
  88. */
  89. blkCnt--;
  90. }
  91. /* Tail */
  92. pSrcA -= 8;
  93. pSrcB -= 8;
  94. blkCnt = (blockSize & 7) >> 1;
  95. while (blkCnt > 0U)
  96. {
  97. a0 = *pSrcA++;
  98. b0 = *pSrcA++;
  99. c0 = *pSrcB++;
  100. d0 = *pSrcB++;
  101. accReal += (q31_t)a0 * c0;
  102. accImag += (q31_t)a0 * d0;
  103. accReal -= (q31_t)b0 * d0;
  104. accImag += (q31_t)b0 * c0;
  105. /* Decrement loop counter */
  106. blkCnt--;
  107. }
  108. /* Store real and imaginary result in 8.24 format */
  109. /* Convert real data in 34.30 to 8.24 by 6 right shifts */
  110. *realResult = (q31_t) (accReal >> 6);
  111. /* Convert imaginary data in 34.30 to 8.24 by 6 right shifts */
  112. *imagResult = (q31_t) (accImag >> 6);
  113. }
  114. #else
  115. void arm_cmplx_dot_prod_q15(
  116. const q15_t * pSrcA,
  117. const q15_t * pSrcB,
  118. uint32_t numSamples,
  119. q31_t * realResult,
  120. q31_t * imagResult)
  121. {
  122. uint32_t blkCnt; /* Loop counter */
  123. q63_t real_sum = 0, imag_sum = 0; /* Temporary result variables */
  124. q15_t a0,b0,c0,d0;
  125. #if defined (ARM_MATH_LOOPUNROLL)
  126. /* Loop unrolling: Compute 4 outputs at a time */
  127. blkCnt = numSamples >> 2U;
  128. while (blkCnt > 0U)
  129. {
  130. a0 = *pSrcA++;
  131. b0 = *pSrcA++;
  132. c0 = *pSrcB++;
  133. d0 = *pSrcB++;
  134. real_sum += (q31_t)a0 * c0;
  135. imag_sum += (q31_t)a0 * d0;
  136. real_sum -= (q31_t)b0 * d0;
  137. imag_sum += (q31_t)b0 * c0;
  138. a0 = *pSrcA++;
  139. b0 = *pSrcA++;
  140. c0 = *pSrcB++;
  141. d0 = *pSrcB++;
  142. real_sum += (q31_t)a0 * c0;
  143. imag_sum += (q31_t)a0 * d0;
  144. real_sum -= (q31_t)b0 * d0;
  145. imag_sum += (q31_t)b0 * c0;
  146. a0 = *pSrcA++;
  147. b0 = *pSrcA++;
  148. c0 = *pSrcB++;
  149. d0 = *pSrcB++;
  150. real_sum += (q31_t)a0 * c0;
  151. imag_sum += (q31_t)a0 * d0;
  152. real_sum -= (q31_t)b0 * d0;
  153. imag_sum += (q31_t)b0 * c0;
  154. a0 = *pSrcA++;
  155. b0 = *pSrcA++;
  156. c0 = *pSrcB++;
  157. d0 = *pSrcB++;
  158. real_sum += (q31_t)a0 * c0;
  159. imag_sum += (q31_t)a0 * d0;
  160. real_sum -= (q31_t)b0 * d0;
  161. imag_sum += (q31_t)b0 * c0;
  162. /* Decrement loop counter */
  163. blkCnt--;
  164. }
  165. /* Loop unrolling: Compute remaining outputs */
  166. blkCnt = numSamples % 0x4U;
  167. #else
  168. /* Initialize blkCnt with number of samples */
  169. blkCnt = numSamples;
  170. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  171. while (blkCnt > 0U)
  172. {
  173. a0 = *pSrcA++;
  174. b0 = *pSrcA++;
  175. c0 = *pSrcB++;
  176. d0 = *pSrcB++;
  177. real_sum += (q31_t)a0 * c0;
  178. imag_sum += (q31_t)a0 * d0;
  179. real_sum -= (q31_t)b0 * d0;
  180. imag_sum += (q31_t)b0 * c0;
  181. /* Decrement loop counter */
  182. blkCnt--;
  183. }
  184. /* Store real and imaginary result in 8.24 format */
  185. /* Convert real data in 34.30 to 8.24 by 6 right shifts */
  186. *realResult = (q31_t) (real_sum >> 6);
  187. /* Convert imaginary data in 34.30 to 8.24 by 6 right shifts */
  188. *imagResult = (q31_t) (imag_sum >> 6);
  189. }
  190. #endif /* defined(ARM_MATH_MVEI) */
  191. /**
  192. @} end of cmplx_dot_prod group
  193. */