back.rtlil: extend unsigned operand of binop if another is signed.
authorwhitequark <whitequark@whitequark.org>
Sat, 11 Dec 2021 10:25:41 +0000 (10:25 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 31 Dec 2021 20:04:26 +0000 (20:04 +0000)
Fixes #580.

nmigen/back/rtlil.py

index 6da4d9cd3c7bc2065d95bc6ccb58a35e85b864ce..306240d53e8e5465ddea9e90dad2702309128636 100644 (file)
@@ -529,8 +529,8 @@ class _RHSValueCompiler(_ValueCompiler):
             lhs_wire = self(lhs)
             rhs_wire = self(rhs)
         else:
+            lhs_bits = rhs_bits = max(lhs_bits + rhs_sign, rhs_bits + lhs_sign)
             lhs_sign = rhs_sign = True
-            lhs_bits = rhs_bits = max(lhs_bits, rhs_bits)
             lhs_wire = self.match_shape(lhs, lhs_bits, lhs_sign)
             rhs_wire = self.match_shape(rhs, rhs_bits, rhs_sign)
         res_bits, res_sign = value.shape()