arm_cmplx_mult_real_f16.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. @defgroup CmplxByRealMult Complex-by-Real Multiplication
  35. Multiplies a complex vector by a real vector and generates a complex result.
  36. The data in the complex arrays is stored in an interleaved fashion
  37. (real, imag, real, imag, ...).
  38. The parameter <code>numSamples</code> represents the number of complex
  39. samples processed. The complex arrays have a total of <code>2*numSamples</code>
  40. real values while the real array has a total of <code>numSamples</code>
  41. real values.
  42. The underlying algorithm is used:
  43. <pre>
  44. for (n = 0; n < numSamples; n++) {
  45. pCmplxDst[(2*n)+0] = pSrcCmplx[(2*n)+0] * pSrcReal[n];
  46. pCmplxDst[(2*n)+1] = pSrcCmplx[(2*n)+1] * pSrcReal[n];
  47. }
  48. </pre>
  49. There are separate functions for floating-point, Q15, and Q31 data types.
  50. */
  51. /**
  52. @addtogroup CmplxByRealMult
  53. @{
  54. */
  55. /**
  56. @brief Floating-point complex-by-real multiplication.
  57. @param[in] pSrcCmplx points to complex input vector
  58. @param[in] pSrcReal points to real input vector
  59. @param[out] pCmplxDst points to complex output vector
  60. @param[in] numSamples number of samples in each vector
  61. @return none
  62. */
  63. #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE)
  64. void arm_cmplx_mult_real_f16(
  65. const float16_t * pSrcCmplx,
  66. const float16_t * pSrcReal,
  67. float16_t * pCmplxDst,
  68. uint32_t numSamples)
  69. {
  70. static const uint16_t stride_cmplx_x_real_16[8] = {
  71. 0, 0, 1, 1, 2, 2, 3, 3
  72. };
  73. uint32_t blockSizeC = numSamples * CMPLX_DIM; /* loop counters */
  74. uint32_t blkCnt;
  75. f16x8_t rVec;
  76. f16x8_t cmplxVec;
  77. f16x8_t dstVec;
  78. uint16x8_t strideVec;
  79. /* stride vector for pairs of real generation */
  80. strideVec = vld1q(stride_cmplx_x_real_16);
  81. /* Compute 4 complex outputs at a time */
  82. blkCnt = blockSizeC >> 3;
  83. while (blkCnt > 0U)
  84. {
  85. cmplxVec = vld1q(pSrcCmplx);
  86. rVec = vldrhq_gather_shifted_offset_f16(pSrcReal, strideVec);
  87. dstVec = vmulq(cmplxVec, rVec);
  88. vst1q(pCmplxDst, dstVec);
  89. pSrcReal += 4;
  90. pSrcCmplx += 8;
  91. pCmplxDst += 8;
  92. blkCnt--;
  93. }
  94. blkCnt = blockSizeC & 7;
  95. if (blkCnt > 0U) {
  96. mve_pred16_t p0 = vctp16q(blkCnt);
  97. cmplxVec = vld1q(pSrcCmplx);
  98. rVec = vldrhq_gather_shifted_offset_f16(pSrcReal, strideVec);
  99. dstVec = vmulq(cmplxVec, rVec);
  100. vstrhq_p_f16(pCmplxDst, dstVec, p0);
  101. }
  102. }
  103. #else
  104. void arm_cmplx_mult_real_f16(
  105. const float16_t * pSrcCmplx,
  106. const float16_t * pSrcReal,
  107. float16_t * pCmplxDst,
  108. uint32_t numSamples)
  109. {
  110. uint32_t blkCnt; /* Loop counter */
  111. float16_t in; /* Temporary variable */
  112. #if defined (ARM_MATH_LOOPUNROLL) && !defined(ARM_MATH_AUTOVECTORIZE)
  113. /* Loop unrolling: Compute 4 outputs at a time */
  114. blkCnt = numSamples >> 2U;
  115. while (blkCnt > 0U)
  116. {
  117. /* C[2 * i ] = A[2 * i ] * B[i]. */
  118. /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */
  119. in = *pSrcReal++;
  120. /* store result in destination buffer. */
  121. *pCmplxDst++ = (_Float16)*pSrcCmplx++ * (_Float16)in;
  122. *pCmplxDst++ = (_Float16)*pSrcCmplx++ * (_Float16)in;
  123. in = *pSrcReal++;
  124. *pCmplxDst++ = (_Float16)*pSrcCmplx++ * (_Float16)in;
  125. *pCmplxDst++ = (_Float16)*pSrcCmplx++ * (_Float16)in;
  126. in = *pSrcReal++;
  127. *pCmplxDst++ = (_Float16)*pSrcCmplx++ * (_Float16)in;
  128. *pCmplxDst++ = (_Float16)*pSrcCmplx++ * (_Float16)in;
  129. in = *pSrcReal++;
  130. *pCmplxDst++ = (_Float16)*pSrcCmplx++ * (_Float16)in;
  131. *pCmplxDst++ = (_Float16)*pSrcCmplx++ * (_Float16)in;
  132. /* Decrement loop counter */
  133. blkCnt--;
  134. }
  135. /* Loop unrolling: Compute remaining outputs */
  136. blkCnt = numSamples % 0x4U;
  137. #else
  138. /* Initialize blkCnt with number of samples */
  139. blkCnt = numSamples;
  140. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  141. while (blkCnt > 0U)
  142. {
  143. /* C[2 * i ] = A[2 * i ] * B[i]. */
  144. /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */
  145. in = *pSrcReal++;
  146. /* store result in destination buffer. */
  147. *pCmplxDst++ = (_Float16)*pSrcCmplx++ * (_Float16)in;
  148. *pCmplxDst++ = (_Float16)*pSrcCmplx++ * (_Float16)in;
  149. /* Decrement loop counter */
  150. blkCnt--;
  151. }
  152. }
  153. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  154. /**
  155. @} end of CmplxByRealMult group
  156. */
  157. #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */