corelogic/misc: contiguous split
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Sat, 11 Feb 2012 10:52:15 +0000 (11:52 +0100)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Sat, 11 Feb 2012 10:52:15 +0000 (11:52 +0100)
migen/corelogic/misc.py

index 3b48bad4e6597b8d8ab2a7bfcc73e0df7ef46b41..dfe44d4a6bfd62c61af5aa0b65add78a638c09f3 100644 (file)
@@ -31,3 +31,11 @@ def optree(op, operands, lb=None, ub=None, default=None):
                return _Operator(op,
                        [optree(op, operands, lb, s, default),
                        optree(op, operands, s, ub, default)])
+
+def split(v, *counts):
+       r = []
+       offset = 0
+       for n in counts:
+               r.append(v[offset:offset+n])
+               offset += n
+       return tuple(r)