1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_cfft_init_q31.c
4 * Description: Initialization function for cfft q31 instance
5 *
6 * $Date: 23 April 2021
7 * $Revision: V1.9.0
8 *
9 * Target Processor: Cortex-M and Cortex-A cores
10 * -------------------------------------------------------------------- */
11 /*
12 * Copyright (C) 2010-2021 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 #define FFTINIT(EXT,SIZE) \
30 S->bitRevLength = arm_cfft_sR_##EXT##_len##SIZE.bitRevLength; \
31 S->pBitRevTable = arm_cfft_sR_##EXT##_len##SIZE.pBitRevTable; \
32 S->pTwiddle = arm_cfft_sR_##EXT##_len##SIZE.pTwiddle;
33
34 /**
35 @addtogroup ComplexFFT
36 @{
37 */
38
39 /**
40 @brief Initialization function for the cfft q31 function
41 @param[in,out] S points to an instance of the floating-point CFFT structure
42 @param[in] fftLen fft length (number of complex samples)
43 @return execution status
44 - \ref ARM_MATH_SUCCESS : Operation successful
45 - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
46
47 @par Use of this function is mandatory only for the MVE version of the FFT.
48 Other versions can still initialize directly the data structure using
49 variables declared in arm_const_structs.h
50 */
51
52 #include "dsp/transform_functions.h"
53 #include "arm_common_tables.h"
54 #include "arm_const_structs.h"
55
56 #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
57
58 #include "arm_vec_fft.h"
59 #include "arm_mve_tables.h"
60
61
arm_cfft_radix4by2_rearrange_twiddles_q31(arm_cfft_instance_q31 * S,int twidCoefModifier)62 arm_status arm_cfft_radix4by2_rearrange_twiddles_q31(arm_cfft_instance_q31 *S, int twidCoefModifier)
63 {
64
65 switch (S->fftLen >> (twidCoefModifier - 1)) {
66
67 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_BITREVIDX_FXT_4096) && defined(ARM_TABLE_TWIDDLECOEF_Q31_4096))
68 case 4096U:
69 S->rearranged_twiddle_tab_stride1_arr = rearranged_twiddle_tab_stride1_arr_4096_q31;
70 S->rearranged_twiddle_stride1 = rearranged_twiddle_stride1_4096_q31;
71
72 S->rearranged_twiddle_tab_stride2_arr = rearranged_twiddle_tab_stride2_arr_4096_q31;
73 S->rearranged_twiddle_stride2 = rearranged_twiddle_stride2_4096_q31;
74
75 S->rearranged_twiddle_tab_stride3_arr = rearranged_twiddle_tab_stride3_arr_4096_q31;
76 S->rearranged_twiddle_stride3 = rearranged_twiddle_stride3_4096_q31;
77 break;
78 #endif
79
80 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_BITREVIDX_FXT_1024) && defined(ARM_TABLE_TWIDDLECOEF_Q31_1024)) || (defined(ARM_TABLE_BITREVIDX_FXT_2048) && defined(ARM_TABLE_TWIDDLECOEF_Q31_2048))
81 case 1024U:
82 S->rearranged_twiddle_tab_stride1_arr = rearranged_twiddle_tab_stride1_arr_1024_q31;
83 S->rearranged_twiddle_stride1 = rearranged_twiddle_stride1_1024_q31;
84
85 S->rearranged_twiddle_tab_stride2_arr = rearranged_twiddle_tab_stride2_arr_1024_q31;
86 S->rearranged_twiddle_stride2 = rearranged_twiddle_stride2_1024_q31;
87
88 S->rearranged_twiddle_tab_stride3_arr = rearranged_twiddle_tab_stride3_arr_1024_q31;
89 S->rearranged_twiddle_stride3 = rearranged_twiddle_stride3_1024_q31;
90 break;
91 #endif
92
93 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_BITREVIDX_FXT_256) && defined(ARM_TABLE_TWIDDLECOEF_Q31_256)) || (defined(ARM_TABLE_BITREVIDX_FXT_512) && defined(ARM_TABLE_TWIDDLECOEF_Q31_512))
94 case 256U:
95 S->rearranged_twiddle_tab_stride1_arr = rearranged_twiddle_tab_stride1_arr_256_q31;
96 S->rearranged_twiddle_stride1 = rearranged_twiddle_stride1_256_q31;
97
98 S->rearranged_twiddle_tab_stride2_arr = rearranged_twiddle_tab_stride2_arr_256_q31;
99 S->rearranged_twiddle_stride2 = rearranged_twiddle_stride2_256_q31;
100
101 S->rearranged_twiddle_tab_stride3_arr = rearranged_twiddle_tab_stride3_arr_256_q31;
102 S->rearranged_twiddle_stride3 = rearranged_twiddle_stride3_256_q31;
103
104 break;
105 #endif
106
107 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_BITREVIDX_FXT_64) && defined(ARM_TABLE_TWIDDLECOEF_Q31_64)) || (defined(ARM_TABLE_BITREVIDX_FXT_128) && defined(ARM_TABLE_TWIDDLECOEF_Q31_128))
108 case 64U:
109 S->rearranged_twiddle_tab_stride1_arr = rearranged_twiddle_tab_stride1_arr_64_q31;
110 S->rearranged_twiddle_stride1 = rearranged_twiddle_stride1_64_q31;
111
112 S->rearranged_twiddle_tab_stride2_arr = rearranged_twiddle_tab_stride2_arr_64_q31;
113 S->rearranged_twiddle_stride2 = rearranged_twiddle_stride2_64_q31;
114
115 S->rearranged_twiddle_tab_stride3_arr = rearranged_twiddle_tab_stride3_arr_64_q31;
116 S->rearranged_twiddle_stride3 = rearranged_twiddle_stride3_64_q31;
117 break;
118 #endif
119
120 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_BITREVIDX_FXT_16) && defined(ARM_TABLE_TWIDDLECOEF_Q31_16)) || (defined(ARM_TABLE_BITREVIDX_FXT_32) && defined(ARM_TABLE_TWIDDLECOEF_Q31_32))
121 case 16U:
122 S->rearranged_twiddle_tab_stride1_arr = rearranged_twiddle_tab_stride1_arr_16_q31;
123 S->rearranged_twiddle_stride1 = rearranged_twiddle_stride1_16_q31;
124
125 S->rearranged_twiddle_tab_stride2_arr = rearranged_twiddle_tab_stride2_arr_16_q31;
126 S->rearranged_twiddle_stride2 = rearranged_twiddle_stride2_16_q31;
127
128 S->rearranged_twiddle_tab_stride3_arr = rearranged_twiddle_tab_stride3_arr_16_q31;
129 S->rearranged_twiddle_stride3 = rearranged_twiddle_stride3_16_q31;
130 break;
131 #endif
132
133 default:
134 return(ARM_MATH_ARGUMENT_ERROR);
135 break;
136 /* invalid sizes already filtered */
137 }
138
139 return(ARM_MATH_SUCCESS);
140
141 }
142
143
144
arm_cfft_init_q31(arm_cfft_instance_q31 * S,uint16_t fftLen)145 arm_status arm_cfft_init_q31(
146 arm_cfft_instance_q31 * S,
147 uint16_t fftLen)
148 {
149
150 /* Initialise the default arm status */
151 arm_status status = ARM_MATH_SUCCESS;
152
153 /* Initialise the FFT length */
154 S->fftLen = fftLen;
155
156 /* Initialise the Twiddle coefficient pointer */
157 S->pTwiddle = NULL;
158
159
160 /* Initializations of Instance structure depending on the FFT length */
161 switch (S->fftLen) {
162 /* Initializations of structure parameters for 4096 point FFT */
163 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_BITREVIDX_FXT_4096) && defined(ARM_TABLE_TWIDDLECOEF_Q31_4096))
164 case 4096U:
165 /* Initialise the bit reversal table modifier */
166 S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH;
167 S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_4096;
168 S->pTwiddle = (q31_t *)twiddleCoef_4096_q31;
169 status=arm_cfft_radix4by2_rearrange_twiddles_q31(S, 1);
170 break;
171 #endif
172
173 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_BITREVIDX_FXT_2048) && defined(ARM_TABLE_TWIDDLECOEF_Q31_2048))
174 /* Initializations of structure parameters for 2048 point FFT */
175 case 2048U:
176 /* Initialise the bit reversal table modifier */
177 S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH;
178 S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_2048;
179 S->pTwiddle = (q31_t *)twiddleCoef_2048_q31;
180 status=arm_cfft_radix4by2_rearrange_twiddles_q31(S, 2);
181 break;
182 #endif
183
184 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_BITREVIDX_FXT_1024) && defined(ARM_TABLE_TWIDDLECOEF_Q31_1024))
185 /* Initializations of structure parameters for 1024 point FFT */
186 case 1024U:
187 /* Initialise the bit reversal table modifier */
188 S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH;
189 S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_1024;
190 S->pTwiddle = (q31_t *)twiddleCoef_1024_q31;
191 status=arm_cfft_radix4by2_rearrange_twiddles_q31(S, 1);
192 break;
193 #endif
194
195 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_BITREVIDX_FXT_512) && defined(ARM_TABLE_TWIDDLECOEF_Q31_512))
196 /* Initializations of structure parameters for 512 point FFT */
197 case 512U:
198 /* Initialise the bit reversal table modifier */
199 S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_512_TABLE_LENGTH;
200 S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_512;
201 S->pTwiddle = (q31_t *)twiddleCoef_512_q31;
202 status=arm_cfft_radix4by2_rearrange_twiddles_q31(S, 2);
203 break;
204 #endif
205
206 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_BITREVIDX_FXT_256) && defined(ARM_TABLE_TWIDDLECOEF_Q31_256))
207 case 256U:
208 S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_256_TABLE_LENGTH;
209 S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_256;
210 S->pTwiddle = (q31_t *)twiddleCoef_256_q31;
211 status=arm_cfft_radix4by2_rearrange_twiddles_q31(S, 1);
212 break;
213 #endif
214
215 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_BITREVIDX_FXT_128) && defined(ARM_TABLE_TWIDDLECOEF_Q31_128))
216 case 128U:
217 S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_128_TABLE_LENGTH;
218 S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_128;
219 S->pTwiddle = (q31_t *)twiddleCoef_128_q31;
220 status=arm_cfft_radix4by2_rearrange_twiddles_q31(S, 2);
221 break;
222 #endif
223
224 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_BITREVIDX_FXT_64) && defined(ARM_TABLE_TWIDDLECOEF_Q31_64))
225 case 64U:
226 S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_64_TABLE_LENGTH;
227 S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_64;
228 S->pTwiddle = (q31_t *)twiddleCoef_64_q31;
229 status=arm_cfft_radix4by2_rearrange_twiddles_q31(S, 1);
230 break;
231 #endif
232
233 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_BITREVIDX_FXT_32) && defined(ARM_TABLE_TWIDDLECOEF_Q31_32))
234 case 32U:
235 S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_32_TABLE_LENGTH;
236 S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_32;
237 S->pTwiddle = (q31_t *)twiddleCoef_32_q31;
238 status=arm_cfft_radix4by2_rearrange_twiddles_q31(S, 2);
239 break;
240 #endif
241
242 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_BITREVIDX_FXT_16) && defined(ARM_TABLE_TWIDDLECOEF_Q31_16))
243 case 16U:
244 /* Initializations of structure parameters for 16 point FFT */
245 S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_16_TABLE_LENGTH;
246 S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_16;
247 S->pTwiddle = (q31_t *)twiddleCoef_16_q31;
248 status=arm_cfft_radix4by2_rearrange_twiddles_q31(S, 1);
249 break;
250 #endif
251
252 default:
253 /* Reporting argument error if fftSize is not valid value */
254 status = ARM_MATH_ARGUMENT_ERROR;
255 break;
256 }
257
258
259 return (status);
260 }
261 #else
arm_cfft_init_q31(arm_cfft_instance_q31 * S,uint16_t fftLen)262 arm_status arm_cfft_init_q31(
263 arm_cfft_instance_q31 * S,
264 uint16_t fftLen)
265 {
266 /* Initialise the default arm status */
267 arm_status status = ARM_MATH_SUCCESS;
268
269 /* Initialise the FFT length */
270 S->fftLen = fftLen;
271
272 /* Initialise the Twiddle coefficient pointer */
273 S->pTwiddle = NULL;
274
275
276 /* Initializations of Instance structure depending on the FFT length */
277 switch (S->fftLen) {
278 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_4096) && defined(ARM_TABLE_BITREVIDX_FXT_4096))
279 /* Initializations of structure parameters for 4096 point FFT */
280 case 4096U:
281 /* Initialise the bit reversal table modifier */
282 FFTINIT(q31,4096);
283 break;
284 #endif
285
286 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_2048) && defined(ARM_TABLE_BITREVIDX_FXT_2048))
287 /* Initializations of structure parameters for 2048 point FFT */
288 case 2048U:
289 /* Initialise the bit reversal table modifier */
290 FFTINIT(q31,2048);
291
292 break;
293 #endif
294
295 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_1024) && defined(ARM_TABLE_BITREVIDX_FXT_1024))
296 /* Initializations of structure parameters for 1024 point FFT */
297 case 1024U:
298 /* Initialise the bit reversal table modifier */
299 FFTINIT(q31,1024);
300
301 break;
302 #endif
303
304 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_512) && defined(ARM_TABLE_BITREVIDX_FXT_512))
305 /* Initializations of structure parameters for 512 point FFT */
306 case 512U:
307 /* Initialise the bit reversal table modifier */
308 FFTINIT(q31,512);
309 break;
310 #endif
311
312 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_256) && defined(ARM_TABLE_BITREVIDX_FXT_256))
313 case 256U:
314 FFTINIT(q31,256);
315 break;
316 #endif
317
318 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_128) && defined(ARM_TABLE_BITREVIDX_FXT_128))
319 case 128U:
320 FFTINIT(q31,128);
321 break;
322 #endif
323
324 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_64) && defined(ARM_TABLE_BITREVIDX_FXT_64))
325 case 64U:
326 FFTINIT(q31,64);
327 break;
328 #endif
329
330 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_32) && defined(ARM_TABLE_BITREVIDX_FXT_32))
331 case 32U:
332 FFTINIT(q31,32);
333 break;
334 #endif
335
336 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_Q31_16) && defined(ARM_TABLE_BITREVIDX_FXT_16))
337 case 16U:
338 /* Initializations of structure parameters for 16 point FFT */
339 FFTINIT(q31,16);
340 break;
341 #endif
342
343 default:
344 /* Reporting argument error if fftSize is not valid value */
345 status = ARM_MATH_ARGUMENT_ERROR;
346 break;
347 }
348
349
350 return (status);
351 }
352 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
353
354 /**
355 @} end of ComplexFFT group
356 */
357