diff --git a/kiss_fft.c b/kiss_fft.c index b0e47b2..79c9392 100644 --- a/kiss_fft.c +++ b/kiss_fft.c @@ -383,3 +383,17 @@ void kiss_fft_cleanup(void) tmpbuf=NULL; ntmpbuf=0; } + +int kiss_fft_next_fast_size(int n) +{ + while(1) { + int m=n; + while ( (m%2) == 0 ) m/=2; + while ( (m%3) == 0 ) m/=3; + while ( (m%5) == 0 ) m/=5; + if (m<=1) + break; /* n is completely factorable by twos, threes, and fives */ + n++; + } + return n; +} diff --git a/kiss_fft.h b/kiss_fft.h index f67963f..9e679ff 100644 --- a/kiss_fft.h +++ b/kiss_fft.h @@ -107,6 +107,11 @@ void kiss_fft_stride(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout void kiss_fft_cleanup(void); +/* + * Returns the smallest integer k, such that k>=n and k has only "fast" factors (2,3,5) + */ +int kiss_fft_next_fast_size(int n); + #ifdef __cplusplus } #endif diff --git a/test/benchkiss.c b/test/benchkiss.c index d379480..378eef5 100644 --- a/test/benchkiss.c +++ b/test/benchkiss.c @@ -23,6 +23,10 @@ int main(int argc,char ** argv) switch (c) { case 'n': nfft = atoi (optarg); + if (nfft != kiss_fft_next_fast_size(nfft) ) { + int ng = kiss_fft_next_fast_size(nfft); + fprintf(stderr,"warning: %d might be a better choice for speed than %d\n",ng,nfft); + } break; case 'x': numffts = atoi (optarg); diff --git a/tools/kiss_fftnd.c b/tools/kiss_fftnd.c index 8a5a93d..9cdf6af 100644 --- a/tools/kiss_fftnd.c +++ b/tools/kiss_fftnd.c @@ -73,7 +73,7 @@ kiss_fftnd_cfg kiss_fftnd_alloc(const int *dims,int ndims,int inverse_fft,void*m st->states[i] = kiss_fft_alloc (st->dims[i], inverse_fft, ptr,&len); ptr += len; } - if ( ptr - (char*)st != memneeded ) { + if ( ptr - (char*)st != (int)memneeded ) { fprintf(stderr, "################################################################################\n" "Internal error! Memory allocation miscalculation\n"