@@ -14,7 +14,7 @@ void compare (const float* ref, const float* test, int N)
1414 assert (fabsf (ref [n ] - test [n ]) < tol );
1515}
1616
17- void test_complex (int N , bool use_avx )
17+ void test_complex (int N , bool use_avx , bool preallocate )
1818{
1919 float * data = (float * ) aligned_malloc (sizeof (float ) * N * 2 );
2020 float * data_ref = (float * ) pffft_aligned_malloc (sizeof (float ) * N * 2 );
@@ -28,7 +28,20 @@ void test_complex (int N, bool use_avx)
2828 }
2929 memcpy (data_ref , data , N * 2 * sizeof (float ));
3030
31- void * fft_setup = fft_new_setup (N , FFT_COMPLEX , use_avx );
31+ void * fft_setup ;
32+ void * prealloc ;
33+ if (preallocate )
34+ {
35+ size_t bytes_required = fft_bytes_required (N , FFT_COMPLEX , use_avx );
36+ prealloc = aligned_malloc (bytes_required );
37+ fft_setup = fft_new_setup_preallocated (N , FFT_COMPLEX , prealloc , use_avx );
38+ }
39+ else
40+ {
41+
42+ fft_setup = fft_new_setup (N , FFT_COMPLEX , use_avx );
43+ }
44+
3245 assert (fft_setup != NULL );
3346 PFFFT_Setup * pffft_setup = pffft_new_setup (N , PFFFT_COMPLEX );
3447
@@ -49,15 +62,18 @@ void test_complex (int N, bool use_avx)
4962
5063 compare (data_ref , data , N * 2 );
5164
52- fft_destroy_setup (fft_setup );
65+ if (preallocate )
66+ aligned_free (prealloc );
67+ else
68+ fft_destroy_setup (fft_setup );
5369 pffft_destroy_setup (pffft_setup );
5470 aligned_free (data );
5571 pffft_aligned_free (data_ref );
5672 aligned_free (work_data );
5773 pffft_aligned_free (work_data_ref );
5874}
5975
60- void test_real (int N , bool use_avx )
76+ void test_real (int N , bool use_avx , bool preallocate )
6177{
6278 float * data = (float * ) aligned_malloc (sizeof (float ) * N );
6379 float * data_ref = (float * ) pffft_aligned_malloc (sizeof (float ) * N );
@@ -70,7 +86,20 @@ void test_real (int N, bool use_avx)
7086 }
7187 memcpy (data_ref , data , N * sizeof (float ));
7288
73- void * fft_setup = fft_new_setup (N , FFT_REAL , use_avx );
89+ void * fft_setup ;
90+ void * prealloc ;
91+ if (preallocate )
92+ {
93+ size_t bytes_required = fft_bytes_required (N , FFT_REAL , use_avx );
94+ prealloc = aligned_malloc (bytes_required );
95+ fft_setup = fft_new_setup_preallocated (N , FFT_REAL , prealloc , use_avx );
96+ }
97+ else
98+ {
99+
100+ fft_setup = fft_new_setup (N , FFT_REAL , use_avx );
101+ }
102+
74103 assert (fft_setup != NULL );
75104 PFFFT_Setup * pffft_setup = pffft_new_setup (N , PFFFT_REAL );
76105
@@ -91,7 +120,10 @@ void test_real (int N, bool use_avx)
91120
92121 compare (data_ref , data , N );
93122
94- fft_destroy_setup (fft_setup );
123+ if (preallocate )
124+ aligned_free (prealloc );
125+ else
126+ fft_destroy_setup (fft_setup );
95127 pffft_destroy_setup (pffft_setup );
96128 aligned_free (data );
97129 pffft_aligned_free (data_ref );
@@ -107,9 +139,9 @@ int main()
107139 {
108140 const int fft_size = 1 << i ;
109141 printf ("Testing Complex FFT with size: %d\n" , fft_size );
110- test_complex (fft_size , false);
142+ test_complex (fft_size , false, false );
111143 printf ("Testing Real FFT with size: %d\n" , fft_size );
112- test_real (fft_size , false);
144+ test_real (fft_size , false, false );
113145 }
114146
115147#if defined(__SSE2__ )
@@ -118,12 +150,22 @@ int main()
118150 {
119151 const int fft_size = 1 << i ;
120152 printf ("Testing Complex FFT with size: %d\n" , fft_size );
121- test_complex (fft_size , true);
153+ test_complex (fft_size , true, false );
122154 printf ("Testing Real FFT with size: %d\n" , fft_size );
123- test_real (fft_size , true);
155+ test_real (fft_size , true, false );
124156 }
125157#endif
126158
159+ printf ("Running pre-allocated Tests\n" );
160+ for (int i = 5 ; i < 20 ; ++ i )
161+ {
162+ const int fft_size = 1 << i ;
163+ printf ("Testing pre-allocated Complex FFT with size: %d\n" , fft_size );
164+ test_complex (fft_size , false, true);
165+ printf ("Testing pre-allocated Real FFT with size: %d\n" , fft_size );
166+ test_real (fft_size , false, true);
167+ }
168+
127169 printf ("Testing complete!\n" );
128170
129171 return 0 ;
0 commit comments