Merge pull request #11270 from haslinghuis/rename_attr
[betaflight.git] / lib / main / CMSIS / DSP / Source / StatisticsFunctions / arm_max_q15.c
blob67d5e346380e018b4139ffc755f3f7e5325293d4
1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_max_q15.c
4 * Description: Maximum value of a Q15 vector
6 * $Date: 27. January 2017
7 * $Revision: V.1.5.1
9 * Target Processor: Cortex-M cores
10 * -------------------------------------------------------------------- */
12 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
14 * SPDX-License-Identifier: Apache-2.0
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
20 * www.apache.org/licenses/LICENSE-2.0
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.
29 #include "arm_math.h"
31 /**
32 * @ingroup groupStats
35 /**
36 * @addtogroup Max
37 * @{
41 /**
42 * @brief Maximum value of a Q15 vector.
43 * @param[in] *pSrc points to the input vector
44 * @param[in] blockSize length of the input vector
45 * @param[out] *pResult maximum value returned here
46 * @param[out] *pIndex index of maximum value returned here
47 * @return none.
50 void arm_max_q15(
51 q15_t * pSrc,
52 uint32_t blockSize,
53 q15_t * pResult,
54 uint32_t * pIndex)
56 #if defined (ARM_MATH_DSP)
57 /* Run the below code for Cortex-M4 and Cortex-M3 */
59 q15_t maxVal1, maxVal2, out; /* Temporary variables to store the output value. */
60 uint32_t blkCnt, outIndex, count; /* loop counter */
62 /* Initialise the count value. */
63 count = 0U;
64 /* Initialise the index value to zero. */
65 outIndex = 0U;
66 /* Load first input value that act as reference value for comparision */
67 out = *pSrc++;
69 /* Loop unrolling */
70 blkCnt = (blockSize - 1U) >> 2U;
72 while (blkCnt > 0U)
74 /* Initialize maxVal to the next consecutive values one by one */
75 maxVal1 = *pSrc++;
76 maxVal2 = *pSrc++;
78 /* compare for the maximum value */
79 if (out < maxVal1)
81 /* Update the maximum value and its index */
82 out = maxVal1;
83 outIndex = count + 1U;
86 /* compare for the maximum value */
87 if (out < maxVal2)
89 /* Update the maximum value and its index */
90 out = maxVal2;
91 outIndex = count + 2U;
94 /* Initialize maxVal to the next consecutive values one by one */
95 maxVal1 = *pSrc++;
96 maxVal2 = *pSrc++;
98 /* compare for the maximum value */
99 if (out < maxVal1)
101 /* Update the maximum value and its index */
102 out = maxVal1;
103 outIndex = count + 3U;
106 /* compare for the maximum value */
107 if (out < maxVal2)
109 /* Update the maximum value and its index */
110 out = maxVal2;
111 outIndex = count + 4U;
114 count += 4U;
116 /* Decrement the loop counter */
117 blkCnt--;
120 /* if (blockSize - 1U) is not multiple of 4 */
121 blkCnt = (blockSize - 1U) % 4U;
123 #else
124 /* Run the below code for Cortex-M0 */
126 q15_t maxVal1, out; /* Temporary variables to store the output value. */
127 uint32_t blkCnt, outIndex; /* loop counter */
129 /* Initialise the index value to zero. */
130 outIndex = 0U;
131 /* Load first input value that act as reference value for comparision */
132 out = *pSrc++;
134 blkCnt = (blockSize - 1U);
136 #endif /* #if defined (ARM_MATH_DSP) */
138 while (blkCnt > 0U)
140 /* Initialize maxVal to the next consecutive values one by one */
141 maxVal1 = *pSrc++;
143 /* compare for the maximum value */
144 if (out < maxVal1)
146 /* Update the maximum value and it's index */
147 out = maxVal1;
148 outIndex = blockSize - blkCnt;
151 /* Decrement the loop counter */
152 blkCnt--;
155 /* Store the maximum value and it's index into destination pointers */
156 *pResult = out;
157 *pIndex = outIndex;
161 * @} end of Max group