arm_max_no_idx_q31.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_max_no_idx_q31.c
  4. * Description: Maximum value of a q31 vector without returning the index
  5. *
  6. * $Date: 16 November 2021
  7. * $Revision: V1.10.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. /**
  30. @ingroup groupStats
  31. */
  32. /**
  33. @addtogroup Max
  34. @{
  35. */
  36. /**
  37. @brief Maximum value of a q31 vector without index.
  38. @param[in] pSrc points to the input vector
  39. @param[in] blockSize number of samples in input vector
  40. @param[out] pResult maximum value returned here
  41. @return none
  42. */
  43. #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
  44. #include "arm_helium_utils.h"
  45. void arm_max_no_idx_q31(
  46. const q31_t * pSrc,
  47. uint32_t blockSize,
  48. q31_t * pResult)
  49. {
  50. int32_t blkCnt; /* loop counters */
  51. q31x4_t vecSrc;
  52. q31_t const *pSrcVec;
  53. q31x4_t curExtremValVec = vdupq_n_s32(Q31_MIN);
  54. q31_t maxValue = Q31_MIN;
  55. mve_pred16_t p0;
  56. pSrcVec = (q31_t const *) pSrc;
  57. blkCnt = blockSize >> 2;
  58. while (blkCnt > 0)
  59. {
  60. vecSrc = vldrwq_s32(pSrcVec);
  61. pSrcVec += 4;
  62. /*
  63. * update per-lane max.
  64. */
  65. curExtremValVec = vmaxq(vecSrc, curExtremValVec);
  66. /*
  67. * Decrement the blockSize loop counter
  68. */
  69. blkCnt--;
  70. }
  71. /*
  72. * tail
  73. * (will be merged thru tail predication)
  74. */
  75. blkCnt = blockSize & 3;
  76. if (blkCnt > 0)
  77. {
  78. vecSrc = vldrwq_s32(pSrcVec);
  79. pSrcVec += 4;
  80. p0 = vctp32q(blkCnt);
  81. /*
  82. * Get current max per lane and current index per lane
  83. * when a max is selected
  84. */
  85. curExtremValVec = vmaxq_m(curExtremValVec, vecSrc, curExtremValVec, p0);
  86. }
  87. /*
  88. * Get max value across the vector
  89. */
  90. maxValue = vmaxvq(maxValue, curExtremValVec);
  91. *pResult = maxValue;
  92. }
  93. #else
  94. void arm_max_no_idx_q31(
  95. const q31_t * pSrc,
  96. uint32_t blockSize,
  97. q31_t * pResult)
  98. {
  99. q31_t maxVal1, out; /* Temporary variables to store the output value. */
  100. uint32_t blkCnt; /* loop counter */
  101. /* Load first input value that act as reference value for comparision */
  102. out = *pSrc++;
  103. blkCnt = (blockSize - 1U);
  104. while (blkCnt > 0U)
  105. {
  106. /* Initialize maxVal to the next consecutive values one by one */
  107. maxVal1 = *pSrc++;
  108. /* compare for the maximum value */
  109. if (out < maxVal1)
  110. {
  111. /* Update the maximum value */
  112. out = maxVal1;
  113. }
  114. /* Decrement the loop counter */
  115. blkCnt--;
  116. }
  117. /* Store the maximum value into destination pointer */
  118. *pResult = out;
  119. }
  120. #endif /* #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE) */
  121. /**
  122. @} end of Max group
  123. */