Move arithmetic actors to actorlib
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Sun, 24 Jun 2012 17:13:49 +0000 (19:13 +0200)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Sun, 24 Jun 2012 17:13:49 +0000 (19:13 +0200)
examples/dataflow/dma.py
examples/dataflow/fibonacci.py
migen/actorlib/ala.py [new file with mode: 0644]
migen/actorlib/composer.py [new file with mode: 0644]
migen/flow/ala.py [deleted file]
migen/flow/composer.py [deleted file]

index ffc4d97998300c0a666a72318cdf8ca6e9690ba7..6e8c88401fcecc4800cd9db08fc692722773366a 100644 (file)
@@ -1,7 +1,7 @@
 from random import Random
 
-from migen.flow.ala import *
 from migen.flow.network import *
+from migen.actorlib.ala import *
 from migen.actorlib import dma_wishbone, dma_asmi
 from migen.actorlib.sim import *
 from migen.bus import wishbone, asmibus
index 709cfe4997f95be2742531269be696d5110e1d7e..e67728bba3770ffd204a96ea9bb6463914c30936 100644 (file)
@@ -1,6 +1,6 @@
-from migen.flow.ala import *
 from migen.flow.network import *
 from migen.flow import plumbing
+from migen.actorlib.ala import *
 from migen.actorlib.sim import *
 from migen.sim.generic import Simulator
 from migen.sim.icarus import Runner
