arm_cmplx_conj_q31.c 4.5 KB

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