source: S-port/trunk/Drivers/CMSIS/DSP/Source/StatisticsFunctions/arm_min_q31.c

Last change on this file was 1, checked in by AlexLir, 3 years ago
File size: 4.2 KB
Line 
1/* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_min_q31.c
4 * Description: Minimum 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/**
37 * @addtogroup Min
38 * @{
39 */
40
41
42/**
43 * @brief Minimum 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 minimum value returned here
47 * @param[out] *pIndex index of minimum value returned here
48 * @return none.
49 */
50
51void arm_min_q31(
52 q31_t * pSrc,
53 uint32_t blockSize,
54 q31_t * pResult,
55 uint32_t * pIndex)
56{
57#if defined (ARM_MATH_DSP)
58 /* Run the below code for Cortex-M4 and Cortex-M3 */
59
60 q31_t minVal1, minVal2, out; /* Temporary variables to store the output value. */
61 uint32_t blkCnt, outIndex, count; /* loop counter */
62
63 /* Initialise the count value. */
64 count = 0U;
65 /* Initialise the index value to zero. */
66 outIndex = 0U;
67 /* Load first input value that act as reference value for comparision */
68 out = *pSrc++;
69
70 /* Loop unrolling */
71 blkCnt = (blockSize - 1U) >> 2U;
72
73 while (blkCnt > 0U)
74 {
75 /* Initialize minVal to the next consecutive values one by one */
76 minVal1 = *pSrc++;
77 minVal2 = *pSrc++;
78
79 /* compare for the minimum value */
80 if (out > minVal1)
81 {
82 /* Update the minimum value and its index */
83 out = minVal1;
84 outIndex = count + 1U;
85 }
86
87 /* compare for the minimum value */
88 if (out > minVal2)
89 {
90 /* Update the minimum value and its index */
91 out = minVal2;
92 outIndex = count + 2U;
93 }
94
95 /* Initialize minVal to the next consecutive values one by one */
96 minVal1 = *pSrc++;
97 minVal2 = *pSrc++;
98
99 /* compare for the minimum value */
100 if (out > minVal1)
101 {
102 /* Update the minimum value and its index */
103 out = minVal1;
104 outIndex = count + 3U;
105 }
106
107 /* compare for the minimum value */
108 if (out > minVal2)
109 {
110 /* Update the minimum value and its index */
111 out = minVal2;
112 outIndex = count + 4U;
113 }
114
115 count += 4U;
116
117 /* Decrement the loop counter */
118 blkCnt--;
119 }
120
121 /* if (blockSize - 1U) is not multiple of 4 */
122 blkCnt = (blockSize - 1U) % 4U;
123
124#else
125 /* Run the below code for Cortex-M0 */
126
127 q31_t minVal1, out; /* Temporary variables to store the output value. */
128 uint32_t blkCnt, outIndex; /* loop counter */
129
130 /* Initialise the index value to zero. */
131 outIndex = 0U;
132 /* Load first input value that act as reference value for comparision */
133 out = *pSrc++;
134
135 blkCnt = (blockSize - 1U);
136
137#endif /* #if defined (ARM_MATH_DSP) */
138
139 while (blkCnt > 0U)
140 {
141 /* Initialize minVal to the next consecutive values one by one */
142 minVal1 = *pSrc++;
143
144 /* compare for the minimum value */
145 if (out > minVal1)
146 {
147 /* Update the minimum value and it's index */
148 out = minVal1;
149 outIndex = blockSize - blkCnt;
150 }
151
152 /* Decrement the loop counter */
153 blkCnt--;
154 }
155
156 /* Store the minimum value and it's index into destination pointers */
157 *pResult = out;
158 *pIndex = outIndex;
159}
160
161/**
162 * @} end of Min group
163 */
Note: See TracBrowser for help on using the repository browser.