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
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 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
49 * <b>Scaling and Overflow Behavior:</b>
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(
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 */
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. */
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));
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));
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 */
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
;
153 /* C[2 * i] = A[2 * i] * B[i]. */
154 /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */
156 /* store the result in the destination buffer. */
158 (q15_t
) __SSAT((((q31_t
) (*pSrcCmplx
++) * (in
)) >> 15), 16);
160 (q15_t
) __SSAT((((q31_t
) (*pSrcCmplx
++) * (in
)) >> 15), 16);
162 /* Decrement the numSamples loop counter */
168 /* Run the below code for Cortex-M0 */
170 while (numSamples
> 0U)
172 /* realOut = realA * realB. */
173 /* imagOut = imagA * realB. */
175 /* store the result in the destination buffer. */
177 (q15_t
) __SSAT((((q31_t
) (*pSrcCmplx
++) * (in
)) >> 15), 16);
179 (q15_t
) __SSAT((((q31_t
) (*pSrcCmplx
++) * (in
)) >> 15), 16);
181 /* Decrement the numSamples loop counter */
185 #endif /* #if defined (ARM_MATH_DSP) */
190 * @} end of CmplxByRealMult group