arm_cmplx_conj_q15.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_cmplx_conj_q15.c
  4. * Description: Q15 complex conjugate
  5. *
  6. * $Date: 27. January 2017
  7. * $Revision: V.1.5.1
  8. *
  9. * Target Processor: Cortex-M cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2017 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 *pSrc points to the input vector
  39. * @param *pDst points to the output vector
  40. * @param numSamples number of complex samples in each vector
  41. * @return none.
  42. *
  43. * <b>Scaling and Overflow Behavior:</b>
  44. * \par
  45. * The function uses saturating arithmetic.
  46. * The Q15 value -1 (0x8000) will be saturated to the maximum allowable positive value 0x7FFF.
  47. */
  48. void arm_cmplx_conj_q15(
  49. q15_t * pSrc,
  50. q15_t * pDst,
  51. uint32_t numSamples)
  52. {
  53. #if defined (ARM_MATH_DSP)
  54. /* Run the below code for Cortex-M4 and Cortex-M3 */
  55. uint32_t blkCnt; /* loop counter */
  56. q31_t in1, in2, in3, in4;
  57. q31_t zero = 0;
  58. /*loop Unrolling */
  59. blkCnt = numSamples >> 2U;
  60. /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
  61. ** a second loop below computes the remaining 1 to 3 samples. */
  62. while (blkCnt > 0U)
  63. {
  64. /* C[0]+jC[1] = A[0]+ j (-1) A[1] */
  65. /* Calculate Complex Conjugate and then store the results in the destination buffer. */
  66. in1 = *__SIMD32(pSrc)++;
  67. in2 = *__SIMD32(pSrc)++;
  68. in3 = *__SIMD32(pSrc)++;
  69. in4 = *__SIMD32(pSrc)++;
  70. #ifndef ARM_MATH_BIG_ENDIAN
  71. in1 = __QASX(zero, in1);
  72. in2 = __QASX(zero, in2);
  73. in3 = __QASX(zero, in3);
  74. in4 = __QASX(zero, in4);
  75. #else
  76. in1 = __QSAX(zero, in1);
  77. in2 = __QSAX(zero, in2);
  78. in3 = __QSAX(zero, in3);
  79. in4 = __QSAX(zero, in4);
  80. #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
  81. in1 = ((uint32_t) in1 >> 16) | ((uint32_t) in1 << 16);
  82. in2 = ((uint32_t) in2 >> 16) | ((uint32_t) in2 << 16);
  83. in3 = ((uint32_t) in3 >> 16) | ((uint32_t) in3 << 16);
  84. in4 = ((uint32_t) in4 >> 16) | ((uint32_t) in4 << 16);
  85. *__SIMD32(pDst)++ = in1;
  86. *__SIMD32(pDst)++ = in2;
  87. *__SIMD32(pDst)++ = in3;
  88. *__SIMD32(pDst)++ = in4;
  89. /* Decrement the loop counter */
  90. blkCnt--;
  91. }
  92. /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
  93. ** No loop unrolling is used. */
  94. blkCnt = numSamples % 0x4U;
  95. while (blkCnt > 0U)
  96. {
  97. /* C[0]+jC[1] = A[0]+ j (-1) A[1] */
  98. /* Calculate Complex Conjugate and then store the results in the destination buffer. */
  99. *pDst++ = *pSrc++;
  100. *pDst++ = __SSAT(-*pSrc++, 16);
  101. /* Decrement the loop counter */
  102. blkCnt--;
  103. }
  104. #else
  105. q15_t in;
  106. /* Run the below code for Cortex-M0 */
  107. while (numSamples > 0U)
  108. {
  109. /* realOut + j (imagOut) = realIn+ j (-1) imagIn */
  110. /* Calculate Complex Conjugate and then store the results in the destination buffer. */
  111. *pDst++ = *pSrc++;
  112. in = *pSrc++;
  113. *pDst++ = (in == (q15_t) 0x8000) ? 0x7fff : -in;
  114. /* Decrement the loop counter */
  115. numSamples--;
  116. }
  117. #endif /* #if defined (ARM_MATH_DSP) */
  118. }
  119. /**
  120. * @} end of cmplx_conj group
  121. */