arm_cmplx_conj_f16.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_cmplx_conj_f16.c
  4. * Description: Floating-point complex conjugate
  5. *
  6. * $Date: 23 April 2021
  7. * $Revision: V1.9.0
  8. *
  9. * Target Processor: Cortex-M and Cortex-A cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2021 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 "dsp/complex_math_functions_f16.h"
  29. #if defined(ARM_FLOAT16_SUPPORTED)
  30. /**
  31. @ingroup groupCmplxMath
  32. */
  33. /**
  34. @addtogroup cmplx_conj
  35. @{
  36. */
  37. /**
  38. @brief Floating-point complex conjugate.
  39. @param[in] pSrc points to the input vector
  40. @param[out] pDst points to the output vector
  41. @param[in] numSamples number of samples in each vector
  42. */
  43. #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE)
  44. void arm_cmplx_conj_f16(
  45. const float16_t * pSrc,
  46. float16_t * pDst,
  47. uint32_t numSamples)
  48. {
  49. static const float16_t cmplx_conj_sign[8] = { 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f };
  50. uint32_t blockSize = numSamples * CMPLX_DIM; /* loop counters */
  51. uint32_t blkCnt;
  52. f16x8_t vecSrc;
  53. f16x8_t vecSign;
  54. /*
  55. * load sign vector
  56. */
  57. vecSign = *(f16x8_t *) cmplx_conj_sign;
  58. /* Compute 4 real samples at a time */
  59. blkCnt = blockSize >> 3U;
  60. while (blkCnt > 0U)
  61. {
  62. vecSrc = vld1q(pSrc);
  63. vst1q(pDst,vmulq(vecSrc, vecSign));
  64. /*
  65. * Decrement the blkCnt loop counter
  66. * Advance vector source and destination pointers
  67. */
  68. pSrc += 8;
  69. pDst += 8;
  70. blkCnt--;
  71. }
  72. /* Tail */
  73. blkCnt = (blockSize & 0x7) >> 1;
  74. while (blkCnt > 0U)
  75. {
  76. /* C[0] + jC[1] = A[0]+ j(-1)A[1] */
  77. /* Calculate Complex Conjugate and store result in destination buffer. */
  78. *pDst++ = *pSrc++;
  79. *pDst++ = -(_Float16)*pSrc++;
  80. /* Decrement loop counter */
  81. blkCnt--;
  82. }
  83. }
  84. #else
  85. void arm_cmplx_conj_f16(
  86. const float16_t * pSrc,
  87. float16_t * pDst,
  88. uint32_t numSamples)
  89. {
  90. uint32_t blkCnt; /* Loop counter */
  91. #if defined (ARM_MATH_LOOPUNROLL) && !defined(ARM_MATH_AUTOVECTORIZE)
  92. /* Loop unrolling: Compute 4 outputs at a time */
  93. blkCnt = numSamples >> 2U;
  94. while (blkCnt > 0U)
  95. {
  96. /* C[0] + jC[1] = A[0]+ j(-1)A[1] */
  97. /* Calculate Complex Conjugate and store result in destination buffer. */
  98. *pDst++ = *pSrc++;
  99. *pDst++ = -(_Float16)*pSrc++;
  100. *pDst++ = *pSrc++;
  101. *pDst++ = -(_Float16)*pSrc++;
  102. *pDst++ = *pSrc++;
  103. *pDst++ = -(_Float16)*pSrc++;
  104. *pDst++ = *pSrc++;
  105. *pDst++ = -(_Float16)*pSrc++;
  106. /* Decrement loop counter */
  107. blkCnt--;
  108. }
  109. /* Loop unrolling: Compute remaining outputs */
  110. blkCnt = numSamples % 0x4U;
  111. #else
  112. /* Initialize blkCnt with number of samples */
  113. blkCnt = numSamples;
  114. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  115. while (blkCnt > 0U)
  116. {
  117. /* C[0] + jC[1] = A[0]+ j(-1)A[1] */
  118. /* Calculate Complex Conjugate and store result in destination buffer. */
  119. *pDst++ = *pSrc++;
  120. *pDst++ = -(_Float16)*pSrc++;
  121. /* Decrement loop counter */
  122. blkCnt--;
  123. }
  124. }
  125. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  126. /**
  127. @} end of cmplx_conj group
  128. */
  129. #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */