X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=FFT_support.cpp;h=23d07f08ca102e114e7428807701f364fcdcc566;hb=a62dbd706365d44bdcac9f8ac4c7c6dd05484642;hp=1876e36ce4302e6cae6511d7113c976b637bcdc6;hpb=e09e88b193ec1b84311b345abb2b9d7943060602;p=matthijs%2Fprojects%2Fmontium-fft.git diff --git a/FFT_support.cpp b/FFT_support.cpp index 1876e36..23d07f0 100644 --- a/FFT_support.cpp +++ b/FFT_support.cpp @@ -4,15 +4,13 @@ /* Didn't the Montium use Q15 instead of Q14? */ -#define FIXED_POINT 14 +#define FIXED_POINT 15 #define WORD_SIZE 16 #define WORDS_PER_LINE 4 #define WORDS_PER_GROUP 1 -extern mem input_a_re, input_a_im, input_b_re, input_b_im, output_a_re, output_a_im, output_b_re, output_b_im, twiddle_re, twiddle_im; - - +mem input_a_re, input_a_im, input_b_re, input_b_im, output_a_re, output_a_im, output_b_re, output_b_im, twiddle_re, twiddle_im; int to_fixed(float n) { @@ -52,42 +50,78 @@ void print_mem(mem m, int offset, int size, bool fixed) void pre_run() { int i; - + /* Assign memories, at least for the first stage */ + input_a_re = alloc_mem(P0M0); + input_a_im = alloc_mem(P1M0); + input_b_re = alloc_mem(P2M0); + input_b_im = alloc_mem(P3M0); + + twiddle_re = alloc_mem(P4M0); + twiddle_im = alloc_mem(P4M1); + /* TODO: Init memory and twiddles */ - for (i=0;iid, i, to_fixed(cos(2*M_PI/SIZE*i))); - set_mem(twiddle_im->id, i, to_fixed(sin(2*M_PI/SIZE*i))); + set_mem(twiddle_re->id, i, to_fixed(cos(i*2*M_PI/PARAM_N_t))); + set_mem(twiddle_im->id, i, to_fixed(sin(i*2*M_PI/PARAM_N_t))); } - for (i=0;iid, i, value); - set_mem(input_a_im->id, i, 0); + if (i % 2 == 0) { + set_mem(input_a_re->id, i, value); + set_mem(input_a_im->id, i, 0); + } else { + set_mem(input_b_re->id, i, value); + set_mem(input_b_im->id, i, 0); + } } else { - set_mem(input_a_re->id, i - SIZE / 2, value); - set_mem(input_a_im->id, i - SIZE / 2, 0); + if (i % 2 == 0) { + set_mem(input_b_re->id, i - PARAM_N_t/2, value); + set_mem(input_b_im->id, i - PARAM_N_t/2, 0); + } else { + set_mem(input_a_re->id, i - PARAM_N_t/2, value); + set_mem(input_a_im->id, i - PARAM_N_t/2, 0); + } } } -} - -void post_run() -{ + printf("re(W)\n"); - print_mem(twiddle_re, 0, SIZE, true); + print_mem(twiddle_re, 0, PARAM_N_t/2, true); printf("im(W)\n"); - print_mem(twiddle_im, 0, SIZE, true); + print_mem(twiddle_im, 0, PARAM_N_t/2, true); printf("re(in_a)\n"); - print_mem(input_a_re, 0, SIZE, true); + print_mem(input_a_re, 0, PARAM_N_t/2, true); printf("re(in_b)\n"); - print_mem(input_b_re, 0, SIZE, true); + print_mem(input_b_re, 0, PARAM_N_t/2, true); +} + +void post_run() +{ + if (PARAM_n_t % 2 == 0) { + /* When the number of stages is odd, the + * outputs end up at the left memories again */ + output_a_re = alloc_mem(P0M0); + output_a_im = alloc_mem(P1M0); + output_b_re = alloc_mem(P2M0); + output_b_im = alloc_mem(P3M0); + } else { + output_a_re = alloc_mem(P0M1); + output_a_im = alloc_mem(P1M1); + output_b_re = alloc_mem(P2M1); + output_b_im = alloc_mem(P3M1); + } printf("re(out_a)\n"); - print_mem(output_a_re, 0, SIZE, true); + print_mem(output_a_re, 0, PARAM_N_t/2, true); + print_mem(output_b_re, 0, PARAM_N_t/2, true); printf("im(out_a)\n"); - print_mem(output_a_im, 0, SIZE, true); + print_mem(output_a_im, 0, PARAM_N_t/2, true); + print_mem(output_b_im, 0, PARAM_N_t/2, true); + }