arm_cmplx_conj_q31.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_cmplx_conj_q31.c
  4. * Description: Q31 complex conjugate
  5. *
  6. * $Date: 23 April 2021
  7. * $Revision: V1.9.0
  8. *
  9. * Target Processor: Cortex-M and Cortex-A cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2021 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 "dsp/complex_math_functions.h"
  29. /**
  30. @ingroup groupCmplxMath
  31. */
  32. /**
  33. @addtogroup cmplx_conj
  34. @{
  35. */
  36. /**
  37. @brief Q31 complex conjugate.
  38. @param[in] pSrc points to the input vector
  39. @param[out] pDst points to the output vector
  40. @param[in] numSamples number of samples in each vector
  41. @return none
  42. @par Scaling and Overflow Behavior
  43. The function uses saturating arithmetic.
  44. The Q31 value -1 (0x80000000) is saturated to the maximum allowable positive value 0x7FFFFFFF.
  45. */
  46. #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
  47. void arm_cmplx_conj_q31(
  48. const q31_t * pSrc,
  49. q31_t * pDst,
  50. uint32_t numSamples)
  51. {
  52. uint32_t blockSize = numSamples * CMPLX_DIM; /* loop counters */
  53. uint32_t blkCnt;
  54. q31x4x2_t vecSrc;
  55. q31_t in; /* Temporary input variable */
  56. q31x4_t zero;
  57. zero = vdupq_n_s32(0);
  58. /* Compute 4 real samples at a time */
  59. blkCnt = blockSize >> 3U;
  60. while (blkCnt > 0U)
  61. {
  62. vecSrc = vld2q(pSrc);
  63. vecSrc.val[1] = vqsubq(zero, vecSrc.val[1]);
  64. vst2q(pDst,vecSrc);
  65. /*
  66. * Decrement the blkCnt loop counter
  67. * Advance vector source and destination pointers
  68. */
  69. pSrc += 8;
  70. pDst += 8;
  71. blkCnt --;
  72. }
  73. /* Tail */
  74. blkCnt = (blockSize & 0x7) >> 1;
  75. while (blkCnt > 0U)
  76. {
  77. /* C[0] + jC[1] = A[0]+ j(-1)A[1] */
  78. /* Calculate Complex Conjugate and store result in destination buffer. */
  79. *pDst++ = *pSrc++;
  80. in = *pSrc++;
  81. *pDst++ = __QSUB(0, in);
  82. /* Decrement loop counter */
  83. blkCnt--;
  84. }
  85. }
  86. #else
  87. void arm_cmplx_conj_q31(
  88. const q31_t * pSrc,
  89. q31_t * pDst,
  90. uint32_t numSamples)
  91. {
  92. uint32_t blkCnt; /* Loop counter */
  93. q31_t in; /* Temporary input variable */
  94. #if defined (ARM_MATH_LOOPUNROLL)
  95. /* Loop unrolling: Compute 4 outputs at a time */
  96. blkCnt = numSamples >> 2U;
  97. while (blkCnt > 0U)
  98. {
  99. /* C[0] + jC[1] = A[0]+ j(-1)A[1] */
  100. /* Calculate Complex Conjugate and store result in destination buffer. */
  101. *pDst++ = *pSrc++;
  102. in = *pSrc++;
  103. #if defined (ARM_MATH_DSP)
  104. *pDst++ = __QSUB(0, in);
  105. #else
  106. *pDst++ = (in == INT32_MIN) ? INT32_MAX : -in;
  107. #endif
  108. *pDst++ = *pSrc++;
  109. in = *pSrc++;
  110. #if defined (ARM_MATH_DSP)
  111. *pDst++ = __QSUB(0, in);
  112. #else
  113. *pDst++ = (in == INT32_MIN) ? INT32_MAX : -in;
  114. #endif
  115. *pDst++ = *pSrc++;
  116. in = *pSrc++;
  117. #if defined (ARM_MATH_DSP)
  118. *pDst++ = __QSUB(0, in);
  119. #else
  120. *pDst++ = (in == INT32_MIN) ? INT32_MAX : -in;
  121. #endif
  122. *pDst++ = *pSrc++;
  123. in = *pSrc++;
  124. #if defined (ARM_MATH_DSP)
  125. *pDst++ = __QSUB(0, in);
  126. #else
  127. *pDst++ = (in == INT32_MIN) ? INT32_MAX : -in;
  128. #endif
  129. /* Decrement loop counter */
  130. blkCnt--;
  131. }
  132. /* Loop unrolling: Compute remaining outputs */
  133. blkCnt = numSamples % 0x4U;
  134. #else
  135. /* Initialize blkCnt with number of samples */
  136. blkCnt = numSamples;
  137. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  138. while (blkCnt > 0U)
  139. {
  140. /* C[0] + jC[1] = A[0]+ j(-1)A[1] */
  141. /* Calculate Complex Conjugate and store result in destination buffer. */
  142. *pDst++ = *pSrc++;
  143. in = *pSrc++;
  144. #if defined (ARM_MATH_DSP)
  145. *pDst++ = __QSUB(0, in);
  146. #else
  147. *pDst++ = (in == INT32_MIN) ? INT32_MAX : -in;
  148. #endif
  149. /* Decrement loop counter */
  150. blkCnt--;
  151. }
  152. }
  153. #endif /* defined(ARM_MATH_MVEI) */
  154. /**
  155. @} end of cmplx_conj group
  156. */