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 */
62
arm_accumulate_f16(const float16_t * pSrc,uint32_t blockSize,float16_t * pResult)63 ARM_DSP_ATTRIBUTE void arm_accumulate_f16(
64 const float16_t * pSrc,
65 uint32_t blockSize,
66 float16_t * pResult)
67 {
68 uint32_t blkCnt; /* Loop counter */
69 float16_t sum = 0.0f16; /* Temporary result storage */
70
71 #if defined (ARM_MATH_LOOPUNROLL) && !defined(ARM_MATH_AUTOVECTORIZE)
72
73 /* Loop unrolling: Compute 4 outputs at a time */
74 blkCnt = blockSize >> 2U;
75
76 while (blkCnt > 0U)
77 {
78 /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) */
79 sum += (_Float16)*pSrc++;
80
81 sum += (_Float16)*pSrc++;
82
83 sum += (_Float16)*pSrc++;
84
85 sum += (_Float16)*pSrc++;
86
87 /* Decrement the loop counter */
88 blkCnt--;
89 }
90
91 /* Loop unrolling: Compute remaining outputs */
92 blkCnt = blockSize % 0x4U;
93
94 #else
95
96 /* Initialize blkCnt with number of samples */
97 blkCnt = blockSize;
98
99 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
100
101 while (blkCnt > 0U)
102 {
103 /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) */
104 sum += (_Float16)*pSrc++;
105
106 /* Decrement loop counter */
107 blkCnt--;
108 }
109
110 /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) */
111 /* Store result to destination */
112 *pResult = sum ;
113 }
114 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
115
116 /**
117 @} end of Accumulation group
118 */
119
120
121