arm_min_q15.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_min_q15.c
  4. * Description: Minimum value of a Q15 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 Min
  34. * @{
  35. */
  36. /**
  37. * @brief Minimum value of a Q15 vector.
  38. * @param[in] *pSrc points to the input vector
  39. * @param[in] blockSize length of the input vector
  40. * @param[out] *pResult minimum value returned here
  41. * @param[out] *pIndex index of minimum value returned here
  42. * @return none.
  43. */
  44. void arm_min_q15(
  45. q15_t * pSrc,
  46. uint32_t blockSize,
  47. q15_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. q15_t minVal1, minVal2, 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 minVal to the next consecutive values one by one */
  65. minVal1 = *pSrc++;
  66. minVal2 = *pSrc++;
  67. /* compare for the minimum value */
  68. if (out > minVal1)
  69. {
  70. /* Update the minimum value and its index */
  71. out = minVal1;
  72. outIndex = count + 1U;
  73. }
  74. /* compare for the minimum value */
  75. if (out > minVal2)
  76. {
  77. /* Update the minimum value and its index */
  78. out = minVal2;
  79. outIndex = count + 2U;
  80. }
  81. /* Initialize minVal to the next consecutive values one by one */
  82. minVal1 = *pSrc++;
  83. minVal2 = *pSrc++;
  84. /* compare for the minimum value */
  85. if (out > minVal1)
  86. {
  87. /* Update the minimum value and its index */
  88. out = minVal1;
  89. outIndex = count + 3U;
  90. }
  91. /* compare for the minimum value */
  92. if (out > minVal2)
  93. {
  94. /* Update the minimum value and its index */
  95. out = minVal2;
  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. q15_t minVal1, 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 minVal to the next consecutive values one by one */
  117. minVal1 = *pSrc++;
  118. /* compare for the minimum value */
  119. if (out > minVal1)
  120. {
  121. /* Update the minimum value and it's index */
  122. out = minVal1;
  123. outIndex = blockSize - blkCnt;
  124. }
  125. /* Decrement the loop counter */
  126. blkCnt--;
  127. }
  128. /* Store the minimum value and it's index into destination pointers */
  129. *pResult = out;
  130. *pIndex = outIndex;
  131. }
  132. /**
  133. * @} end of Min group
  134. */