arm_cmplx_conj_q15.c 5.3 KB

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