CMSIS DSP Software Library: arm_max_q7.c Source File

- Main Page
- Modules
- Data Structures
- Files
- Examples

- File List
- Globals

# arm_max_q7.c

Go to the documentation of this file.

    00001 /* ----------------------------------------------------------------------
    00002 * Copyright (C) 2010 ARM Limited. All rights reserved.
    00003 *
    00004 * $Date:        15. July 2011
    00005 * $Revision:    V1.0.10
    00006 *
    00007 * Project:      CMSIS DSP Library
    00008 * Title:        arm_max_q7.c
    00009 *
    00010 * Description:  Maximum value of a Q7 vector.
    00011 *
    00012 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
    00013 *
    00014 * Version 1.0.10 2011/7/15
    00015 *    Big Endian support added and Merged M0 and M3/M4 Source code.
    00016 *
    00017 * Version 1.0.3 2010/11/29
    00018 *    Re-organized the CMSIS folders and updated documentation.
    00019 *
    00020 * Version 1.0.2 2010/11/11
    00021 *    Documentation updated.
    00022 *
    00023 * Version 1.0.1 2010/10/05
    00024 *    Production release and review comments incorporated.
    00025 *
    00026 * Version 1.0.0 2010/09/20
    00027 *    Production release and review comments incorporated.
    00028 * ---------------------------------------------------------------------------- */
    00029
    00030 #include "arm_math.h"
    00031
    00051 void arm_max_q7(
    00052   q7_t * pSrc,
    00053   uint32_t blockSize,
    00054   q7_t * pResult,
    00055   uint32_t * pIndex)
    00056 {
    00057
    00058 #ifndef ARM_MATH_CM0
    00059
    00060   /* Run the below code for Cortex-M4 and Cortex-M3 */
    00061
    00062   q7_t res, maxVal, x0, x1, maxVal2, maxVal1;    /* Temporary variables to store the output value. */
    00063   uint32_t blkCnt, index1, index2, index3, indx, indxMod;       /* loop counter */
    00064
    00065   /* Initialise the index value to zero. */
    00066   indx = 0u;
    00067
    00068   /* Load first input value that act as reference value for comparision */
    00069   res = *pSrc++;
    00070
    00071   /* Loop unrolling */
    00072   blkCnt = (blockSize - 1u) >> 2u;
    00073
    00074   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.
    00075    ** a second loop below computes the remaining 1 to 3 samples. */
    00076   while(blkCnt > 0u)
    00077   {
    00078     indxMod = blockSize - (blkCnt * 4u);
    00079
    00080     /* Load two input values for comparision */
    00081     x0 = *pSrc++;
    00082     x1 = *pSrc++;
    00083
    00084     if(x0 < x1)
    00085     {
    00086       /* Update the maximum value and its index */
    00087       maxVal1 = x1;
    00088       index1 = indxMod + 1u;
    00089     }
    00090     else
    00091     {
    00092       /* Update the maximum value and its index */
    00093       maxVal1 = x0;
    00094       index1 = indxMod;
    00095     }
    00096
    00097     /* Load two input values for comparision */
    00098     x0 = *pSrc++;
    00099     x1 = *pSrc++;
    00100
    00101     if(x0 < x1)
    00102     {
    00103       /* Update the maximum value and its index */
    00104       maxVal2 = x1;
    00105       index2 = indxMod + 3u;
    00106     }
    00107     else
    00108     {
    00109       /* Update the maximum value and its index */
    00110       maxVal2 = x0;
    00111       index2 = indxMod + 2u;
    00112     }
    00113
    00114     if(maxVal1 < maxVal2)
    00115     {
    00116       /* Update the maximum value and its index */
    00117       maxVal = maxVal2;
    00118       index3 = index2;
    00119     }
    00120     else
    00121     {
    00122       /* Update the maximum value and its index */
    00123       maxVal = maxVal1;
    00124       index3 = index1;
    00125     }
    00126
    00127     if(res < maxVal)
    00128     {
    00129       /* Update the maximum value and its index */
    00130       res = maxVal;
    00131       indx = index3;
    00132     }
    00133
    00134     /* Decrement the loop counter */
    00135     blkCnt--;
    00136
    00137   }
    00138
    00139   /* If the blockSize - 1 is not a multiple of 4, compute any remaining output samples here.
    00140    ** No loop unrolling is used. */
    00141   blkCnt = (blockSize - 1u) % 0x04u;
    00142
    00143   while(blkCnt > 0u)
    00144   {
    00145     /* Initialize maxVal to the next consecutive values one by one */
    00146     maxVal = *pSrc++;
    00147
    00148     /* compare for the maximum value */
    00149     if(res < maxVal)
    00150     {
    00151       /* Update the maximum value and its index */
    00152       res = maxVal;
    00153       indx = blockSize - blkCnt;
    00154     }
    00155
    00156     /* Decrement the loop counter */
    00157     blkCnt--;
    00158   }
    00159
    00160   /* Store the maximum value and its index into destination pointers */
    00161   *pResult = res;
    00162   *pIndex = indx;
    00163
    00164 #else
    00165
    00166   /* Run the below code for Cortex-M0 */
    00167
    00168   q7_t maxVal, out;                              /* Temporary variables to store the output value. */
    00169   uint32_t blkCnt, outIndex;                     /* loop counter */
    00170
    00171   /* Initialise the index value to zero. */
    00172   outIndex = 0u;
    00173   /* Load first input value that act as reference value for comparision */
    00174   out = *pSrc++;
    00175
    00176   /* Loop over blockSize - 1 number of values */
    00177   blkCnt = (blockSize - 1u);
    00178
    00179   while(blkCnt > 0u)
    00180   {
    00181     /* Initialize maxVal to the next consecutive values one by one */
    00182     maxVal = *pSrc++;
    00183
    00184     /* compare for the maximum value */
    00185     if(out < maxVal)
    00186     {
    00187       /* Update the maximum value and its index */
    00188       out = maxVal;
    00189       outIndex = blockSize - blkCnt;
    00190     }
    00191     /* Decrement the loop counter */
    00192     blkCnt--;
    00193
    00194   }
    00195
    00196   /* Store the maximum value and its index into destination pointers */
    00197   *pResult = out;
    00198   *pIndex = outIndex;
    00199
    00200 #endif /* #ifndef ARM_MATH_CM0 */
    00201
    00202 }
    00203

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines