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