arm_cmplx_conj_q15.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_cmplx_conj_q15.c
  4. * Description: Q15 complex conjugate
  5. *
  6. * $Date: 18. March 2019
  7. * $Revision: V1.6.0
  8. *
  9. * Target Processor: Cortex-M cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2019 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 "arm_math.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. void arm_cmplx_conj_q15(
  47. const q15_t * pSrc,
  48. q15_t * pDst,
  49. uint32_t numSamples)
  50. {
  51. uint32_t blkCnt; /* Loop counter */
  52. q31_t in1; /* Temporary input variable */
  53. #if defined (ARM_MATH_LOOPUNROLL) && defined (ARM_MATH_DSP)
  54. q31_t in2, in3, in4; /* Temporary input variables */
  55. #endif
  56. #if defined (ARM_MATH_LOOPUNROLL)
  57. /* Loop unrolling: Compute 4 outputs at a time */
  58. blkCnt = numSamples >> 2U;
  59. while (blkCnt > 0U)
  60. {
  61. /* C[0] + jC[1] = A[0]+ j(-1)A[1] */
  62. /* Calculate Complex Conjugate and store result in destination buffer. */
  63. #if defined (ARM_MATH_DSP)
  64. in1 = read_q15x2_ia ((q15_t **) &pSrc);
  65. in2 = read_q15x2_ia ((q15_t **) &pSrc);
  66. in3 = read_q15x2_ia ((q15_t **) &pSrc);
  67. in4 = read_q15x2_ia ((q15_t **) &pSrc);
  68. #ifndef ARM_MATH_BIG_ENDIAN
  69. in1 = __QASX(0, in1);
  70. in2 = __QASX(0, in2);
  71. in3 = __QASX(0, in3);
  72. in4 = __QASX(0, in4);
  73. #else
  74. in1 = __QSAX(0, in1);
  75. in2 = __QSAX(0, in2);
  76. in3 = __QSAX(0, in3);
  77. in4 = __QSAX(0, in4);
  78. #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
  79. in1 = ((uint32_t) in1 >> 16) | ((uint32_t) in1 << 16);
  80. in2 = ((uint32_t) in2 >> 16) | ((uint32_t) in2 << 16);
  81. in3 = ((uint32_t) in3 >> 16) | ((uint32_t) in3 << 16);
  82. in4 = ((uint32_t) in4 >> 16) | ((uint32_t) in4 << 16);
  83. write_q15x2_ia (&pDst, in1);
  84. write_q15x2_ia (&pDst, in2);
  85. write_q15x2_ia (&pDst, in3);
  86. write_q15x2_ia (&pDst, in4);
  87. #else
  88. *pDst++ = *pSrc++;
  89. in1 = *pSrc++;
  90. *pDst++ = (in1 == (q15_t) 0x8000) ? (q15_t) 0x7fff : -in1;
  91. *pDst++ = *pSrc++;
  92. in1 = *pSrc++;
  93. *pDst++ = (in1 == (q15_t) 0x8000) ? (q15_t) 0x7fff : -in1;
  94. *pDst++ = *pSrc++;
  95. in1 = *pSrc++;
  96. *pDst++ = (in1 == (q15_t) 0x8000) ? (q15_t) 0x7fff : -in1;
  97. *pDst++ = *pSrc++;
  98. in1 = *pSrc++;
  99. *pDst++ = (in1 == (q15_t) 0x8000) ? (q15_t) 0x7fff : -in1;
  100. #endif /* #if defined (ARM_MATH_DSP) */
  101. /* Decrement loop counter */
  102. blkCnt--;
  103. }
  104. /* Loop unrolling: Compute remaining outputs */
  105. blkCnt = numSamples % 0x4U;
  106. #else
  107. /* Initialize blkCnt with number of samples */
  108. blkCnt = numSamples;
  109. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  110. while (blkCnt > 0U)
  111. {
  112. /* C[0] + jC[1] = A[0]+ j(-1)A[1] */
  113. /* Calculate Complex Conjugate and store result in destination buffer. */
  114. *pDst++ = *pSrc++;
  115. in1 = *pSrc++;
  116. #if defined (ARM_MATH_DSP)
  117. *pDst++ = __SSAT(-in1, 16);
  118. #else
  119. *pDst++ = (in1 == (q15_t) 0x8000) ? (q15_t) 0x7fff : -in1;
  120. #endif
  121. /* Decrement loop counter */
  122. blkCnt--;
  123. }
  124. }
  125. /**
  126. @} end of cmplx_conj group
  127. */