From 2f5481dbb9ff22cff03f21e8e7d418442b778908 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Tue, 28 Feb 2023 10:16:25 +0100 Subject: [PATCH] gen/common: Add Unsigned/Signed Signal wrappers. --- litex/gen/common.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/litex/gen/common.py b/litex/gen/common.py index 604cec853..81c2fca88 100644 --- a/litex/gen/common.py +++ b/litex/gen/common.py @@ -19,10 +19,6 @@ def colorer(s, color="bright"): trailer = "\x1b[0m" return header + str(s) + trailer -# Signals ------------------------------------------------------------------------------------------ - -class Open(Signal) : pass - # Bit/Bytes Reversing ------------------------------------------------------------------------------ def reverse_bits(s): @@ -34,6 +30,20 @@ def reverse_bytes(s): return Cat(*[s[i*8:min((i + 1)*8, len(s))] for i in reversed(range(n))]) +# Signals ------------------------------------------------------------------------------------------ + +class Open(Signal): pass + +class Unsigned(Signal): + def __init__(self, bits=1, *args, **kwargs): + assert isinstance(bits, int) + Signal.__init__(self, bits_sign=(bits, 0), *args, **kwargs) + +class Signed(Signal): + def __init__(self, bits=1, *args, **kwargs): + assert isinstance(bits, int) + Signal.__init__(self, bits_sign=(bits, 1), *args, **kwargs) + # Reduction ---------------------------------------------------------------------------------------- from functools import reduce