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