Added all the F4 libraries to the project
[fw/stlink] / exampleF4 / CMSIS / DSP_Lib / Source / StatisticsFunctions / arm_max_q31.c
1 /* ----------------------------------------------------------------------   
2 * Copyright (C) 2010 ARM Limited. All rights reserved.   
3 *   
4 * $Date:        15. July 2011  
5 * $Revision:    V1.0.10  
6 *   
7 * Project:          CMSIS DSP Library   
8 * Title:                arm_max_q31.c   
9 *   
10 * Description:  Maximum value of a Q31 vector.   
11 *   
12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
13 *  
14 * Version 1.0.10 2011/7/15 
15 *    Big Endian support added and Merged M0 and M3/M4 Source code.  
16 *   
17 * Version 1.0.3 2010/11/29  
18 *    Re-organized the CMSIS folders and updated documentation.   
19 *    
20 * Version 1.0.2 2010/11/11   
21 *    Documentation updated.    
22 *   
23 * Version 1.0.1 2010/10/05    
24 *    Production release and review comments incorporated.   
25 *   
26 * Version 1.0.0 2010/09/20    
27 *    Production release and review comments incorporated.   
28 * ---------------------------------------------------------------------------- */
29
30 #include "arm_math.h"
31
32 /**   
33  * @ingroup groupStats   
34  */
35
36 /**   
37  * @addtogroup Max   
38  * @{   
39  */
40
41
42 /**   
43  * @brief Maximum value of a Q31 vector.   
44  * @param[in]       *pSrc points to the input vector   
45  * @param[in]       blockSize length of the input vector   
46  * @param[out]      *pResult maximum value returned here   
47  * @param[out]      *pIndex index of maximum value returned here   
48  * @return none.   
49  */
50
51 void arm_max_q31(
52   q31_t * pSrc,
53   uint32_t blockSize,
54   q31_t * pResult,
55   uint32_t * pIndex)
56 {
57   q31_t maxVal, out;                             /* Temporary variables to store the output value. */
58   uint32_t blkCnt, outIndex;                     /* loop counter */
59
60   /* Initialise the index value to zero. */
61   outIndex = 0u;
62   /* Load first input value that act as reference value for comparision */
63   out = *pSrc++;
64
65   /* Loop over blockSize number of values */
66   blkCnt = (blockSize - 1u);
67
68 #ifndef ARM_MATH_CM0
69
70   /* Run the below code for Cortex-M4 and Cortex-M3 */
71
72   do
73   {
74     /* Initialize maxVal to the next consecutive values one by one */
75     maxVal = *pSrc++;
76
77     /* compare for the maximum value */
78     if(out < maxVal)
79     {
80       /* Update the maximum value and its index */
81       out = maxVal;
82       outIndex = blockSize - blkCnt;
83     }
84
85     /* Decrement the loop counter */
86     blkCnt--;
87
88   } while(blkCnt > 0u);
89
90 #else
91
92   /* Run the below code for Cortex-M0 */
93
94   while(blkCnt > 0u)
95   {
96     /* Initialize maxVal to the next consecutive values one by one */
97     maxVal = *pSrc++;
98
99     /* Compare for the maximum value */
100     if(out < maxVal)
101     {
102       /* Update the maximum value and its index */
103       out = maxVal;
104       outIndex = blockSize - blkCnt;
105     }
106
107     /* Decrement the loop counter */
108     blkCnt--;
109
110   }
111
112 #endif /* #ifndef ARM_MATH_CM0 */
113
114   /* Store the maximum value and its index into destination pointers */
115   *pResult = out;
116   *pIndex = outIndex;
117 }
118
119 /**   
120  * @} end of Max group   
121  */