arm_cmplx_mag_squared_f16.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_cmplx_mag_squared_f16.c
  4. * Description: Floating-point complex magnitude squared
  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_mag_squared
  35. @{
  36. */
  37. /**
  38. @brief Floating-point complex magnitude squared.
  39. @param[in] pSrc points to input vector
  40. @param[out] pDst points to 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_mag_squared_f16(
  45. const float16_t * pSrc,
  46. float16_t * pDst,
  47. uint32_t numSamples)
  48. {
  49. int32_t blockSize = numSamples; /* loop counters */
  50. f16x8x2_t vecSrc;
  51. f16x8_t sum;
  52. /* Compute 4 complex samples at a time */
  53. while (blockSize > 0)
  54. {
  55. mve_pred16_t p = vctp16q(blockSize);
  56. vecSrc = vld2q(pSrc);
  57. sum = vmulq_m(vuninitializedq_f16(),vecSrc.val[0], vecSrc.val[0],p);
  58. sum = vfmaq_m(sum, vecSrc.val[1], vecSrc.val[1],p);
  59. vstrhq_p_f16(pDst, sum,p);
  60. pSrc += 16;
  61. pDst += 8;
  62. /*
  63. * Decrement the blockSize loop counter
  64. */
  65. blockSize-= 8;
  66. }
  67. }
  68. #else
  69. void arm_cmplx_mag_squared_f16(
  70. const float16_t * pSrc,
  71. float16_t * pDst,
  72. uint32_t numSamples)
  73. {
  74. uint32_t blkCnt; /* Loop counter */
  75. _Float16 real, imag; /* Temporary input variables */
  76. #if defined (ARM_MATH_LOOPUNROLL) && !defined(ARM_MATH_AUTOVECTORIZE)
  77. /* Loop unrolling: Compute 4 outputs at a time */
  78. blkCnt = numSamples >> 2U;
  79. while (blkCnt > 0U)
  80. {
  81. /* C[0] = (A[0] * A[0] + A[1] * A[1]) */
  82. real = *pSrc++;
  83. imag = *pSrc++;
  84. *pDst++ = (real * real) + (imag * imag);
  85. real = *pSrc++;
  86. imag = *pSrc++;
  87. *pDst++ = (real * real) + (imag * imag);
  88. real = *pSrc++;
  89. imag = *pSrc++;
  90. *pDst++ = (real * real) + (imag * imag);
  91. real = *pSrc++;
  92. imag = *pSrc++;
  93. *pDst++ = (real * real) + (imag * imag);
  94. /* Decrement loop counter */
  95. blkCnt--;
  96. }
  97. /* Loop unrolling: Compute remaining outputs */
  98. blkCnt = numSamples % 0x4U;
  99. #else
  100. /* Initialize blkCnt with number of samples */
  101. blkCnt = numSamples;
  102. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  103. while (blkCnt > 0U)
  104. {
  105. /* C[0] = (A[0] * A[0] + A[1] * A[1]) */
  106. real = *pSrc++;
  107. imag = *pSrc++;
  108. /* store result in destination buffer. */
  109. *pDst++ = (real * real) + (imag * imag);
  110. /* Decrement loop counter */
  111. blkCnt--;
  112. }
  113. }
  114. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  115. /**
  116. @} end of cmplx_mag_squared group
  117. */
  118. #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */