arm_cmplx_mult_cmplx_q15.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_cmplx_mult_cmplx_q15.c
  4. * Description: Q15 complex-by-complex multiplication
  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. * @addtogroup CmplxByCmplxMult
  34. * @{
  35. */
  36. /**
  37. * @brief Q15 complex-by-complex multiplication
  38. * @param[in] *pSrcA points to the first input vector
  39. * @param[in] *pSrcB points to the second input vector
  40. * @param[out] *pDst points to the output vector
  41. * @param[in] numSamples number of complex samples in each vector
  42. * @return none.
  43. *
  44. * <b>Scaling and Overflow Behavior:</b>
  45. * \par
  46. * The function implements 1.15 by 1.15 multiplications and finally output is converted into 3.13 format.
  47. */
  48. void arm_cmplx_mult_cmplx_q15(
  49. q15_t * pSrcA,
  50. q15_t * pSrcB,
  51. q15_t * pDst,
  52. uint32_t numSamples)
  53. {
  54. q15_t a, b, c, d; /* Temporary variables to store real and imaginary values */
  55. #if defined (ARM_MATH_DSP)
  56. /* Run the below code for Cortex-M4 and Cortex-M3 */
  57. uint32_t blkCnt; /* loop counters */
  58. /* loop Unrolling */
  59. blkCnt = numSamples >> 2U;
  60. /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
  61. ** a second loop below computes the remaining 1 to 3 samples. */
  62. while (blkCnt > 0U)
  63. {
  64. /* C[2 * i] = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1]. */
  65. /* C[2 * i + 1] = A[2 * i] * B[2 * i + 1] + A[2 * i + 1] * B[2 * i]. */
  66. a = *pSrcA++;
  67. b = *pSrcA++;
  68. c = *pSrcB++;
  69. d = *pSrcB++;
  70. /* store the result in 3.13 format in the destination buffer. */
  71. *pDst++ =
  72. (q15_t) (q31_t) (((q31_t) a * c) >> 17) - (((q31_t) b * d) >> 17);
  73. /* store the result in 3.13 format in the destination buffer. */
  74. *pDst++ =
  75. (q15_t) (q31_t) (((q31_t) a * d) >> 17) + (((q31_t) b * c) >> 17);
  76. a = *pSrcA++;
  77. b = *pSrcA++;
  78. c = *pSrcB++;
  79. d = *pSrcB++;
  80. /* store the result in 3.13 format in the destination buffer. */
  81. *pDst++ =
  82. (q15_t) (q31_t) (((q31_t) a * c) >> 17) - (((q31_t) b * d) >> 17);
  83. /* store the result in 3.13 format in the destination buffer. */
  84. *pDst++ =
  85. (q15_t) (q31_t) (((q31_t) a * d) >> 17) + (((q31_t) b * c) >> 17);
  86. a = *pSrcA++;
  87. b = *pSrcA++;
  88. c = *pSrcB++;
  89. d = *pSrcB++;
  90. /* store the result in 3.13 format in the destination buffer. */
  91. *pDst++ =
  92. (q15_t) (q31_t) (((q31_t) a * c) >> 17) - (((q31_t) b * d) >> 17);
  93. /* store the result in 3.13 format in the destination buffer. */
  94. *pDst++ =
  95. (q15_t) (q31_t) (((q31_t) a * d) >> 17) + (((q31_t) b * c) >> 17);
  96. a = *pSrcA++;
  97. b = *pSrcA++;
  98. c = *pSrcB++;
  99. d = *pSrcB++;
  100. /* store the result in 3.13 format in the destination buffer. */
  101. *pDst++ =
  102. (q15_t) (q31_t) (((q31_t) a * c) >> 17) - (((q31_t) b * d) >> 17);
  103. /* store the result in 3.13 format in the destination buffer. */
  104. *pDst++ =
  105. (q15_t) (q31_t) (((q31_t) a * d) >> 17) + (((q31_t) b * c) >> 17);
  106. /* Decrement the blockSize loop counter */
  107. blkCnt--;
  108. }
  109. /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
  110. ** No loop unrolling is used. */
  111. blkCnt = numSamples % 0x4U;
  112. while (blkCnt > 0U)
  113. {
  114. /* C[2 * i] = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1]. */
  115. /* C[2 * i + 1] = A[2 * i] * B[2 * i + 1] + A[2 * i + 1] * B[2 * i]. */
  116. a = *pSrcA++;
  117. b = *pSrcA++;
  118. c = *pSrcB++;
  119. d = *pSrcB++;
  120. /* store the result in 3.13 format in the destination buffer. */
  121. *pDst++ =
  122. (q15_t) (q31_t) (((q31_t) a * c) >> 17) - (((q31_t) b * d) >> 17);
  123. /* store the result in 3.13 format in the destination buffer. */
  124. *pDst++ =
  125. (q15_t) (q31_t) (((q31_t) a * d) >> 17) + (((q31_t) b * c) >> 17);
  126. /* Decrement the blockSize loop counter */
  127. blkCnt--;
  128. }
  129. #else
  130. /* Run the below code for Cortex-M0 */
  131. while (numSamples > 0U)
  132. {
  133. /* C[2 * i] = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1]. */
  134. /* C[2 * i + 1] = A[2 * i] * B[2 * i + 1] + A[2 * i + 1] * B[2 * i]. */
  135. a = *pSrcA++;
  136. b = *pSrcA++;
  137. c = *pSrcB++;
  138. d = *pSrcB++;
  139. /* store the result in 3.13 format in the destination buffer. */
  140. *pDst++ =
  141. (q15_t) (q31_t) (((q31_t) a * c) >> 17) - (((q31_t) b * d) >> 17);
  142. /* store the result in 3.13 format in the destination buffer. */
  143. *pDst++ =
  144. (q15_t) (q31_t) (((q31_t) a * d) >> 17) + (((q31_t) b * c) >> 17);
  145. /* Decrement the blockSize loop counter */
  146. numSamples--;
  147. }
  148. #endif /* #if defined (ARM_MATH_DSP) */
  149. }
  150. /**
  151. * @} end of CmplxByCmplxMult group
  152. */