arm_max_q7.c 5.0 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_max_q7.c
  9. *
  10. * Description: Maximum value of a Q7 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 Max
  46. * @{
  47. */
  48. /**
  49. * @brief Maximum value of a Q7 vector.
  50. * @param[in] *pSrc points to the input vector
  51. * @param[in] blockSize length of the input vector
  52. * @param[out] *pResult maximum value returned here
  53. * @param[out] *pIndex index of maximum value returned here
  54. * @return none.
  55. */
  56. void arm_max_q7(
  57. q7_t * pSrc,
  58. uint32_t blockSize,
  59. q7_t * pResult,
  60. uint32_t * pIndex)
  61. {
  62. #ifndef ARM_MATH_CM0_FAMILY
  63. /* Run the below code for Cortex-M4 and Cortex-M3 */
  64. q7_t maxVal1, maxVal2, out; /* Temporary variables to store the output value. */
  65. uint32_t blkCnt, outIndex, count; /* loop counter */
  66. /* Initialise the count value. */
  67. count = 0u;
  68. /* Initialise the index value to zero. */
  69. outIndex = 0u;
  70. /* Load first input value that act as reference value for comparision */
  71. out = *pSrc++;
  72. /* Loop unrolling */
  73. blkCnt = (blockSize - 1u) >> 2u;
  74. /* Run the below code for Cortex-M4 and Cortex-M3 */
  75. while(blkCnt > 0u)
  76. {
  77. /* Initialize maxVal to the next consecutive values one by one */
  78. maxVal1 = *pSrc++;
  79. maxVal2 = *pSrc++;
  80. /* compare for the maximum value */
  81. if(out < maxVal1)
  82. {
  83. /* Update the maximum value and its index */
  84. out = maxVal1;
  85. outIndex = count + 1u;
  86. }
  87. maxVal1 = *pSrc++;
  88. /* compare for the maximum value */
  89. if(out < maxVal2)
  90. {
  91. /* Update the maximum value and its index */
  92. out = maxVal2;
  93. outIndex = count + 2u;
  94. }
  95. maxVal2 = *pSrc++;
  96. /* compare for the maximum value */
  97. if(out < maxVal1)
  98. {
  99. /* Update the maximum value and its index */
  100. out = maxVal1;
  101. outIndex = count + 3u;
  102. }
  103. /* compare for the maximum value */
  104. if(out < maxVal2)
  105. {
  106. /* Update the maximum value and its index */
  107. out = maxVal2;
  108. outIndex = count + 4u;
  109. }
  110. count += 4u;
  111. /* Decrement the loop counter */
  112. blkCnt--;
  113. }
  114. /* if (blockSize - 1u) is not multiple of 4 */
  115. blkCnt = (blockSize - 1u) % 4u;
  116. #else
  117. /* Run the below code for Cortex-M0 */
  118. q7_t maxVal1, out; /* Temporary variables to store the output value. */
  119. uint32_t blkCnt, outIndex; /* loop counter */
  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. blkCnt = (blockSize - 1u);
  125. #endif /* #ifndef ARM_MATH_CM0_FAMILY */
  126. while(blkCnt > 0u)
  127. {
  128. /* Initialize maxVal to the next consecutive values one by one */
  129. maxVal1 = *pSrc++;
  130. /* compare for the maximum value */
  131. if(out < maxVal1)
  132. {
  133. /* Update the maximum value and it's index */
  134. out = maxVal1;
  135. outIndex = blockSize - blkCnt;
  136. }
  137. /* Decrement the loop counter */
  138. blkCnt--;
  139. }
  140. /* Store the maximum value and its index into destination pointers */
  141. *pResult = out;
  142. *pIndex = outIndex;
  143. }
  144. /**
  145. * @} end of Max group
  146. */