1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_cmplx_mult_cmplx_q15.c
4 * Description: Q15 complex-by-complex 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 CmplxByCmplxMult
41 * @brief Q15 complex-by-complex multiplication
42 * @param[in] *pSrcA points to the first input vector
43 * @param[in] *pSrcB points to the second input vector
44 * @param[out] *pDst points to the output vector
45 * @param[in] numSamples number of complex samples in each vector
48 * <b>Scaling and Overflow Behavior:</b>
50 * The function implements 1.15 by 1.15 multiplications and finally output is converted into 3.13 format.
53 void arm_cmplx_mult_cmplx_q15(
59 q15_t a
, b
, c
, d
; /* Temporary variables to store real and imaginary values */
61 #if defined (ARM_MATH_DSP)
63 /* Run the below code for Cortex-M4 and Cortex-M3 */
64 uint32_t blkCnt
; /* loop counters */
67 blkCnt
= numSamples
>> 2U;
69 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
70 ** a second loop below computes the remaining 1 to 3 samples. */
73 /* C[2 * i] = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1]. */
74 /* C[2 * i + 1] = A[2 * i] * B[2 * i + 1] + A[2 * i + 1] * B[2 * i]. */
80 /* store the result in 3.13 format in the destination buffer. */
82 (q15_t
) (q31_t
) (((q31_t
) a
* c
) >> 17) - (((q31_t
) b
* d
) >> 17);
83 /* store the result in 3.13 format in the destination buffer. */
85 (q15_t
) (q31_t
) (((q31_t
) a
* d
) >> 17) + (((q31_t
) b
* c
) >> 17);
92 /* store the result in 3.13 format in the destination buffer. */
94 (q15_t
) (q31_t
) (((q31_t
) a
* c
) >> 17) - (((q31_t
) b
* d
) >> 17);
95 /* store the result in 3.13 format in the destination buffer. */
97 (q15_t
) (q31_t
) (((q31_t
) a
* d
) >> 17) + (((q31_t
) b
* c
) >> 17);
104 /* store the result in 3.13 format in the destination buffer. */
106 (q15_t
) (q31_t
) (((q31_t
) a
* c
) >> 17) - (((q31_t
) b
* d
) >> 17);
107 /* store the result in 3.13 format in the destination buffer. */
109 (q15_t
) (q31_t
) (((q31_t
) a
* d
) >> 17) + (((q31_t
) b
* c
) >> 17);
116 /* store the result in 3.13 format in the destination buffer. */
118 (q15_t
) (q31_t
) (((q31_t
) a
* c
) >> 17) - (((q31_t
) b
* d
) >> 17);
119 /* store the result in 3.13 format in the destination buffer. */
121 (q15_t
) (q31_t
) (((q31_t
) a
* d
) >> 17) + (((q31_t
) b
* c
) >> 17);
123 /* Decrement the blockSize loop counter */
127 /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
128 ** No loop unrolling is used. */
129 blkCnt
= numSamples
% 0x4U
;
133 /* C[2 * i] = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1]. */
134 /* C[2 * i + 1] = A[2 * i] * B[2 * i + 1] + A[2 * i + 1] * B[2 * i]. */
140 /* store the result in 3.13 format in the destination buffer. */
142 (q15_t
) (q31_t
) (((q31_t
) a
* c
) >> 17) - (((q31_t
) b
* d
) >> 17);
143 /* store the result in 3.13 format in the destination buffer. */
145 (q15_t
) (q31_t
) (((q31_t
) a
* d
) >> 17) + (((q31_t
) b
* c
) >> 17);
147 /* Decrement the blockSize loop counter */
153 /* Run the below code for Cortex-M0 */
155 while (numSamples
> 0U)
157 /* C[2 * i] = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1]. */
158 /* C[2 * i + 1] = A[2 * i] * B[2 * i + 1] + A[2 * i + 1] * B[2 * i]. */
164 /* store the result in 3.13 format in the destination buffer. */
166 (q15_t
) (q31_t
) (((q31_t
) a
* c
) >> 17) - (((q31_t
) b
* d
) >> 17);
167 /* store the result in 3.13 format in the destination buffer. */
169 (q15_t
) (q31_t
) (((q31_t
) a
* d
) >> 17) + (((q31_t
) b
* c
) >> 17);
171 /* Decrement the blockSize loop counter */
175 #endif /* #if defined (ARM_MATH_DSP) */
180 * @} end of CmplxByCmplxMult group