• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   @return        none
50  */
51 
52 #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
53 
arm_max_no_idx_f32(const float32_t * pSrc,uint32_t blockSize,float32_t * pResult)54 void arm_max_no_idx_f32(
55     const float32_t *pSrc,
56     uint32_t   blockSize,
57     float32_t *pResult)
58 {
59    f32x4_t     vecSrc;
60    f32x4_t     curExtremValVec = vdupq_n_f32(F32_MIN);
61    float32_t   maxValue = F32_MIN;
62    float32_t   newVal;
63    uint32_t    blkCnt;
64 
65    /* Loop unrolling: Compute 4 outputs at a time */
66    blkCnt = blockSize >> 2U;
67 
68    while (blkCnt > 0U)
69    {
70 
71         vecSrc = vldrwq_f32(pSrc);
72         /*
73          * update per-lane max.
74          */
75         curExtremValVec = vmaxnmq(vecSrc, curExtremValVec);
76         /*
77          * Decrement the blockSize loop counter
78          * Advance vector source and destination pointers
79          */
80         pSrc += 4;
81         blkCnt --;
82     }
83     /*
84      * Get max value across the vector
85      */
86     maxValue = vmaxnmvq(maxValue, curExtremValVec);
87 
88     blkCnt = blockSize & 3;
89 
90     while (blkCnt > 0U)
91     {
92         newVal = *pSrc++;
93 
94         /* compare for the maximum value */
95         if (maxValue < newVal)
96         {
97             /* Update the maximum value and it's index */
98             maxValue = newVal;
99         }
100 
101         blkCnt --;
102     }
103 
104     *pResult = maxValue;
105 }
106 
107 #else
108 
arm_max_no_idx_f32(const float32_t * pSrc,uint32_t blockSize,float32_t * pResult)109 void arm_max_no_idx_f32(
110     const float32_t *pSrc,
111     uint32_t   blockSize,
112     float32_t *pResult)
113 {
114    float32_t   maxValue = F32_MIN;
115    float32_t   newVal;
116 
117    while (blockSize > 0U)
118    {
119        newVal = *pSrc++;
120 
121        /* compare for the maximum value */
122        if (maxValue < newVal)
123        {
124            /* Update the maximum value and it's index */
125            maxValue = newVal;
126        }
127 
128        blockSize --;
129    }
130 
131    *pResult = maxValue;
132 }
133 
134 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
135 
136 /**
137   @} end of Max group
138  */
139