actorlib/structuring: add reverse parameter to Unpack and Pack
This commit is contained in:
parent
6c9810532b
commit
967b73bef3
|
@ -29,7 +29,7 @@ def pack_layout(l, n):
|
||||||
return [("chunk"+str(i), l) for i in range(n)]
|
return [("chunk"+str(i), l) for i in range(n)]
|
||||||
|
|
||||||
class Unpack(Module):
|
class Unpack(Module):
|
||||||
def __init__(self, n, layout_to):
|
def __init__(self, n, layout_to, reverse=False):
|
||||||
self.sink = Sink(pack_layout(layout_to, n))
|
self.sink = Sink(pack_layout(layout_to, n))
|
||||||
self.source = Source(layout_to)
|
self.source = Source(layout_to)
|
||||||
self.busy = Signal()
|
self.busy = Signal()
|
||||||
|
@ -54,11 +54,12 @@ class Unpack(Module):
|
||||||
]
|
]
|
||||||
cases = {}
|
cases = {}
|
||||||
for i in range(n):
|
for i in range(n):
|
||||||
cases[i] = [self.source.payload.raw_bits().eq(getattr(self.sink.payload, "chunk"+str(i)).raw_bits())]
|
chunk = n-i-1 if reverse else i
|
||||||
|
cases[i] = [self.source.payload.raw_bits().eq(getattr(self.sink.payload, "chunk"+str(chunk)).raw_bits())]
|
||||||
self.comb += Case(mux, cases).makedefault()
|
self.comb += Case(mux, cases).makedefault()
|
||||||
|
|
||||||
class Pack(Module):
|
class Pack(Module):
|
||||||
def __init__(self, layout_from, n):
|
def __init__(self, layout_from, n, reverse=False):
|
||||||
self.sink = Sink(layout_from)
|
self.sink = Sink(layout_from)
|
||||||
self.source = Source(pack_layout(layout_from, n))
|
self.source = Source(pack_layout(layout_from, n))
|
||||||
self.busy = Signal()
|
self.busy = Signal()
|
||||||
|
@ -71,7 +72,8 @@ class Pack(Module):
|
||||||
strobe_all = Signal()
|
strobe_all = Signal()
|
||||||
cases = {}
|
cases = {}
|
||||||
for i in range(n):
|
for i in range(n):
|
||||||
cases[i] = [getattr(self.source.payload, "chunk"+str(i)).raw_bits().eq(self.sink.payload.raw_bits())]
|
chunk = n-i-1 if reverse else i
|
||||||
|
cases[i] = [getattr(self.source.payload, "chunk"+str(chunk)).raw_bits().eq(self.sink.payload.raw_bits())]
|
||||||
self.comb += [
|
self.comb += [
|
||||||
self.busy.eq(strobe_all),
|
self.busy.eq(strobe_all),
|
||||||
self.sink.ack.eq(~strobe_all | self.source.ack),
|
self.sink.ack.eq(~strobe_all | self.source.ack),
|
||||||
|
|
Loading…
Reference in New Issue