1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_accumulate_f16.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_f16.h"
30
31 #if defined(ARM_FLOAT16_SUPPORTED)
32
33
34 /**
35 @ingroup groupStats
36 */
37
38 /**
39 @defgroup Accumulation Accumulation functions
40
41 Calculates the accumulation of the input vector. Sum is defined as the addition of the elements in the vector.
42 The underlying algorithm is used:
43
44 <pre>
45 Result = (pSrc[0] + pSrc[1] + pSrc[2] + ... + pSrc[blockSize-1]);
46 </pre>
47
48 There are separate functions for floating-point, Q31, Q15, and Q7 data types.
49 */
50
51 /**
52 @addtogroup Accumulation
53 @{
54 */
55
56 /**
57 @brief accumulate value of a floating-point vector.
58 @param[in] pSrc points to the input vector.
59 @param[in] blockSize number of samples in input vector.
60 @param[out] pResult sum of values in input vector.
61 @return none
62 */
63
arm_accumulate_f16(const float16_t * pSrc,uint32_t blockSize,float16_t * pResult)64 void arm_accumulate_f16(
65 const float16_t * pSrc,
66 uint32_t blockSize,
67 float16_t * pResult)
68 {
69 uint32_t blkCnt; /* Loop counter */
70 float16_t sum = 0.0f16; /* Temporary result storage */
71
72 #if defined (ARM_MATH_LOOPUNROLL) && !defined(ARM_MATH_AUTOVECTORIZE)
73
74 /* Loop unrolling: Compute 4 outputs at a time */
75 blkCnt = blockSize >> 2U;
76
77 while (blkCnt > 0U)
78 {
79 /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) */
80 sum += (_Float16)*pSrc++;
81
82 sum += (_Float16)*pSrc++;
83
84 sum += (_Float16)*pSrc++;
85
86 sum += (_Float16)*pSrc++;
87
88 /* Decrement the loop counter */
89 blkCnt--;
90 }
91
92 /* Loop unrolling: Compute remaining outputs */
93 blkCnt = blockSize % 0x4U;
94
95 #else
96
97 /* Initialize blkCnt with number of samples */
98 blkCnt = blockSize;
99
100 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
101
102 while (blkCnt > 0U)
103 {
104 /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) */
105 sum += (_Float16)*pSrc++;
106
107 /* Decrement loop counter */
108 blkCnt--;
109 }
110
111 /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) */
112 /* Store result to destination */
113 *pResult = sum ;
114 }
115 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
116
117 /**
118 @} end of Accumulation group
119 */
120
121
122