1 /* ----------------------------------------------------------------------
2  * Project:      CMSIS DSP Library
3  * Title:        arm_max_no_idx_f32.c
4  * Description:  Maximum value of a floating-point vector without returning the index
5  *
6  * $Date:        23 April 2021
7  * $Revision:    V1.9.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 #if (defined(ARM_MATH_NEON) || defined(ARM_MATH_MVEF)) && !defined(ARM_MATH_AUTOVECTORIZE)
31 #include <limits.h>
32 #endif
33 
34 /**
35   @ingroup groupStats
36  */
37 
38 
39 /**
40   @addtogroup Max
41   @{
42  */
43 
44 /**
45   @brief         Maximum value of a floating-point vector.
46   @param[in]     pSrc       points to the input vector
47   @param[in]     blockSize  number of samples in input vector
48   @param[out]    pResult    maximum value returned here
49  */
50 
51 #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
52 
arm_max_no_idx_f32(const float32_t * pSrc,uint32_t blockSize,float32_t * pResult)53 ARM_DSP_ATTRIBUTE void arm_max_no_idx_f32(
54     const float32_t *pSrc,
55     uint32_t   blockSize,
56     float32_t *pResult)
57 {
58    f32x4_t     vecSrc;
59    f32x4_t     curExtremValVec = vdupq_n_f32(F32_MIN);
60    float32_t   maxValue = F32_MIN;
61    float32_t   newVal;
62    uint32_t    blkCnt;
63 
64    /* Loop unrolling: Compute 4 outputs at a time */
65    blkCnt = blockSize >> 2U;
66 
67    while (blkCnt > 0U)
68    {
69 
70         vecSrc = vldrwq_f32(pSrc);
71         /*
72          * update per-lane max.
73          */
74         curExtremValVec = vmaxnmq(vecSrc, curExtremValVec);
75         /*
76          * Decrement the blockSize loop counter
77          * Advance vector source and destination pointers
78          */
79         pSrc += 4;
80         blkCnt --;
81     }
82     /*
83      * Get max value across the vector
84      */
85     maxValue = vmaxnmvq(maxValue, curExtremValVec);
86 
87     blkCnt = blockSize & 3;
88 
89     while (blkCnt > 0U)
90     {
91         newVal = *pSrc++;
92 
93         /* compare for the maximum value */
94         if (maxValue < newVal)
95         {
96             /* Update the maximum value and it's index */
97             maxValue = newVal;
98         }
99 
100         blkCnt --;
101     }
102 
103     *pResult = maxValue;
104 }
105 
106 #else
107 
arm_max_no_idx_f32(const float32_t * pSrc,uint32_t blockSize,float32_t * pResult)108 ARM_DSP_ATTRIBUTE void arm_max_no_idx_f32(
109     const float32_t *pSrc,
110     uint32_t   blockSize,
111     float32_t *pResult)
112 {
113    float32_t   maxValue = F32_MIN;
114    float32_t   newVal;
115 
116    while (blockSize > 0U)
117    {
118        newVal = *pSrc++;
119 
120        /* compare for the maximum value */
121        if (maxValue < newVal)
122        {
123            /* Update the maximum value and it's index */
124            maxValue = newVal;
125        }
126 
127        blockSize --;
128    }
129 
130    *pResult = maxValue;
131 }
132 
133 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
134 
135 /**
136   @} end of Max group
137  */
138