]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/dsp/cmsis_dsp/StatisticsFunctions/arm_max_q31.c
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / dsp / cmsis_dsp / StatisticsFunctions / arm_max_q31.c
1 /* ----------------------------------------------------------------------
2 * Copyright (C) 2010-2013 ARM Limited. All rights reserved.
3 *
4 * $Date: 17. January 2013
5 * $Revision: V1.4.1
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 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * - Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * - Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in
21 * the documentation and/or other materials provided with the
22 * distribution.
23 * - Neither the name of ARM LIMITED nor the names of its contributors
24 * may be used to endorse or promote products derived from this
25 * software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
39 * ---------------------------------------------------------------------------- */
40
41 #include "arm_math.h"
42
43 /**
44 * @ingroup groupStats
45 */
46
47 /**
48 * @addtogroup Max
49 * @{
50 */
51
52
53 /**
54 * @brief Maximum value of a Q31 vector.
55 * @param[in] *pSrc points to the input vector
56 * @param[in] blockSize length of the input vector
57 * @param[out] *pResult maximum value returned here
58 * @param[out] *pIndex index of maximum value returned here
59 * @return none.
60 */
61
62 void arm_max_q31(
63 q31_t * pSrc,
64 uint32_t blockSize,
65 q31_t * pResult,
66 uint32_t * pIndex)
67 {
68 #ifndef ARM_MATH_CM0_FAMILY
69
70 /* Run the below code for Cortex-M4 and Cortex-M3 */
71 q31_t maxVal1, maxVal2, out; /* Temporary variables to store the output value. */
72 uint32_t blkCnt, outIndex, count; /* loop counter */
73
74 /* Initialise the count value. */
75 count = 0u;
76 /* Initialise the index value to zero. */
77 outIndex = 0u;
78 /* Load first input value that act as reference value for comparision */
79 out = *pSrc++;
80
81 /* Loop unrolling */
82 blkCnt = (blockSize - 1u) >> 2u;
83
84 /* Run the below code for Cortex-M4 and Cortex-M3 */
85 while(blkCnt > 0u)
86 {
87 /* Initialize maxVal to the next consecutive values one by one */
88 maxVal1 = *pSrc++;
89
90 maxVal2 = *pSrc++;
91
92 /* compare for the maximum value */
93 if(out < maxVal1)
94 {
95 /* Update the maximum value and its index */
96 out = maxVal1;
97 outIndex = count + 1u;
98 }
99
100 maxVal1 = *pSrc++;
101
102 /* compare for the maximum value */
103 if(out < maxVal2)
104 {
105 /* Update the maximum value and its index */
106 out = maxVal2;
107 outIndex = count + 2u;
108 }
109
110 maxVal2 = *pSrc++;
111
112 /* compare for the maximum value */
113 if(out < maxVal1)
114 {
115 /* Update the maximum value and its index */
116 out = maxVal1;
117 outIndex = count + 3u;
118 }
119
120 /* compare for the maximum value */
121 if(out < maxVal2)
122 {
123 /* Update the maximum value and its index */
124 out = maxVal2;
125 outIndex = count + 4u;
126 }
127
128 count += 4u;
129
130 /* Decrement the loop counter */
131 blkCnt--;
132 }
133
134 /* if (blockSize - 1u) is not multiple of 4 */
135 blkCnt = (blockSize - 1u) % 4u;
136
137 #else
138
139 /* Run the below code for Cortex-M0 */
140 q31_t maxVal1, out; /* Temporary variables to store the output value. */
141 uint32_t blkCnt, outIndex; /* loop counter */
142
143 /* Initialise the index value to zero. */
144 outIndex = 0u;
145 /* Load first input value that act as reference value for comparision */
146 out = *pSrc++;
147
148 blkCnt = (blockSize - 1u);
149
150 #endif /* #ifndef ARM_MATH_CM0_FAMILY */
151
152 while(blkCnt > 0u)
153 {
154 /* Initialize maxVal to the next consecutive values one by one */
155 maxVal1 = *pSrc++;
156
157 /* compare for the maximum value */
158 if(out < maxVal1)
159 {
160 /* Update the maximum value and it's index */
161 out = maxVal1;
162 outIndex = blockSize - blkCnt;
163 }
164
165 /* Decrement the loop counter */
166 blkCnt--;
167
168 }
169
170 /* Store the maximum value and its index into destination pointers */
171 *pResult = out;
172 *pIndex = outIndex;
173 }
174
175 /**
176 * @} end of Max group
177 */
Imprint / Impressum