From: Luke Kenneth Casson Leighton Date: Wed, 20 May 2020 13:28:03 +0000 (+0100) Subject: add sign/zero extending utilities X-Git-Tag: 24jan2021_ls180~58 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f74008fcc2ce1525e919e4062f9d49506726edf6;p=nmutil.git add sign/zero extending utilities --- 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) + +