Keyboard firmwares for Atmel AVR and Cortex-M
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.

arm_cmplx_dot_prod_q31.c 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* ----------------------------------------------------------------------
  2. * Copyright (C) 2010-2013 ARM Limited. All rights reserved.
  3. *
  4. * $Date: 17. January 2013
  5. * $Revision: V1.4.1
  6. *
  7. * Project: CMSIS DSP Library
  8. * Title: arm_cmplx_dot_prod_q31.c
  9. *
  10. * Description: Q31 complex dot product
  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 cmplx_dot_prod
  46. * @{
  47. */
  48. /**
  49. * @brief Q31 complex dot product
  50. * @param *pSrcA points to the first input vector
  51. * @param *pSrcB points to the second input vector
  52. * @param numSamples number of complex samples in each vector
  53. * @param *realResult real part of the result returned here
  54. * @param *imagResult imaginary part of the result returned here
  55. * @return none.
  56. *
  57. * <b>Scaling and Overflow Behavior:</b>
  58. * \par
  59. * The function is implemented using an internal 64-bit accumulator.
  60. * The intermediate 1.31 by 1.31 multiplications are performed with 64-bit precision and then shifted to 16.48 format.
  61. * The internal real and imaginary accumulators are in 16.48 format and provide 15 guard bits.
  62. * Additions are nonsaturating and no overflow will occur as long as <code>numSamples</code> is less than 32768.
  63. * The return results <code>realResult</code> and <code>imagResult</code> are in 16.48 format.
  64. * Input down scaling is not required.
  65. */
  66. void arm_cmplx_dot_prod_q31(
  67. q31_t * pSrcA,
  68. q31_t * pSrcB,
  69. uint32_t numSamples,
  70. q63_t * realResult,
  71. q63_t * imagResult)
  72. {
  73. q63_t real_sum = 0, imag_sum = 0; /* Temporary result storage */
  74. #ifndef ARM_MATH_CM0_FAMILY
  75. /* Run the below code for Cortex-M4 and Cortex-M3 */
  76. uint32_t blkCnt; /* loop counter */
  77. /*loop Unrolling */
  78. blkCnt = numSamples >> 2u;
  79. /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
  80. ** a second loop below computes the remaining 1 to 3 samples. */
  81. while(blkCnt > 0u)
  82. {
  83. /* CReal = A[0]* B[0] + A[2]* B[2] + A[4]* B[4] + .....+ A[numSamples-2]* B[numSamples-2] */
  84. /* Convert real data in 2.62 to 16.48 by 14 right shifts */
  85. real_sum += (q63_t) * pSrcA++ * (*pSrcB++) >> 14;
  86. /* CImag = A[1]* B[1] + A[3]* B[3] + A[5]* B[5] + .....+ A[numSamples-1]* B[numSamples-1] */
  87. /* Convert imag data in 2.62 to 16.48 by 14 right shifts */
  88. imag_sum += (q63_t) * pSrcA++ * (*pSrcB++) >> 14;
  89. real_sum += (q63_t) * pSrcA++ * (*pSrcB++) >> 14;
  90. imag_sum += (q63_t) * pSrcA++ * (*pSrcB++) >> 14;
  91. real_sum += (q63_t) * pSrcA++ * (*pSrcB++) >> 14;
  92. imag_sum += (q63_t) * pSrcA++ * (*pSrcB++) >> 14;
  93. real_sum += (q63_t) * pSrcA++ * (*pSrcB++) >> 14;
  94. imag_sum += (q63_t) * pSrcA++ * (*pSrcB++) >> 14;
  95. /* Decrement the loop counter */
  96. blkCnt--;
  97. }
  98. /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
  99. ** No loop unrolling is used. */
  100. blkCnt = numSamples % 0x4u;
  101. while(blkCnt > 0u)
  102. {
  103. /* CReal = A[0]* B[0] + A[2]* B[2] + A[4]* B[4] + .....+ A[numSamples-2]* B[numSamples-2] */
  104. real_sum += (q63_t) * pSrcA++ * (*pSrcB++) >> 14;
  105. /* CImag = A[1]* B[1] + A[3]* B[3] + A[5]* B[5] + .....+ A[numSamples-1]* B[numSamples-1] */
  106. imag_sum += (q63_t) * pSrcA++ * (*pSrcB++) >> 14;
  107. /* Decrement the loop counter */
  108. blkCnt--;
  109. }
  110. #else
  111. /* Run the below code for Cortex-M0 */
  112. while(numSamples > 0u)
  113. {
  114. /* outReal = realA[0]* realB[0] + realA[2]* realB[2] + realA[4]* realB[4] + .....+ realA[numSamples-2]* realB[numSamples-2] */
  115. real_sum += (q63_t) * pSrcA++ * (*pSrcB++) >> 14;
  116. /* outImag = imagA[1]* imagB[1] + imagA[3]* imagB[3] + imagA[5]* imagB[5] + .....+ imagA[numSamples-1]* imagB[numSamples-1] */
  117. imag_sum += (q63_t) * pSrcA++ * (*pSrcB++) >> 14;
  118. /* Decrement the loop counter */
  119. numSamples--;
  120. }
  121. #endif /* #ifndef ARM_MATH_CM0_FAMILY */
  122. /* Store the real and imaginary results in 16.48 format */
  123. *realResult = real_sum;
  124. *imagResult = imag_sum;
  125. }
  126. /**
  127. * @} end of cmplx_dot_prod group
  128. */