Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 3 commits
  • 6 files changed
  • 0 commit comments
  • 1 contributor
View
4 migen/bus/csr.py
@@ -1,4 +1,5 @@
from migen.fhdl.structure import *
+from migen.corelogic.misc import optree
from migen.bus.simple import Simple
_desc = [
@@ -23,11 +24,10 @@ def __init__(self, master, slaves):
def get_fragment(self):
comb = []
- rb = Constant(0, BV(8))
for slave in self.slaves:
comb.append(slave.a_i.eq(self.master.a_o))
comb.append(slave.we_i.eq(self.master.we_o))
comb.append(slave.d_i.eq(self.master.d_o))
- rb = rb | slave.d_o
+ rb = optree('|', [slave.d_o for slave in self.slaves])
comb.append(self.master.d_i.eq(rb))
return Fragment(comb)
View
22 migen/bus/wishbone.py
@@ -1,5 +1,6 @@
from migen.fhdl.structure import *
-from migen.corelogic import roundrobin, multimux
+from migen.corelogic import roundrobin
+from migen.corelogic.misc import multimux, optree
from migen.bus.simple import Simple, get_sig_name
_desc = [
@@ -37,7 +38,7 @@ def get_fragment(self):
m2s_names = [get_sig_name(x, False) for x in _desc if x[0]]
m2s_masters = [[getattr(m, name) for name in m2s_names] for m in self.masters]
m2s_target = [getattr(self.target, name) for name in m2s_names]
- comb += multimux.multimux(self.rr.grant, m2s_masters, m2s_target)
+ comb += multimux(self.rr.grant, m2s_masters, m2s_target)
# connect slave->master signals
s2m_names = [get_sig_name(x, False) for x in _desc if not x[0]]
@@ -115,21 +116,12 @@ def get_fragment(self):
i += 1
# generate master ack (resp. err) by ORing all slave acks (resp. errs)
- ackv = Constant(0)
- errv = Constant(0)
- for slave in self.slaves:
- ackv = ackv | slave[1].ack_o
- errv = errv | slave[1].err_o
- comb.append(self.master.ack_i.eq(ackv))
- comb.append(self.master.err_i.eq(errv))
+ comb.append(self.master.ack_i.eq(optree('|', [slave[1].ack_o for slave in self.slaves])))
+ comb.append(self.master.err_i.eq(optree('|', [slave[1].err_o for slave in self.slaves])))
# mux (1-hot) slave data return
- i = 0
- datav = Constant(0, self.master.dat_i.bv)
- for slave in self.slaves:
- datav = datav | (Replicate(slave_sel_r[i], self.master.dat_i.bv.width) & slave[1].dat_o)
- i += 1
- comb.append(self.master.dat_i.eq(datav))
+ masked = [Replicate(slave_sel_r[i], self.master.dat_i.bv.width) & self.slaves[i][1].dat_o for i in range(len(self.slaves))]
+ comb.append(self.master.dat_i.eq(optree('|', masked)))
return Fragment(comb, sync)
View
33 migen/corelogic/misc.py
@@ -0,0 +1,33 @@
+from migen.fhdl.structure import *
+from migen.fhdl.structure import _Operator
+
+def multimux(sel, inputs, output):
+ n = len(inputs)
+ i = 0
+ comb = []
+ for osig in output:
+ choices = [x[i] for x in inputs]
+ cases = [[Constant(j, sel.bv), osig.eq(choices[j])] for j in range(n)]
+ cases[n-1][0] = Default()
+ comb.append(Case(sel, *cases))
+ i += 1
+ return comb
+
+def optree(op, operands, lb=None, ub=None, default=None):
+ if lb is None:
+ lb = 0
+ if ub is None:
+ ub = len(operands)
+ l = ub - lb
+ if l == 0:
+ if default is None:
+ raise AttributeError
+ else:
+ return default
+ elif l == 1:
+ return operands[lb]
+ else:
+ s = lb + l//2
+ return _Operator(op,
+ [optree(op, operands, lb, s, default),
+ optree(op, operands, s, ub, default)])
View
13 migen/corelogic/multimux.py
@@ -1,13 +0,0 @@
-from migen.fhdl.structure import *
-
-def multimux(sel, inputs, output):
- n = len(inputs)
- i = 0
- comb = []
- for osig in output:
- choices = [x[i] for x in inputs]
- cases = [[Constant(j, sel.bv), osig.eq(choices[j])] for j in range(n)]
- cases[n-1][0] = Default()
- comb.append(Case(sel, *cases))
- i += 1
- return comb
View
0  migen/flow/__init__.py
No changes.
View
114 migen/flow/actor.py
@@ -0,0 +1,114 @@
+from migen.fhdl.structure import *
+from migen.corelogic.optree import optree
+
+class SchedulingModel:
+ COMBINATORIAL, SEQUENTIAL, PIPELINE, DYNAMIC = range(6)
+
+ def __init__(self, model, latency=1):
+ self.model = model
+ self.latency = latency
+
+ def __str__(self):
+ if self.model == SchedulingModel.COMBINATORIAL:
+ return "<SchedulingModel: COMBINATORIAL>"
+ elif self.model == SchedulingModel.SEQUENTIAL:
+ return "<SchedulingModel: SEQUENTIAL({0})>".format(self.latency)
+ elif self.model == SchedulingModel.PIPELINE:
+ return "<SchedulingModel: PIPELINE({0})>".format(self.latency)
+ elif self.model == SchedulingModel.DYNAMIC:
+ return "<SchedulingModel: DYNAMIC>"
+ else:
+ raise AttributeError
+
+class Sink:
+ def __init__(self, actor, token):
+ self.actor = actor
+ self.token = token
+ self.stb_i = Signal()
+ self.ack_o = Signal()
+
+class Source:
+ def __init__(self, actor, token):
+ self.actor = actor
+ self.token = token
+ self.stb_o = Signal()
+ self.ack_i = Signal()
+
+def _control_fragment_comb(l_stb_i, l_ack_o, l_stb_o, l_ack_i):
+ en = Signal()
+ comb = [en.eq(optree('&', l_stb_i + l_ack_i))]
+ comb += [o.eq(en) for o in l_ack_o + l_stb_o]
+ return Fragment(comb)
+
+def _control_fragment_seq(latency, l_stb_i, l_ack_o, l_stb_o, l_ack_i, trigger):
+ ready = Signal()
+ timer = Signal(BV(bits_for(latency)))
+ comb = [ready.eq(timer == 0))]
+ sync = [
+ If(trigger,
+ timer.eq(latency)
+ ).Elif(~ready,
+ timer.eq(timer - 1)
+ )
+ ]
+
+ nsources = len(l_stb_o)
+ mask = Signal(BV(nsources))
+ sync.append(If(trigger, mask.eq(0)).Else(mask.eq(mask | Cat(*l_ack_i))))
+
+ comb.append(Cat(*l_stb_o).eq(Replicate(len(l_stb_o), ready) & ~mask))
+ comb.append(Cat(*l_ack_o).eq(Replicate(len(l_ack_o), trigger)))
+
+ stb_all = Signal()
+ comb.append(stb_all.eq(optree('&', l_stb_i)))
+ comb.append(trigger.eq(ready & stb_all & ((mask | Cat(*l_ack_i)) == Replicate(nsources, 1))))
+
+ return Fragment(comb, sync)
+
+def _control_fragment_pipe(latency, l_stb_i, l_ack_o, l_stb_o, l_ack_i, pipe_ce):
+ stb_all = Signal()
+ comb = [stb_all.eq(optree('&', l_stb_i))]
+ valid = Signal(BV(latency))
+ if latency > 1:
+ sync = [If(pipe_ce, valid.eq(Cat(stb_all, valid[1:])))]
+ else:
+ sync = [If(pipe_ce, valid.eq(stb_all))]
+ last_valid = valid[latency-1]
+
+ nsources = len(l_stb_o)
+ mask = Signal(BV(nsources))
+ sync.append(If(pipe_ce, mask.eq(0)).Else(mask.eq(mask | Cat(*l_ack_i))))
+
+ comb.append(Cat(*l_stb_o).eq(Replicate(len(l_stb_o), last_valid) & ~mask))
+ comb.append(Cat(*l_ack_o).eq(Replicate(len(l_ack_o), pipe_ce)))
+
+ comb.append(pipe_ce.eq(~last_valid | ((mask | Cat(*l_ack_i)) == Replicate(nsources, 1))))
+
+ return Fragment(comb, sync)
+
+class Actor:
+ def __init__(self, scheduling_model, sinks, sources):
+ self.scheduling_model = scheduling_model
+ self.sinks = sinks
+ self.sources = sources
+ if self.scheduling_model.model == SEQUENTIAL:
+ self.trigger = Signal()
+ elif self.scheduling_model.model == PIPELINE:
+ self.pipe_ce = Signal()
+
+ def get_control_fragment():
+ l_stb_i = [e.stb_i for e in self.sinks]
+ l_ack_o = [e.ack_o for e in self.sinks]
+ l_stb_o = [e.stb_o for e in self.sources]
+ l_ack_i = [e.ack_i for e in self.sources]
+ if self.scheduling_model.model == COMBINATORIAL:
+ return _control_fragment_comb(l_stb_i, l_ack_o, l_stb_o, l_ack_i)
+ elif self.scheduling_model.model == SEQUENTIAL:
+ return _control_fragment_seq(self.scheduling_model.latency, l_stb_i, l_ack_o, l_stb_o, l_ack_i, self.trigger)
+ elif self.scheduling_model.model == PIPELINE:
+ return _control_fragment_pipe(self.scheduling_model.latency, l_stb_i, l_ack_o, l_stb_o, l_ack_i, self.pipe_ce)
+ elif self.scheduling_model.model == DYNAMIC:
+ raise NotImplementedError("Actor classes with dynamic scheduling must overload get_control_fragment")
+
+ def get_process_fragment():
+ raise NotImplementedError("Actor classes must overload get_process_fragment")

No commit comments for this range

Something went wrong with that request. Please try again.