From f74008fcc2ce1525e919e4062f9d49506726edf6 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Wed, 20 May 2020 14:28:03 +0100 Subject: [PATCH] add sign/zero extending utilities --- src/nmutil/extend.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/nmutil/extend.py diff --git a/src/nmutil/extend.py b/src/nmutil/extend.py new file mode 100644 index 0000000..a1675ef --- /dev/null +++ b/src/nmutil/extend.py @@ -0,0 +1,17 @@ +from nmigen import Repl, Cat, Const + + +def exts(exts_data, width, fullwidth): + exts_data = exts_data[0:width] + topbit = exts_data[-1] + signbits = Repl(topbit, fullwidth-width) + return Cat(exts_data, signbits) + + +def extz(exts_data, width, fullwidth): + exts_data = exts_data[0:width] + topbit = Const(0) + signbits = Repl(topbit, fullwidth-width) + return Cat(exts_data, signbits) + + -- 2.30.2