gen: add common with reverse_bits/reverse_bytes functions
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Tue, 30 Oct 2018 09:15:29 +0000 (10:15 +0100)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Tue, 30 Oct 2018 09:15:29 +0000 (10:15 +0100)
litex/gen/__init__.py
litex/gen/common.py [new file with mode: 0644]

index 7d751ff9bd58109a864292da16fccf9ebdde347f..56a7f89fa50cb84d4a393d151629406bda32c2e3 100644 (file)
@@ -1 +1,2 @@
 from litex.gen.sim import *
+from litex.gen.common import *
diff --git a/litex/gen/common.py b/litex/gen/common.py
new file mode 100644 (file)
index 0000000..4e3e199
--- /dev/null
@@ -0,0 +1,11 @@
+from migen import *
+
+
+def reverse_bits(s):
+    return s[::-1]
+
+
+def reverse_bytes(s):
+    n = (len(s) + 7)//8
+    return Cat(*[s[i*8:min((i + 1)*8, len(s))]
+        for i in reversed(range(n))])