Merge pull request #11270 from haslinghuis/rename_attr
[betaflight.git] / lib / main / CMSIS / DSP / Source / StatisticsFunctions / arm_max_f32.c
bloba0a68acdf5c4cee273c99989b0762161e96f7757
1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_max_f32.c
4 * Description: Maximum value of a floating-point 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 * @defgroup Max Maximum
38 * Computes the maximum value of an array of data.
39 * The function returns both the maximum value and its position within the array.
40 * There are separate functions for floating-point, Q31, Q15, and Q7 data types.
43 /**
44 * @addtogroup Max
45 * @{
49 /**
50 * @brief Maximum value of a floating-point vector.
51 * @param[in] *pSrc points to the input vector
52 * @param[in] blockSize length of the input vector
53 * @param[out] *pResult maximum value returned here
54 * @param[out] *pIndex index of maximum value returned here
55 * @return none.
58 void arm_max_f32(
59 float32_t * pSrc,
60 uint32_t blockSize,
61 float32_t * pResult,
62 uint32_t * pIndex)
64 #if defined (ARM_MATH_DSP)
65 /* Run the below code for Cortex-M4 and Cortex-M3 */
67 float32_t maxVal1, maxVal2, out; /* Temporary variables to store the output value. */
68 uint32_t blkCnt, outIndex, count; /* loop counter */
70 /* Initialise the count value. */
71 count = 0U;
72 /* Initialise the index value to zero. */
73 outIndex = 0U;
74 /* Load first input value that act as reference value for comparision */
75 out = *pSrc++;
77 /* Loop unrolling */
78 blkCnt = (blockSize - 1U) >> 2U;
80 while (blkCnt > 0U)
82 /* Initialize maxVal to the next consecutive values one by one */
83 maxVal1 = *pSrc++;
84 maxVal2 = *pSrc++;
86 /* compare for the maximum value */
87 if (out < maxVal1)
89 /* Update the maximum value and its index */
90 out = maxVal1;
91 outIndex = count + 1U;
94 /* compare for the maximum value */
95 if (out < maxVal2)
97 /* Update the maximum value and its index */
98 out = maxVal2;
99 outIndex = count + 2U;
102 /* Initialize maxVal to the next consecutive values one by one */
103 maxVal1 = *pSrc++;
104 maxVal2 = *pSrc++;
106 /* compare for the maximum value */
107 if (out < maxVal1)
109 /* Update the maximum value and its index */
110 out = maxVal1;
111 outIndex = count + 3U;
114 /* compare for the maximum value */
115 if (out < maxVal2)
117 /* Update the maximum value and its index */
118 out = maxVal2;
119 outIndex = count + 4U;
122 count += 4U;
124 /* Decrement the loop counter */
125 blkCnt--;
128 /* if (blockSize - 1U) is not multiple of 4 */
129 blkCnt = (blockSize - 1U) % 4U;
131 #else
132 /* Run the below code for Cortex-M0 */
134 float32_t maxVal1, out; /* Temporary variables to store the output value. */
135 uint32_t blkCnt, outIndex; /* loop counter */
137 /* Initialise the index value to zero. */
138 outIndex = 0U;
139 /* Load first input value that act as reference value for comparision */
140 out = *pSrc++;
142 blkCnt = (blockSize - 1U);
144 #endif /* #if defined (ARM_MATH_DSP) */
146 while (blkCnt > 0U)
148 /* Initialize maxVal to the next consecutive values one by one */
149 maxVal1 = *pSrc++;
151 /* compare for the maximum value */
152 if (out < maxVal1)
154 /* Update the maximum value and it's index */
155 out = maxVal1;
156 outIndex = blockSize - blkCnt;
159 /* Decrement the loop counter */
160 blkCnt--;
163 /* Store the maximum value and it's index into destination pointers */
164 *pResult = out;
165 *pIndex = outIndex;
169 * @} end of Max group