From b7968538939bb5ec0ddc12d527c1c1e2eab49a2e Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Tue, 30 Oct 2018 10:15:29 +0100 Subject: [PATCH] gen: add common with reverse_bits/reverse_bytes functions --- litex/gen/__init__.py | 1 + litex/gen/common.py | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 litex/gen/common.py diff --git a/litex/gen/__init__.py b/litex/gen/__init__.py index 7d751ff9..56a7f89f 100644 --- a/litex/gen/__init__.py +++ b/litex/gen/__init__.py @@ -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 index 00000000..4e3e1998 --- /dev/null +++ b/litex/gen/common.py @@ -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))]) -- 2.30.2