arm_cmplx_mult_real_f16.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_cmplx_mult_real_f16.c
  4. * Description: Floating-point complex by real multiplication
  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 CmplxByRealMult
  35. @{
  36. */
  37. /**
  38. @brief Floating-point complex-by-real multiplication.
  39. @param[in] pSrcCmplx points to complex input vector
  40. @param[in] pSrcReal points to real input vector
  41. @param[out] pCmplxDst points to complex output vector
  42. @param[in] numSamples number of samples in each vector
  43. */
  44. #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE)
  45. void arm_cmplx_mult_real_f16(
  46. const float16_t * pSrcCmplx,
  47. const float16_t * pSrcReal,
  48. float16_t * pCmplxDst,
  49. uint32_t numSamples)
  50. {
  51. static const uint16_t stride_cmplx_x_real_16[8] = {
  52. 0, 0, 1, 1, 2, 2, 3, 3
  53. };
  54. uint32_t blockSizeC = numSamples * CMPLX_DIM; /* loop counters */
  55. uint32_t blkCnt;
  56. f16x8_t rVec;
  57. f16x8_t cmplxVec;
  58. f16x8_t dstVec;
  59. uint16x8_t strideVec;
  60. /* stride vector for pairs of real generation */
  61. strideVec = vld1q(stride_cmplx_x_real_16);
  62. /* Compute 4 complex outputs at a time */
  63. blkCnt = blockSizeC >> 3;
  64. while (blkCnt > 0U)
  65. {
  66. cmplxVec = vld1q(pSrcCmplx);
  67. rVec = vldrhq_gather_shifted_offset_f16(pSrcReal, strideVec);
  68. dstVec = vmulq(cmplxVec, rVec);
  69. vst1q(pCmplxDst, dstVec);
  70. pSrcReal += 4;
  71. pSrcCmplx += 8;
  72. pCmplxDst += 8;
  73. blkCnt--;
  74. }
  75. blkCnt = blockSizeC & 7;
  76. if (blkCnt > 0U) {
  77. mve_pred16_t p0 = vctp16q(blkCnt);
  78. cmplxVec = vld1q(pSrcCmplx);
  79. rVec = vldrhq_gather_shifted_offset_f16(pSrcReal, strideVec);
  80. dstVec = vmulq(cmplxVec, rVec);
  81. vstrhq_p_f16(pCmplxDst, dstVec, p0);
  82. }
  83. }
  84. #else
  85. void arm_cmplx_mult_real_f16(
  86. const float16_t * pSrcCmplx,
  87. const float16_t * pSrcReal,
  88. float16_t * pCmplxDst,
  89. uint32_t numSamples)
  90. {
  91. uint32_t blkCnt; /* Loop counter */
  92. float16_t in; /* Temporary variable */
  93. #if defined (ARM_MATH_LOOPUNROLL) && !defined(ARM_MATH_AUTOVECTORIZE)
  94. /* Loop unrolling: Compute 4 outputs at a time */
  95. blkCnt = numSamples >> 2U;
  96. while (blkCnt > 0U)
  97. {
  98. /* C[2 * i ] = A[2 * i ] * B[i]. */
  99. /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */
  100. in = *pSrcReal++;
  101. /* store result in destination buffer. */
  102. *pCmplxDst++ = (_Float16)*pSrcCmplx++ * (_Float16)in;
  103. *pCmplxDst++ = (_Float16)*pSrcCmplx++ * (_Float16)in;
  104. in = *pSrcReal++;
  105. *pCmplxDst++ = (_Float16)*pSrcCmplx++ * (_Float16)in;
  106. *pCmplxDst++ = (_Float16)*pSrcCmplx++ * (_Float16)in;
  107. in = *pSrcReal++;
  108. *pCmplxDst++ = (_Float16)*pSrcCmplx++ * (_Float16)in;
  109. *pCmplxDst++ = (_Float16)*pSrcCmplx++ * (_Float16)in;
  110. in = *pSrcReal++;
  111. *pCmplxDst++ = (_Float16)*pSrcCmplx++ * (_Float16)in;
  112. *pCmplxDst++ = (_Float16)*pSrcCmplx++ * (_Float16)in;
  113. /* Decrement loop counter */
  114. blkCnt--;
  115. }
  116. /* Loop unrolling: Compute remaining outputs */
  117. blkCnt = numSamples % 0x4U;
  118. #else
  119. /* Initialize blkCnt with number of samples */
  120. blkCnt = numSamples;
  121. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  122. while (blkCnt > 0U)
  123. {
  124. /* C[2 * i ] = A[2 * i ] * B[i]. */
  125. /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */
  126. in = *pSrcReal++;
  127. /* store result in destination buffer. */
  128. *pCmplxDst++ = (_Float16)*pSrcCmplx++ * (_Float16)in;
  129. *pCmplxDst++ = (_Float16)*pSrcCmplx++ * (_Float16)in;
  130. /* Decrement loop counter */
  131. blkCnt--;
  132. }
  133. }
  134. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  135. /**
  136. @} end of CmplxByRealMult group
  137. */
  138. #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */