Merge pull request #11270 from haslinghuis/rename_attr
[betaflight.git] / lib / main / CMSIS / DSP / Source / StatisticsFunctions / arm_min_f32.c
blob858b0a26e6fde993c9806be838bc0cb1b1b649e9
1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_min_f32.c
4 * Description: Minimum 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 Min Minimum
38 * Computes the minimum value of an array of data.
39 * The function returns both the minimum value and its position within the array.
40 * There are separate functions for floating-point, Q31, Q15, and Q7 data types.
43 /**
44 * @addtogroup Min
45 * @{
49 /**
50 * @brief Minimum 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 minimum value returned here
54 * @param[out] *pIndex index of minimum value returned here
55 * @return none.
58 void arm_min_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 minVal1, minVal2, 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 minVal to the next consecutive values one by one */
83 minVal1 = *pSrc++;
84 minVal2 = *pSrc++;
86 /* compare for the minimum value */
87 if (out > minVal1)
89 /* Update the minimum value and its index */
90 out = minVal1;
91 outIndex = count + 1U;
94 /* compare for the minimum value */
95 if (out > minVal2)
97 /* Update the minimum value and its index */
98 out = minVal2;
99 outIndex = count + 2U;
102 /* Initialize minVal to the next consecutive values one by one */
103 minVal1 = *pSrc++;
104 minVal2 = *pSrc++;
106 /* compare for the minimum value */
107 if (out > minVal1)
109 /* Update the minimum value and its index */
110 out = minVal1;
111 outIndex = count + 3U;
114 /* compare for the minimum value */
115 if (out > minVal2)
117 /* Update the minimum value and its index */
118 out = minVal2;
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 minVal1, 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 minVal to the next consecutive values one by one */
149 minVal1 = *pSrc++;
151 /* compare for the minimum value */
152 if (out > minVal1)
154 /* Update the minimum value and it's index */
155 out = minVal1;
156 outIndex = blockSize - blkCnt;
159 /* Decrement the loop counter */
160 blkCnt--;
163 /* Store the minimum value and it's index into destination pointers */
164 *pResult = out;
165 *pIndex = outIndex;
169 * @} end of Min group