1 /* ----------------------------------------------------------------------
2  * Project:      CMSIS DSP Library
3  * Title:        arm_min_no_idx_q7.c
4  * Description:  Minimum value of a q7 vector without returning the index
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 /**
33   @ingroup groupStats
34  */
35 
36 /**
37   @addtogroup Min
38   @{
39  */
40 
41 /**
42   @brief         Minimum value of a q7 vector without index.
43   @param[in]     pSrc       points to the input vector
44   @param[in]     blockSize  number of samples in input vector
45   @param[out]    pResult    minimum value returned here
46  */
47 #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
48 
49 #include "arm_helium_utils.h"
50 
arm_min_no_idx_q7(const q7_t * pSrc,uint32_t blockSize,q7_t * pResult)51 void arm_min_no_idx_q7(
52   const q7_t * pSrc,
53         uint32_t blockSize,
54         q7_t * pResult)
55 {
56     int32_t  blkCnt;           /* loop counters */
57     q7x16_t vecSrc;
58     q7_t const *pSrcVec;
59     q7x16_t curExtremValVec = vdupq_n_s8(Q7_MAX);
60     q7_t minValue = Q7_MAX;
61     mve_pred16_t p0;
62 
63 
64     pSrcVec = (q7_t const *) pSrc;
65     blkCnt = blockSize >> 4;
66     while (blkCnt > 0)
67     {
68         vecSrc = vld1q(pSrcVec);
69         pSrcVec += 16;
70         /*
71          * update per-lane min.
72          */
73         curExtremValVec = vminq(vecSrc, curExtremValVec);
74         /*
75          * Decrement the blockSize loop counter
76          */
77         blkCnt--;
78     }
79     /*
80      * tail
81      * (will be merged thru tail predication)
82      */
83     blkCnt = blockSize & 0xF;
84     if (blkCnt > 0)
85     {
86         vecSrc = vld1q(pSrcVec);
87         pSrcVec += 16;
88         p0 = vctp8q(blkCnt);
89         /*
90          * Get current min per lane and current index per lane
91          * when a min is selected
92          */
93          curExtremValVec = vminq_m(curExtremValVec, vecSrc, curExtremValVec, p0);
94     }
95     /*
96      * Get min value across the vector
97      */
98     minValue = vminvq(minValue, curExtremValVec);
99     *pResult = minValue;
100 }
101 
102 #else
arm_min_no_idx_q7(const q7_t * pSrc,uint32_t blockSize,q7_t * pResult)103 void arm_min_no_idx_q7(
104   const q7_t * pSrc,
105         uint32_t blockSize,
106         q7_t * pResult)
107 {
108   q7_t minVal1, out;       /* Temporary variables to store the output value. */
109   uint32_t blkCnt;              /* loop counter */
110 
111   /* Load first input value that act as reference value for comparision */
112   out = *pSrc++;
113 
114   blkCnt = (blockSize - 1U);
115 
116 
117   while (blkCnt > 0U)
118   {
119     /* Initialize minVal to the next consecutive values one by one */
120     minVal1 = *pSrc++;
121 
122     /* compare for the minimum value */
123     if (out > minVal1)
124     {
125       /* Update the minimum value */
126       out = minVal1;
127     }
128 
129     /* Decrement the loop counter */
130     blkCnt--;
131   }
132 
133   /* Store the minimum value into destination pointer */
134   *pResult = out;
135 }
136 
137 #endif /* #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE) */
138 /**
139   @} end of Min group
140  */
141