Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | mjames | 1 | /* ---------------------------------------------------------------------- |
2 | * Project: CMSIS DSP Library |
||
3 | * Title: arm_max_q31.c |
||
4 | * Description: Maximum value of a Q31 vector |
||
5 | * |
||
6 | * $Date: 27. January 2017 |
||
7 | * $Revision: V.1.5.1 |
||
8 | * |
||
9 | * Target Processor: Cortex-M cores |
||
10 | * -------------------------------------------------------------------- */ |
||
11 | /* |
||
12 | * Copyright (C) 2010-2017 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 "arm_math.h" |
||
30 | |||
31 | /** |
||
32 | * @ingroup groupStats |
||
33 | */ |
||
34 | |||
35 | /** |
||
36 | * @addtogroup Max |
||
37 | * @{ |
||
38 | */ |
||
39 | |||
40 | |||
41 | /** |
||
42 | * @brief Maximum value of a Q31 vector. |
||
43 | * @param[in] *pSrc points to the input vector |
||
44 | * @param[in] blockSize length of the input vector |
||
45 | * @param[out] *pResult maximum value returned here |
||
46 | * @param[out] *pIndex index of maximum value returned here |
||
47 | * @return none. |
||
48 | */ |
||
49 | |||
50 | void arm_max_q31( |
||
51 | q31_t * pSrc, |
||
52 | uint32_t blockSize, |
||
53 | q31_t * pResult, |
||
54 | uint32_t * pIndex) |
||
55 | { |
||
56 | #if defined (ARM_MATH_DSP) |
||
57 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
||
58 | |||
59 | q31_t maxVal1, maxVal2, out; /* Temporary variables to store the output value. */ |
||
60 | uint32_t blkCnt, outIndex, count; /* loop counter */ |
||
61 | |||
62 | /* Initialise the count value. */ |
||
63 | count = 0U; |
||
64 | /* Initialise the index value to zero. */ |
||
65 | outIndex = 0U; |
||
66 | /* Load first input value that act as reference value for comparision */ |
||
67 | out = *pSrc++; |
||
68 | |||
69 | /* Loop unrolling */ |
||
70 | blkCnt = (blockSize - 1U) >> 2U; |
||
71 | |||
72 | while (blkCnt > 0U) |
||
73 | { |
||
74 | /* Initialize maxVal to the next consecutive values one by one */ |
||
75 | maxVal1 = *pSrc++; |
||
76 | maxVal2 = *pSrc++; |
||
77 | |||
78 | /* compare for the maximum value */ |
||
79 | if (out < maxVal1) |
||
80 | { |
||
81 | /* Update the maximum value and its index */ |
||
82 | out = maxVal1; |
||
83 | outIndex = count + 1U; |
||
84 | } |
||
85 | |||
86 | /* compare for the maximum value */ |
||
87 | if (out < maxVal2) |
||
88 | { |
||
89 | /* Update the maximum value and its index */ |
||
90 | out = maxVal2; |
||
91 | outIndex = count + 2U; |
||
92 | } |
||
93 | |||
94 | /* Initialize maxVal to the next consecutive values one by one */ |
||
95 | maxVal1 = *pSrc++; |
||
96 | maxVal2 = *pSrc++; |
||
97 | |||
98 | /* compare for the maximum value */ |
||
99 | if (out < maxVal1) |
||
100 | { |
||
101 | /* Update the maximum value and its index */ |
||
102 | out = maxVal1; |
||
103 | outIndex = count + 3U; |
||
104 | } |
||
105 | |||
106 | /* compare for the maximum value */ |
||
107 | if (out < maxVal2) |
||
108 | { |
||
109 | /* Update the maximum value and its index */ |
||
110 | out = maxVal2; |
||
111 | outIndex = count + 4U; |
||
112 | } |
||
113 | |||
114 | count += 4U; |
||
115 | |||
116 | /* Decrement the loop counter */ |
||
117 | blkCnt--; |
||
118 | } |
||
119 | |||
120 | /* if (blockSize - 1U) is not multiple of 4 */ |
||
121 | blkCnt = (blockSize - 1U) % 4U; |
||
122 | |||
123 | #else |
||
124 | /* Run the below code for Cortex-M0 */ |
||
125 | |||
126 | q31_t maxVal1, out; /* Temporary variables to store the output value. */ |
||
127 | uint32_t blkCnt, outIndex; /* loop counter */ |
||
128 | |||
129 | /* Initialise the index value to zero. */ |
||
130 | outIndex = 0U; |
||
131 | /* Load first input value that act as reference value for comparision */ |
||
132 | out = *pSrc++; |
||
133 | |||
134 | blkCnt = (blockSize - 1U); |
||
135 | |||
136 | #endif /* #if defined (ARM_MATH_DSP) */ |
||
137 | |||
138 | while (blkCnt > 0U) |
||
139 | { |
||
140 | /* Initialize maxVal to the next consecutive values one by one */ |
||
141 | maxVal1 = *pSrc++; |
||
142 | |||
143 | /* compare for the maximum value */ |
||
144 | if (out < maxVal1) |
||
145 | { |
||
146 | /* Update the maximum value and it's index */ |
||
147 | out = maxVal1; |
||
148 | outIndex = blockSize - blkCnt; |
||
149 | } |
||
150 | |||
151 | /* Decrement the loop counter */ |
||
152 | blkCnt--; |
||
153 | } |
||
154 | |||
155 | /* Store the maximum value and it's index into destination pointers */ |
||
156 | *pResult = out; |
||
157 | *pIndex = outIndex; |
||
158 | } |
||
159 | |||
160 | /** |
||
161 | * @} end of Max group |
||
162 | */ |