1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_rms_f16.c
4 * Description: Root mean square value of the elements of a floating-point vector
5 *
6 * $Date: 23 April 2021
7 * $Revision: V1.9.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
40 /**
41 @addtogroup RMS
42 @{
43 */
44
45 /**
46 @brief Root Mean Square of the elements of a floating-point vector.
47 @param[in] pSrc points to the input vector
48 @param[in] blockSize number of samples in input vector
49 @param[out] pResult root mean square value returned here
50 */
51
52 #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE)
53
arm_rms_f16(const float16_t * pSrc,uint32_t blockSize,float16_t * pResult)54 ARM_DSP_ATTRIBUTE void arm_rms_f16(
55 const float16_t * pSrc,
56 uint32_t blockSize,
57 float16_t * pResult)
58 {
59 float16_t pow = 0.0f;
60
61 arm_power_f16(pSrc, blockSize, &pow);
62
63 /* Compute Rms and store the result in the destination */
64 arm_sqrt_f16((_Float16)pow / (_Float16) blockSize, pResult);
65 }
66 #else
67
arm_rms_f16(const float16_t * pSrc,uint32_t blockSize,float16_t * pResult)68 ARM_DSP_ATTRIBUTE void arm_rms_f16(
69 const float16_t * pSrc,
70 uint32_t blockSize,
71 float16_t * pResult)
72 {
73 uint32_t blkCnt; /* Loop counter */
74 _Float16 sum = 0.0f16; /* Temporary result storage */
75 _Float16 in; /* Temporary variable to store input value */
76
77 #if defined (ARM_MATH_LOOPUNROLL) && !defined(ARM_MATH_AUTOVECTORIZE)
78
79 /* Loop unrolling: Compute 4 outputs at a time */
80 blkCnt = blockSize >> 2U;
81
82 while (blkCnt > 0U)
83 {
84 /* C = A[0] * A[0] + A[1] * A[1] + ... + A[blockSize-1] * A[blockSize-1] */
85
86 in = *pSrc++;
87 /* Compute sum of squares and store result in a temporary variable, sum. */
88 sum += in * in;
89
90 in = *pSrc++;
91 sum += in * in;
92
93 in = *pSrc++;
94 sum += in * in;
95
96 in = *pSrc++;
97 sum += in * in;
98
99 /* Decrement loop counter */
100 blkCnt--;
101 }
102
103 /* Loop unrolling: Compute remaining outputs */
104 blkCnt = blockSize % 0x4U;
105
106 #else
107
108 /* Initialize blkCnt with number of samples */
109 blkCnt = blockSize;
110
111 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
112
113 while (blkCnt > 0U)
114 {
115 /* C = A[0] * A[0] + A[1] * A[1] + ... + A[blockSize-1] * A[blockSize-1] */
116
117 in = *pSrc++;
118 /* Compute sum of squares and store result in a temporary variable. */
119 sum += ( in * in);
120
121 /* Decrement loop counter */
122 blkCnt--;
123 }
124
125 /* Compute Rms and store result in destination */
126 arm_sqrt_f16((_Float16)sum / (_Float16) blockSize, pResult);
127 }
128 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
129
130 /**
131 @} end of RMS group
132 */
133
134 #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */
135
136