Set blackbox file handler to NULL after closing file
[inav.git] / lib / main / CMSIS / DSP / Source / ComplexMathFunctions / arm_cmplx_mult_real_q15.c
blob340d8520daae548515c52dcd58c0d6ace851ae6b
1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_cmplx_mult_real_q15.c
4 * Description: Q15 complex by real multiplication
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 CmplxByRealMult
37 * @{
41 /**
42 * @brief Q15 complex-by-real multiplication
43 * @param[in] *pSrcCmplx points to the complex input vector
44 * @param[in] *pSrcReal points to the real input vector
45 * @param[out] *pCmplxDst points to the complex output vector
46 * @param[in] numSamples number of samples in each vector
47 * @return none.
49 * <b>Scaling and Overflow Behavior:</b>
50 * \par
51 * The function uses saturating arithmetic.
52 * Results outside of the allowable Q15 range [0x8000 0x7FFF] will be saturated.
55 void arm_cmplx_mult_real_q15(
56 q15_t * pSrcCmplx,
57 q15_t * pSrcReal,
58 q15_t * pCmplxDst,
59 uint32_t numSamples)
61 q15_t in; /* Temporary variable to store input value */
63 #if defined (ARM_MATH_DSP)
65 /* Run the below code for Cortex-M4 and Cortex-M3 */
66 uint32_t blkCnt; /* loop counters */
67 q31_t inA1, inA2; /* Temporary variables to hold input data */
68 q31_t inB1; /* Temporary variables to hold input data */
69 q15_t out1, out2, out3, out4; /* Temporary variables to hold output data */
70 q31_t mul1, mul2, mul3, mul4; /* Temporary variables to hold intermediate data */
72 /* loop Unrolling */
73 blkCnt = numSamples >> 2U;
75 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
76 ** a second loop below computes the remaining 1 to 3 samples. */
77 while (blkCnt > 0U)
79 /* C[2 * i] = A[2 * i] * B[i]. */
80 /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */
81 /* read complex number both real and imaginary from complex input buffer */
82 inA1 = *__SIMD32(pSrcCmplx)++;
83 /* read two real values at a time from real input buffer */
84 inB1 = *__SIMD32(pSrcReal)++;
85 /* read complex number both real and imaginary from complex input buffer */
86 inA2 = *__SIMD32(pSrcCmplx)++;
88 /* multiply complex number with real numbers */
89 #ifndef ARM_MATH_BIG_ENDIAN
91 mul1 = (q31_t) ((q15_t) (inA1) * (q15_t) (inB1));
92 mul2 = (q31_t) ((q15_t) (inA1 >> 16) * (q15_t) (inB1));
93 mul3 = (q31_t) ((q15_t) (inA2) * (q15_t) (inB1 >> 16));
94 mul4 = (q31_t) ((q15_t) (inA2 >> 16) * (q15_t) (inB1 >> 16));
96 #else
98 mul2 = (q31_t) ((q15_t) (inA1 >> 16) * (q15_t) (inB1 >> 16));
99 mul1 = (q31_t) ((q15_t) inA1 * (q15_t) (inB1 >> 16));
100 mul4 = (q31_t) ((q15_t) (inA2 >> 16) * (q15_t) inB1);
101 mul3 = (q31_t) ((q15_t) inA2 * (q15_t) inB1);
103 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
105 /* saturate the result */
106 out1 = (q15_t) __SSAT(mul1 >> 15U, 16);
107 out2 = (q15_t) __SSAT(mul2 >> 15U, 16);
108 out3 = (q15_t) __SSAT(mul3 >> 15U, 16);
109 out4 = (q15_t) __SSAT(mul4 >> 15U, 16);
111 /* pack real and imaginary outputs and store them to destination */
112 *__SIMD32(pCmplxDst)++ = __PKHBT(out1, out2, 16);
113 *__SIMD32(pCmplxDst)++ = __PKHBT(out3, out4, 16);
115 inA1 = *__SIMD32(pSrcCmplx)++;
116 inB1 = *__SIMD32(pSrcReal)++;
117 inA2 = *__SIMD32(pSrcCmplx)++;
119 #ifndef ARM_MATH_BIG_ENDIAN
121 mul1 = (q31_t) ((q15_t) (inA1) * (q15_t) (inB1));
122 mul2 = (q31_t) ((q15_t) (inA1 >> 16) * (q15_t) (inB1));
123 mul3 = (q31_t) ((q15_t) (inA2) * (q15_t) (inB1 >> 16));
124 mul4 = (q31_t) ((q15_t) (inA2 >> 16) * (q15_t) (inB1 >> 16));
126 #else
128 mul2 = (q31_t) ((q15_t) (inA1 >> 16) * (q15_t) (inB1 >> 16));
129 mul1 = (q31_t) ((q15_t) inA1 * (q15_t) (inB1 >> 16));
130 mul4 = (q31_t) ((q15_t) (inA2 >> 16) * (q15_t) inB1);
131 mul3 = (q31_t) ((q15_t) inA2 * (q15_t) inB1);
133 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
135 out1 = (q15_t) __SSAT(mul1 >> 15U, 16);
136 out2 = (q15_t) __SSAT(mul2 >> 15U, 16);
137 out3 = (q15_t) __SSAT(mul3 >> 15U, 16);
138 out4 = (q15_t) __SSAT(mul4 >> 15U, 16);
140 *__SIMD32(pCmplxDst)++ = __PKHBT(out1, out2, 16);
141 *__SIMD32(pCmplxDst)++ = __PKHBT(out3, out4, 16);
143 /* Decrement the numSamples loop counter */
144 blkCnt--;
147 /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
148 ** No loop unrolling is used. */
149 blkCnt = numSamples % 0x4U;
151 while (blkCnt > 0U)
153 /* C[2 * i] = A[2 * i] * B[i]. */
154 /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */
155 in = *pSrcReal++;
156 /* store the result in the destination buffer. */
157 *pCmplxDst++ =
158 (q15_t) __SSAT((((q31_t) (*pSrcCmplx++) * (in)) >> 15), 16);
159 *pCmplxDst++ =
160 (q15_t) __SSAT((((q31_t) (*pSrcCmplx++) * (in)) >> 15), 16);
162 /* Decrement the numSamples loop counter */
163 blkCnt--;
166 #else
168 /* Run the below code for Cortex-M0 */
170 while (numSamples > 0U)
172 /* realOut = realA * realB. */
173 /* imagOut = imagA * realB. */
174 in = *pSrcReal++;
175 /* store the result in the destination buffer. */
176 *pCmplxDst++ =
177 (q15_t) __SSAT((((q31_t) (*pSrcCmplx++) * (in)) >> 15), 16);
178 *pCmplxDst++ =
179 (q15_t) __SSAT((((q31_t) (*pSrcCmplx++) * (in)) >> 15), 16);
181 /* Decrement the numSamples loop counter */
182 numSamples--;
185 #endif /* #if defined (ARM_MATH_DSP) */
190 * @} end of CmplxByRealMult group