Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 2 files changed
  • 0 comments
  • 2 contributors
Mar 12, 2013
Lars-Peter Clausen 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
Lars-Peter Clausen 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
Mar 17, 2013
Sébastien Bourdeauducq Merge pull request #6 from larsclausen/master
Minor improvements
2a4cc38
43  migen/actorlib/sim.py
@@ -22,27 +22,31 @@ def _process_transactions(self, s):
22 22
 		for token in self.active:
23 23
 			ep = self.actor.endpoints[token.endpoint]
24 24
 			if isinstance(ep, Sink):
25  
-				if s.rd(ep.ack):
26  
-					if s.rd(ep.stb):
27  
-						token.value = s.multiread(ep.token)
28  
-						completed.add(token)
29  
-						s.wr(ep.ack, 0)
30  
-				else:
31  
-					s.wr(ep.ack, 1)
  25
+				if s.rd(ep.ack) and s.rd(ep.stb):
  26
+					token.value = s.multiread(ep.token)
  27
+					completed.add(token)
  28
+					s.wr(ep.ack, 0)
32 29
 			elif isinstance(ep, Source):
33  
-				if s.rd(ep.stb):
34  
-					if s.rd(ep.ack):
35  
-						completed.add(token)
36  
-						s.wr(ep.stb, 0)
37  
-				else:
38  
-					s.wr(ep.stb, 1)
39  
-					s.multiwrite(ep.token, token.value)
  30
+				if s.rd(ep.ack) and s.rd(ep.stb):
  31
+					completed.add(token)
  32
+					s.wr(ep.stb, 0)
40 33
 			else:
41 34
 				raise TypeError
42 35
 		self.active -= completed
43 36
 		if not self.active:
44 37
 			self.busy = True
45  
-	
  38
+
  39
+	def _update_control_signals(self, s):
  40
+		for token in self.active:
  41
+			ep = self.actor.endpoints[token.endpoint]
  42
+			if isinstance(ep, Sink):
  43
+				s.wr(ep.ack, 1)
  44
+			elif isinstance(ep, Source):
  45
+				s.multiwrite(ep.token, token.value)
  46
+				s.wr(ep.stb, 1)
  47
+			else:
  48
+				raise TypeError
  49
+
46 50
 	def _next_transactions(self):
47 51
 		try:
48 52
 			transactions = next(self.generator)
@@ -62,13 +66,16 @@ def _next_transactions(self):
62 66
 			raise TypeError
63 67
 		if self.active and all(transaction.idle_wait for transaction in self.active):
64 68
 			self.busy = False
65  
-	
  69
+
66 70
 	def do_simulation(self, s):
67 71
 		if not self.done:
68  
-			if not self.active:
69  
-				self._next_transactions()
70 72
 			if self.active:
71 73
 				self._process_transactions(s)
  74
+			if not self.active:
  75
+				self._next_transactions()
  76
+				self._update_control_signals(s)
  77
+
  78
+	do_simulation.initialize = True
72 79
 
73 80
 class SimActor(Actor):
74 81
 	def __init__(self, generator, *endpoint_descriptions, **misc):
6  migen/fhdl/structure.py
@@ -89,10 +89,16 @@ def __ge__(self, other):
89 89
 	
90 90
 	def __getitem__(self, key):
91 91
 		if isinstance(key, int):
  92
+			if (key < 0):
  93
+				key += len(self)
92 94
 			return _Slice(self, key, key+1)
93 95
 		elif isinstance(key, slice):
94 96
 			start = key.start or 0
95 97
 			stop = key.stop or len(self)
  98
+			if (start < 0):
  99
+				start += len(self)
  100
+			if (stop < 0):
  101
+				stop += len(self)
96 102
 			if stop > len(self):
97 103
 				stop = len(self)
98 104
 			if key.step != None:

No commit comments for this range

Something went wrong with that request. Please try again.