add better comments on mul overflow
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 15 Jul 2020 15:11:19 +0000 (16:11 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 15 Jul 2020 15:11:19 +0000 (16:11 +0100)
src/soc/config/endian.py
src/soc/fu/mul/post_stage.py

index 0aaa61c25ea4c59f88cfe0ed7c8bfa9cab4cbee8..eb6e0c3f97be5b76b785d318e469c13e96190e9e 100644 (file)
@@ -1,5 +1,5 @@
 global bigendian
-bigendian = 1
+bigendian = 0
 
 def set_endian_mode(mode):
     bigendian = mode
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