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