A bundled STM32F10x Std Periph and CMSIS library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

224 lines
6.9 KiB

  1. /* ----------------------------------------------------------------------
  2. * Copyright (C) 2010-2014 ARM Limited. All rights reserved.
  3. *
  4. * $Date: 12. March 2014
  5. * $Revision: V1.4.4
  6. *
  7. * Project: CMSIS DSP Library
  8. * Title: arm_cmplx_mult_real_q31.c
  9. *
  10. * Description: Q31 complex by real multiplication
  11. *
  12. * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions
  16. * are met:
  17. * - Redistributions of source code must retain the above copyright
  18. * notice, this list of conditions and the following disclaimer.
  19. * - Redistributions in binary form must reproduce the above copyright
  20. * notice, this list of conditions and the following disclaimer in
  21. * the documentation and/or other materials provided with the
  22. * distribution.
  23. * - Neither the name of ARM LIMITED nor the names of its contributors
  24. * may be used to endorse or promote products derived from this
  25. * software without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  30. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  31. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  32. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  33. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  34. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  35. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  37. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  38. * POSSIBILITY OF SUCH DAMAGE.
  39. * -------------------------------------------------------------------- */
  40. #include "arm_math.h"
  41. /**
  42. * @ingroup groupCmplxMath
  43. */
  44. /**
  45. * @addtogroup CmplxByRealMult
  46. * @{
  47. */
  48. /**
  49. * @brief Q31 complex-by-real multiplication
  50. * @param[in] *pSrcCmplx points to the complex input vector
  51. * @param[in] *pSrcReal points to the real input vector
  52. * @param[out] *pCmplxDst points to the complex output vector
  53. * @param[in] numSamples number of samples in each vector
  54. * @return none.
  55. *
  56. * <b>Scaling and Overflow Behavior:</b>
  57. * \par
  58. * The function uses saturating arithmetic.
  59. * Results outside of the allowable Q31 range[0x80000000 0x7FFFFFFF] will be saturated.
  60. */
  61. void arm_cmplx_mult_real_q31(
  62. q31_t * pSrcCmplx,
  63. q31_t * pSrcReal,
  64. q31_t * pCmplxDst,
  65. uint32_t numSamples)
  66. {
  67. q31_t inA1; /* Temporary variable to store input value */
  68. #ifndef ARM_MATH_CM0_FAMILY
  69. /* Run the below code for Cortex-M4 and Cortex-M3 */
  70. uint32_t blkCnt; /* loop counters */
  71. q31_t inA2, inA3, inA4; /* Temporary variables to hold input data */
  72. q31_t inB1, inB2; /* Temporary variabels to hold input data */
  73. q31_t out1, out2, out3, out4; /* Temporary variables to hold output data */
  74. /* loop Unrolling */
  75. blkCnt = numSamples >> 2u;
  76. /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
  77. ** a second loop below computes the remaining 1 to 3 samples. */
  78. while(blkCnt > 0u)
  79. {
  80. /* C[2 * i] = A[2 * i] * B[i]. */
  81. /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */
  82. /* read real input from complex input buffer */
  83. inA1 = *pSrcCmplx++;
  84. inA2 = *pSrcCmplx++;
  85. /* read input from real input bufer */
  86. inB1 = *pSrcReal++;
  87. inB2 = *pSrcReal++;
  88. /* read imaginary input from complex input buffer */
  89. inA3 = *pSrcCmplx++;
  90. inA4 = *pSrcCmplx++;
  91. /* multiply complex input with real input */
  92. out1 = ((q63_t) inA1 * inB1) >> 32;
  93. out2 = ((q63_t) inA2 * inB1) >> 32;
  94. out3 = ((q63_t) inA3 * inB2) >> 32;
  95. out4 = ((q63_t) inA4 * inB2) >> 32;
  96. /* sature the result */
  97. out1 = __SSAT(out1, 31);
  98. out2 = __SSAT(out2, 31);
  99. out3 = __SSAT(out3, 31);
  100. out4 = __SSAT(out4, 31);
  101. /* get result in 1.31 format */
  102. out1 = out1 << 1;
  103. out2 = out2 << 1;
  104. out3 = out3 << 1;
  105. out4 = out4 << 1;
  106. /* store the result to destination buffer */
  107. *pCmplxDst++ = out1;
  108. *pCmplxDst++ = out2;
  109. *pCmplxDst++ = out3;
  110. *pCmplxDst++ = out4;
  111. /* read real input from complex input buffer */
  112. inA1 = *pSrcCmplx++;
  113. inA2 = *pSrcCmplx++;
  114. /* read input from real input bufer */
  115. inB1 = *pSrcReal++;
  116. inB2 = *pSrcReal++;
  117. /* read imaginary input from complex input buffer */
  118. inA3 = *pSrcCmplx++;
  119. inA4 = *pSrcCmplx++;
  120. /* multiply complex input with real input */
  121. out1 = ((q63_t) inA1 * inB1) >> 32;
  122. out2 = ((q63_t) inA2 * inB1) >> 32;
  123. out3 = ((q63_t) inA3 * inB2) >> 32;
  124. out4 = ((q63_t) inA4 * inB2) >> 32;
  125. /* sature the result */
  126. out1 = __SSAT(out1, 31);
  127. out2 = __SSAT(out2, 31);
  128. out3 = __SSAT(out3, 31);
  129. out4 = __SSAT(out4, 31);
  130. /* get result in 1.31 format */
  131. out1 = out1 << 1;
  132. out2 = out2 << 1;
  133. out3 = out3 << 1;
  134. out4 = out4 << 1;
  135. /* store the result to destination buffer */
  136. *pCmplxDst++ = out1;
  137. *pCmplxDst++ = out2;
  138. *pCmplxDst++ = out3;
  139. *pCmplxDst++ = out4;
  140. /* Decrement the numSamples loop counter */
  141. blkCnt--;
  142. }
  143. /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
  144. ** No loop unrolling is used. */
  145. blkCnt = numSamples % 0x4u;
  146. while(blkCnt > 0u)
  147. {
  148. /* C[2 * i] = A[2 * i] * B[i]. */
  149. /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */
  150. /* read real input from complex input buffer */
  151. inA1 = *pSrcCmplx++;
  152. inA2 = *pSrcCmplx++;
  153. /* read input from real input bufer */
  154. inB1 = *pSrcReal++;
  155. /* multiply complex input with real input */
  156. out1 = ((q63_t) inA1 * inB1) >> 32;
  157. out2 = ((q63_t) inA2 * inB1) >> 32;
  158. /* sature the result */
  159. out1 = __SSAT(out1, 31);
  160. out2 = __SSAT(out2, 31);
  161. /* get result in 1.31 format */
  162. out1 = out1 << 1;
  163. out2 = out2 << 1;
  164. /* store the result to destination buffer */
  165. *pCmplxDst++ = out1;
  166. *pCmplxDst++ = out2;
  167. /* Decrement the numSamples loop counter */
  168. blkCnt--;
  169. }
  170. #else
  171. /* Run the below code for Cortex-M0 */
  172. while(numSamples > 0u)
  173. {
  174. /* realOut = realA * realB. */
  175. /* imagReal = imagA * realB. */
  176. inA1 = *pSrcReal++;
  177. /* store the result in the destination buffer. */
  178. *pCmplxDst++ =
  179. (q31_t) clip_q63_to_q31(((q63_t) * pSrcCmplx++ * inA1) >> 31);
  180. *pCmplxDst++ =
  181. (q31_t) clip_q63_to_q31(((q63_t) * pSrcCmplx++ * inA1) >> 31);
  182. /* Decrement the numSamples loop counter */
  183. numSamples--;
  184. }
  185. #endif /* #ifndef ARM_MATH_CM0_FAMILY */
  186. }
  187. /**
  188. * @} end of CmplxByRealMult group
  189. */