/ Drivers / CMSIS / DSP / Source / StatisticsFunctions / arm_max_no_idx_q7.c
arm_max_no_idx_q7.c
  1  /* ----------------------------------------------------------------------
  2   * Project:      CMSIS DSP Library
  3   * Title:        arm_max_no_idx_q7.c
  4   * Description:  Maximum 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 Max
 38    @{
 39   */
 40  
 41  /**
 42    @brief         Maximum 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    maximum 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"
 52  
 53  void arm_max_no_idx_q7(
 54    const q7_t * pSrc,
 55          uint32_t blockSize,
 56          q7_t * pResult)
 57  {
 58      int32_t  blkCnt;           /* loop counters */
 59      q7x16_t       vecSrc;
 60      q7_t const *pSrcVec;
 61      q7x16_t       curExtremValVec = vdupq_n_s8(Q7_MIN);
 62      q7_t           maxValue = Q7_MIN;
 63      mve_pred16_t    p0;
 64  
 65  
 66      pSrcVec = (q7_t const *) pSrc;
 67      blkCnt = blockSize >> 4;
 68      while (blkCnt > 0)
 69      {
 70          vecSrc = vld1q(pSrcVec); 
 71          pSrcVec += 16;
 72          /*
 73           * update per-lane max.
 74           */
 75          curExtremValVec = vmaxq(vecSrc, curExtremValVec);
 76          /*
 77           * Decrement the blockSize loop counter
 78           */
 79          blkCnt--;
 80      }
 81      /*
 82       * tail
 83       * (will be merged thru tail predication)
 84       */
 85      blkCnt = blockSize & 0xF;
 86      if (blkCnt > 0)
 87      {
 88          vecSrc = vld1q(pSrcVec); 
 89          pSrcVec += 16;
 90          p0 = vctp8q(blkCnt);
 91          /*
 92           * Get current max per lane and current index per lane
 93           * when a max is selected
 94           */
 95           curExtremValVec = vmaxq_m(curExtremValVec, vecSrc, curExtremValVec, p0);
 96      }
 97      /*
 98       * Get max value across the vector
 99       */
100      maxValue = vmaxvq(maxValue, curExtremValVec);
101      *pResult = maxValue;
102  }
103  
104  #else
105  
106  void arm_max_no_idx_q7(
107    const q7_t * pSrc,
108          uint32_t blockSize,
109          q7_t * pResult)
110  {
111    q7_t maxVal1, out;       /* Temporary variables to store the output value. */     
112    uint32_t blkCnt;              /* loop counter */                                  
113                                                                                      
114    /* Load first input value that act as reference value for comparision */          
115    out = *pSrc++;                                                                    
116                                                                                      
117    blkCnt = (blockSize - 1U);                                                        
118                                                                                      
119                                                                                      
120    while (blkCnt > 0U)                                                               
121    {                                                                                 
122      /* Initialize maxVal to the next consecutive values one by one */               
123      maxVal1 = *pSrc++;                                                              
124                                                                                      
125      /* compare for the maximum value */                                             
126      if (out < maxVal1)                                                              
127      {                                                                               
128        /* Update the maximum value */                                                
129        out = maxVal1;                                                                
130      }                                                                               
131                                                                                      
132      /* Decrement the loop counter */                                                
133      blkCnt--;                                                                       
134    }                                                                                 
135                                                                                      
136    /* Store the maximum value into destination pointer */                            
137    *pResult = out;
138  }
139  
140  #endif /* #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE) */
141  /**
142    @} end of Max group
143   */