arm_max_no_idx_f32.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. */
  45. #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
  46. void arm_max_no_idx_f32(
  47. const float32_t *pSrc,
  48. uint32_t blockSize,
  49. float32_t *pResult)
  50. {
  51. f32x4_t vecSrc;
  52. f32x4_t curExtremValVec = vdupq_n_f32(F32_MIN);
  53. float32_t maxValue = F32_MIN;
  54. float32_t newVal;
  55. uint32_t blkCnt;
  56. /* Loop unrolling: Compute 4 outputs at a time */
  57. blkCnt = blockSize >> 2U;
  58. while (blkCnt > 0U)
  59. {
  60. vecSrc = vldrwq_f32(pSrc);
  61. /*
  62. * update per-lane max.
  63. */
  64. curExtremValVec = vmaxnmq(vecSrc, curExtremValVec);
  65. /*
  66. * Decrement the blockSize loop counter
  67. * Advance vector source and destination pointers
  68. */
  69. pSrc += 4;
  70. blkCnt --;
  71. }
  72. /*
  73. * Get max value across the vector
  74. */
  75. maxValue = vmaxnmvq(maxValue, curExtremValVec);
  76. blkCnt = blockSize & 3;
  77. while (blkCnt > 0U)
  78. {
  79. newVal = *pSrc++;
  80. /* compare for the maximum value */
  81. if (maxValue < newVal)
  82. {
  83. /* Update the maximum value and it's index */
  84. maxValue = newVal;
  85. }
  86. blkCnt --;
  87. }
  88. *pResult = maxValue;
  89. }
  90. #else
  91. void arm_max_no_idx_f32(
  92. const float32_t *pSrc,
  93. uint32_t blockSize,
  94. float32_t *pResult)
  95. {
  96. float32_t maxValue = F32_MIN;
  97. float32_t newVal;
  98. while (blockSize > 0U)
  99. {
  100. newVal = *pSrc++;
  101. /* compare for the maximum value */
  102. if (maxValue < newVal)
  103. {
  104. /* Update the maximum value and it's index */
  105. maxValue = newVal;
  106. }
  107. blockSize --;
  108. }
  109. *pResult = maxValue;
  110. }
  111. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  112. /**
  113. @} end of Max group
  114. */