arm_max_no_idx_f16.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_max_no_idx_f16.c
  4. * Description: Maximum value of a floating-point vector without returning the index
  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. #if (defined(ARM_MATH_NEON) || defined(ARM_MATH_MVEF)) && !defined(ARM_MATH_AUTOVECTORIZE)
  31. #include <limits.h>
  32. #endif
  33. /**
  34. @ingroup groupStats
  35. */
  36. /**
  37. @addtogroup Max
  38. @{
  39. */
  40. /**
  41. @brief Maximum value of a floating-point vector.
  42. @param[in] pSrc points to the input vector
  43. @param[in] blockSize number of samples in input vector
  44. @param[out] pResult maximum value returned here
  45. @return none
  46. */
  47. #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE)
  48. void arm_max_no_idx_f16(
  49. const float16_t *pSrc,
  50. uint32_t blockSize,
  51. float16_t *pResult)
  52. {
  53. f16x8_t vecSrc;
  54. f16x8_t curExtremValVec = vdupq_n_f16(F16_MIN);
  55. float16_t maxValue = F16_MIN;
  56. float16_t newVal;
  57. uint32_t blkCnt;
  58. /* Loop unrolling: Compute 4 outputs at a time */
  59. blkCnt = blockSize >> 3U;
  60. while (blkCnt > 0U)
  61. {
  62. vecSrc = vldrhq_f16(pSrc);
  63. /*
  64. * update per-lane max.
  65. */
  66. curExtremValVec = vmaxnmq(vecSrc, curExtremValVec);
  67. /*
  68. * Decrement the blockSize loop counter
  69. * Advance vector source and destination pointers
  70. */
  71. pSrc += 8;
  72. blkCnt --;
  73. }
  74. /*
  75. * Get max value across the vector
  76. */
  77. maxValue = vmaxnmvq(maxValue, curExtremValVec);
  78. blkCnt = blockSize & 7;
  79. while (blkCnt > 0U)
  80. {
  81. newVal = *pSrc++;
  82. /* compare for the maximum value */
  83. if ((_Float16)maxValue < (_Float16)newVal)
  84. {
  85. /* Update the maximum value and it's index */
  86. maxValue = newVal;
  87. }
  88. blkCnt --;
  89. }
  90. *pResult = maxValue;
  91. }
  92. #else
  93. void arm_max_no_idx_f16(
  94. const float16_t *pSrc,
  95. uint32_t blockSize,
  96. float16_t *pResult)
  97. {
  98. float16_t maxValue = F16_MIN;
  99. float16_t newVal;
  100. while (blockSize > 0U)
  101. {
  102. newVal = *pSrc++;
  103. /* compare for the maximum value */
  104. if ((_Float16)maxValue < (_Float16)newVal)
  105. {
  106. /* Update the maximum value and it's index */
  107. maxValue = newVal;
  108. }
  109. blockSize --;
  110. }
  111. *pResult = maxValue;
  112. }
  113. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  114. /**
  115. @} end of Max group
  116. */
  117. #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */