arm_max_q7.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_max_q7.c
  4. * Description: Maximum value of a Q7 vector
  5. *
  6. * $Date: 27. January 2017
  7. * $Revision: V.1.5.1
  8. *
  9. * Target Processor: Cortex-M cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2017 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 "arm_math.h"
  29. /**
  30. * @ingroup groupStats
  31. */
  32. /**
  33. * @addtogroup Max
  34. * @{
  35. */
  36. /**
  37. * @brief Maximum value of a Q7 vector.
  38. * @param[in] *pSrc points to the input vector
  39. * @param[in] blockSize length of the input vector
  40. * @param[out] *pResult maximum value returned here
  41. * @param[out] *pIndex index of maximum value returned here
  42. * @return none.
  43. */
  44. void arm_max_q7(
  45. q7_t * pSrc,
  46. uint32_t blockSize,
  47. q7_t * pResult,
  48. uint32_t * pIndex)
  49. {
  50. #if defined (ARM_MATH_DSP)
  51. /* Run the below code for Cortex-M4 and Cortex-M3 */
  52. q7_t maxVal1, maxVal2, out; /* Temporary variables to store the output value. */
  53. uint32_t blkCnt, outIndex, count; /* loop counter */
  54. /* Initialise the count value. */
  55. count = 0U;
  56. /* Initialise the index value to zero. */
  57. outIndex = 0U;
  58. /* Load first input value that act as reference value for comparision */
  59. out = *pSrc++;
  60. /* Loop unrolling */
  61. blkCnt = (blockSize - 1U) >> 2U;
  62. while (blkCnt > 0U)
  63. {
  64. /* Initialize maxVal to the next consecutive values one by one */
  65. maxVal1 = *pSrc++;
  66. maxVal2 = *pSrc++;
  67. /* compare for the maximum value */
  68. if (out < maxVal1)
  69. {
  70. /* Update the maximum value and its index */
  71. out = maxVal1;
  72. outIndex = count + 1U;
  73. }
  74. /* compare for the maximum value */
  75. if (out < maxVal2)
  76. {
  77. /* Update the maximum value and its index */
  78. out = maxVal2;
  79. outIndex = count + 2U;
  80. }
  81. /* Initialize maxVal to the next consecutive values one by one */
  82. maxVal1 = *pSrc++;
  83. maxVal2 = *pSrc++;
  84. /* compare for the maximum value */
  85. if (out < maxVal1)
  86. {
  87. /* Update the maximum value and its index */
  88. out = maxVal1;
  89. outIndex = count + 3U;
  90. }
  91. /* compare for the maximum value */
  92. if (out < maxVal2)
  93. {
  94. /* Update the maximum value and its index */
  95. out = maxVal2;
  96. outIndex = count + 4U;
  97. }
  98. count += 4U;
  99. /* Decrement the loop counter */
  100. blkCnt--;
  101. }
  102. /* if (blockSize - 1U) is not multiple of 4 */
  103. blkCnt = (blockSize - 1U) % 4U;
  104. #else
  105. /* Run the below code for Cortex-M0 */
  106. q7_t maxVal1, out; /* Temporary variables to store the output value. */
  107. uint32_t blkCnt, outIndex; /* loop counter */
  108. /* Initialise the index value to zero. */
  109. outIndex = 0U;
  110. /* Load first input value that act as reference value for comparision */
  111. out = *pSrc++;
  112. blkCnt = (blockSize - 1U);
  113. #endif /* #if defined (ARM_MATH_DSP) */
  114. while (blkCnt > 0U)
  115. {
  116. /* Initialize maxVal to the next consecutive values one by one */
  117. maxVal1 = *pSrc++;
  118. /* compare for the maximum value */
  119. if (out < maxVal1)
  120. {
  121. /* Update the maximum value and it's index */
  122. out = maxVal1;
  123. outIndex = blockSize - blkCnt;
  124. }
  125. /* Decrement the loop counter */
  126. blkCnt--;
  127. }
  128. /* Store the maximum value and it's index into destination pointers */
  129. *pResult = out;
  130. *pIndex = outIndex;
  131. }
  132. /**
  133. * @} end of Max group
  134. */