Merge pull request #11270 from haslinghuis/rename_attr
[betaflight.git] / lib / main / CMSIS / DSP / Source / StatisticsFunctions / arm_mean_q15.c
blob7bf55c2ffb32c9aebd4479d310df449cfe1dbc13
1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_mean_q15.c
4 * Description: Mean value of a Q15 vector
6 * $Date: 27. January 2017
7 * $Revision: V.1.5.1
9 * Target Processor: Cortex-M cores
10 * -------------------------------------------------------------------- */
12 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
14 * SPDX-License-Identifier: Apache-2.0
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
20 * www.apache.org/licenses/LICENSE-2.0
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.
29 #include "arm_math.h"
31 /**
32 * @ingroup groupStats
35 /**
36 * @addtogroup mean
37 * @{
41 /**
42 * @brief Mean value of a Q15 vector.
43 * @param[in] *pSrc points to the input vector
44 * @param[in] blockSize length of the input vector
45 * @param[out] *pResult mean value returned here
46 * @return none.
48 * @details
49 * <b>Scaling and Overflow Behavior:</b>
50 * \par
51 * The function is implemented using a 32-bit internal accumulator.
52 * The input is represented in 1.15 format and is accumulated in a 32-bit
53 * accumulator in 17.15 format.
54 * There is no risk of internal overflow with this approach, and the
55 * full precision of intermediate result is preserved.
56 * Finally, the accumulator is saturated and truncated to yield a result of 1.15 format.
60 void arm_mean_q15(
61 q15_t * pSrc,
62 uint32_t blockSize,
63 q15_t * pResult)
65 q31_t sum = 0; /* Temporary result storage */
66 uint32_t blkCnt; /* loop counter */
68 #if defined (ARM_MATH_DSP)
69 /* Run the below code for Cortex-M4 and Cortex-M3 */
71 q31_t in;
73 /*loop Unrolling */
74 blkCnt = blockSize >> 2U;
76 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
77 ** a second loop below computes the remaining 1 to 3 samples. */
78 while (blkCnt > 0U)
80 /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) */
81 in = *__SIMD32(pSrc)++;
82 sum += ((in << 16U) >> 16U);
83 sum += (in >> 16U);
84 in = *__SIMD32(pSrc)++;
85 sum += ((in << 16U) >> 16U);
86 sum += (in >> 16U);
88 /* Decrement the loop counter */
89 blkCnt--;
92 /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
93 ** No loop unrolling is used. */
94 blkCnt = blockSize % 0x4U;
96 #else
97 /* Run the below code for Cortex-M0 */
99 /* Loop over blockSize number of values */
100 blkCnt = blockSize;
102 #endif /* #if defined (ARM_MATH_DSP) */
104 while (blkCnt > 0U)
106 /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) */
107 sum += *pSrc++;
109 /* Decrement the loop counter */
110 blkCnt--;
113 /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) / blockSize */
114 /* Store the result to the destination */
115 *pResult = (q15_t) (sum / (q31_t)blockSize);
119 * @} end of mean group