arm_weighted_sum_f16.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_weighted_sum_f16.c
  4. * Description: Weighted Sum
  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 <limits.h>
  29. #include <math.h>
  30. #include "dsp/support_functions_f16.h"
  31. #if defined(ARM_FLOAT16_SUPPORTED)
  32. /**
  33. @ingroup groupSupport
  34. */
  35. /**
  36. @defgroup weightedsum Weighted Sum
  37. Weighted sum of values
  38. */
  39. /**
  40. * @addtogroup weightedsum
  41. * @{
  42. */
  43. /**
  44. * @brief Weighted sum
  45. *
  46. *
  47. * @param[in] *in Array of input values.
  48. * @param[in] *weigths Weights
  49. * @param[in] blockSize Number of samples in the input array.
  50. * @return Weighted sum
  51. *
  52. */
  53. #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE)
  54. #include "arm_helium_utils.h"
  55. float16_t arm_weighted_sum_f16(const float16_t *in,const float16_t *weigths, uint32_t blockSize)
  56. {
  57. _Float16 accum1, accum2;
  58. float16x8_t accum1V, accum2V;
  59. float16x8_t inV, wV;
  60. const float16_t *pIn, *pW;
  61. uint32_t blkCnt;
  62. pIn = in;
  63. pW = weigths;
  64. accum1V = vdupq_n_f16(0.0f16);
  65. accum2V = vdupq_n_f16(0.0f16);
  66. blkCnt = blockSize >> 3;
  67. while (blkCnt > 0)
  68. {
  69. inV = vld1q(pIn);
  70. wV = vld1q(pW);
  71. pIn += 4;
  72. pW += 4;
  73. accum1V = vfmaq(accum1V, inV, wV);
  74. accum2V = vaddq(accum2V, wV);
  75. blkCnt--;
  76. }
  77. accum1 = vecAddAcrossF16Mve(accum1V);
  78. accum2 = vecAddAcrossF16Mve(accum2V);
  79. blkCnt = blockSize & 7;
  80. while(blkCnt > 0)
  81. {
  82. accum1 += (_Float16)*pIn++ * (_Float16)*pW;
  83. accum2 += (_Float16)*pW++;
  84. blkCnt--;
  85. }
  86. return (accum1 / accum2);
  87. }
  88. #else
  89. float16_t arm_weighted_sum_f16(const float16_t *in, const float16_t *weigths, uint32_t blockSize)
  90. {
  91. _Float16 accum1, accum2;
  92. const float16_t *pIn, *pW;
  93. uint32_t blkCnt;
  94. pIn = in;
  95. pW = weigths;
  96. accum1=0.0f16;
  97. accum2=0.0f16;
  98. blkCnt = blockSize;
  99. while(blkCnt > 0)
  100. {
  101. accum1 += (_Float16)*pIn++ * (_Float16)*pW;
  102. accum2 += (_Float16)*pW++;
  103. blkCnt--;
  104. }
  105. return(accum1 / accum2);
  106. }
  107. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  108. /**
  109. * @} end of weightedsum group
  110. */
  111. #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */