1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_min_no_idx_f16.c
4 * Description: Minimum value of a floating-point vector without returning the index
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 #if (defined(ARM_MATH_NEON) || defined(ARM_MATH_MVEF)) && !defined(ARM_MATH_AUTOVECTORIZE)
34 #include <limits.h>
35 #endif
36
37 /**
38 @ingroup groupStats
39 */
40
41
42 /**
43 @addtogroup Min
44 @{
45 */
46
47 /**
48 @brief Minimum value of a floating-point vector.
49 @param[in] pSrc points to the input vector
50 @param[in] blockSize number of samples in input vector
51 @param[out] pResult minimum value returned here
52 @return none
53 */
54
55 #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE)
56
arm_min_no_idx_f16(const float16_t * pSrc,uint32_t blockSize,float16_t * pResult)57 void arm_min_no_idx_f16(
58 const float16_t *pSrc,
59 uint32_t blockSize,
60 float16_t *pResult)
61 {
62 f16x8_t vecSrc;
63 f16x8_t curExtremValVec = vdupq_n_f16(F16_MAX);
64 float16_t minValue = F16_MAX;
65 float16_t newVal;
66 uint32_t blkCnt;
67
68 /* Loop unrolling: Compute 4 outputs at a time */
69 blkCnt = blockSize >> 3U;
70
71 while (blkCnt > 0U)
72 {
73
74 vecSrc = vldrhq_f16(pSrc);
75 /*
76 * update per-lane min.
77 */
78 curExtremValVec = vminnmq(vecSrc, curExtremValVec);
79 /*
80 * Decrement the blockSize loop counter
81 * Advance vector source and destination pointers
82 */
83 pSrc += 8;
84 blkCnt --;
85 }
86 /*
87 * Get min value across the vector
88 */
89 minValue = vminnmvq(minValue, curExtremValVec);
90
91 blkCnt = blockSize & 7;
92
93 while (blkCnt > 0U)
94 {
95 newVal = *pSrc++;
96
97 /* compare for the minimum value */
98 if ((_Float16)minValue > (_Float16)newVal)
99 {
100 /* Update the minimum value and it's index */
101 minValue = newVal;
102 }
103
104 blkCnt --;
105 }
106
107 *pResult = minValue;
108 }
109
110 #else
111
arm_min_no_idx_f16(const float16_t * pSrc,uint32_t blockSize,float16_t * pResult)112 void arm_min_no_idx_f16(
113 const float16_t *pSrc,
114 uint32_t blockSize,
115 float16_t *pResult)
116 {
117 float16_t minValue = F16_MAX;
118 float16_t newVal;
119
120 while (blockSize > 0U)
121 {
122 newVal = *pSrc++;
123
124 /* compare for the minimum value */
125 if ((_Float16)minValue > (_Float16)newVal)
126 {
127 /* Update the minimum value and it's index */
128 minValue = newVal;
129 }
130
131 blockSize --;
132 }
133
134 *pResult = minValue;
135 }
136
137 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
138
139 /**
140 @} end of Min group
141 */
142
143 #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */
144
145