1 /* ----------------------------------------------------------------------
2  * Project:      CMSIS DSP Library
3  * Title:        arm_cfft_init_f16.c
4  * Description:  Initialization function for cfft f16 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 f16 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_f16.h"
53 #include "arm_common_tables_f16.h"
54 #include "arm_const_structs_f16.h"
55 
56 
57 #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE)
58 
59 #include "arm_vec_fft.h"
60 #include "arm_mve_tables_f16.h"
61 
arm_cfft_radix4by2_rearrange_twiddles_f16(arm_cfft_instance_f16 * S,int twidCoefModifier)62 arm_status arm_cfft_radix4by2_rearrange_twiddles_f16(arm_cfft_instance_f16 *S, int twidCoefModifier)
63 {
64 
65         switch (S->fftLen >> (twidCoefModifier - 1)) {
66 
67 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) \
68             || defined(ARM_TABLE_TWIDDLECOEF_F16_4096)
69         case 4096U:
70             S->rearranged_twiddle_tab_stride1_arr = rearranged_twiddle_tab_stride1_arr_4096_f16;
71             S->rearranged_twiddle_stride1  =  rearranged_twiddle_stride1_4096_f16;
72 
73             S->rearranged_twiddle_tab_stride2_arr = rearranged_twiddle_tab_stride2_arr_4096_f16;
74             S->rearranged_twiddle_stride2  =  rearranged_twiddle_stride2_4096_f16;
75 
76             S->rearranged_twiddle_tab_stride3_arr = rearranged_twiddle_tab_stride3_arr_4096_f16;
77             S->rearranged_twiddle_stride3  =  rearranged_twiddle_stride3_4096_f16;
78             break;
79 #endif
80 
81 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) \
82             || defined(ARM_TABLE_TWIDDLECOEF_F16_1024) || defined(ARM_TABLE_TWIDDLECOEF_F16_2048)
83         case 1024U:
84             S->rearranged_twiddle_tab_stride1_arr = rearranged_twiddle_tab_stride1_arr_1024_f16;
85             S->rearranged_twiddle_stride1  =  rearranged_twiddle_stride1_1024_f16;
86 
87             S->rearranged_twiddle_tab_stride2_arr = rearranged_twiddle_tab_stride2_arr_1024_f16;
88             S->rearranged_twiddle_stride2  =  rearranged_twiddle_stride2_1024_f16;
89 
90             S->rearranged_twiddle_tab_stride3_arr = rearranged_twiddle_tab_stride3_arr_1024_f16;
91             S->rearranged_twiddle_stride3  =  rearranged_twiddle_stride3_1024_f16;
92             break;
93  #endif
94 
95  #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) \
96     || defined(ARM_TABLE_TWIDDLECOEF_F16_256) || defined(ARM_TABLE_TWIDDLECOEF_F16_512)
97         case 256U:
98             S->rearranged_twiddle_tab_stride1_arr = rearranged_twiddle_tab_stride1_arr_256_f16;
99             S->rearranged_twiddle_stride1  =  rearranged_twiddle_stride1_256_f16;
100 
101             S->rearranged_twiddle_tab_stride2_arr = rearranged_twiddle_tab_stride2_arr_256_f16;
102             S->rearranged_twiddle_stride2  =  rearranged_twiddle_stride2_256_f16;
103 
104             S->rearranged_twiddle_tab_stride3_arr = rearranged_twiddle_tab_stride3_arr_256_f16;
105             S->rearranged_twiddle_stride3  =  rearranged_twiddle_stride3_256_f16;
106 
107             break;
108 #endif
109 
110 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) \
111             || defined(ARM_TABLE_TWIDDLECOEF_F16_64) || defined(ARM_TABLE_TWIDDLECOEF_F16_128)
112         case 64U:
113             S->rearranged_twiddle_tab_stride1_arr = rearranged_twiddle_tab_stride1_arr_64_f16;
114             S->rearranged_twiddle_stride1  =  rearranged_twiddle_stride1_64_f16;
115 
116             S->rearranged_twiddle_tab_stride2_arr = rearranged_twiddle_tab_stride2_arr_64_f16;
117             S->rearranged_twiddle_stride2  =  rearranged_twiddle_stride2_64_f16;
118 
119             S->rearranged_twiddle_tab_stride3_arr = rearranged_twiddle_tab_stride3_arr_64_f16;
120             S->rearranged_twiddle_stride3  =  rearranged_twiddle_stride3_64_f16;
121             break;
122 #endif
123 
124 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) \
125             || defined(ARM_TABLE_TWIDDLECOEF_F16_16) || defined(ARM_TABLE_TWIDDLECOEF_F16_32)
126         case 16U:
127             S->rearranged_twiddle_tab_stride1_arr = rearranged_twiddle_tab_stride1_arr_16_f16;
128             S->rearranged_twiddle_stride1  =  rearranged_twiddle_stride1_16_f16;
129 
130             S->rearranged_twiddle_tab_stride2_arr = rearranged_twiddle_tab_stride2_arr_16_f16;
131             S->rearranged_twiddle_stride2  =  rearranged_twiddle_stride2_16_f16;
132 
133             S->rearranged_twiddle_tab_stride3_arr = rearranged_twiddle_tab_stride3_arr_16_f16;
134             S->rearranged_twiddle_stride3  =  rearranged_twiddle_stride3_16_f16;
135             break;
136 #endif
137 
138         default:
139             return(ARM_MATH_ARGUMENT_ERROR);
140             break;
141             /* invalid sizes already filtered */
142         }
143 
144         return(ARM_MATH_SUCCESS);
145 
146 }
147 
arm_cfft_init_f16(arm_cfft_instance_f16 * S,uint16_t fftLen)148 arm_status arm_cfft_init_f16(
149   arm_cfft_instance_f16 * S,
150   uint16_t fftLen)
151 {
152 
153         /*  Initialise the default arm status */
154         arm_status status = ARM_MATH_SUCCESS;
155 
156         /*  Initialise the FFT length */
157         S->fftLen = fftLen;
158 
159         /*  Initialise the Twiddle coefficient pointer */
160         S->pTwiddle = NULL;
161 
162 
163         /*  Initializations of Instance structure depending on the FFT length */
164         switch (S->fftLen) {
165             /*  Initializations of structure parameters for 4096 point FFT */
166 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_BITREVIDX_FXT_4096) && defined(ARM_TABLE_TWIDDLECOEF_F16_4096))
167         case 4096U:
168             /*  Initialise the bit reversal table modifier */
169             S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH;
170             S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_4096;
171             S->pTwiddle = (float16_t *)twiddleCoefF16_4096;
172             status=arm_cfft_radix4by2_rearrange_twiddles_f16(S, 1);
173             break;
174 #endif
175 
176 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_BITREVIDX_FXT_2048) && defined(ARM_TABLE_TWIDDLECOEF_F16_2048))
177             /*  Initializations of structure parameters for 2048 point FFT */
178         case 2048U:
179             /*  Initialise the bit reversal table modifier */
180             S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH;
181             S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_2048;
182             S->pTwiddle = (float16_t *)twiddleCoefF16_2048;
183             status=arm_cfft_radix4by2_rearrange_twiddles_f16(S, 2);
184             break;
185 #endif
186 
187 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_BITREVIDX_FXT_1024) && defined(ARM_TABLE_TWIDDLECOEF_F16_1024))
188             /*  Initializations of structure parameters for 1024 point FFT */
189         case 1024U:
190             /*  Initialise the bit reversal table modifier */
191             S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH;
192             S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_1024;
193             S->pTwiddle = (float16_t *)twiddleCoefF16_1024;
194             status=arm_cfft_radix4by2_rearrange_twiddles_f16(S, 1);
195             break;
196 #endif
197 
198 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_BITREVIDX_FXT_512) && defined(ARM_TABLE_TWIDDLECOEF_F16_512))
199             /*  Initializations of structure parameters for 512 point FFT */
200         case 512U:
201             /*  Initialise the bit reversal table modifier */
202             S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_512_TABLE_LENGTH;
203             S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_512;
204             S->pTwiddle = (float16_t *)twiddleCoefF16_512;
205             status=arm_cfft_radix4by2_rearrange_twiddles_f16(S, 2);
206             break;
207 #endif
208 
209 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_BITREVIDX_FXT_256) && defined(ARM_TABLE_TWIDDLECOEF_F16_256))
210         case 256U:
211             S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_256_TABLE_LENGTH;
212             S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_256;
213             S->pTwiddle = (float16_t *)twiddleCoefF16_256;
214             status=arm_cfft_radix4by2_rearrange_twiddles_f16(S, 1);
215             break;
216 #endif
217 
218 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_BITREVIDX_FXT_128) && defined(ARM_TABLE_TWIDDLECOEF_F16_128))
219         case 128U:
220             S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_128_TABLE_LENGTH;
221             S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_128;
222             S->pTwiddle = (float16_t *)twiddleCoefF16_128;
223             status=arm_cfft_radix4by2_rearrange_twiddles_f16(S, 2);
224             break;
225 #endif
226 
227 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_BITREVIDX_FXT_64) && defined(ARM_TABLE_TWIDDLECOEF_F16_64))
228         case 64U:
229             S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_64_TABLE_LENGTH;
230             S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_64;
231             S->pTwiddle = (float16_t *)twiddleCoefF16_64;
232             status=arm_cfft_radix4by2_rearrange_twiddles_f16(S, 1);
233             break;
234 #endif
235 
236 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_BITREVIDX_FXT_32) && defined(ARM_TABLE_TWIDDLECOEF_F16_32))
237         case 32U:
238             S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_32_TABLE_LENGTH;
239             S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_32;
240             S->pTwiddle = (float16_t *)twiddleCoefF16_32;
241             status=arm_cfft_radix4by2_rearrange_twiddles_f16(S, 2);
242             break;
243 #endif
244 
245 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_BITREVIDX_FXT_16) && defined(ARM_TABLE_TWIDDLECOEF_F16_16))
246         case 16U:
247             /*  Initializations of structure parameters for 16 point FFT */
248             S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_16_TABLE_LENGTH;
249             S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_16;
250             S->pTwiddle = (float16_t *)twiddleCoefF16_16;
251             status=arm_cfft_radix4by2_rearrange_twiddles_f16(S, 1);
252             break;
253 #endif
254 
255         default:
256             /*  Reporting argument error if fftSize is not valid value */
257             status = ARM_MATH_ARGUMENT_ERROR;
258             break;
259         }
260 
261 
262         return (status);
263 }
264 #else
265 
266 #if defined(ARM_FLOAT16_SUPPORTED)
267 
arm_cfft_init_f16(arm_cfft_instance_f16 * S,uint16_t fftLen)268 arm_status arm_cfft_init_f16(
269   arm_cfft_instance_f16 * S,
270   uint16_t fftLen)
271 {
272         /*  Initialise the default arm status */
273         arm_status status = ARM_MATH_SUCCESS;
274 
275         /*  Initialise the FFT length */
276         S->fftLen = fftLen;
277 
278         /*  Initialise the Twiddle coefficient pointer */
279         S->pTwiddle = NULL;
280 
281 
282         /*  Initializations of Instance structure depending on the FFT length */
283         switch (S->fftLen) {
284 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F16_4096) && defined(ARM_TABLE_BITREVIDX_FLT_4096))
285             /*  Initializations of structure parameters for 4096 point FFT */
286         case 4096U:
287             /*  Initialise the bit reversal table modifier */
288             FFTINIT(f16,4096);
289             break;
290 #endif
291 
292 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F16_2048) && defined(ARM_TABLE_BITREVIDX_FLT_2048))
293             /*  Initializations of structure parameters for 2048 point FFT */
294         case 2048U:
295             /*  Initialise the bit reversal table modifier */
296             FFTINIT(f16,2048);
297 
298             break;
299 #endif
300 
301 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F16_1024) && defined(ARM_TABLE_BITREVIDX_FLT_1024))
302             /*  Initializations of structure parameters for 1024 point FFT */
303         case 1024U:
304             /*  Initialise the bit reversal table modifier */
305             FFTINIT(f16,1024);
306 
307             break;
308 #endif
309 
310 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F16_512) && defined(ARM_TABLE_BITREVIDX_FLT_512))
311             /*  Initializations of structure parameters for 512 point FFT */
312         case 512U:
313             /*  Initialise the bit reversal table modifier */
314             FFTINIT(f16,512);
315             break;
316 #endif
317 
318 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F16_256) && defined(ARM_TABLE_BITREVIDX_FLT_256))
319         case 256U:
320             FFTINIT(f16,256);
321             break;
322 #endif
323 
324 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F16_128) && defined(ARM_TABLE_BITREVIDX_FLT_128))
325         case 128U:
326             FFTINIT(f16,128);
327             break;
328 #endif
329 
330 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F16_64) && defined(ARM_TABLE_BITREVIDX_FLT_64))
331         case 64U:
332             FFTINIT(f16,64);
333             break;
334 #endif
335 
336 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F16_32) && defined(ARM_TABLE_BITREVIDX_FLT_32))
337         case 32U:
338             FFTINIT(f16,32);
339             break;
340 #endif
341 
342 #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F16_16) && defined(ARM_TABLE_BITREVIDX_FLT_16))
343         case 16U:
344             /*  Initializations of structure parameters for 16 point FFT */
345             FFTINIT(f16,16);
346             break;
347 #endif
348 
349         default:
350             /*  Reporting argument error if fftSize is not valid value */
351             status = ARM_MATH_ARGUMENT_ERROR;
352             break;
353         }
354 
355 
356         return (status);
357 }
358 #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */
359 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
360 
361 /**
362   @} end of ComplexFFT group
363  */
364