arm_cmplx_conj_q15.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_cmplx_conj_q15.c
  4. * Description: Q15 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 Q15 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 Q15 value -1 (0x8000) is saturated to the maximum allowable positive value 0x7FFF.
  45. */
  46. #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
  47. void arm_cmplx_conj_q15(
  48. const q15_t * pSrc,
  49. q15_t * pDst,
  50. uint32_t numSamples)
  51. {
  52. uint32_t blockSize = numSamples * CMPLX_DIM; /* loop counters */
  53. uint32_t blkCnt;
  54. q31_t in1;
  55. q15x8x2_t vecSrc;
  56. q15x8_t zero;
  57. zero = vdupq_n_s16(0);
  58. /* Compute 8 real samples at a time */
  59. blkCnt = blockSize >> 4U;
  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 += 16;
  70. pDst += 16;
  71. blkCnt --;
  72. }
  73. /* Tail */
  74. blkCnt = (blockSize & 0xF) >> 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. in1 = *pSrc++;
  81. *pDst++ = __SSAT(-in1, 16);
  82. /* Decrement loop counter */
  83. blkCnt--;
  84. }
  85. }
  86. #else
  87. void arm_cmplx_conj_q15(
  88. const q15_t * pSrc,
  89. q15_t * pDst,
  90. uint32_t numSamples)
  91. {
  92. uint32_t blkCnt; /* Loop counter */
  93. q31_t in1; /* Temporary input variable */
  94. #if defined (ARM_MATH_LOOPUNROLL) && defined (ARM_MATH_DSP)
  95. q31_t in2, in3, in4; /* Temporary input variables */
  96. #endif
  97. #if defined (ARM_MATH_LOOPUNROLL)
  98. /* Loop unrolling: Compute 4 outputs at a time */
  99. blkCnt = numSamples >> 2U;
  100. while (blkCnt > 0U)
  101. {
  102. /* C[0] + jC[1] = A[0]+ j(-1)A[1] */
  103. /* Calculate Complex Conjugate and store result in destination buffer. */
  104. #if defined (ARM_MATH_DSP)
  105. in1 = read_q15x2_ia (&pSrc);
  106. in2 = read_q15x2_ia (&pSrc);
  107. in3 = read_q15x2_ia (&pSrc);
  108. in4 = read_q15x2_ia (&pSrc);
  109. #ifndef ARM_MATH_BIG_ENDIAN
  110. in1 = __QASX(0, in1);
  111. in2 = __QASX(0, in2);
  112. in3 = __QASX(0, in3);
  113. in4 = __QASX(0, in4);
  114. #else
  115. in1 = __QSAX(0, in1);
  116. in2 = __QSAX(0, in2);
  117. in3 = __QSAX(0, in3);
  118. in4 = __QSAX(0, in4);
  119. #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
  120. in1 = ((uint32_t) in1 >> 16) | ((uint32_t) in1 << 16);
  121. in2 = ((uint32_t) in2 >> 16) | ((uint32_t) in2 << 16);
  122. in3 = ((uint32_t) in3 >> 16) | ((uint32_t) in3 << 16);
  123. in4 = ((uint32_t) in4 >> 16) | ((uint32_t) in4 << 16);
  124. write_q15x2_ia (&pDst, in1);
  125. write_q15x2_ia (&pDst, in2);
  126. write_q15x2_ia (&pDst, in3);
  127. write_q15x2_ia (&pDst, in4);
  128. #else
  129. *pDst++ = *pSrc++;
  130. in1 = *pSrc++;
  131. *pDst++ = (in1 == (q15_t) 0x8000) ? (q15_t) 0x7fff : -in1;
  132. *pDst++ = *pSrc++;
  133. in1 = *pSrc++;
  134. *pDst++ = (in1 == (q15_t) 0x8000) ? (q15_t) 0x7fff : -in1;
  135. *pDst++ = *pSrc++;
  136. in1 = *pSrc++;
  137. *pDst++ = (in1 == (q15_t) 0x8000) ? (q15_t) 0x7fff : -in1;
  138. *pDst++ = *pSrc++;
  139. in1 = *pSrc++;
  140. *pDst++ = (in1 == (q15_t) 0x8000) ? (q15_t) 0x7fff : -in1;
  141. #endif /* #if defined (ARM_MATH_DSP) */
  142. /* Decrement loop counter */
  143. blkCnt--;
  144. }
  145. /* Loop unrolling: Compute remaining outputs */
  146. blkCnt = numSamples % 0x4U;
  147. #else
  148. /* Initialize blkCnt with number of samples */
  149. blkCnt = numSamples;
  150. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  151. while (blkCnt > 0U)
  152. {
  153. /* C[0] + jC[1] = A[0]+ j(-1)A[1] */
  154. /* Calculate Complex Conjugate and store result in destination buffer. */
  155. *pDst++ = *pSrc++;
  156. in1 = *pSrc++;
  157. #if defined (ARM_MATH_DSP)
  158. *pDst++ = __SSAT(-in1, 16);
  159. #else
  160. *pDst++ = (in1 == (q15_t) 0x8000) ? (q15_t) 0x7fff : -in1;
  161. #endif
  162. /* Decrement loop counter */
  163. blkCnt--;
  164. }
  165. }
  166. #endif /* defined(ARM_MATH_MVEI) */
  167. /**
  168. @} end of cmplx_conj group
  169. */