1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_cmplx_dot_prod_q15.c
4 * Description: Processing function for the Q15 Complex Dot product
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 cmplx_dot_prod
41 * @brief Q15 complex dot product
42 * @param *pSrcA points to the first input vector
43 * @param *pSrcB points to the second input vector
44 * @param numSamples number of complex samples in each vector
45 * @param *realResult real part of the result returned here
46 * @param *imagResult imaginary part of the result returned here
49 * <b>Scaling and Overflow Behavior:</b>
51 * The function is implemented using an internal 64-bit accumulator.
52 * The intermediate 1.15 by 1.15 multiplications are performed with full precision and yield a 2.30 result.
53 * These are accumulated in a 64-bit accumulator with 34.30 precision.
54 * As a final step, the accumulators are converted to 8.24 format.
55 * The return results <code>realResult</code> and <code>imagResult</code> are in 8.24 format.
58 void arm_cmplx_dot_prod_q15(
65 q63_t real_sum
= 0, imag_sum
= 0; /* Temporary result storage */
68 #if defined (ARM_MATH_DSP)
70 /* Run the below code for Cortex-M4 and Cortex-M3 */
71 uint32_t blkCnt
; /* loop counter */
75 blkCnt
= numSamples
>> 2U;
77 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
78 ** a second loop below computes the remaining 1 to 3 samples. */
86 real_sum
+= (q31_t
)a0
* c0
;
87 imag_sum
+= (q31_t
)a0
* d0
;
88 real_sum
-= (q31_t
)b0
* d0
;
89 imag_sum
+= (q31_t
)b0
* c0
;
96 real_sum
+= (q31_t
)a0
* c0
;
97 imag_sum
+= (q31_t
)a0
* d0
;
98 real_sum
-= (q31_t
)b0
* d0
;
99 imag_sum
+= (q31_t
)b0
* c0
;
106 real_sum
+= (q31_t
)a0
* c0
;
107 imag_sum
+= (q31_t
)a0
* d0
;
108 real_sum
-= (q31_t
)b0
* d0
;
109 imag_sum
+= (q31_t
)b0
* c0
;
116 real_sum
+= (q31_t
)a0
* c0
;
117 imag_sum
+= (q31_t
)a0
* d0
;
118 real_sum
-= (q31_t
)b0
* d0
;
119 imag_sum
+= (q31_t
)b0
* c0
;
121 /* Decrement the loop counter */
125 /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
126 ** No loop unrolling is used. */
127 blkCnt
= numSamples
% 0x4U
;
136 real_sum
+= (q31_t
)a0
* c0
;
137 imag_sum
+= (q31_t
)a0
* d0
;
138 real_sum
-= (q31_t
)b0
* d0
;
139 imag_sum
+= (q31_t
)b0
* c0
;
141 /* Decrement the loop counter */
147 /* Run the below code for Cortex-M0 */
149 while (numSamples
> 0U)
162 /* Decrement the loop counter */
166 #endif /* #if defined (ARM_MATH_DSP) */
168 /* Store the real and imaginary results in 8.24 format */
169 /* Convert real data in 34.30 to 8.24 by 6 right shifts */
170 *realResult
= (q31_t
) (real_sum
>> 6);
171 /* Convert imaginary data in 34.30 to 8.24 by 6 right shifts */
172 *imagResult
= (q31_t
) (imag_sum
>> 6);
176 * @} end of cmplx_dot_prod group