arm_cmplx_mult_real_q31.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_cmplx_mult_real_q31.c
  4. * Description: Q31 complex by real 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 CmplxByRealMult
  34. * @{
  35. */
  36. /**
  37. * @brief Q31 complex-by-real multiplication
  38. * @param[in] *pSrcCmplx points to the complex input vector
  39. * @param[in] *pSrcReal points to the real input vector
  40. * @param[out] *pCmplxDst points to the complex output vector
  41. * @param[in] numSamples number of samples in each vector
  42. * @return none.
  43. *
  44. * <b>Scaling and Overflow Behavior:</b>
  45. * \par
  46. * The function uses saturating arithmetic.
  47. * Results outside of the allowable Q31 range[0x80000000 0x7FFFFFFF] will be saturated.
  48. */
  49. void arm_cmplx_mult_real_q31(
  50. q31_t * pSrcCmplx,
  51. q31_t * pSrcReal,
  52. q31_t * pCmplxDst,
  53. uint32_t numSamples)
  54. {
  55. q31_t inA1; /* Temporary variable to store input value */
  56. #if defined (ARM_MATH_DSP)
  57. /* Run the below code for Cortex-M4 and Cortex-M3 */
  58. uint32_t blkCnt; /* loop counters */
  59. q31_t inA2, inA3, inA4; /* Temporary variables to hold input data */
  60. q31_t inB1, inB2; /* Temporary variabels to hold input data */
  61. q31_t out1, out2, out3, out4; /* Temporary variables to hold output data */
  62. /* loop Unrolling */
  63. blkCnt = numSamples >> 2U;
  64. /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
  65. ** a second loop below computes the remaining 1 to 3 samples. */
  66. while (blkCnt > 0U)
  67. {
  68. /* C[2 * i] = A[2 * i] * B[i]. */
  69. /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */
  70. /* read real input from complex input buffer */
  71. inA1 = *pSrcCmplx++;
  72. inA2 = *pSrcCmplx++;
  73. /* read input from real input bufer */
  74. inB1 = *pSrcReal++;
  75. inB2 = *pSrcReal++;
  76. /* read imaginary input from complex input buffer */
  77. inA3 = *pSrcCmplx++;
  78. inA4 = *pSrcCmplx++;
  79. /* multiply complex input with real input */
  80. out1 = ((q63_t) inA1 * inB1) >> 32;
  81. out2 = ((q63_t) inA2 * inB1) >> 32;
  82. out3 = ((q63_t) inA3 * inB2) >> 32;
  83. out4 = ((q63_t) inA4 * inB2) >> 32;
  84. /* sature the result */
  85. out1 = __SSAT(out1, 31);
  86. out2 = __SSAT(out2, 31);
  87. out3 = __SSAT(out3, 31);
  88. out4 = __SSAT(out4, 31);
  89. /* get result in 1.31 format */
  90. out1 = out1 << 1;
  91. out2 = out2 << 1;
  92. out3 = out3 << 1;
  93. out4 = out4 << 1;
  94. /* store the result to destination buffer */
  95. *pCmplxDst++ = out1;
  96. *pCmplxDst++ = out2;
  97. *pCmplxDst++ = out3;
  98. *pCmplxDst++ = out4;
  99. /* read real input from complex input buffer */
  100. inA1 = *pSrcCmplx++;
  101. inA2 = *pSrcCmplx++;
  102. /* read input from real input bufer */
  103. inB1 = *pSrcReal++;
  104. inB2 = *pSrcReal++;
  105. /* read imaginary input from complex input buffer */
  106. inA3 = *pSrcCmplx++;
  107. inA4 = *pSrcCmplx++;
  108. /* multiply complex input with real input */
  109. out1 = ((q63_t) inA1 * inB1) >> 32;
  110. out2 = ((q63_t) inA2 * inB1) >> 32;
  111. out3 = ((q63_t) inA3 * inB2) >> 32;
  112. out4 = ((q63_t) inA4 * inB2) >> 32;
  113. /* sature the result */
  114. out1 = __SSAT(out1, 31);
  115. out2 = __SSAT(out2, 31);
  116. out3 = __SSAT(out3, 31);
  117. out4 = __SSAT(out4, 31);
  118. /* get result in 1.31 format */
  119. out1 = out1 << 1;
  120. out2 = out2 << 1;
  121. out3 = out3 << 1;
  122. out4 = out4 << 1;
  123. /* store the result to destination buffer */
  124. *pCmplxDst++ = out1;
  125. *pCmplxDst++ = out2;
  126. *pCmplxDst++ = out3;
  127. *pCmplxDst++ = out4;
  128. /* Decrement the numSamples loop counter */
  129. blkCnt--;
  130. }
  131. /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
  132. ** No loop unrolling is used. */
  133. blkCnt = numSamples % 0x4U;
  134. while (blkCnt > 0U)
  135. {
  136. /* C[2 * i] = A[2 * i] * B[i]. */
  137. /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */
  138. /* read real input from complex input buffer */
  139. inA1 = *pSrcCmplx++;
  140. inA2 = *pSrcCmplx++;
  141. /* read input from real input bufer */
  142. inB1 = *pSrcReal++;
  143. /* multiply complex input with real input */
  144. out1 = ((q63_t) inA1 * inB1) >> 32;
  145. out2 = ((q63_t) inA2 * inB1) >> 32;
  146. /* sature the result */
  147. out1 = __SSAT(out1, 31);
  148. out2 = __SSAT(out2, 31);
  149. /* get result in 1.31 format */
  150. out1 = out1 << 1;
  151. out2 = out2 << 1;
  152. /* store the result to destination buffer */
  153. *pCmplxDst++ = out1;
  154. *pCmplxDst++ = out2;
  155. /* Decrement the numSamples loop counter */
  156. blkCnt--;
  157. }
  158. #else
  159. /* Run the below code for Cortex-M0 */
  160. while (numSamples > 0U)
  161. {
  162. /* realOut = realA * realB. */
  163. /* imagReal = imagA * realB. */
  164. inA1 = *pSrcReal++;
  165. /* store the result in the destination buffer. */
  166. *pCmplxDst++ =
  167. (q31_t) clip_q63_to_q31(((q63_t) * pSrcCmplx++ * inA1) >> 31);
  168. *pCmplxDst++ =
  169. (q31_t) clip_q63_to_q31(((q63_t) * pSrcCmplx++ * inA1) >> 31);
  170. /* Decrement the numSamples loop counter */
  171. numSamples--;
  172. }
  173. #endif /* #if defined (ARM_MATH_DSP) */
  174. }
  175. /**
  176. * @} end of CmplxByRealMult group
  177. */