add better comments on mul overflow
[soc.git] / src / soc / fu / mul / post_stage.py
index 1c144ad1c85281170231003a48b721a2a7b10950..dbe560e96e61c5ffbd2897e8d8345529aa101bad 100644 (file)
@@ -54,14 +54,18 @@ class MulMainStage3(PipeModBase):
                 # take the low 64 bits of the mul
                 comb += o.data.eq(mul_o[0:64])
 
-                # compute overflow
+                # compute overflow 32/64
                 mul_ov = Signal(reset_less=True)
                 with m.If(is_32bit):
-                    m32 = mul_o[31:64] # yes really bits 31 to 63 (incl)
-                    comb += mul_ov.eq(m32.bool() & ~m32.all())
+                    # here we're checking that the top 32 bits is the
+                    # sign-extended version of the bottom 32 bits.
+                    m31 = mul_o[31:64] # yes really bits 31 to 63 (incl)
+                    comb += mul_ov.eq(m31.bool() & ~m31.all())
                 with m.Else():
-                    m64 = mul_o[63:128] # yes really bits 63 to 127 (incl)
-                    comb += mul_ov.eq(m64.bool() & ~m64.all())
+                    # here we're checking that the top 64 bits is the
+                    # sign-extended version of the bottom 64 bits.
+                    m63 = mul_o[63:128] # yes really bits 63 to 127 (incl)
+                    comb += mul_ov.eq(m63.bool() & ~m63.all())
 
                 # 32-bit (ov[1]) and 64-bit (ov[0]) overflow - both same
                 comb += ov_o.data.eq(Repl(mul_ov, 2)) # sets OV _and_ OV32