1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_absmax_no_idx_q15.c
4 * Description: Maximum value of absolute values of a Q15 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 Q15 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 */
46 #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
47
48 #include "arm_helium_utils.h"
49
arm_absmax_no_idx_q15(const q15_t * pSrc,uint32_t blockSize,q15_t * pResult)50 ARM_DSP_ATTRIBUTE void arm_absmax_no_idx_q15(
51 const q15_t * pSrc,
52 uint32_t blockSize,
53 q15_t * pResult)
54 {
55 int32_t blkCnt; /* loop counters */
56 q15x8_t vecSrc;
57 q15_t const *pSrcVec;
58 uint16x8_t curExtremValVec = vdupq_n_u16(Q15_ABSMIN);
59 uint16_t maxValue = Q15_ABSMIN;
60
61
62 pSrcVec = (q15_t const *) pSrc;
63 blkCnt = blockSize;
64 while (blkCnt > 0)
65 {
66 mve_pred16_t p = vctp16q(blkCnt);
67 vecSrc = vld1q_z_s16(pSrcVec,p);
68 pSrcVec += 8;
69 /*
70 * update per-lane max.
71 */
72 curExtremValVec = vmaxaq_m(curExtremValVec, vecSrc,p);
73 /*
74 * Decrement the blockSize loop counter
75 */
76 blkCnt -= 8;
77 }
78 /*
79 * Get max value across the vector
80 */
81 maxValue = vmaxvq(maxValue, curExtremValVec);
82 *pResult = __USAT(maxValue, 15);
83 }
84
85 #else
86 #if defined(ARM_MATH_DSP)
arm_absmax_no_idx_q15(const q15_t * pSrc,uint32_t blockSize,q15_t * pResult)87 ARM_DSP_ATTRIBUTE void arm_absmax_no_idx_q15(
88 const q15_t * pSrc,
89 uint32_t blockSize,
90 q15_t * pResult)
91 {
92 q15_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 : (q15_t)__QSUB16(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 : (q15_t)__QSUB16(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 : (q15_t)__QSUB16(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 : (q15_t)__QSUB16(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 : (q15_t)__QSUB16(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 : (q15_t)__QSUB16(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_q15(const q15_t * pSrc,uint32_t blockSize,q15_t * pResult)163 ARM_DSP_ATTRIBUTE void arm_absmax_no_idx_q15(
164 const q15_t * pSrc,
165 uint32_t blockSize,
166 q15_t * pResult)
167 {
168 q15_t maxVal, out; /* Temporary variables to store the output value. */
169 uint32_t blkCnt; /* Loop counter */
170
171
172 /* Load first input value that act as reference value for comparision */
173 out = (*pSrc > 0) ? *pSrc : ((*pSrc == (q15_t) 0x8000) ? 0x7fff : -*pSrc);
174 pSrc++;
175
176 /* Initialize blkCnt with number of samples */
177 blkCnt = (blockSize - 1U);
178
179 while (blkCnt > 0U)
180 {
181 /* Initialize maxVal to the next consecutive values one by one */
182 maxVal = (*pSrc > 0) ? *pSrc : ((*pSrc == (q15_t) 0x8000) ? 0x7fff : -*pSrc);
183 pSrc++;
184
185 /* compare for the maximum value */
186 if (out < maxVal)
187 {
188 /* Update the maximum value and it's index */
189 out = maxVal;
190 }
191
192 /* Decrement loop counter */
193 blkCnt--;
194 }
195
196 /* Store the maximum value and it's index into destination pointers */
197 *pResult = out;
198 }
199 #endif /* defined(ARM_MATH_DSP) */
200 #endif /* defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE) */
201 /**
202 @} end of AbsMax group
203 */
204