arm_mse_f16.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_mse_f16.c
  4. * Description: Half floating point mean square error
  5. *
  6. * $Date: 05 April 2022
  7. * $Revision: V1.10.0
  8. *
  9. * Target Processor: Cortex-M and Cortex-A cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2022 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. /**
  30. @ingroup groupStats
  31. */
  32. /**
  33. @addtogroup MSE
  34. @{
  35. */
  36. /**
  37. @brief Mean square error between two half floating point vectors.
  38. @param[in] pSrcA points to the first input vector
  39. @param[in] pSrcB points to the second input vector
  40. @param[in] blockSize number of samples in input vector
  41. @param[out] result mean square error
  42. @return none
  43. */
  44. #if !defined(ARM_MATH_AUTOVECTORIZE)
  45. #if defined(ARM_MATH_MVE_FLOAT16)
  46. #include "arm_helium_utils.h"
  47. void arm_mse_f16(
  48. const float16_t * pSrcA,
  49. const float16_t * pSrcB,
  50. uint32_t blockSize,
  51. float16_t * result)
  52. {
  53. float16x8_t vecA, vecB;
  54. float16x8_t vecSum;
  55. uint32_t blkCnt;
  56. _Float16 sum = 0.0f16;
  57. vecSum = vdupq_n_f16(0.0f16);
  58. blkCnt = (blockSize) >> 3;
  59. while (blkCnt > 0U)
  60. {
  61. vecA = vld1q(pSrcA);
  62. pSrcA += 8;
  63. vecB = vld1q(pSrcB);
  64. pSrcB += 8;
  65. vecA = vsubq(vecA, vecB);
  66. vecSum = vfmaq(vecSum, vecA, vecA);
  67. /*
  68. * Decrement the blockSize loop counter
  69. */
  70. blkCnt --;
  71. }
  72. blkCnt = (blockSize) & 7;
  73. if (blkCnt > 0U)
  74. {
  75. mve_pred16_t p0 = vctp16q(blkCnt);
  76. vecA = vld1q(pSrcA);
  77. vecB = vld1q(pSrcB);
  78. vecA = vsubq(vecA, vecB);
  79. vecSum = vfmaq_m(vecSum, vecA, vecA, p0);
  80. }
  81. sum = vecAddAcrossF16Mve(vecSum);
  82. /* Store result in destination buffer */
  83. *result = (_Float16)sum / (_Float16)blockSize;
  84. }
  85. #endif
  86. #endif /*#if !defined(ARM_MATH_AUTOVECTORIZE)*/
  87. #if defined(ARM_FLOAT16_SUPPORTED)
  88. #if (!defined(ARM_MATH_MVE_FLOAT16)) || defined(ARM_MATH_AUTOVECTORIZE)
  89. void arm_mse_f16(
  90. const float16_t * pSrcA,
  91. const float16_t * pSrcB,
  92. uint32_t blockSize,
  93. float16_t * result)
  94. {
  95. uint32_t blkCnt; /* Loop counter */
  96. _Float16 inA, inB;
  97. _Float16 sum = 0.0f16; /* Temporary return variable */
  98. #if defined (ARM_MATH_LOOPUNROLL)
  99. blkCnt = (blockSize) >> 3;
  100. while (blkCnt > 0U)
  101. {
  102. inA = *pSrcA++;
  103. inB = *pSrcB++;
  104. inA = (_Float16)inA - (_Float16)inB;
  105. sum += (_Float16)inA * (_Float16)inA;
  106. inA = *pSrcA++;
  107. inB = *pSrcB++;
  108. inA = (_Float16)inA - (_Float16)inB;
  109. sum += (_Float16)inA * (_Float16)inA;
  110. inA = *pSrcA++;
  111. inB = *pSrcB++;
  112. inA = (_Float16)inA - (_Float16)inB;
  113. sum += (_Float16)inA * (_Float16)inA;
  114. inA = *pSrcA++;
  115. inB = *pSrcB++;
  116. inA = (_Float16)inA - (_Float16)inB;
  117. sum += (_Float16)inA * (_Float16)inA;
  118. inA = *pSrcA++;
  119. inB = *pSrcB++;
  120. inA = (_Float16)inA - (_Float16)inB;
  121. sum += (_Float16)inA * (_Float16)inA;
  122. inA = *pSrcA++;
  123. inB = *pSrcB++;
  124. inA = (_Float16)inA - (_Float16)inB;
  125. sum += (_Float16)inA * (_Float16)inA;
  126. inA = *pSrcA++;
  127. inB = *pSrcB++;
  128. inA = (_Float16)inA - (_Float16)inB;
  129. sum += (_Float16)inA * (_Float16)inA;
  130. inA = *pSrcA++;
  131. inB = *pSrcB++;
  132. inA = (_Float16)inA - (_Float16)inB;
  133. sum += (_Float16)inA * (_Float16)inA;
  134. /* Decrement loop counter */
  135. blkCnt--;
  136. }
  137. /* Loop unrolling: Compute remaining outputs */
  138. blkCnt = (blockSize) & 7;
  139. #else
  140. /* Initialize blkCnt with number of samples */
  141. blkCnt = blockSize;
  142. #endif
  143. while (blkCnt > 0U)
  144. {
  145. inA = *pSrcA++;
  146. inB = *pSrcB++;
  147. inA = (_Float16)inA - (_Float16)inB;
  148. sum += (_Float16)inA * (_Float16)inA;
  149. /* Decrement loop counter */
  150. blkCnt--;
  151. }
  152. /* Store result in destination buffer */
  153. *result = (_Float16)sum / (_Float16)blockSize;
  154. }
  155. #endif /* end of test for vector instruction availability */
  156. #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */
  157. /**
  158. @} end of MSE group
  159. */