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
  • 2 files changed
  • 0 commit comments
  • 2 contributors
Commits on Mar 12, 2013
@larsclausen larsclausen Add support for negative slice indices
In python a negative indices usually mean start counting from the right side.
I.e. if the index is negative is acutal index used is len(l) + i. E.g. l[-2]
equals l[len(l)-2].

Being able to specify an index this way also comes in handy for migen slices in
some cases. E.g. the following snippet can be implement to shift an abitrary
length register n bits to the right:
	reg.eq(Cat(Replicate(0, n), reg[-n:])

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
72579a6
@larsclausen larsclausen Allow SimActors to produce/consume a constant stream of tokens
Currently a SimActor requires one clock period to recover from consuming or
producing a token. ack/stb are deasserted in the cycle where the token is
consumed/produced and only re-asserted in the next cycle. This patch updates the
code to keep the control signals asserted if the actor is able to produce or
consume a token in the next cycle.

The patch also sets 'initialize' attribute on the simulation method, this will
make sure that the control and data signals will be ready right on the first
clock cycle.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
dea4674
Commits on Mar 17, 2013
@sbourdeauducq sbourdeauducq Merge pull request #6 from larsclausen/master
Minor improvements
2a4cc38
Showing with 31 additions and 18 deletions.
  1. +25 −18 migen/actorlib/sim.py
  2. +6 −0 migen/fhdl/structure.py
View
43 migen/actorlib/sim.py
@@ -22,27 +22,31 @@ def _process_transactions(self, s):
for token in self.active:
ep = self.actor.endpoints[token.endpoint]
if isinstance(ep, Sink):
- if s.rd(ep.ack):
- if s.rd(ep.stb):
- token.value = s.multiread(ep.token)
- completed.add(token)
- s.wr(ep.ack, 0)
- else:
- s.wr(ep.ack, 1)
+ if s.rd(ep.ack) and s.rd(ep.stb):
+ token.value = s.multiread(ep.token)
+ completed.add(token)
+ s.wr(ep.ack, 0)
elif isinstance(ep, Source):
- if s.rd(ep.stb):
- if s.rd(ep.ack):
- completed.add(token)
- s.wr(ep.stb, 0)
- else:
- s.wr(ep.stb, 1)
- s.multiwrite(ep.token, token.value)
+ if s.rd(ep.ack) and s.rd(ep.stb):
+ completed.add(token)
+ s.wr(ep.stb, 0)
else:
raise TypeError
self.active -= completed
if not self.active:
self.busy = True
-
+
+ def _update_control_signals(self, s):
+ for token in self.active:
+ ep = self.actor.endpoints[token.endpoint]
+ if isinstance(ep, Sink):
+ s.wr(ep.ack, 1)
+ elif isinstance(ep, Source):
+ s.multiwrite(ep.token, token.value)
+ s.wr(ep.stb, 1)
+ else:
+ raise TypeError
+
def _next_transactions(self):
try:
transactions = next(self.generator)
@@ -62,13 +66,16 @@ def _next_transactions(self):
raise TypeError
if self.active and all(transaction.idle_wait for transaction in self.active):
self.busy = False
-
+
def do_simulation(self, s):
if not self.done:
- if not self.active:
- self._next_transactions()
if self.active:
self._process_transactions(s)
+ if not self.active:
+ self._next_transactions()
+ self._update_control_signals(s)
+
+ do_simulation.initialize = True
class SimActor(Actor):
def __init__(self, generator, *endpoint_descriptions, **misc):
View
6 migen/fhdl/structure.py
@@ -89,10 +89,16 @@ def __ge__(self, other):
def __getitem__(self, key):
if isinstance(key, int):
+ if (key < 0):
+ key += len(self)
return _Slice(self, key, key+1)
elif isinstance(key, slice):
start = key.start or 0
stop = key.stop or len(self)
+ if (start < 0):
+ start += len(self)
+ if (stop < 0):
+ stop += len(self)
if stop > len(self):
stop = len(self)
if key.step != None:

No commit comments for this range

Something went wrong with that request. Please try again.