arm_power_f16.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_power_f16.c
  4. * Description: Sum of the squares of the elements of a floating-point vector
  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/statistics_functions_f16.h"
  29. #if defined(ARM_FLOAT16_SUPPORTED)
  30. /**
  31. @ingroup groupStats
  32. */
  33. /**
  34. @addtogroup power
  35. @{
  36. */
  37. /**
  38. @brief Sum of the squares of the elements of a floating-point vector.
  39. @param[in] pSrc points to the input vector
  40. @param[in] blockSize number of samples in input vector
  41. @param[out] pResult sum of the squares value returned here
  42. */
  43. #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE)
  44. #include "arm_helium_utils.h"
  45. void arm_power_f16(
  46. const float16_t * pSrc,
  47. uint32_t blockSize,
  48. float16_t * pResult)
  49. {
  50. int32_t blkCnt; /* loop counters */
  51. f16x8_t vecSrc;
  52. f16x8_t sumVec = vdupq_n_f16(0.0f);
  53. blkCnt = blockSize;
  54. do {
  55. mve_pred16_t p = vctp16q(blkCnt);
  56. vecSrc = vldrhq_z_f16((float16_t const *) pSrc, p);
  57. /*
  58. * sum lanes
  59. */
  60. sumVec = vfmaq_m(sumVec, vecSrc, vecSrc, p);
  61. blkCnt -= 8;
  62. pSrc += 8;
  63. }
  64. while (blkCnt > 0);
  65. *pResult = vecAddAcrossF16Mve(sumVec);
  66. }
  67. #else
  68. void arm_power_f16(
  69. const float16_t * pSrc,
  70. uint32_t blockSize,
  71. float16_t * pResult)
  72. {
  73. uint32_t blkCnt; /* Loop counter */
  74. _Float16 sum = 0.0f16; /* Temporary result storage */
  75. _Float16 in; /* Temporary variable to store input value */
  76. #if defined (ARM_MATH_LOOPUNROLL) && !defined(ARM_MATH_AUTOVECTORIZE)
  77. /* Loop unrolling: Compute 4 outputs at a time */
  78. blkCnt = blockSize >> 2U;
  79. while (blkCnt > 0U)
  80. {
  81. /* C = A[0] * A[0] + A[1] * A[1] + ... + A[blockSize-1] * A[blockSize-1] */
  82. /* Compute Power and store result in a temporary variable, sum. */
  83. in = *pSrc++;
  84. sum += in * in;
  85. in = *pSrc++;
  86. sum += in * in;
  87. in = *pSrc++;
  88. sum += in * in;
  89. in = *pSrc++;
  90. sum += in * in;
  91. /* Decrement loop counter */
  92. blkCnt--;
  93. }
  94. /* Loop unrolling: Compute remaining outputs */
  95. blkCnt = blockSize % 0x4U;
  96. #else
  97. /* Initialize blkCnt with number of samples */
  98. blkCnt = blockSize;
  99. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  100. while (blkCnt > 0U)
  101. {
  102. /* C = A[0] * A[0] + A[1] * A[1] + ... + A[blockSize-1] * A[blockSize-1] */
  103. /* Compute Power and store result in a temporary variable, sum. */
  104. in = *pSrc++;
  105. sum += in * in;
  106. /* Decrement loop counter */
  107. blkCnt--;
  108. }
  109. /* Store result to destination */
  110. *pResult = sum;
  111. }
  112. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  113. /**
  114. @} end of power group
  115. */
  116. #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */