1 /* ----------------------------------------------------------------------
2  * Project:      CMSIS DSP Library
3  * Title:        arm_mean_f64.c
4  * Description:  Mean value of a floating-point vector
5  *
6  * $Date:        03 June 2022
7  * $Revision:    V1.10.1
8  *
9  * Target Processor: Cortex-M and Cortex-A cores
10  * -------------------------------------------------------------------- */
11 /*
12  * Copyright (C) 2010-2021 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 "dsp/statistics_functions.h"
30 
31 /**
32   @ingroup groupStats
33  */
34 
35 
36 /**
37   @addtogroup mean
38   @{
39  */
40 
41 /**
42   @brief         Mean value of a floating-point vector.
43   @param[in]     pSrc       points to the input vector.
44   @param[in]     blockSize  number of samples in input vector.
45   @param[out]    pResult    mean value returned here.
46  */
47 
48 #if defined(ARM_MATH_NEON) && defined(__aarch64__)
49 
arm_mean_f64(const float64_t * pSrc,uint32_t blockSize,float64_t * pResult)50 ARM_DSP_ATTRIBUTE void arm_mean_f64(
51     const float64_t * pSrc,
52     uint32_t blockSize,
53     float64_t * pResult)
54 {
55     uint32_t blkCnt;                               /* Loop counter */
56     float64x2_t vSum = vdupq_n_f64(0.0);
57     float64_t sum = 0.;                            /* Temporary result storage */
58     float64x2_t afterLoad ;
59     /* Initialize blkCnt with number of samples */
60     blkCnt = blockSize >> 1U;
61 
62 
63     while (blkCnt > 0U)
64     {
65         /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) */
66 
67         afterLoad = vld1q_f64(pSrc);
68         vSum = vaddq_f64(vSum, afterLoad);
69         pSrc += 2;
70         /* Decrement loop counter */
71         blkCnt--;
72 
73 
74     }
75     sum = vaddvq_f64(vSum);
76 
77     blkCnt = blockSize & 1;
78 
79     while (blkCnt > 0U)
80     {
81         /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) */
82         sum += *pSrc++;
83 
84         /* Decrement loop counter */
85         blkCnt--;
86     }
87     *pResult = (sum/blockSize);
88 }
89 #else
arm_mean_f64(const float64_t * pSrc,uint32_t blockSize,float64_t * pResult)90 ARM_DSP_ATTRIBUTE void arm_mean_f64(
91     const float64_t * pSrc,
92     uint32_t blockSize,
93     float64_t * pResult)
94 {
95     uint32_t blkCnt;                               /* Loop counter */
96     float64_t sum = 0.;                            /* Temporary result storage */
97 
98     /* Initialize blkCnt with number of samples */
99     blkCnt = blockSize;
100 
101     while (blkCnt > 0U)
102     {
103         /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) */
104         sum += *pSrc++;
105 
106         /* Decrement loop counter */
107         blkCnt--;
108     }
109 
110     /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) / blockSize  */
111     /* Store result to destination */
112     *pResult = (sum / blockSize);
113 }
114 #endif
115 /**
116   @} end of mean group
117  */
118