arm_min_q15.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /* ----------------------------------------------------------------------
  2. * Copyright (C) 2010-2014 ARM Limited. All rights reserved.
  3. *
  4. * $Date: 12. March 2014
  5. * $Revision: V1.4.4
  6. *
  7. * Project: CMSIS DSP Library
  8. * Title: arm_min_q15.c
  9. *
  10. * Description: Minimum value of a Q15 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. * @addtogroup Min
  46. * @{
  47. */
  48. /**
  49. * @brief Minimum value of a Q15 vector.
  50. * @param[in] *pSrc points to the input vector
  51. * @param[in] blockSize length of the input vector
  52. * @param[out] *pResult minimum value returned here
  53. * @param[out] *pIndex index of minimum value returned here
  54. * @return none.
  55. *
  56. */
  57. void arm_min_q15(
  58. q15_t * pSrc,
  59. uint32_t blockSize,
  60. q15_t * pResult,
  61. uint32_t * pIndex)
  62. {
  63. #ifndef ARM_MATH_CM0_FAMILY
  64. /* Run the below code for Cortex-M4 and Cortex-M3 */
  65. q15_t minVal1, minVal2, out; /* Temporary variables to store the output value. */
  66. uint32_t blkCnt, outIndex, count; /* loop counter */
  67. /* Initialise the count value. */
  68. count = 0u;
  69. /* Initialise the index value to zero. */
  70. outIndex = 0u;
  71. /* Load first input value that act as reference value for comparision */
  72. out = *pSrc++;
  73. /* Loop unrolling */
  74. blkCnt = (blockSize - 1u) >> 2u;
  75. while(blkCnt > 0)
  76. {
  77. /* Initialize minVal to the next consecutive values one by one */
  78. minVal1 = *pSrc++;
  79. minVal2 = *pSrc++;
  80. /* compare for the minimum value */
  81. if(out > minVal1)
  82. {
  83. /* Update the minimum value and its index */
  84. out = minVal1;
  85. outIndex = count + 1u;
  86. }
  87. minVal1 = *pSrc++;
  88. /* compare for the minimum value */
  89. if(out > minVal2)
  90. {
  91. /* Update the minimum value and its index */
  92. out = minVal2;
  93. outIndex = count + 2u;
  94. }
  95. minVal2 = *pSrc++;
  96. /* compare for the minimum value */
  97. if(out > minVal1)
  98. {
  99. /* Update the minimum value and its index */
  100. out = minVal1;
  101. outIndex = count + 3u;
  102. }
  103. /* compare for the minimum value */
  104. if(out > minVal2)
  105. {
  106. /* Update the minimum value and its index */
  107. out = minVal2;
  108. outIndex = count + 4u;
  109. }
  110. count += 4u;
  111. blkCnt--;
  112. }
  113. /* if (blockSize - 1u ) is not multiple of 4 */
  114. blkCnt = (blockSize - 1u) % 4u;
  115. #else
  116. /* Run the below code for Cortex-M0 */
  117. q15_t minVal1, out; /* Temporary variables to store the output value. */
  118. uint32_t blkCnt, outIndex; /* loop counter */
  119. blkCnt = (blockSize - 1u);
  120. /* Initialise the index value to zero. */
  121. outIndex = 0u;
  122. /* Load first input value that act as reference value for comparision */
  123. out = *pSrc++;
  124. #endif // #ifndef ARM_MATH_CM0_FAMILY
  125. while(blkCnt > 0)
  126. {
  127. /* Initialize minVal to the next consecutive values one by one */
  128. minVal1 = *pSrc++;
  129. /* compare for the minimum value */
  130. if(out > minVal1)
  131. {
  132. /* Update the minimum value and it's index */
  133. out = minVal1;
  134. outIndex = blockSize - blkCnt;
  135. }
  136. blkCnt--;
  137. }
  138. /* Store the minimum value and its index into destination pointers */
  139. *pResult = out;
  140. *pIndex = outIndex;
  141. }
  142. /**
  143. * @} end of Min group
  144. */