1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_power_f64.c
4 * Description: Sum of the squares of the elements of a floating-point vector
5 *
6 * $Date: 10 August 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 @addtogroup power
37 @{
38 */
39
40 /**
41 @brief Sum of the squares of the elements of a floating-point vector.
42 @param[in] pSrc points to the input vector
43 @param[in] blockSize number of samples in input vector
44 @param[out] pResult sum of the squares value returned here
45 */
46 #if defined(ARM_MATH_NEON) && defined(__aarch64__)
arm_power_f64(const float64_t * pSrc,uint32_t blockSize,float64_t * pResult)47 ARM_DSP_ATTRIBUTE void arm_power_f64(
48 const float64_t * pSrc,
49 uint32_t blockSize,
50 float64_t * pResult)
51 {
52 uint32_t blkCnt; /* Loop counter */
53 float64_t sum = 0.; /* Temporary result storage */
54 float64x2_t sumV ; /* Temporary variable to store input value */
55 sumV = vdupq_n_f64(0.0);
56 float64x2_t pSrcV;
57
58 /* Initialize blkCnt with number of samples */
59 blkCnt = blockSize >> 1U;
60
61 while (blkCnt > 0U)
62 {
63 /* C = A[0] * A[0] + A[1] * A[1] + ... + A[blockSize-1] * A[blockSize-1] */
64
65 /* Compute Power and store result in a temporary variable, sum. */
66 pSrcV = vld1q_f64(pSrc);
67 sumV = vmlaq_f64(sumV, pSrcV, pSrcV);
68 pSrc+= 2 ;
69
70
71
72 /* Decrement loop counter */
73 blkCnt--;
74 }
75 sum = vaddvq_f64(sumV);
76
77
78 float64_t in;
79 blkCnt = blockSize & 1;
80
81 while (blkCnt > 0U)
82 {
83 /* C = A[0] * A[0] + A[1] * A[1] + ... + A[blockSize-1] * A[blockSize-1] */
84
85 /* Compute Power and store result in a temporary variable, sum. */
86 in = *pSrc++;
87 sum += in * in;
88
89 /* Decrement loop counter */
90 blkCnt--;
91 }
92
93 /* Store result to destination */
94 *pResult = sum;
95 }
96 #else
arm_power_f64(const float64_t * pSrc,uint32_t blockSize,float64_t * pResult)97 ARM_DSP_ATTRIBUTE void arm_power_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 float64_t in; /* Temporary variable to store input value */
105
106 /* Initialize blkCnt with number of samples */
107 blkCnt = blockSize;
108
109 while (blkCnt > 0U)
110 {
111 /* C = A[0] * A[0] + A[1] * A[1] + ... + A[blockSize-1] * A[blockSize-1] */
112
113 /* Compute Power and store result in a temporary variable, sum. */
114 in = *pSrc++;
115 sum += in * in;
116
117 /* Decrement loop counter */
118 blkCnt--;
119 }
120
121 /* Store result to destination */
122 *pResult = sum;
123 }
124 #endif
125 /**
126 @} end of power group
127 */
128