* Actually make the output addressing different in the second half, it was
[matthijs/projects/montium-fft.git] / FFT.mc
diff --git a/FFT.mc b/FFT.mc
index 330b7f5be67632df7d362477e7651dc8492ac31c..3ad081668c51b058cece7d041f772a5c415ad94c 100644 (file)
--- a/FFT.mc
+++ b/FFT.mc
@@ -16,8 +16,10 @@ INLINE struct bf_out butterfly(struct bf_in in) {
        /* ALU 0 & 1 */\r
                /* im(W) * im(b) */\r
                aluexp Wixbi = west(fmul(rd1(in.W_im), rb1(in.b_im)));\r
+       \r
                /* re(W * b) = re(W) * re(b) - im(W) * im(b) */\r
                aluexp Wxbr  = ssub_acc(fmul(rc1(in.W_re), ra1(in.b_re)), Wixbi);\r
+\r
                \r
                /* re(out_a) = re(a) + re(W * b) */\r
                out.a_re =   p0o0(sadd_bf(rb1(in.a_re), Wxbr));\r
@@ -147,10 +149,10 @@ INLINE void init_output_addresses_regular(struct mems m, bool stage_odd, bool se
                set_offset(m.output_b_re, 0-2);\r
                set_offset(m.output_b_im, 0-2);\r
        } else {\r
-               set_offset(m.output_a_re, 1-2);\r
-               set_offset(m.output_a_im, 1-2);\r
-               set_offset(m.output_b_re, 0-2);\r
-               set_offset(m.output_b_im, 0-2);\r
+               set_offset(m.output_a_re, 0-2);\r
+               set_offset(m.output_a_im, 0-2);\r
+               set_offset(m.output_b_re, 1-2);\r
+               set_offset(m.output_b_im, 1-2);\r
        }\r
 }\r
 \r
@@ -176,10 +178,10 @@ INLINE void do_half_regular_stage(struct mems m, bool stage_odd, bool second_hal
        struct bf_in in = read_input_regular(m, EVEN_CYCLE, stage_odd);\r
        struct bf_out out = butterfly(in);\r
 \r
-       /* Now, do a single stage. That means N_t / 2 cycles. Since we do 2\r
+       /* Now, do half a single stage. That means N_t / 4 cycles. Since we do 2\r
         * cycles on every iteration, plus one before and after the loop,\r
-        * we will loop N_t / 4 - 1 times. */\r
-       init_loop(LC2, (PARAM_N_t / 4) - 1);\r
+        * we will loop N_t / 8 - 1 times. */\r
+       init_loop(LC2, (PARAM_N_t / 8) - 1);\r
        do {\r
                /* Write outputs of previous cycle */\r
                write_output_regular(m, out, second_half);\r
@@ -243,17 +245,22 @@ INLINE struct mems init_mem_mapping(bool stage_odd){
 void run() {\r
        do { freeze(); } while (gpi(0) == 0);\r
        struct mems m;\r
-       \r
-       m = init_mem_mapping(EVEN_STAGE);\r
-       init_input_addresses_regular(m, EVEN_STAGE);\r
-       /* do_half_regular_stage will init output addresses */\r
-       next_cycle();\r
-       do_half_regular_stage(m, EVEN_STAGE, FIRST_HALF);\r
-       do_half_regular_stage(m, EVEN_STAGE, SECOND_HALF);\r
-       next_cycle();\r
-       init_input_addresses_regular(m, ODD_STAGE);\r
-       m = init_mem_mapping(ODD_STAGE);\r
-       next_cycle();\r
-       do_half_regular_stage(m, ODD_STAGE, FIRST_HALF);\r
-       do_half_regular_stage(m, ODD_STAGE, SECOND_HALF);\r
+\r
+       /* We need to do n_t regular stages. Since we do two stages each\r
+        * iteration, we'll do n_t / 2 iterations. */\r
+       init_loop(LC1, (PARAM_n_t / 2));\r
+       do {\r
+               m = init_mem_mapping(EVEN_STAGE);\r
+               init_input_addresses_regular(m, EVEN_STAGE);\r
+               /* do_half_regular_stage will init output addresses */\r
+               next_cycle();\r
+               do_half_regular_stage(m, EVEN_STAGE, FIRST_HALF);\r
+               do_half_regular_stage(m, EVEN_STAGE, SECOND_HALF);\r
+               next_cycle();\r
+               init_input_addresses_regular(m, ODD_STAGE);\r
+               m = init_mem_mapping(ODD_STAGE);\r
+               next_cycle();\r
+               do_half_regular_stage(m, ODD_STAGE, FIRST_HALF);\r
+               do_half_regular_stage(m, ODD_STAGE, SECOND_HALF);\r
+       } while (loop_next(LC1));\r
 }\r