A bundled STM32F10x Std Periph and CMSIS library
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

327 lignes
9.4 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_cmplx_q31.c
  9. *
  10. * Description: Q31 complex-by-complex 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 CmplxByCmplxMult
  46. * @{
  47. */
  48. /**
  49. * @brief Q31 complex-by-complex multiplication
  50. * @param[in] *pSrcA points to the first input vector
  51. * @param[in] *pSrcB points to the second input vector
  52. * @param[out] *pDst points to the output vector
  53. * @param[in] numSamples number of complex samples in each vector
  54. * @return none.
  55. *
  56. * <b>Scaling and Overflow Behavior:</b>
  57. * \par
  58. * The function implements 1.31 by 1.31 multiplications and finally output is converted into 3.29 format.
  59. * Input down scaling is not required.
  60. */
  61. void arm_cmplx_mult_cmplx_q31(
  62. q31_t * pSrcA,
  63. q31_t * pSrcB,
  64. q31_t * pDst,
  65. uint32_t numSamples)
  66. {
  67. q31_t a, b, c, d; /* Temporary variables to store real and imaginary values */
  68. uint32_t blkCnt; /* loop counters */
  69. q31_t mul1, mul2, mul3, mul4;
  70. q31_t out1, out2;
  71. #ifndef ARM_MATH_CM0_FAMILY
  72. /* Run the below code for Cortex-M4 and Cortex-M3 */
  73. /* loop Unrolling */
  74. blkCnt = numSamples >> 2u;
  75. /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
  76. ** a second loop below computes the remaining 1 to 3 samples. */
  77. while(blkCnt > 0u)
  78. {
  79. /* C[2 * i] = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1]. */
  80. /* C[2 * i + 1] = A[2 * i] * B[2 * i + 1] + A[2 * i + 1] * B[2 * i]. */
  81. a = *pSrcA++;
  82. b = *pSrcA++;
  83. c = *pSrcB++;
  84. d = *pSrcB++;
  85. mul1 = (q31_t) (((q63_t) a * c) >> 32);
  86. mul2 = (q31_t) (((q63_t) b * d) >> 32);
  87. mul3 = (q31_t) (((q63_t) a * d) >> 32);
  88. mul4 = (q31_t) (((q63_t) b * c) >> 32);
  89. mul1 = (mul1 >> 1);
  90. mul2 = (mul2 >> 1);
  91. mul3 = (mul3 >> 1);
  92. mul4 = (mul4 >> 1);
  93. out1 = mul1 - mul2;
  94. out2 = mul3 + mul4;
  95. /* store the real result in 3.29 format in the destination buffer. */
  96. *pDst++ = out1;
  97. /* store the imag result in 3.29 format in the destination buffer. */
  98. *pDst++ = out2;
  99. a = *pSrcA++;
  100. b = *pSrcA++;
  101. c = *pSrcB++;
  102. d = *pSrcB++;
  103. mul1 = (q31_t) (((q63_t) a * c) >> 32);
  104. mul2 = (q31_t) (((q63_t) b * d) >> 32);
  105. mul3 = (q31_t) (((q63_t) a * d) >> 32);
  106. mul4 = (q31_t) (((q63_t) b * c) >> 32);
  107. mul1 = (mul1 >> 1);
  108. mul2 = (mul2 >> 1);
  109. mul3 = (mul3 >> 1);
  110. mul4 = (mul4 >> 1);
  111. out1 = mul1 - mul2;
  112. out2 = mul3 + mul4;
  113. /* store the real result in 3.29 format in the destination buffer. */
  114. *pDst++ = out1;
  115. /* store the imag result in 3.29 format in the destination buffer. */
  116. *pDst++ = out2;
  117. a = *pSrcA++;
  118. b = *pSrcA++;
  119. c = *pSrcB++;
  120. d = *pSrcB++;
  121. mul1 = (q31_t) (((q63_t) a * c) >> 32);
  122. mul2 = (q31_t) (((q63_t) b * d) >> 32);
  123. mul3 = (q31_t) (((q63_t) a * d) >> 32);
  124. mul4 = (q31_t) (((q63_t) b * c) >> 32);
  125. mul1 = (mul1 >> 1);
  126. mul2 = (mul2 >> 1);
  127. mul3 = (mul3 >> 1);
  128. mul4 = (mul4 >> 1);
  129. out1 = mul1 - mul2;
  130. out2 = mul3 + mul4;
  131. /* store the real result in 3.29 format in the destination buffer. */
  132. *pDst++ = out1;
  133. /* store the imag result in 3.29 format in the destination buffer. */
  134. *pDst++ = out2;
  135. a = *pSrcA++;
  136. b = *pSrcA++;
  137. c = *pSrcB++;
  138. d = *pSrcB++;
  139. mul1 = (q31_t) (((q63_t) a * c) >> 32);
  140. mul2 = (q31_t) (((q63_t) b * d) >> 32);
  141. mul3 = (q31_t) (((q63_t) a * d) >> 32);
  142. mul4 = (q31_t) (((q63_t) b * c) >> 32);
  143. mul1 = (mul1 >> 1);
  144. mul2 = (mul2 >> 1);
  145. mul3 = (mul3 >> 1);
  146. mul4 = (mul4 >> 1);
  147. out1 = mul1 - mul2;
  148. out2 = mul3 + mul4;
  149. /* store the real result in 3.29 format in the destination buffer. */
  150. *pDst++ = out1;
  151. /* store the imag result in 3.29 format in the destination buffer. */
  152. *pDst++ = out2;
  153. /* Decrement the blockSize loop counter */
  154. blkCnt--;
  155. }
  156. /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
  157. ** No loop unrolling is used. */
  158. blkCnt = numSamples % 0x4u;
  159. while(blkCnt > 0u)
  160. {
  161. /* C[2 * i] = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1]. */
  162. /* C[2 * i + 1] = A[2 * i] * B[2 * i + 1] + A[2 * i + 1] * B[2 * i]. */
  163. a = *pSrcA++;
  164. b = *pSrcA++;
  165. c = *pSrcB++;
  166. d = *pSrcB++;
  167. mul1 = (q31_t) (((q63_t) a * c) >> 32);
  168. mul2 = (q31_t) (((q63_t) b * d) >> 32);
  169. mul3 = (q31_t) (((q63_t) a * d) >> 32);
  170. mul4 = (q31_t) (((q63_t) b * c) >> 32);
  171. mul1 = (mul1 >> 1);
  172. mul2 = (mul2 >> 1);
  173. mul3 = (mul3 >> 1);
  174. mul4 = (mul4 >> 1);
  175. out1 = mul1 - mul2;
  176. out2 = mul3 + mul4;
  177. /* store the real result in 3.29 format in the destination buffer. */
  178. *pDst++ = out1;
  179. /* store the imag result in 3.29 format in the destination buffer. */
  180. *pDst++ = out2;
  181. /* Decrement the blockSize loop counter */
  182. blkCnt--;
  183. }
  184. #else
  185. /* Run the below code for Cortex-M0 */
  186. /* loop Unrolling */
  187. blkCnt = numSamples >> 1u;
  188. /* First part of the processing with loop unrolling. Compute 2 outputs at a time.
  189. ** a second loop below computes the remaining 1 sample. */
  190. while(blkCnt > 0u)
  191. {
  192. /* C[2 * i] = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1]. */
  193. /* C[2 * i + 1] = A[2 * i] * B[2 * i + 1] + A[2 * i + 1] * B[2 * i]. */
  194. a = *pSrcA++;
  195. b = *pSrcA++;
  196. c = *pSrcB++;
  197. d = *pSrcB++;
  198. mul1 = (q31_t) (((q63_t) a * c) >> 32);
  199. mul2 = (q31_t) (((q63_t) b * d) >> 32);
  200. mul3 = (q31_t) (((q63_t) a * d) >> 32);
  201. mul4 = (q31_t) (((q63_t) b * c) >> 32);
  202. mul1 = (mul1 >> 1);
  203. mul2 = (mul2 >> 1);
  204. mul3 = (mul3 >> 1);
  205. mul4 = (mul4 >> 1);
  206. out1 = mul1 - mul2;
  207. out2 = mul3 + mul4;
  208. /* store the real result in 3.29 format in the destination buffer. */
  209. *pDst++ = out1;
  210. /* store the imag result in 3.29 format in the destination buffer. */
  211. *pDst++ = out2;
  212. a = *pSrcA++;
  213. b = *pSrcA++;
  214. c = *pSrcB++;
  215. d = *pSrcB++;
  216. mul1 = (q31_t) (((q63_t) a * c) >> 32);
  217. mul2 = (q31_t) (((q63_t) b * d) >> 32);
  218. mul3 = (q31_t) (((q63_t) a * d) >> 32);
  219. mul4 = (q31_t) (((q63_t) b * c) >> 32);
  220. mul1 = (mul1 >> 1);
  221. mul2 = (mul2 >> 1);
  222. mul3 = (mul3 >> 1);
  223. mul4 = (mul4 >> 1);
  224. out1 = mul1 - mul2;
  225. out2 = mul3 + mul4;
  226. /* store the real result in 3.29 format in the destination buffer. */
  227. *pDst++ = out1;
  228. /* store the imag result in 3.29 format in the destination buffer. */
  229. *pDst++ = out2;
  230. /* Decrement the blockSize loop counter */
  231. blkCnt--;
  232. }
  233. /* If the blockSize is not a multiple of 2, compute any remaining output samples here.
  234. ** No loop unrolling is used. */
  235. blkCnt = numSamples % 0x2u;
  236. while(blkCnt > 0u)
  237. {
  238. /* C[2 * i] = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1]. */
  239. /* C[2 * i + 1] = A[2 * i] * B[2 * i + 1] + A[2 * i + 1] * B[2 * i]. */
  240. a = *pSrcA++;
  241. b = *pSrcA++;
  242. c = *pSrcB++;
  243. d = *pSrcB++;
  244. mul1 = (q31_t) (((q63_t) a * c) >> 32);
  245. mul2 = (q31_t) (((q63_t) b * d) >> 32);
  246. mul3 = (q31_t) (((q63_t) a * d) >> 32);
  247. mul4 = (q31_t) (((q63_t) b * c) >> 32);
  248. mul1 = (mul1 >> 1);
  249. mul2 = (mul2 >> 1);
  250. mul3 = (mul3 >> 1);
  251. mul4 = (mul4 >> 1);
  252. out1 = mul1 - mul2;
  253. out2 = mul3 + mul4;
  254. /* store the real result in 3.29 format in the destination buffer. */
  255. *pDst++ = out1;
  256. /* store the imag result in 3.29 format in the destination buffer. */
  257. *pDst++ = out2;
  258. /* Decrement the blockSize loop counter */
  259. blkCnt--;
  260. }
  261. #endif /* #ifndef ARM_MATH_CM0_FAMILY */
  262. }
  263. /**
  264. * @} end of CmplxByCmplxMult group
  265. */