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