X-Git-Url: https://git.stderr.nl/gitweb?p=matthijs%2Fprojects%2Fmontium-fft.git;a=blobdiff_plain;f=FFT_support.cpp;h=2ddf150b6f1bb8e3e215dac89d9256cbb4fe31cd;hp=6f21e5a24afa1e9cca6fe74a37bfa4965ff6d2ea;hb=HEAD;hpb=1efd07a9676d63cd5ffe6535ee45101e87f89c86 diff --git a/FFT_support.cpp b/FFT_support.cpp index 6f21e5a..2ddf150 100644 --- a/FFT_support.cpp +++ b/FFT_support.cpp @@ -2,9 +2,8 @@ #include #include - -/* Didn't the Montium use Q15 instead of Q14? */ -#define FIXED_POINT 14 +/* Use Q15 fixed point format (1 sign bit plus 15 fractional bits) */ +#define FIXED_POINT 15 #define WORD_SIZE 16 #define WORDS_PER_LINE 4 @@ -28,7 +27,7 @@ float from_fixed(int n) return n / (float)(1<id, i))); else printf("%04hx", (short)get_mem(m->id, i)); - if ((i + 1) % WORDS_PER_LINE == 0) + if (newline && (i + 1) % WORDS_PER_LINE == 0) printf("\n"); else if ((i + 1) % WORDS_PER_GROUP == 0) printf(" "); } - if (i % WORDS_PER_LINE != 0) + if (newline && i % WORDS_PER_LINE != 0) printf("\n"); } @@ -55,46 +54,98 @@ void pre_run() input_a_im = alloc_mem(P1M0); input_b_re = alloc_mem(P2M0); input_b_im = alloc_mem(P3M0); - output_a_re = alloc_mem(P0M1); - output_a_im = alloc_mem(P1M1); - output_b_re = alloc_mem(P2M1); - output_b_im = alloc_mem(P3M1); + + 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, true); printf("im(W)\n"); - print_mem(twiddle_im, 0, SIZE, true); + print_mem(twiddle_im, 0, PARAM_N_t/2, true, 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, true); printf("re(in_b)\n"); - print_mem(input_b_re, 0, SIZE, true); - printf("re(out_a)\n"); - print_mem(output_a_re, 0, SIZE, true); - printf("im(out_a)\n"); - print_mem(output_a_im, 0, SIZE, true); + print_mem(input_b_re, 0, PARAM_N_t/2, true, true); + + printf("re_in = ["); + print_mem(input_a_re, 0, PARAM_N_t/2, true, false); + print_mem(input_b_re, 0, PARAM_N_t/2, true, false); + printf("];\n"); + +/* Write out memory contents for use by the python simulator */ + save_mem_range_to_file(input_a_re->id, 0, PARAM_N_t/2, "Memory/sin_a_re.mm"); + save_mem_range_to_file(input_a_im->id, 0, PARAM_N_t/2, "Memory/sin_a_im.mm"); + save_mem_range_to_file(input_b_re->id, 0, PARAM_N_t/2, "Memory/sin_b_re.mm"); + save_mem_range_to_file(input_b_im->id, 0, PARAM_N_t/2, "Memory/sin_b_im.mm"); + save_mem_range_to_file(twiddle_re->id, 0, PARAM_N_t/2, "Memory/twiddle_re.mm"); + save_mem_range_to_file(twiddle_im->id, 0, PARAM_N_t/2, "Memory/twiddle_im.mm"); +} + +void post_run() +{ + if (PARAM_n_t % 2 == 0) { + /* When the number of stages is even, 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 = ["); + print_mem(output_a_re, 0, PARAM_N_t/2, true, false); + print_mem(output_b_re, 0, PARAM_N_t/2, true, false); + printf("];\n"); + printf("im_out = ["); + print_mem(output_a_im, 0, PARAM_N_t/2, true, false); + print_mem(output_b_im, 0, PARAM_N_t/2, true, false); + printf("];\n"); + /* + printf("re(out)\n"); + print_mem(output_a_re, 0, PARAM_N_t/2, false, true); + print_mem(output_b_re, 0, PARAM_N_t/2, false, true); + printf("im(out)\n"); + print_mem(output_a_im, 0, PARAM_N_t/2, false, true); + print_mem(output_b_im, 0, PARAM_N_t/2, false, true); + */ + }