arm_cmplx_conj_f16.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_cmplx_conj_f16.c
  4. * Description: Floating-point complex conjugate
  5. *
  6. *
  7. * Target Processor: Cortex-M cores
  8. * -------------------------------------------------------------------- */
  9. /*
  10. * Copyright (C) 2010-2020 ARM Limited or its affiliates. All rights reserved.
  11. *
  12. * SPDX-License-Identifier: Apache-2.0
  13. *
  14. * Licensed under the Apache License, Version 2.0 (the License); you may
  15. * not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at
  17. *
  18. * www.apache.org/licenses/LICENSE-2.0
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  22. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. */
  26. #include "dsp/complex_math_functions_f16.h"
  27. #if defined(ARM_FLOAT16_SUPPORTED)
  28. /**
  29. @ingroup groupCmplxMath
  30. */
  31. /**
  32. @defgroup cmplx_conj Complex Conjugate
  33. Conjugates the elements of a complex data vector.
  34. The <code>pSrc</code> points to the source data and
  35. <code>pDst</code> points to the destination data where the result should be written.
  36. <code>numSamples</code> specifies the number of complex samples
  37. and the data in each array is stored in an interleaved fashion
  38. (real, imag, real, imag, ...).
  39. Each array has a total of <code>2*numSamples</code> values.
  40. The underlying algorithm is used:
  41. <pre>
  42. for (n = 0; n < numSamples; n++) {
  43. pDst[(2*n) ] = pSrc[(2*n) ]; // real part
  44. pDst[(2*n)+1] = -pSrc[(2*n)+1]; // imag part
  45. }
  46. </pre>
  47. There are separate functions for floating-point, Q15, and Q31 data types.
  48. */
  49. /**
  50. @addtogroup cmplx_conj
  51. @{
  52. */
  53. /**
  54. @brief Floating-point complex conjugate.
  55. @param[in] pSrc points to the input vector
  56. @param[out] pDst points to the output vector
  57. @param[in] numSamples number of samples in each vector
  58. @return none
  59. */
  60. #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE)
  61. void arm_cmplx_conj_f16(
  62. const float16_t * pSrc,
  63. float16_t * pDst,
  64. uint32_t numSamples)
  65. {
  66. static const float16_t cmplx_conj_sign[8] = { 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f };
  67. uint32_t blockSize = numSamples * CMPLX_DIM; /* loop counters */
  68. uint32_t blkCnt;
  69. f16x8_t vecSrc;
  70. f16x8_t vecSign;
  71. /*
  72. * load sign vector
  73. */
  74. vecSign = *(f16x8_t *) cmplx_conj_sign;
  75. /* Compute 4 real samples at a time */
  76. blkCnt = blockSize >> 3U;
  77. while (blkCnt > 0U)
  78. {
  79. vecSrc = vld1q(pSrc);
  80. vst1q(pDst,vmulq(vecSrc, vecSign));
  81. /*
  82. * Decrement the blkCnt loop counter
  83. * Advance vector source and destination pointers
  84. */
  85. pSrc += 8;
  86. pDst += 8;
  87. blkCnt--;
  88. }
  89. /* Tail */
  90. blkCnt = (blockSize & 0x7) >> 1;
  91. while (blkCnt > 0U)
  92. {
  93. /* C[0] + jC[1] = A[0]+ j(-1)A[1] */
  94. /* Calculate Complex Conjugate and store result in destination buffer. */
  95. *pDst++ = *pSrc++;
  96. *pDst++ = -*pSrc++;
  97. /* Decrement loop counter */
  98. blkCnt--;
  99. }
  100. }
  101. #else
  102. void arm_cmplx_conj_f16(
  103. const float16_t * pSrc,
  104. float16_t * pDst,
  105. uint32_t numSamples)
  106. {
  107. uint32_t blkCnt; /* Loop counter */
  108. #if defined (ARM_MATH_LOOPUNROLL) && !defined(ARM_MATH_AUTOVECTORIZE)
  109. /* Loop unrolling: Compute 4 outputs at a time */
  110. blkCnt = numSamples >> 2U;
  111. while (blkCnt > 0U)
  112. {
  113. /* C[0] + jC[1] = A[0]+ j(-1)A[1] */
  114. /* Calculate Complex Conjugate and store result in destination buffer. */
  115. *pDst++ = *pSrc++;
  116. *pDst++ = -*pSrc++;
  117. *pDst++ = *pSrc++;
  118. *pDst++ = -*pSrc++;
  119. *pDst++ = *pSrc++;
  120. *pDst++ = -*pSrc++;
  121. *pDst++ = *pSrc++;
  122. *pDst++ = -*pSrc++;
  123. /* Decrement loop counter */
  124. blkCnt--;
  125. }
  126. /* Loop unrolling: Compute remaining outputs */
  127. blkCnt = numSamples % 0x4U;
  128. #else
  129. /* Initialize blkCnt with number of samples */
  130. blkCnt = numSamples;
  131. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  132. while (blkCnt > 0U)
  133. {
  134. /* C[0] + jC[1] = A[0]+ j(-1)A[1] */
  135. /* Calculate Complex Conjugate and store result in destination buffer. */
  136. *pDst++ = *pSrc++;
  137. *pDst++ = -*pSrc++;
  138. /* Decrement loop counter */
  139. blkCnt--;
  140. }
  141. }
  142. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  143. /**
  144. @} end of cmplx_conj group
  145. */
  146. #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */