add sign/zero extending utilities
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 20 May 2020 13:28:03 +0000 (14:28 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 20 May 2020 13:28:03 +0000 (14:28 +0100)
src/nmutil/extend.py [new file with mode: 0644]

diff --git a/src/nmutil/extend.py b/src/nmutil/extend.py
new file mode 100644 (file)
index 0000000..a1675ef
--- /dev/null
@@ -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)
+
+