• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   @return        none
51  */
52 
53 #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE)
54 
arm_rms_f16(const float16_t * pSrc,uint32_t blockSize,float16_t * pResult)55 void arm_rms_f16(
56   const float16_t * pSrc,
57   uint32_t blockSize,
58   float16_t * pResult)
59 {
60     float16_t pow = 0.0f;
61 
62     arm_power_f16(pSrc, blockSize, &pow);
63 
64     /* Compute Rms and store the result in the destination */
65     arm_sqrt_f16((_Float16)pow / (_Float16) blockSize, pResult);
66 }
67 #else
68 
arm_rms_f16(const float16_t * pSrc,uint32_t blockSize,float16_t * pResult)69 void arm_rms_f16(
70   const float16_t * pSrc,
71         uint32_t blockSize,
72         float16_t * pResult)
73 {
74         uint32_t blkCnt;                               /* Loop counter */
75         _Float16 sum = 0.0f16;                          /* Temporary result storage */
76         _Float16 in;                                  /* Temporary variable to store input value */
77 
78 #if defined (ARM_MATH_LOOPUNROLL) && !defined(ARM_MATH_AUTOVECTORIZE)
79 
80   /* Loop unrolling: Compute 4 outputs at a time */
81   blkCnt = blockSize >> 2U;
82 
83   while (blkCnt > 0U)
84   {
85     /* C = A[0] * A[0] + A[1] * A[1] + ... + A[blockSize-1] * A[blockSize-1] */
86 
87     in = *pSrc++;
88     /* Compute sum of squares and store result in a temporary variable, sum. */
89     sum += in * in;
90 
91     in = *pSrc++;
92     sum += in * in;
93 
94     in = *pSrc++;
95     sum += in * in;
96 
97     in = *pSrc++;
98     sum += in * in;
99 
100     /* Decrement loop counter */
101     blkCnt--;
102   }
103 
104   /* Loop unrolling: Compute remaining outputs */
105   blkCnt = blockSize % 0x4U;
106 
107 #else
108 
109   /* Initialize blkCnt with number of samples */
110   blkCnt = blockSize;
111 
112 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
113 
114   while (blkCnt > 0U)
115   {
116     /* C = A[0] * A[0] + A[1] * A[1] + ... + A[blockSize-1] * A[blockSize-1] */
117 
118     in = *pSrc++;
119     /* Compute sum of squares and store result in a temporary variable. */
120     sum += ( in * in);
121 
122     /* Decrement loop counter */
123     blkCnt--;
124   }
125 
126   /* Compute Rms and store result in destination */
127   arm_sqrt_f16((_Float16)sum / (_Float16) blockSize, pResult);
128 }
129 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
130 
131 /**
132   @} end of RMS group
133  */
134 
135 #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */
136 
137