1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_cmplx_mult_real_q31.c
4 * Description: Q31 complex by real multiplication
6 * $Date: 27. January 2017
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.
32 * @ingroup groupCmplxMath
36 * @addtogroup CmplxByRealMult
42 * @brief Q31 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
49 * <b>Scaling and Overflow Behavior:</b>
51 * The function uses saturating arithmetic.
52 * Results outside of the allowable Q31 range[0x80000000 0x7FFFFFFF] will be saturated.
55 void arm_cmplx_mult_real_q31(
61 q31_t inA1
; /* 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 inA2
, inA3
, inA4
; /* Temporary variables to hold input data */
68 q31_t inB1
, inB2
; /* Temporary variabels to hold input data */
69 q31_t out1
, out2
, out3
, out4
; /* Temporary variables to hold output data */
72 blkCnt
= numSamples
>> 2U;
74 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
75 ** a second loop below computes the remaining 1 to 3 samples. */
78 /* C[2 * i] = A[2 * i] * B[i]. */
79 /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */
80 /* read real input from complex input buffer */
83 /* read input from real input bufer */
86 /* read imaginary input from complex input buffer */
90 /* multiply complex input with real input */
91 out1
= ((q63_t
) inA1
* inB1
) >> 32;
92 out2
= ((q63_t
) inA2
* inB1
) >> 32;
93 out3
= ((q63_t
) inA3
* inB2
) >> 32;
94 out4
= ((q63_t
) inA4
* inB2
) >> 32;
96 /* sature the result */
97 out1
= __SSAT(out1
, 31);
98 out2
= __SSAT(out2
, 31);
99 out3
= __SSAT(out3
, 31);
100 out4
= __SSAT(out4
, 31);
102 /* get result in 1.31 format */
108 /* store the result to destination buffer */
114 /* read real input from complex input buffer */
117 /* read input from real input bufer */
120 /* read imaginary input from complex input buffer */
124 /* multiply complex input with real input */
125 out1
= ((q63_t
) inA1
* inB1
) >> 32;
126 out2
= ((q63_t
) inA2
* inB1
) >> 32;
127 out3
= ((q63_t
) inA3
* inB2
) >> 32;
128 out4
= ((q63_t
) inA4
* inB2
) >> 32;
130 /* sature the result */
131 out1
= __SSAT(out1
, 31);
132 out2
= __SSAT(out2
, 31);
133 out3
= __SSAT(out3
, 31);
134 out4
= __SSAT(out4
, 31);
136 /* get result in 1.31 format */
142 /* store the result to destination buffer */
148 /* Decrement the numSamples loop counter */
152 /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
153 ** No loop unrolling is used. */
154 blkCnt
= numSamples
% 0x4U
;
158 /* C[2 * i] = A[2 * i] * B[i]. */
159 /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */
160 /* read real input from complex input buffer */
163 /* read input from real input bufer */
166 /* multiply complex input with real input */
167 out1
= ((q63_t
) inA1
* inB1
) >> 32;
168 out2
= ((q63_t
) inA2
* inB1
) >> 32;
170 /* sature the result */
171 out1
= __SSAT(out1
, 31);
172 out2
= __SSAT(out2
, 31);
174 /* get result in 1.31 format */
178 /* store the result to destination buffer */
182 /* Decrement the numSamples loop counter */
188 /* Run the below code for Cortex-M0 */
190 while (numSamples
> 0U)
192 /* realOut = realA * realB. */
193 /* imagReal = imagA * realB. */
195 /* store the result in the destination buffer. */
197 (q31_t
) clip_q63_to_q31(((q63_t
) * pSrcCmplx
++ * inA1
) >> 31);
199 (q31_t
) clip_q63_to_q31(((q63_t
) * pSrcCmplx
++ * inA1
) >> 31);
201 /* Decrement the numSamples loop counter */
205 #endif /* #if defined (ARM_MATH_DSP) */
210 * @} end of CmplxByRealMult group