]>
git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/dsp/cmsis_dsp/ComplexMathFunctions/arm_cmplx_dot_prod_q15.c
1 /* ----------------------------------------------------------------------
2 * Copyright (C) 2010-2013 ARM Limited. All rights reserved.
4 * $Date: 17. January 2013
7 * Project: CMSIS DSP Library
8 * Title: arm_cmplx_dot_prod_q15.c
10 * Description: Processing function for the Q15 Complex Dot product
12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * - Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * - Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in
21 * the documentation and/or other materials provided with the
23 * - Neither the name of ARM LIMITED nor the names of its contributors
24 * may be used to endorse or promote products derived from this
25 * software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
39 * -------------------------------------------------------------------- */
44 * @ingroup groupCmplxMath
48 * @addtogroup cmplx_dot_prod
53 * @brief Q15 complex dot product
54 * @param *pSrcA points to the first input vector
55 * @param *pSrcB points to the second input vector
56 * @param numSamples number of complex samples in each vector
57 * @param *realResult real part of the result returned here
58 * @param *imagResult imaginary part of the result returned here
61 * <b>Scaling and Overflow Behavior:</b>
63 * The function is implemented using an internal 64-bit accumulator.
64 * The intermediate 1.15 by 1.15 multiplications are performed with full precision and yield a 2.30 result.
65 * These are accumulated in a 64-bit accumulator with 34.30 precision.
66 * As a final step, the accumulators are converted to 8.24 format.
67 * The return results <code>realResult</code> and <code>imagResult</code> are in 8.24 format.
70 void arm_cmplx_dot_prod_q15(
77 q63_t real_sum
= 0, imag_sum
= 0; /* Temporary result storage */
79 #ifndef ARM_MATH_CM0_FAMILY
81 /* Run the below code for Cortex-M4 and Cortex-M3 */
82 uint32_t blkCnt
; /* loop counter */
86 blkCnt
= numSamples
>> 2u;
88 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
89 ** a second loop below computes the remaining 1 to 3 samples. */
92 /* CReal = A[0]* B[0] + A[2]* B[2] + A[4]* B[4] + .....+ A[numSamples-2]* B[numSamples-2] */
93 real_sum
+= ((q31_t
) * pSrcA
++ * *pSrcB
++);
95 /* CImag = A[1]* B[1] + A[3]* B[3] + A[5]* B[5] + .....+ A[numSamples-1]* B[numSamples-1] */
96 imag_sum
+= ((q31_t
) * pSrcA
++ * *pSrcB
++);
98 real_sum
+= ((q31_t
) * pSrcA
++ * *pSrcB
++);
99 imag_sum
+= ((q31_t
) * pSrcA
++ * *pSrcB
++);
101 real_sum
+= ((q31_t
) * pSrcA
++ * *pSrcB
++);
102 imag_sum
+= ((q31_t
) * pSrcA
++ * *pSrcB
++);
104 real_sum
+= ((q31_t
) * pSrcA
++ * *pSrcB
++);
105 imag_sum
+= ((q31_t
) * pSrcA
++ * *pSrcB
++);
107 /* Decrement the loop counter */
111 /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
112 ** No loop unrolling is used. */
113 blkCnt
= numSamples
% 0x4u
;
117 /* CReal = A[0]* B[0] + A[2]* B[2] + A[4]* B[4] + .....+ A[numSamples-2]* B[numSamples-2] */
118 real_sum
+= ((q31_t
) * pSrcA
++ * *pSrcB
++);
119 /* CImag = A[1]* B[1] + A[3]* B[3] + A[5]* B[5] + .....+ A[numSamples-1]* B[numSamples-1] */
120 imag_sum
+= ((q31_t
) * pSrcA
++ * *pSrcB
++);
122 /* Decrement the loop counter */
128 /* Run the below code for Cortex-M0 */
130 while(numSamples
> 0u)
132 /* CReal = A[0]* B[0] + A[2]* B[2] + A[4]* B[4] + .....+ A[numSamples-2]* B[numSamples-2] */
133 real_sum
+= ((q31_t
) * pSrcA
++ * *pSrcB
++);
134 /* CImag = A[1]* B[1] + A[3]* B[3] + A[5]* B[5] + .....+ A[numSamples-1]* B[numSamples-1] */
135 imag_sum
+= ((q31_t
) * pSrcA
++ * *pSrcB
++);
137 /* Decrement the loop counter */
141 #endif /* #ifndef ARM_MATH_CM0_FAMILY */
143 /* Store the real and imaginary results in 8.24 format */
144 /* Convert real data in 34.30 to 8.24 by 6 right shifts */
145 *realResult
= (q31_t
) (real_sum
) >> 6;
146 /* Convert imaginary data in 34.30 to 8.24 by 6 right shifts */
147 *imagResult
= (q31_t
) (imag_sum
) >> 6;
151 * @} end of cmplx_dot_prod group