arm_cmplx_conj_q31.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_cmplx_conj_q31.c
  4. * Description: Q31 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 Q31 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 Q31 value -1 (0x80000000) will be saturated to the maximum allowable positive value 0x7FFFFFFF.
  47. */
  48. void arm_cmplx_conj_q31(
  49. q31_t * pSrc,
  50. q31_t * pDst,
  51. uint32_t numSamples)
  52. {
  53. uint32_t blkCnt; /* loop counter */
  54. q31_t in; /* Input value */
  55. #if defined (ARM_MATH_DSP)
  56. /* Run the below code for Cortex-M4 and Cortex-M3 */
  57. q31_t inR1, inR2, inR3, inR4; /* Temporary real variables */
  58. q31_t inI1, inI2, inI3, inI4; /* Temporary imaginary variables */
  59. /*loop Unrolling */
  60. blkCnt = numSamples >> 2U;
  61. /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
  62. ** a second loop below computes the remaining 1 to 3 samples. */
  63. while (blkCnt > 0U)
  64. {
  65. /* C[0]+jC[1] = A[0]+ j (-1) A[1] */
  66. /* Calculate Complex Conjugate and then store the results in the destination buffer. */
  67. /* Saturated to 0x7fffffff if the input is -1(0x80000000) */
  68. /* read real input sample */
  69. inR1 = pSrc[0];
  70. /* store real input sample */
  71. pDst[0] = inR1;
  72. /* read imaginary input sample */
  73. inI1 = pSrc[1];
  74. /* read real input sample */
  75. inR2 = pSrc[2];
  76. /* store real input sample */
  77. pDst[2] = inR2;
  78. /* read imaginary input sample */
  79. inI2 = pSrc[3];
  80. /* negate imaginary input sample */
  81. inI1 = __QSUB(0, inI1);
  82. /* read real input sample */
  83. inR3 = pSrc[4];
  84. /* store real input sample */
  85. pDst[4] = inR3;
  86. /* read imaginary input sample */
  87. inI3 = pSrc[5];
  88. /* negate imaginary input sample */
  89. inI2 = __QSUB(0, inI2);
  90. /* read real input sample */
  91. inR4 = pSrc[6];
  92. /* store real input sample */
  93. pDst[6] = inR4;
  94. /* negate imaginary input sample */
  95. inI3 = __QSUB(0, inI3);
  96. /* store imaginary input sample */
  97. inI4 = pSrc[7];
  98. /* store imaginary input samples */
  99. pDst[1] = inI1;
  100. /* negate imaginary input sample */
  101. inI4 = __QSUB(0, inI4);
  102. /* store imaginary input samples */
  103. pDst[3] = inI2;
  104. /* increment source pointer by 8 to proecess next samples */
  105. pSrc += 8U;
  106. /* store imaginary input samples */
  107. pDst[5] = inI3;
  108. pDst[7] = inI4;
  109. /* increment destination pointer by 8 to process next samples */
  110. pDst += 8U;
  111. /* Decrement the loop counter */
  112. blkCnt--;
  113. }
  114. /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
  115. ** No loop unrolling is used. */
  116. blkCnt = numSamples % 0x4U;
  117. #else
  118. /* Run the below code for Cortex-M0 */
  119. blkCnt = numSamples;
  120. #endif /* #if defined (ARM_MATH_DSP) */
  121. while (blkCnt > 0U)
  122. {
  123. /* C[0]+jC[1] = A[0]+ j (-1) A[1] */
  124. /* Calculate Complex Conjugate and then store the results in the destination buffer. */
  125. /* Saturated to 0x7fffffff if the input is -1(0x80000000) */
  126. *pDst++ = *pSrc++;
  127. in = *pSrc++;
  128. *pDst++ = (in == INT32_MIN) ? INT32_MAX : -in;
  129. /* Decrement the loop counter */
  130. blkCnt--;
  131. }
  132. }
  133. /**
  134. * @} end of cmplx_conj group
  135. */