Subversion Repositories dashGPS

Rev

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_f32.c
4
 * Description:  Maximum value of a floating-point 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
 * @defgroup Max Maximum
37
 *
38
 * Computes the maximum value of an array of data.
39
 * The function returns both the maximum value and its position within the array.
40
 * There are separate functions for floating-point, Q31, Q15, and Q7 data types.
41
 */
42
 
43
/**
44
 * @addtogroup Max
45
 * @{
46
 */
47
 
48
 
49
/**
50
 * @brief Maximum value of a floating-point vector.
51
 * @param[in]       *pSrc points to the input vector
52
 * @param[in]       blockSize length of the input vector
53
 * @param[out]      *pResult maximum value returned here
54
 * @param[out]      *pIndex index of maximum value returned here
55
 * @return none.
56
 */
57
 
58
void arm_max_f32(
59
  float32_t * pSrc,
60
  uint32_t blockSize,
61
  float32_t * pResult,
62
  uint32_t * pIndex)
63
{
64
#if defined (ARM_MATH_DSP)
65
  /* Run the below code for Cortex-M4 and Cortex-M3 */
66
 
67
  float32_t maxVal1, maxVal2, out;               /* Temporary variables to store the output value. */
68
  uint32_t blkCnt, outIndex, count;              /* loop counter */
69
 
70
  /* Initialise the count value. */
71
  count = 0U;
72
  /* Initialise the index value to zero. */
73
  outIndex = 0U;
74
  /* Load first input value that act as reference value for comparision */
75
  out = *pSrc++;
76
 
77
  /* Loop unrolling */
78
  blkCnt = (blockSize - 1U) >> 2U;
79
 
80
  while (blkCnt > 0U)
81
  {
82
    /* Initialize maxVal to the next consecutive values one by one */
83
    maxVal1 = *pSrc++;
84
    maxVal2 = *pSrc++;
85
 
86
    /* compare for the maximum value */
87
    if (out < maxVal1)
88
    {
89
      /* Update the maximum value and its index */
90
      out = maxVal1;
91
      outIndex = count + 1U;
92
    }
93
 
94
    /* compare for the maximum value */
95
    if (out < maxVal2)
96
    {
97
      /* Update the maximum value and its index */
98
      out = maxVal2;
99
      outIndex = count + 2U;
100
    }
101
 
102
    /* Initialize maxVal to the next consecutive values one by one */
103
    maxVal1 = *pSrc++;
104
    maxVal2 = *pSrc++;
105
 
106
    /* compare for the maximum value */
107
    if (out < maxVal1)
108
    {
109
      /* Update the maximum value and its index */
110
      out = maxVal1;
111
      outIndex = count + 3U;
112
    }
113
 
114
    /* compare for the maximum value */
115
    if (out < maxVal2)
116
    {
117
      /* Update the maximum value and its index */
118
      out = maxVal2;
119
      outIndex = count + 4U;
120
    }
121
 
122
    count += 4U;
123
 
124
    /* Decrement the loop counter */
125
    blkCnt--;
126
  }
127
 
128
  /* if (blockSize - 1U) is not multiple of 4 */
129
  blkCnt = (blockSize - 1U) % 4U;
130
 
131
#else
132
  /* Run the below code for Cortex-M0 */
133
 
134
  float32_t maxVal1, out;                        /* Temporary variables to store the output value. */
135
  uint32_t blkCnt, outIndex;                     /* loop counter */
136
 
137
  /* Initialise the index value to zero. */
138
  outIndex = 0U;
139
  /* Load first input value that act as reference value for comparision */
140
  out = *pSrc++;
141
 
142
  blkCnt = (blockSize - 1U);
143
 
144
#endif /* #if defined (ARM_MATH_DSP) */
145
 
146
  while (blkCnt > 0U)
147
  {
148
    /* Initialize maxVal to the next consecutive values one by one */
149
    maxVal1 = *pSrc++;
150
 
151
    /* compare for the maximum value */
152
    if (out < maxVal1)
153
    {
154
      /* Update the maximum value and it's index */
155
      out = maxVal1;
156
      outIndex = blockSize - blkCnt;
157
    }
158
 
159
    /* Decrement the loop counter */
160
    blkCnt--;
161
  }
162
 
163
  /* Store the maximum value and it's index into destination pointers */
164
  *pResult = out;
165
  *pIndex = outIndex;
166
}
167
 
168
/**
169
 * @} end of Max group
170
 */