1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_absmin_no_idx_f16.c
4 * Description: Minimum value of absolute values of a floating-point vector
5 *
6 * $Date: 16 November 2021
7 * $Revision: V1.10.0
8 *
9 * Target Processor: Cortex-M and Cortex-A cores
10 * -------------------------------------------------------------------- */
11 /*
12 * Copyright (C) 2010-2021 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 "dsp/statistics_functions_f16.h"
30
31 #if defined(ARM_FLOAT16_SUPPORTED)
32
33
34 #if (defined(ARM_MATH_NEON) || defined(ARM_MATH_MVEF)) && !defined(ARM_MATH_AUTOVECTORIZE)
35 #include <limits.h>
36 #endif
37
38
39 /**
40 @ingroup groupStats
41 */
42
43 /**
44 @addtogroup AbsMin
45 @{
46 */
47
48 /**
49 @brief Minimum value of absolute values of a floating-point vector.
50 @param[in] pSrc points to the input vector
51 @param[in] blockSize number of samples in input vector
52 @param[out] pResult minimum value returned here
53 @return none
54 */
55
56 #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE)
57
58 #include "arm_helium_utils.h"
arm_absmin_no_idx_f16(const float16_t * pSrc,uint32_t blockSize,float16_t * pResult)59 void arm_absmin_no_idx_f16(
60 const float16_t * pSrc,
61 uint32_t blockSize,
62 float16_t * pResult)
63 {
64 int32_t blkCnt; /* loop counters */
65 f16x8_t vecSrc;
66 float16_t const *pSrcVec;
67 f16x8_t curExtremValVec = vdupq_n_f16(F16_ABSMAX);
68 float16_t minValue = F16_ABSMAX;
69 mve_pred16_t p0;
70
71
72 pSrcVec = (float16_t const *) pSrc;
73 blkCnt = blockSize >> 3;
74 while (blkCnt > 0)
75 {
76 vecSrc = vld1q(pSrcVec);
77 pSrcVec += 8;
78 /*
79 * update per-lane min.
80 */
81 curExtremValVec = vminnmaq(vecSrc, curExtremValVec);
82 /*
83 * Decrement the blockSize loop counter
84 */
85 blkCnt--;
86 }
87 /*
88 * tail
89 * (will be merged thru tail predication)
90 */
91 blkCnt = blockSize & 7;
92 if (blkCnt > 0)
93 {
94 vecSrc = vld1q(pSrcVec);
95 pSrcVec += 8;
96 p0 = vctp16q(blkCnt);
97 /*
98 * Get current min per lane and current index per lane
99 * when a min is selected
100 */
101 curExtremValVec = vminnmaq_m(curExtremValVec, vecSrc, p0);
102 }
103 /*
104 * Get min value across the vector
105 */
106 minValue = vminnmavq(minValue, curExtremValVec);
107 *pResult = minValue;
108 }
109
110 #else
111 #if defined(ARM_MATH_LOOPUNROLL)
arm_absmin_no_idx_f16(const float16_t * pSrc,uint32_t blockSize,float16_t * pResult)112 void arm_absmin_no_idx_f16(
113 const float16_t * pSrc,
114 uint32_t blockSize,
115 float16_t * pResult)
116 {
117 float16_t cur_absmin, out; /* Temporary variables to store the output value. */\
118 uint32_t blkCnt; /* Loop counter */ \
119 \
120 \
121 /* Load first input value that act as reference value for comparision */ \
122 out = *pSrc++; \
123 out = ((_Float16)out > 0.0f16) ? out : -(_Float16)out; \
124 \
125 \
126 /* Loop unrolling: Compute 4 outputs at a time */ \
127 blkCnt = (blockSize - 1U) >> 2U; \
128 \
129 while (blkCnt > 0U) \
130 { \
131 /* Initialize cur_absmin to next consecutive values one by one */ \
132 cur_absmin = *pSrc++; \
133 cur_absmin = ((_Float16)cur_absmin > 0.0f16) ? cur_absmin : -(_Float16)cur_absmin; \
134 /* compare for the extrema value */ \
135 if ((_Float16)cur_absmin < (_Float16)out) \
136 { \
137 /* Update the extrema value and it's index */ \
138 out = cur_absmin; \
139 } \
140 \
141 cur_absmin = *pSrc++; \
142 cur_absmin = ((_Float16)cur_absmin > 0.0f16) ? cur_absmin : -(_Float16)cur_absmin; \
143 if ((_Float16)cur_absmin < (_Float16)out) \
144 { \
145 out = cur_absmin; \
146 } \
147 \
148 cur_absmin = *pSrc++; \
149 cur_absmin = ((_Float16)cur_absmin > 0.0f16) ? cur_absmin : -(_Float16)cur_absmin; \
150 if ((_Float16)cur_absmin < (_Float16)out) \
151 { \
152 out = cur_absmin; \
153 } \
154 \
155 cur_absmin = *pSrc++; \
156 cur_absmin = ((_Float16)cur_absmin > 0.0f16) ? cur_absmin : -(_Float16)cur_absmin; \
157 if ((_Float16)cur_absmin < (_Float16)out) \
158 { \
159 out = cur_absmin; \
160 } \
161 \
162 \
163 /* Decrement loop counter */ \
164 blkCnt--; \
165 } \
166 \
167 /* Loop unrolling: Compute remaining outputs */ \
168 blkCnt = (blockSize - 1U) % 4U; \
169 \
170 \
171 while (blkCnt > 0U) \
172 { \
173 cur_absmin = *pSrc++; \
174 cur_absmin = ((_Float16)cur_absmin > 0.0f16) ? cur_absmin : -(_Float16)cur_absmin; \
175 if ((_Float16)cur_absmin < (_Float16)out) \
176 { \
177 out = cur_absmin; \
178 } \
179 \
180 /* Decrement loop counter */ \
181 blkCnt--; \
182 } \
183 \
184 /* Store the extrema value and it's index into destination pointers */ \
185 *pResult = out; \
186 }
187 #else
arm_absmin_no_idx_f16(const float16_t * pSrc,uint32_t blockSize,float16_t * pResult)188 void arm_absmin_no_idx_f16(
189 const float16_t * pSrc,
190 uint32_t blockSize,
191 float16_t * pResult)
192 {
193 float16_t minVal, out; /* Temporary variables to store the output value. */
194 uint32_t blkCnt; /* Loop counter */
195
196
197
198 /* Load first input value that act as reference value for comparision */
199 out = (_Float16)fabsf((float32_t)*pSrc++);
200
201 /* Initialize blkCnt with number of samples */
202 blkCnt = (blockSize - 1U);
203
204 while (blkCnt > 0U)
205 {
206 /* Initialize minVal to the next consecutive values one by one */
207 minVal = (_Float16)fabsf((float32_t)*pSrc++);
208
209 /* compare for the minimum value */
210 if ((_Float16)out > (_Float16)minVal)
211 {
212 /* Update the minimum value and it's index */
213 out = minVal;
214 }
215
216 /* Decrement loop counter */
217 blkCnt--;
218 }
219
220 /* Store the minimum value and it's index into destination pointers */
221 *pResult = out;
222 }
223 #endif /* defined(ARM_MATH_LOOPUNROLL) */
224 #endif /* defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE) */
225 /**
226 @} end of AbsMin group
227 */
228
229 #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */
230
231