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