Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | mjames | 1 | /* ---------------------------------------------------------------------- |
2 | * Project: CMSIS DSP Library |
||
3 | * Title: arm_cmplx_mult_real_q31.c |
||
4 | * Description: Q31 complex by real multiplication |
||
5 | * |
||
6 | * $Date: 27. January 2017 |
||
7 | * $Revision: V.1.5.1 |
||
8 | * |
||
9 | * Target Processor: Cortex-M cores |
||
10 | * -------------------------------------------------------------------- */ |
||
11 | /* |
||
12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. |
||
13 | * |
||
14 | * SPDX-License-Identifier: Apache-2.0 |
||
15 | * |
||
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 |
||
19 | * |
||
20 | * www.apache.org/licenses/LICENSE-2.0 |
||
21 | * |
||
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. |
||
27 | */ |
||
28 | |||
29 | #include "arm_math.h" |
||
30 | |||
31 | /** |
||
32 | * @ingroup groupCmplxMath |
||
33 | */ |
||
34 | |||
35 | /** |
||
36 | * @addtogroup CmplxByRealMult |
||
37 | * @{ |
||
38 | */ |
||
39 | |||
40 | |||
41 | /** |
||
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 |
||
47 | * @return none. |
||
48 | * |
||
49 | * <b>Scaling and Overflow Behavior:</b> |
||
50 | * \par |
||
51 | * The function uses saturating arithmetic. |
||
52 | * Results outside of the allowable Q31 range[0x80000000 0x7FFFFFFF] will be saturated. |
||
53 | */ |
||
54 | |||
55 | void arm_cmplx_mult_real_q31( |
||
56 | q31_t * pSrcCmplx, |
||
57 | q31_t * pSrcReal, |
||
58 | q31_t * pCmplxDst, |
||
59 | uint32_t numSamples) |
||
60 | { |
||
61 | q31_t inA1; /* Temporary variable to store input value */ |
||
62 | |||
63 | #if defined (ARM_MATH_DSP) |
||
64 | |||
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 */ |
||
70 | |||
71 | /* loop Unrolling */ |
||
72 | blkCnt = numSamples >> 2U; |
||
73 | |||
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. */ |
||
76 | while (blkCnt > 0U) |
||
77 | { |
||
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 */ |
||
81 | inA1 = *pSrcCmplx++; |
||
82 | inA2 = *pSrcCmplx++; |
||
83 | /* read input from real input bufer */ |
||
84 | inB1 = *pSrcReal++; |
||
85 | inB2 = *pSrcReal++; |
||
86 | /* read imaginary input from complex input buffer */ |
||
87 | inA3 = *pSrcCmplx++; |
||
88 | inA4 = *pSrcCmplx++; |
||
89 | |||
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; |
||
95 | |||
96 | /* sature the result */ |
||
97 | out1 = __SSAT(out1, 31); |
||
98 | out2 = __SSAT(out2, 31); |
||
99 | out3 = __SSAT(out3, 31); |
||
100 | out4 = __SSAT(out4, 31); |
||
101 | |||
102 | /* get result in 1.31 format */ |
||
103 | out1 = out1 << 1; |
||
104 | out2 = out2 << 1; |
||
105 | out3 = out3 << 1; |
||
106 | out4 = out4 << 1; |
||
107 | |||
108 | /* store the result to destination buffer */ |
||
109 | *pCmplxDst++ = out1; |
||
110 | *pCmplxDst++ = out2; |
||
111 | *pCmplxDst++ = out3; |
||
112 | *pCmplxDst++ = out4; |
||
113 | |||
114 | /* read real input from complex input buffer */ |
||
115 | inA1 = *pSrcCmplx++; |
||
116 | inA2 = *pSrcCmplx++; |
||
117 | /* read input from real input bufer */ |
||
118 | inB1 = *pSrcReal++; |
||
119 | inB2 = *pSrcReal++; |
||
120 | /* read imaginary input from complex input buffer */ |
||
121 | inA3 = *pSrcCmplx++; |
||
122 | inA4 = *pSrcCmplx++; |
||
123 | |||
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; |
||
129 | |||
130 | /* sature the result */ |
||
131 | out1 = __SSAT(out1, 31); |
||
132 | out2 = __SSAT(out2, 31); |
||
133 | out3 = __SSAT(out3, 31); |
||
134 | out4 = __SSAT(out4, 31); |
||
135 | |||
136 | /* get result in 1.31 format */ |
||
137 | out1 = out1 << 1; |
||
138 | out2 = out2 << 1; |
||
139 | out3 = out3 << 1; |
||
140 | out4 = out4 << 1; |
||
141 | |||
142 | /* store the result to destination buffer */ |
||
143 | *pCmplxDst++ = out1; |
||
144 | *pCmplxDst++ = out2; |
||
145 | *pCmplxDst++ = out3; |
||
146 | *pCmplxDst++ = out4; |
||
147 | |||
148 | /* Decrement the numSamples loop counter */ |
||
149 | blkCnt--; |
||
150 | } |
||
151 | |||
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; |
||
155 | |||
156 | while (blkCnt > 0U) |
||
157 | { |
||
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 */ |
||
161 | inA1 = *pSrcCmplx++; |
||
162 | inA2 = *pSrcCmplx++; |
||
163 | /* read input from real input bufer */ |
||
164 | inB1 = *pSrcReal++; |
||
165 | |||
166 | /* multiply complex input with real input */ |
||
167 | out1 = ((q63_t) inA1 * inB1) >> 32; |
||
168 | out2 = ((q63_t) inA2 * inB1) >> 32; |
||
169 | |||
170 | /* sature the result */ |
||
171 | out1 = __SSAT(out1, 31); |
||
172 | out2 = __SSAT(out2, 31); |
||
173 | |||
174 | /* get result in 1.31 format */ |
||
175 | out1 = out1 << 1; |
||
176 | out2 = out2 << 1; |
||
177 | |||
178 | /* store the result to destination buffer */ |
||
179 | *pCmplxDst++ = out1; |
||
180 | *pCmplxDst++ = out2; |
||
181 | |||
182 | /* Decrement the numSamples loop counter */ |
||
183 | blkCnt--; |
||
184 | } |
||
185 | |||
186 | #else |
||
187 | |||
188 | /* Run the below code for Cortex-M0 */ |
||
189 | |||
190 | while (numSamples > 0U) |
||
191 | { |
||
192 | /* realOut = realA * realB. */ |
||
193 | /* imagReal = imagA * realB. */ |
||
194 | inA1 = *pSrcReal++; |
||
195 | /* store the result in the destination buffer. */ |
||
196 | *pCmplxDst++ = |
||
197 | (q31_t) clip_q63_to_q31(((q63_t) * pSrcCmplx++ * inA1) >> 31); |
||
198 | *pCmplxDst++ = |
||
199 | (q31_t) clip_q63_to_q31(((q63_t) * pSrcCmplx++ * inA1) >> 31); |
||
200 | |||
201 | /* Decrement the numSamples loop counter */ |
||
202 | numSamples--; |
||
203 | } |
||
204 | |||
205 | #endif /* #if defined (ARM_MATH_DSP) */ |
||
206 | |||
207 | } |
||
208 | |||
209 | /** |
||
210 | * @} end of CmplxByRealMult group |
||
211 | */ |