You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

arm_min_f32.c 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /* ----------------------------------------------------------------------
  2. * Copyright (C) 2010-2013 ARM Limited. All rights reserved.
  3. *
  4. * $Date: 17. January 2013
  5. * $Revision: V1.4.1
  6. *
  7. * Project: CMSIS DSP Library
  8. * Title: arm_min_f32.c
  9. *
  10. * Description: Minimum value of a floating-point vector.
  11. *
  12. * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions
  16. * are met:
  17. * - Redistributions of source code must retain the above copyright
  18. * notice, this list of conditions and the following disclaimer.
  19. * - Redistributions in binary form must reproduce the above copyright
  20. * notice, this list of conditions and the following disclaimer in
  21. * the documentation and/or other materials provided with the
  22. * distribution.
  23. * - Neither the name of ARM LIMITED nor the names of its contributors
  24. * may be used to endorse or promote products derived from this
  25. * software without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  30. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  31. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  32. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  33. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  34. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  35. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  37. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  38. * POSSIBILITY OF SUCH DAMAGE.
  39. * ---------------------------------------------------------------------------- */
  40. #include "arm_math.h"
  41. /**
  42. * @ingroup groupStats
  43. */
  44. /**
  45. * @defgroup Min Minimum
  46. *
  47. * Computes the minimum value of an array of data.
  48. * The function returns both the minimum value and its position within the array.
  49. * There are separate functions for floating-point, Q31, Q15, and Q7 data types.
  50. */
  51. /**
  52. * @addtogroup Min
  53. * @{
  54. */
  55. /**
  56. * @brief Minimum value of a floating-point vector.
  57. * @param[in] *pSrc points to the input vector
  58. * @param[in] blockSize length of the input vector
  59. * @param[out] *pResult minimum value returned here
  60. * @param[out] *pIndex index of minimum value returned here
  61. * @return none.
  62. *
  63. */
  64. void arm_min_f32(
  65. float32_t * pSrc,
  66. uint32_t blockSize,
  67. float32_t * pResult,
  68. uint32_t * pIndex)
  69. {
  70. #ifndef ARM_MATH_CM0_FAMILY
  71. /* Run the below code for Cortex-M4 and Cortex-M3 */
  72. float32_t minVal1, minVal2, out; /* Temporary variables to store the output value. */
  73. uint32_t blkCnt, outIndex, count; /* loop counter */
  74. /* Initialise the count value. */
  75. count = 0u;
  76. /* Initialise the index value to zero. */
  77. outIndex = 0u;
  78. /* Load first input value that act as reference value for comparision */
  79. out = *pSrc++;
  80. /* Loop unrolling */
  81. blkCnt = (blockSize - 1u) >> 2u;
  82. while(blkCnt > 0)
  83. {
  84. /* Initialize minVal to the next consecutive values one by one */
  85. minVal1 = *pSrc++;
  86. minVal2 = *pSrc++;
  87. /* compare for the minimum value */
  88. if(out > minVal1)
  89. {
  90. /* Update the minimum value and its index */
  91. out = minVal1;
  92. outIndex = count + 1u;
  93. }
  94. minVal1 = *pSrc++;
  95. /* compare for the minimum value */
  96. if(out > minVal2)
  97. {
  98. /* Update the minimum value and its index */
  99. out = minVal2;
  100. outIndex = count + 2u;
  101. }
  102. minVal2 = *pSrc++;
  103. /* compare for the minimum value */
  104. if(out > minVal1)
  105. {
  106. /* Update the minimum value and its index */
  107. out = minVal1;
  108. outIndex = count + 3u;
  109. }
  110. /* compare for the minimum value */
  111. if(out > minVal2)
  112. {
  113. /* Update the minimum value and its index */
  114. out = minVal2;
  115. outIndex = count + 4u;
  116. }
  117. count += 4u;
  118. blkCnt--;
  119. }
  120. /* if (blockSize - 1u ) is not multiple of 4 */
  121. blkCnt = (blockSize - 1u) % 4u;
  122. #else
  123. /* Run the below code for Cortex-M0 */
  124. float32_t minVal1, out; /* Temporary variables to store the output value. */
  125. uint32_t blkCnt, outIndex; /* loop counter */
  126. /* Initialise the index value to zero. */
  127. outIndex = 0u;
  128. /* Load first input value that act as reference value for comparision */
  129. out = *pSrc++;
  130. blkCnt = (blockSize - 1u);
  131. #endif // #ifndef ARM_MATH_CM0_FAMILY
  132. while(blkCnt > 0)
  133. {
  134. /* Initialize minVal to the next consecutive values one by one */
  135. minVal1 = *pSrc++;
  136. /* compare for the minimum value */
  137. if(out > minVal1)
  138. {
  139. /* Update the minimum value and it's index */
  140. out = minVal1;
  141. outIndex = blockSize - blkCnt;
  142. }
  143. blkCnt--;
  144. }
  145. /* Store the minimum value and it's index into destination pointers */
  146. *pResult = out;
  147. *pIndex = outIndex;
  148. }
  149. /**
  150. * @} end of Min group
  151. */