arm_max_no_idx_f32.c 3.3 KB

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