Set blackbox file handler to NULL after closing file
[inav.git] / lib / main / CMSIS / DSP / Source / ComplexMathFunctions / arm_cmplx_mag_squared_q31.c
blobc2b2c50058cec85c02fa34b05e29aedf0c6ca61d
1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_cmplx_mag_squared_q31.c
4 * Description: Q31 complex magnitude squared
6 * $Date: 27. January 2017
7 * $Revision: V.1.5.1
9 * Target Processor: Cortex-M cores
10 * -------------------------------------------------------------------- */
12 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
14 * SPDX-License-Identifier: Apache-2.0
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
20 * www.apache.org/licenses/LICENSE-2.0
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.
29 #include "arm_math.h"
31 /**
32 * @ingroup groupCmplxMath
35 /**
36 * @addtogroup cmplx_mag_squared
37 * @{
41 /**
42 * @brief Q31 complex magnitude squared
43 * @param *pSrc points to the complex input vector
44 * @param *pDst points to the real output vector
45 * @param numSamples number of complex samples in the input vector
46 * @return none.
48 * <b>Scaling and Overflow Behavior:</b>
49 * \par
50 * The function implements 1.31 by 1.31 multiplications and finally output is converted into 3.29 format.
51 * Input down scaling is not required.
54 void arm_cmplx_mag_squared_q31(
55 q31_t * pSrc,
56 q31_t * pDst,
57 uint32_t numSamples)
59 q31_t real, imag; /* Temporary variables to store real and imaginary values */
60 q31_t acc0, acc1; /* Accumulators */
62 #if defined (ARM_MATH_DSP)
64 /* Run the below code for Cortex-M4 and Cortex-M3 */
65 uint32_t blkCnt; /* loop counter */
67 /* loop Unrolling */
68 blkCnt = numSamples >> 2U;
70 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
71 ** a second loop below computes the remaining 1 to 3 samples. */
72 while (blkCnt > 0U)
74 /* C[0] = (A[0] * A[0] + A[1] * A[1]) */
75 real = *pSrc++;
76 imag = *pSrc++;
77 acc0 = (q31_t) (((q63_t) real * real) >> 33);
78 acc1 = (q31_t) (((q63_t) imag * imag) >> 33);
79 /* store the result in 3.29 format in the destination buffer. */
80 *pDst++ = acc0 + acc1;
82 real = *pSrc++;
83 imag = *pSrc++;
84 acc0 = (q31_t) (((q63_t) real * real) >> 33);
85 acc1 = (q31_t) (((q63_t) imag * imag) >> 33);
86 /* store the result in 3.29 format in the destination buffer. */
87 *pDst++ = acc0 + acc1;
89 real = *pSrc++;
90 imag = *pSrc++;
91 acc0 = (q31_t) (((q63_t) real * real) >> 33);
92 acc1 = (q31_t) (((q63_t) imag * imag) >> 33);
93 /* store the result in 3.29 format in the destination buffer. */
94 *pDst++ = acc0 + acc1;
96 real = *pSrc++;
97 imag = *pSrc++;
98 acc0 = (q31_t) (((q63_t) real * real) >> 33);
99 acc1 = (q31_t) (((q63_t) imag * imag) >> 33);
100 /* store the result in 3.29 format in the destination buffer. */
101 *pDst++ = acc0 + acc1;
103 /* Decrement the loop counter */
104 blkCnt--;
107 /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
108 ** No loop unrolling is used. */
109 blkCnt = numSamples % 0x4U;
111 while (blkCnt > 0U)
113 /* C[0] = (A[0] * A[0] + A[1] * A[1]) */
114 real = *pSrc++;
115 imag = *pSrc++;
116 acc0 = (q31_t) (((q63_t) real * real) >> 33);
117 acc1 = (q31_t) (((q63_t) imag * imag) >> 33);
118 /* store the result in 3.29 format in the destination buffer. */
119 *pDst++ = acc0 + acc1;
121 /* Decrement the loop counter */
122 blkCnt--;
125 #else
127 /* Run the below code for Cortex-M0 */
129 while (numSamples > 0U)
131 /* out = ((real * real) + (imag * imag)) */
132 real = *pSrc++;
133 imag = *pSrc++;
134 acc0 = (q31_t) (((q63_t) real * real) >> 33);
135 acc1 = (q31_t) (((q63_t) imag * imag) >> 33);
136 /* store the result in 3.29 format in the destination buffer. */
137 *pDst++ = acc0 + acc1;
139 /* Decrement the loop counter */
140 numSamples--;
143 #endif /* #if defined (ARM_MATH_DSP) */
148 * @} end of cmplx_mag_squared group