arm_min_f32.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_min_f32.c
  4. * Description: Minimum value of a floating-point 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. * @defgroup Min Minimum
  34. *
  35. * Computes the minimum value of an array of data.
  36. * The function returns both the minimum value and its position within the array.
  37. * There are separate functions for floating-point, Q31, Q15, and Q7 data types.
  38. */
  39. /**
  40. * @addtogroup Min
  41. * @{
  42. */
  43. /**
  44. * @brief Minimum value of a floating-point vector.
  45. * @param[in] *pSrc points to the input vector
  46. * @param[in] blockSize length of the input vector
  47. * @param[out] *pResult minimum value returned here
  48. * @param[out] *pIndex index of minimum value returned here
  49. * @return none.
  50. */
  51. void arm_min_f32(
  52. float32_t * pSrc,
  53. uint32_t blockSize,
  54. float32_t * pResult,
  55. uint32_t * pIndex)
  56. {
  57. #if defined (ARM_MATH_DSP)
  58. /* Run the below code for Cortex-M4 and Cortex-M3 */
  59. float32_t minVal1, minVal2, out; /* Temporary variables to store the output value. */
  60. uint32_t blkCnt, outIndex, count; /* loop counter */
  61. /* Initialise the count value. */
  62. count = 0U;
  63. /* Initialise the index value to zero. */
  64. outIndex = 0U;
  65. /* Load first input value that act as reference value for comparision */
  66. out = *pSrc++;
  67. /* Loop unrolling */
  68. blkCnt = (blockSize - 1U) >> 2U;
  69. while (blkCnt > 0U)
  70. {
  71. /* Initialize minVal to the next consecutive values one by one */
  72. minVal1 = *pSrc++;
  73. minVal2 = *pSrc++;
  74. /* compare for the minimum value */
  75. if (out > minVal1)
  76. {
  77. /* Update the minimum value and its index */
  78. out = minVal1;
  79. outIndex = count + 1U;
  80. }
  81. /* compare for the minimum value */
  82. if (out > minVal2)
  83. {
  84. /* Update the minimum value and its index */
  85. out = minVal2;
  86. outIndex = count + 2U;
  87. }
  88. /* Initialize minVal to the next consecutive values one by one */
  89. minVal1 = *pSrc++;
  90. minVal2 = *pSrc++;
  91. /* compare for the minimum value */
  92. if (out > minVal1)
  93. {
  94. /* Update the minimum value and its index */
  95. out = minVal1;
  96. outIndex = count + 3U;
  97. }
  98. /* compare for the minimum value */
  99. if (out > minVal2)
  100. {
  101. /* Update the minimum value and its index */
  102. out = minVal2;
  103. outIndex = count + 4U;
  104. }
  105. count += 4U;
  106. /* Decrement the loop counter */
  107. blkCnt--;
  108. }
  109. /* if (blockSize - 1U) is not multiple of 4 */
  110. blkCnt = (blockSize - 1U) % 4U;
  111. #else
  112. /* Run the below code for Cortex-M0 */
  113. float32_t minVal1, out; /* Temporary variables to store the output value. */
  114. uint32_t blkCnt, outIndex; /* loop counter */
  115. /* Initialise the index value to zero. */
  116. outIndex = 0U;
  117. /* Load first input value that act as reference value for comparision */
  118. out = *pSrc++;
  119. blkCnt = (blockSize - 1U);
  120. #endif /* #if defined (ARM_MATH_DSP) */
  121. while (blkCnt > 0U)
  122. {
  123. /* Initialize minVal to the next consecutive values one by one */
  124. minVal1 = *pSrc++;
  125. /* compare for the minimum value */
  126. if (out > minVal1)
  127. {
  128. /* Update the minimum value and it's index */
  129. out = minVal1;
  130. outIndex = blockSize - blkCnt;
  131. }
  132. /* Decrement the loop counter */
  133. blkCnt--;
  134. }
  135. /* Store the minimum value and it's index into destination pointers */
  136. *pResult = out;
  137. *pIndex = outIndex;
  138. }
  139. /**
  140. * @} end of Min group
  141. */