arm_cmplx_conj_q31.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_cmplx_conj_q31.c
  4. * Description: Q31 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 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. @return none
  42. @par Scaling and Overflow Behavior
  43. The function uses saturating arithmetic.
  44. The Q31 value -1 (0x80000000) is saturated to the maximum allowable positive value 0x7FFFFFFF.
  45. */
  46. void arm_cmplx_conj_q31(
  47. const q31_t * pSrc,
  48. q31_t * pDst,
  49. uint32_t numSamples)
  50. {
  51. uint32_t blkCnt; /* Loop counter */
  52. q31_t in; /* Temporary input variable */
  53. #if defined (ARM_MATH_LOOPUNROLL)
  54. /* Loop unrolling: Compute 4 outputs at a time */
  55. blkCnt = numSamples >> 2U;
  56. while (blkCnt > 0U)
  57. {
  58. /* C[0] + jC[1] = A[0]+ j(-1)A[1] */
  59. /* Calculate Complex Conjugate and store result in destination buffer. */
  60. *pDst++ = *pSrc++;
  61. in = *pSrc++;
  62. #if defined (ARM_MATH_DSP)
  63. *pDst++ = __QSUB(0, in);
  64. #else
  65. *pDst++ = (in == INT32_MIN) ? INT32_MAX : -in;
  66. #endif
  67. *pDst++ = *pSrc++;
  68. in = *pSrc++;
  69. #if defined (ARM_MATH_DSP)
  70. *pDst++ = __QSUB(0, in);
  71. #else
  72. *pDst++ = (in == INT32_MIN) ? INT32_MAX : -in;
  73. #endif
  74. *pDst++ = *pSrc++;
  75. in = *pSrc++;
  76. #if defined (ARM_MATH_DSP)
  77. *pDst++ = __QSUB(0, in);
  78. #else
  79. *pDst++ = (in == INT32_MIN) ? INT32_MAX : -in;
  80. #endif
  81. *pDst++ = *pSrc++;
  82. in = *pSrc++;
  83. #if defined (ARM_MATH_DSP)
  84. *pDst++ = __QSUB(0, in);
  85. #else
  86. *pDst++ = (in == INT32_MIN) ? INT32_MAX : -in;
  87. #endif
  88. /* Decrement loop counter */
  89. blkCnt--;
  90. }
  91. /* Loop unrolling: Compute remaining outputs */
  92. blkCnt = numSamples % 0x4U;
  93. #else
  94. /* Initialize blkCnt with number of samples */
  95. blkCnt = numSamples;
  96. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  97. while (blkCnt > 0U)
  98. {
  99. /* C[0] + jC[1] = A[0]+ j(-1)A[1] */
  100. /* Calculate Complex Conjugate and store result in destination buffer. */
  101. *pDst++ = *pSrc++;
  102. in = *pSrc++;
  103. #if defined (ARM_MATH_DSP)
  104. *pDst++ = __QSUB(0, in);
  105. #else
  106. *pDst++ = (in == INT32_MIN) ? INT32_MAX : -in;
  107. #endif
  108. /* Decrement loop counter */
  109. blkCnt--;
  110. }
  111. }
  112. /**
  113. @} end of cmplx_conj group
  114. */