From: Florent Kermarrec Date: Tue, 30 Oct 2018 09:15:29 +0000 (+0100) Subject: gen: add common with reverse_bits/reverse_bytes functions X-Git-Tag: 24jan2021_ls180~1530 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b7968538939bb5ec0ddc12d527c1c1e2eab49a2e;p=litex.git gen: add common with reverse_bits/reverse_bytes functions --- 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))])