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