diff --git a/migen/actorlib/ala.py b/migen/actorlib/ala.py
new file mode 100644 (file)
index 0000000..9921418
--- /dev/null
@@ -0,0 +1,81 @@
+from migen.fhdl.structure import *
+from migen.fhdl.structure import _Operator
+from migen.flow.actor import *
+from migen.corelogic.record import *
+from migen.corelogic import divider
+
+class _SimpleBinary(CombinatorialActor):
+       def __init__(self, bv_op, bv_r=None):
+               self.bv_op = bv_op
+               if bv_r is None:
+                       bv_r = self.__class__.get_result_bv(bv_op)
+               self.bv_r = bv_r
+               super().__init__(
+                       ("operands", Sink, [("a", bv_op), ("b", bv_op)]),
+                       ("result", Source, [("r", bv_r)]))
+
+       def get_process_fragment(self):
+               return Fragment([
+                       self.token("result").r.eq(_Operator(self.op, 
+                               [self.token("operands").a, self.token("operands").b]))
+               ])
+
+class Add(_SimpleBinary):
+       op = "+"
+       def get_result_bv(bv):
+               return BV(bv.width+1, bv.signed)
+
+class Sub(_SimpleBinary):
+       op = "-"
+       def get_result_bv(bv):
+               return BV(bv.width+1, bv.signed)
+
+class Mul(_SimpleBinary):
+       op = "*"
+       def get_result_bv(bv):
+               return BV(2*bv.width, bv.signed)
+
+class And(_SimpleBinary):
+       op = "&"
+       def get_result_bv(bv):
+               return bv
+
+class Xor(_SimpleBinary):
+       op = "^"
+       def get_result_bv(bv):
+               return bv
+
+class Or(_SimpleBinary):
+       op = "|"
+       def get_result_bv(bv):
+               return bv
+
+class LT(_SimpleBinary):
+       op = "<"
+       def get_result_bv(bv):
+               return BV(1)
+
+class LE(_SimpleBinary):
+       op = "<="
+       def get_result_bv(bv):
+               return BV(1)
+
+class EQ(_SimpleBinary):
+       op = "=="
+       def get_result_bv(bv):
+               return BV(1)
+
+class NE(_SimpleBinary):
+       op = "!="
+       def get_result_bv(bv):
+               return BV(1)
+
+class DivMod(SequentialActor):
+       def __init__(self, width):
+               self.div = divider.Divider(width)
+               super().__init__(width,
+                       ("operands", Sink, [("dividend", self.div.dividend_i), ("divisor", self.div.divisor_i)]),
+                       ("result", Source, [("quotient", self.div.quotient_o), ("remainder", self.div.remainder_o)]))
+
+       def get_process_fragment(self):
+               return self.div.get_fragment() + Fragment([self.div.start_i.eq(self.trigger)])
diff --git a/migen/actorlib/composer.py b/migen/actorlib/composer.py
new file mode 100644 (file)
index 0000000..683186d
--- /dev/null
@@ -0,0 +1,64 @@
+from migen.flow.actor import *
+from migen.flow.plumbing import *
+from migen.flow.network import *
+from migen.actorlib.ala import *
+
+def _create(a, b, actor_class):
+       assert id(a.dfg) == id(b.dfg)
+       dfg = a.dfg
+       
+       bva = a.actor_node.get_dict()["bv_r"]
+       bvb = b.actor_node.get_dict()["bv_r"]
+       bv_op = BV(max(bva.width, bvb.width), bva.signed and bvb.signed)
+       bv_r = actor_class.get_result_bv(bv_op)
+       
+       new_actor = ActorNode(actor_class, {"bv_op": bv_op, "bv_r": bv_r})
+       dfg.add_connection(a.actor_node, new_actor, "result", "operands", sink_subr=["a"])
+       dfg.add_connection(b.actor_node, new_actor, "result", "operands", sink_subr=["b"])
+       
+       return ComposableSource(dfg, new_actor)
+
+class ComposableSource:
+       def __init__(self, dfg, actor_node):
+               self.dfg = dfg
+               if not isinstance(actor_node, ActorNode):
+                       actor_node = ActorNode(actor_node)
+               self.actor_node = actor_node
+       
+       def __add__(self, other):
+               return _create(self, other, Add)
+       def __radd__(self, other):
+               return _create(other, self, Add)
+       def __sub__(self, other):
+               return _create(self, other, Sub)
+       def __rsub__(self, other):
+               return _create(other, self, Sub)
+       def __mul__(self, other):
+               return _create(self, other, Mul)
+       def __rmul__(self, other):
+               return _create(other, self, Mul)
+       def __and__(self, other):
+               return _create(self, other, And)
+       def __rand__(self, other):
+               return _create(other, self, And)
+       def __xor__(self, other):
+               return _create(self, other, Xor)
+       def __rxor__(self, other):
+               return _create(other, self, Xor)
+       def __or__(self, other):
+               return _create(self, other, Or)
+       def __ror__(self, other):
+               return _create(other, self, Or)
+
+       def __lt__(self, other):
+               return _create(self, other, LT)
+       def __le__(self, other):
+               return _create(self, other, LE)
+       def __eq__(self, other):
+               return _create(self, other, EQ)
+       def __ne__(self, other):
+               return _create(self, other, NE)
+       def __gt__(self, other):
+               return _create(other, self, LT)
+       def __ge__(self, other):
+               return _create(other, self, LE)
diff --git a/migen/flow/ala.py b/migen/flow/ala.py
deleted file mode 100644 (file)
index 9921418..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-from migen.fhdl.structure import *
-from migen.fhdl.structure import _Operator
-from migen.flow.actor import *
-from migen.corelogic.record import *
-from migen.corelogic import divider
-
-class _SimpleBinary(CombinatorialActor):
-       def __init__(self, bv_op, bv_r=None):
-               self.bv_op = bv_op
-               if bv_r is None:
-                       bv_r = self.__class__.get_result_bv(bv_op)
-               self.bv_r = bv_r
-               super().__init__(
-                       ("operands", Sink, [("a", bv_op), ("b", bv_op)]),
-                       ("result", Source, [("r", bv_r)]))
-
-       def get_process_fragment(self):
-               return Fragment([
-                       self.token("result").r.eq(_Operator(self.op, 
-                               [self.token("operands").a, self.token("operands").b]))
-               ])
-
-class Add(_SimpleBinary):
-       op = "+"
-       def get_result_bv(bv):
-               return BV(bv.width+1, bv.signed)
-
-class Sub(_SimpleBinary):
-       op = "-"
-       def get_result_bv(bv):
-               return BV(bv.width+1, bv.signed)
-
-class Mul(_SimpleBinary):
-       op = "*"
-       def get_result_bv(bv):
-               return BV(2*bv.width, bv.signed)
-
-class And(_SimpleBinary):
-       op = "&"
-       def get_result_bv(bv):
-               return bv
-
-class Xor(_SimpleBinary):
-       op = "^"
-       def get_result_bv(bv):
-               return bv
-
-class Or(_SimpleBinary):
-       op = "|"
-       def get_result_bv(bv):
-               return bv
-
-class LT(_SimpleBinary):
-       op = "<"
-       def get_result_bv(bv):
-               return BV(1)
-
-class LE(_SimpleBinary):
-       op = "<="
-       def get_result_bv(bv):
-               return BV(1)
-
-class EQ(_SimpleBinary):
-       op = "=="
-       def get_result_bv(bv):
-               return BV(1)
-
-class NE(_SimpleBinary):
-       op = "!="
-       def get_result_bv(bv):
-               return BV(1)
-
-class DivMod(SequentialActor):
-       def __init__(self, width):
-               self.div = divider.Divider(width)
-               super().__init__(width,
-                       ("operands", Sink, [("dividend", self.div.dividend_i), ("divisor", self.div.divisor_i)]),
-                       ("result", Source, [("quotient", self.div.quotient_o), ("remainder", self.div.remainder_o)]))
-
-       def get_process_fragment(self):
-               return self.div.get_fragment() + Fragment([self.div.start_i.eq(self.trigger)])
diff --git a/migen/flow/composer.py b/migen/flow/composer.py
deleted file mode 100644 (file)
index 2c58c96..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-from migen.flow.actor import *
-from migen.flow.ala import *
-from migen.flow.plumbing import *
-from migen.flow.network import *
-
-def _create(a, b, actor_class):
-       assert id(a.dfg) == id(b.dfg)
-       dfg = a.dfg
-       
-       bva = a.actor_node.get_dict()["bv_r"]
-       bvb = b.actor_node.get_dict()["bv_r"]
-       bv_op = BV(max(bva.width, bvb.width), bva.signed and bvb.signed)
-       bv_r = actor_class.get_result_bv(bv_op)
-       
-       new_actor = ActorNode(actor_class, {"bv_op": bv_op, "bv_r": bv_r})
-       dfg.add_connection(a.actor_node, new_actor, "result", "operands", sink_subr=["a"])
-       dfg.add_connection(b.actor_node, new_actor, "result", "operands", sink_subr=["b"])
-       
-       return ComposableSource(dfg, new_actor)
-
-class ComposableSource:
-       def __init__(self, dfg, actor_node):
-               self.dfg = dfg
-               if not isinstance(actor_node, ActorNode):
-                       actor_node = ActorNode(actor_node)
-               self.actor_node = actor_node
-       
-       def __add__(self, other):
-               return _create(self, other, Add)
-       def __radd__(self, other):
-               return _create(other, self, Add)
-       def __sub__(self, other):
-               return _create(self, other, Sub)
-       def __rsub__(self, other):
-               return _create(other, self, Sub)
-       def __mul__(self, other):
-               return _create(self, other, Mul)
-       def __rmul__(self, other):
-               return _create(other, self, Mul)
-       def __and__(self, other):
-               return _create(self, other, And)
-       def __rand__(self, other):
-               return _create(other, self, And)
-       def __xor__(self, other):
-               return _create(self, other, Xor)
-       def __rxor__(self, other):
-               return _create(other, self, Xor)
-       def __or__(self, other):
-               return _create(self, other, Or)
-       def __ror__(self, other):
-               return _create(other, self, Or)
-
-       def __lt__(self, other):
-               return _create(self, other, LT)
-       def __le__(self, other):
-               return _create(self, other, LE)
-       def __eq__(self, other):
-               return _create(self, other, EQ)
-       def __ne__(self, other):
-               return _create(self, other, NE)
-       def __gt__(self, other):
-               return _create(other, self, LT)
-       def __ge__(self, other):
-               return _create(other, self, LE)