From fe9d773e253b3cd32d97b7ce9a74be46beb2d991 Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 24 Dec 2018 01:38:32 +0000 Subject: [PATCH] back.rtlil: always output negative values as two's complement. - is valid in RTLIL but means something entirely different. --- nmigen/back/rtlil.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nmigen/back/rtlil.py b/nmigen/back/rtlil.py index 0bd5f08..91bd1c1 100644 --- a/nmigen/back/rtlil.py +++ b/nmigen/back/rtlil.py @@ -361,7 +361,8 @@ class _RHSValueCompiler(_ValueCompiler): if isinstance(value.value, str): return "{}'{}".format(value.nbits, value.value) else: - return "{}'{:0{}b}".format(value.nbits, value.value, value.nbits) + value_twos_compl = value.value & ((1 << value.nbits) - 1) + return "{}'{:0{}b}".format(value.nbits, value_twos_compl, value.nbits) def on_Signal(self, value): wire_curr, wire_next = self.s.resolve(value) -- 2.30.2