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