1 /* ----------------------------------------------------------------------
2  * Project:      CMSIS DSP Library
3  * Title:        arm_accumulate_f64.c
4  * Description:  Accumulation value of a floating-point vector
5  *
6  * $Date:        14 July 2022
7  * $Revision:    V1.0.0
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 Accumulation
38  @{
39  */
40 
41 /**
42  @brief         Accumulation 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    sum of values in input vector.
46  */
47 #if defined(ARM_MATH_NEON) && defined(__aarch64__)
arm_accumulate_f64(const float64_t * pSrc,uint32_t blockSize,float64_t * pResult)48 ARM_DSP_ATTRIBUTE void arm_accumulate_f64(
49                         const float64_t * pSrc,
50                         uint32_t blockSize,
51                         float64_t * pResult)
52 {
53   uint32_t blkCnt;                               /* Loop counter */
54 
55   /*Neon buffers*/
56   float64x2_t vSum = vdupq_n_f64(0.0);
57   float64x2_t afterLoad ;
58 
59   float64_t sum = 0.;                            /* Temporary result storage */
60 
61   /* Initialize blkCnt with number of samples */
62   blkCnt = blockSize >> 1U;
63 
64 
65   while (blkCnt > 0U)
66   {
67     /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) */
68 
69     afterLoad = vld1q_f64(pSrc);
70     vSum = vaddq_f64(vSum, afterLoad);
71 
72     /* Decrement loop counter */
73     blkCnt--;
74 
75     pSrc += 2;
76   }
77   sum = vaddvq_f64(vSum);
78 
79   /* Tail */
80   blkCnt = blockSize & 1 ;
81 
82   while (blkCnt > 0U)
83   {
84     /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) */
85     sum += *pSrc++;
86 
87     /* Decrement loop counter */
88     blkCnt--;
89   }
90 
91   /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1])  */
92   /* Store result to destination */
93   *pResult = sum;
94 }
95 #else
arm_accumulate_f64(const float64_t * pSrc,uint32_t blockSize,float64_t * pResult)96 ARM_DSP_ATTRIBUTE void arm_accumulate_f64(
97                         const float64_t * pSrc,
98                         uint32_t blockSize,
99                         float64_t *  pResult)
100 {
101   uint32_t blkCnt;                               /* Loop counter */
102   float64_t sum = 0.;                            /* Temporary result storage */
103 
104   /* Initialize blkCnt with number of samples */
105   blkCnt = blockSize;
106 
107   while (blkCnt > 0U)
108   {
109     /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) */
110     sum += *pSrc++;
111 
112     /* Decrement loop counter */
113     blkCnt--;
114   }
115 
116   /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1])  */
117   /* Store result to destination */
118   *pResult = sum;
119 }
120 
121 #endif
122 
123 
124 /**
125  @} end of Accumulation group
126  */
127