source: S-port/trunk/Drivers/CMSIS/DSP/Source/StatisticsFunctions/arm_min_f32.c

Last change on this file was 1, checked in by AlexLir, 3 years ago
File size: 4.5 KB
Line 
1/* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_min_f32.c
4 * Description: Minimum value of a floating-point vector
5 *
6 * $Date: 27. January 2017
7 * $Revision: V.1.5.1
8 *
9 * Target Processor: Cortex-M cores
10 * -------------------------------------------------------------------- */
11/*
12 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
13 *
14 * SPDX-License-Identifier: Apache-2.0
15 *
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
19 *
20 * www.apache.org/licenses/LICENSE-2.0
21 *
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.
27 */
28
29#include "arm_math.h"
30
31/**
32 * @ingroup groupStats
33 */
34
35/**
36 * @defgroup Min Minimum
37 *
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.
41 */
42
43/**
44 * @addtogroup Min
45 * @{
46 */
47
48
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.
56 */
57
58void arm_min_f32(
59 float32_t * pSrc,
60 uint32_t blockSize,
61 float32_t * pResult,
62 uint32_t * pIndex)
63{
64#if defined (ARM_MATH_DSP)
65 /* Run the below code for Cortex-M4 and Cortex-M3 */
66
67 float32_t minVal1, minVal2, out; /* Temporary variables to store the output value. */
68 uint32_t blkCnt, outIndex, count; /* loop counter */
69
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++;
76
77 /* Loop unrolling */
78 blkCnt = (blockSize - 1U) >> 2U;
79
80 while (blkCnt > 0U)
81 {
82 /* Initialize minVal to the next consecutive values one by one */
83 minVal1 = *pSrc++;
84 minVal2 = *pSrc++;
85
86 /* compare for the minimum value */
87 if (out > minVal1)
88 {
89 /* Update the minimum value and its index */
90 out = minVal1;
91 outIndex = count + 1U;
92 }
93
94 /* compare for the minimum value */
95 if (out > minVal2)
96 {
97 /* Update the minimum value and its index */
98 out = minVal2;
99 outIndex = count + 2U;
100 }
101
102 /* Initialize minVal to the next consecutive values one by one */
103 minVal1 = *pSrc++;
104 minVal2 = *pSrc++;
105
106 /* compare for the minimum value */
107 if (out > minVal1)
108 {
109 /* Update the minimum value and its index */
110 out = minVal1;
111 outIndex = count + 3U;
112 }
113
114 /* compare for the minimum value */
115 if (out > minVal2)
116 {
117 /* Update the minimum value and its index */
118 out = minVal2;
119 outIndex = count + 4U;
120 }
121
122 count += 4U;
123
124 /* Decrement the loop counter */
125 blkCnt--;
126 }
127
128 /* if (blockSize - 1U) is not multiple of 4 */
129 blkCnt = (blockSize - 1U) % 4U;
130
131#else
132 /* Run the below code for Cortex-M0 */
133
134 float32_t minVal1, out; /* Temporary variables to store the output value. */
135 uint32_t blkCnt, outIndex; /* loop counter */
136
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++;
141
142 blkCnt = (blockSize - 1U);
143
144#endif /* #if defined (ARM_MATH_DSP) */
145
146 while (blkCnt > 0U)
147 {
148 /* Initialize minVal to the next consecutive values one by one */
149 minVal1 = *pSrc++;
150
151 /* compare for the minimum value */
152 if (out > minVal1)
153 {
154 /* Update the minimum value and it's index */
155 out = minVal1;
156 outIndex = blockSize - blkCnt;
157 }
158
159 /* Decrement the loop counter */
160 blkCnt--;
161 }
162
163 /* Store the minimum value and it's index into destination pointers */
164 *pResult = out;
165 *pIndex = outIndex;
166}
167
168/**
169 * @} end of Min group
170 */
Note: See TracBrowser for help on using the repository browser.