CO is sign extension only if signed multiplier
authorEddie Hung <eddie@fpgeh.com>
Thu, 1 Aug 2019 17:00:49 +0000 (10:00 -0700)
committerEddie Hung <eddie@fpgeh.com>
Thu, 1 Aug 2019 17:00:49 +0000 (10:00 -0700)
passes/pmgen/ice40_dsp.cc

index 00794ca0df8670bcfd40e49db7d70b7273e9ce24..f88cd62ddc6a52d33f8062199ff1a8b7989a90b1 100644 (file)
@@ -147,7 +147,12 @@ void create_ice40_dsp(ice40_dsp_pm &pm)
        int O_width = GetSize(O);
        if (O_width == 33) {
                log_assert(st.addAB);
-               cell->setPort("\\CO", O[-1]);
+               // If we have a signed multiply-add, then perform sign extension
+               // TODO: Need to check CD[31:16] is sign extension of CD[15:0]?
+               if (st.addAB->getParam("\\A_SIGNED").as_bool() && st.addAB->getParam("\\B_SIGNED").as_bool())
+                       pm.module->connect(O[-1], O[-2]);
+               else
+                       cell->setPort("\\CO", O[-1]);
                O.remove(O_width-1);
        }
        else