* Let the libmontiumc write the contents of the input memories to file before
[matthijs/projects/montium-fft.git] / FFT_support.cpp
index 23d07f08ca102e114e7428807701f364fcdcc566..7fc2484be97043c091505e99354a165015e2e2a1 100644 (file)
@@ -2,12 +2,11 @@
 #include <cstdio>\r
 #include <cmath>\r
 \r
-\r
-/* Didn't the Montium use Q15 instead of Q14? */\r
+/* Use Q15 fixed point format (1 sign bit plus 15 fractional bits) */\r
 #define FIXED_POINT 15\r
 #define WORD_SIZE   16\r
 \r
-#define WORDS_PER_LINE 4\r
+#define WORDS_PER_LINE 8\r
 #define WORDS_PER_GROUP 1\r
 \r
 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; \r
@@ -68,7 +67,9 @@ void pre_run()
        \r
        for (i=0;i<PARAM_N_t;i++)\r
        {\r
-               int value = to_fixed(sin((float)i*2*M_PI/PARAM_N_t));\r
+               /* We take the sine from 0 to 2*2*Pi, ie two periods. We divide \r
+                * the value by PARAM_N_t to prevent overflow. */\r
+               int value = to_fixed(sin((float)i*2*2*M_PI/PARAM_N_t)/PARAM_N_t);\r
 \r
                if (i<PARAM_N_t/2)\r
                {\r
@@ -100,12 +101,20 @@ void pre_run()
        print_mem(input_a_re, 0, PARAM_N_t/2, true);\r
        printf("re(in_b)\n");\r
        print_mem(input_b_re, 0, PARAM_N_t/2, true);\r
+       \r
+/* Write out memory contents for use by the python simulator */\r
+       save_mem_range_to_file(input_a_re->id, 0, PARAM_N_t/2, "Memory/sin_a_re.mm");\r
+       save_mem_range_to_file(input_a_im->id, 0, PARAM_N_t/2, "Memory/sin_a_im.mm");\r
+       save_mem_range_to_file(input_b_re->id, 0, PARAM_N_t/2, "Memory/sin_b_re.mm");\r
+       save_mem_range_to_file(input_b_im->id, 0, PARAM_N_t/2, "Memory/sin_b_im.mm");\r
+       save_mem_range_to_file(twiddle_re->id, 0, PARAM_N_t/2, "Memory/twiddle_re.mm");\r
+       save_mem_range_to_file(twiddle_im->id, 0, PARAM_N_t/2, "Memory/twiddle_im.mm");\r
 }\r
 \r
 void post_run()\r
 {\r
        if (PARAM_n_t % 2 == 0) {\r
-               /* When the number of stages is odd, the \r
+               /* When the number of stages is even, the \r
                 * outputs end up at the left memories again */\r
                output_a_re  = alloc_mem(P0M0);\r
                output_a_im  = alloc_mem(P1M0);\r
@@ -117,11 +126,18 @@ void post_run()
                output_b_re  = alloc_mem(P2M1);\r
                output_b_im  = alloc_mem(P3M1);\r
        }\r
-       printf("re(out_a)\n");\r
+       printf("re(out)\n");\r
        print_mem(output_a_re, 0, PARAM_N_t/2, true);\r
        print_mem(output_b_re, 0, PARAM_N_t/2, true);\r
-       printf("im(out_a)\n");\r
+       printf("im(out)\n");\r
        print_mem(output_a_im, 0, PARAM_N_t/2, true);\r
        print_mem(output_b_im, 0, PARAM_N_t/2, true);\r
+       \r
+       printf("re(out)\n");\r
+       print_mem(output_a_re, 0, PARAM_N_t/2, false);\r
+       print_mem(output_b_re, 0, PARAM_N_t/2, false);\r
+       printf("im(out)\n");\r
+       print_mem(output_a_im, 0, PARAM_N_t/2, false);\r
+       print_mem(output_b_im, 0, PARAM_N_t/2, false);\r
 \r
 }\r