New specification for width and signedness
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Thu, 29 Nov 2012 20:22:38 +0000 (21:22 +0100)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Thu, 29 Nov 2012 20:22:38 +0000 (21:22 +0100)
40 files changed:
examples/basic/arrays.py
examples/basic/lm32_inst.py
examples/basic/namer.py
examples/basic/simple_gpio.py
examples/basic/using_record.py
examples/dataflow/arithmetic.py [deleted file]
examples/dataflow/dma.py
examples/dataflow/fibonacci.py [deleted file]
examples/dataflow/misc.py
examples/dataflow/structuring.py
examples/pytholite/basic.py
examples/pytholite/uio.py
examples/sim/basic1.py
examples/sim/basic2.py
examples/sim/dataflow.py
examples/sim/fir.py
migen/actorlib/ala.py [deleted file]
migen/actorlib/dma_asmi.py
migen/actorlib/dma_wishbone.py
migen/actorlib/misc.py
migen/actorlib/structuring.py
migen/bank/description.py
migen/bus/asmibus.py
migen/bus/simple.py
migen/bus/wishbone.py
migen/bus/wishbone2asmi.py
migen/corelogic/buffers.py
migen/corelogic/divider.py
migen/corelogic/fsm.py
migen/corelogic/misc.py
migen/corelogic/record.py
migen/corelogic/roundrobin.py
migen/fhdl/structure.py
migen/fhdl/tools.py
migen/fhdl/verilog.py
migen/flow/actor.py
migen/flow/isd.py
migen/flow/plumbing.py
migen/pytholite/reg.py
migen/sim/generic.py

index e89ec89215e1442a3efa604201078c5e8edf7b2b..d8152c7e53dd5781a8cc166258c3efde808e451e 100644 (file)
@@ -4,8 +4,8 @@ from migen.fhdl import verilog
 dx = 5
 dy = 5
 
-x = Signal(BV(bits_for(dx-1)))
-y = Signal(BV(bits_for(dy-1)))
+x = Signal(bits_for(dx-1))
+y = Signal(bits_for(dy-1))
 out = Signal()
 
 my_2d_array = Array(Array(Signal() for a in range(dx)) for b in range(dy))
index 2213f780289acfffd611fba08aefde4745301b22..8711dae3d4a408f2412a36ecffce29568e4cc37a 100644 (file)
@@ -7,36 +7,36 @@ class LM32:
                        Instance.ClockPort("clk_i"),
                        Instance.ResetPort("rst_i"),
                
-                       Instance.Input("interrupt", BV(32)),
-                       Instance.Input("ext_break", BV(1)),
+                       Instance.Input("interrupt", 32),
+                       Instance.Input("ext_break", 1),
                
-                       Instance.Output("I_ADR_O", BV(32)),
-                       Instance.Output("I_DAT_O", BV(32)),
-                       Instance.Output("I_SEL_O", BV(4)),
-                       Instance.Output("I_CYC_O", BV(1)),
-                       Instance.Output("I_STB_O", BV(1)),
-                       Instance.Output("I_WE_O", BV(1)),
-                       Instance.Output("I_CTI_O", BV(3)),
-                       Instance.Output("I_LOCK_O", BV(1)),
-                       Instance.Output("I_BTE_O", BV(1)),
-                       Instance.Input("I_DAT_I", BV(32)),
-                       Instance.Input("I_ACK_I", BV(1)),
-                       Instance.Input("I_ERR_I", BV(1)),
-                       Instance.Input("I_RTY_I", BV(1)),
+                       Instance.Output("I_ADR_O", 32),
+                       Instance.Output("I_DAT_O", 32),
+                       Instance.Output("I_SEL_O", 4),
+                       Instance.Output("I_CYC_O", 1),
+                       Instance.Output("I_STB_O", 1),
+                       Instance.Output("I_WE_O", 1),
+                       Instance.Output("I_CTI_O", 3),
+                       Instance.Output("I_LOCK_O", 1),
+                       Instance.Output("I_BTE_O", 1),
+                       Instance.Input("I_DAT_I", 32),
+                       Instance.Input("I_ACK_I", 1),
+                       Instance.Input("I_ERR_I", 1),
+                       Instance.Input("I_RTY_I", 1),
                        
-                       Instance.Output("D_ADR_O", BV(32)),
-                       Instance.Output("D_DAT_O", BV(32)),
-                       Instance.Output("D_SEL_O", BV(4)),
-                       Instance.Output("D_CYC_O", BV(1)),
-                       Instance.Output("D_STB_O", BV(1)),
-                       Instance.Output("D_WE_O", BV(1)),
-                       Instance.Output("D_CTI_O", BV(3)),
-                       Instance.Output("D_LOCK_O", BV(1)),
-                       Instance.Output("D_BTE_O", BV(1)),
-                       Instance.Input("D_DAT_I", BV(32)),
-                       Instance.Input("D_ACK_I", BV(1)),
-                       Instance.Input("D_ERR_I", BV(1)),
-                       Instance.Input("D_RTY_I", BV(1)),
+                       Instance.Output("D_ADR_O", 32),
+                       Instance.Output("D_DAT_O", 32),
+                       Instance.Output("D_SEL_O", 4),
+                       Instance.Output("D_CYC_O", 1),
+                       Instance.Output("D_STB_O", 1),
+                       Instance.Output("D_WE_O", 1),
+                       Instance.Output("D_CTI_O", 3),
+                       Instance.Output("D_LOCK_O", 1),
+                       Instance.Output("D_BTE_O", 1),
+                       Instance.Input("D_DAT_I", 32),
+                       Instance.Input("D_ACK_I", 1),
+                       Instance.Input("D_ERR_I", 1),
+                       Instance.Input("D_RTY_I", 1),
                        
                        name="lm32")
        
index f3e31c6ebe1476f67994cbf70e72d1a2e9110a78..2928c84066035f2f5c765290bd8c661354218228 100644 (file)
@@ -7,7 +7,7 @@ def gen_list(n):
        return s
 
 def gen_2list(n):
-       s = [Signal(BV(2)) for i in range(n)]
+       s = [Signal(2) for i in range(n)]
        return s
 
 class Foo:
index d469eec285ef7734c2994c99688c6d0b4b18316e..16d2eae8cc19fffb53293b9dffb05ffa35e7d05c 100644 (file)
@@ -10,8 +10,8 @@ oreg = description.RegisterField("o", noutputs, atomic_write=True)
 ireg = description.RegisterField("i", ninputs, READ_ONLY, WRITE_ONLY)
 
 # input path
-gpio_in = Signal(BV(ninputs))
-gpio_in_s = Signal(BV(ninputs)) # synchronizer
+gpio_in = Signal(ninputs)
+gpio_in_s = Signal(ninputs) # synchronizer
 insync = [gpio_in_s.eq(gpio_in), ireg.field.w.eq(gpio_in_s)]
 inf = Fragment(sync=insync)
 
index 7c757aa4ff47b9e9206354eb36da5dc8350ab80a..8e715a517e27bddc5496ccdf1cab24a255af81f9 100644 (file)
@@ -2,11 +2,11 @@ from migen.fhdl.structure import *
 from migen.corelogic.record import *
 
 L = [
-       ("x", BV(10), 8),
-       ("y", BV(10), 8),
+       ("x", 10, 8),
+       ("y", 10, 8),
        ("level2", [
-               ("a", BV(5), 32),
-               ("b", BV(5), 16)
+               ("a", 5, 32),
+               ("b", 5, 16)
        ])
 ]
 
diff --git a/examples/dataflow/arithmetic.py b/examples/dataflow/arithmetic.py
deleted file mode 100644 (file)
index 89efa0b..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-import sys
-
-import matplotlib.pyplot as plt
-import networkx as nx
-
-from migen.flow.network import *
-from migen.actorlib.ala import *
-from migen.actorlib.sim import *
-from migen.sim.generic import Simulator
-from migen.sim.icarus import Runner
-
-class NumberGen(SimActor):
-       def __init__(self):
-               self.bv_r = BV(16)
-               def number_gen():
-                       for i in range(10):
-                               yield Token("result", {"r": i})
-               super().__init__(number_gen(),
-                       ("result", Source, [("r", self.bv_r)]))
-
-def draw(g):
-       if len(sys.argv) > 1 and sys.argv[1] == "draw":
-               nx.draw_spectral(g)
-               plt.show()
-
-def main():
-       # Create graph
-       g = DataFlowGraph()
-       gen1 = ComposableNode(g, NumberGen())
-       gen2 = ComposableNode(g, NumberGen())
-       
-       ps = gen1 + gen2
-       result = ps*gen1 + ps*gen2
-       
-       g.add_connection(result, ActorNode(Dumper([("r", BV(32))])))
-
-       gen1.actor.name = "gen1"
-       gen2.actor.name = "gen2"
-       result.name = "result"
-       
-       # Elaborate
-       print("is_abstract before elaboration: " + str(g.is_abstract()))
-       draw(g)
-       g.elaborate()
-       print("is_abstract after elaboration : " + str(g.is_abstract()))
-       draw(g)
-
-       # Simulate
-       c = CompositeActor(g)
-       fragment = c.get_fragment()
-       sim = Simulator(fragment, Runner())
-       sim.run(100)
-
-main()
index 1de8d6f9fa0bfc8e5a61418626b6476b05f3e0b4..5bcd063ed5accaefab4415bd0a9c6d8ad89c313a 100644 (file)
@@ -70,9 +70,9 @@ def asmi_sim(efragment, hub, end_simulation):
 
 def test_wb_reader():
        print("*** Testing Wishbone reader")
-       adrgen = ActorNode(SimActor(adrgen_gen(), ("address", Source, [("a", BV(30))])))
+       adrgen = ActorNode(SimActor(adrgen_gen(), ("address", Source, [("a", 30)])))
        reader = ActorNode(dma_wishbone.Reader())
-       dumper = ActorNode(SimActor(dumper_gen(), ("data", Sink, [("d", BV(32))])))
+       dumper = ActorNode(SimActor(dumper_gen(), ("data", Sink, [("d", 32)])))
        g = DataFlowGraph()
        g.add_connection(adrgen, reader)
        g.add_connection(reader, dumper)
@@ -83,7 +83,7 @@ def test_wb_reader():
 
 def test_wb_writer():
        print("*** Testing Wishbone writer")
-       trgen = ActorNode(SimActor(trgen_gen(), ("address_data", Source, [("a", BV(30)), ("d", BV(32))])))
+       trgen = ActorNode(SimActor(trgen_gen(), ("address_data", Source, [("a", 30), ("d", 32)])))
        writer = ActorNode(dma_wishbone.Writer())
        g = DataFlowGraph()
        g.add_connection(trgen, writer)
@@ -99,9 +99,9 @@ def test_asmi_reader(nslots):
        port = hub.get_port(nslots)
        hub.finalize()
        
-       adrgen = ActorNode(SimActor(adrgen_gen(), ("address", Source, [("a", BV(32))])))
+       adrgen = ActorNode(SimActor(adrgen_gen(), ("address", Source, [("a", 32)])))
        reader = ActorNode(dma_asmi.Reader(port))
-       dumper = ActorNode(SimActor(dumper_gen(), ("data", Sink, [("d", BV(32))])))
+       dumper = ActorNode(SimActor(dumper_gen(), ("data", Sink, [("d", 32)])))
        g = DataFlowGraph()
        g.add_connection(adrgen, reader)
        g.add_connection(reader, dumper)
diff --git a/examples/dataflow/fibonacci.py b/examples/dataflow/fibonacci.py
deleted file mode 100644 (file)
index 8e1276e..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-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
-
-# Pushes a "1" token and then becomes transparent.
-class Init(Actor):
-       def __init__(self, nbits):
-               super().__init__(
-                       ("in", Sink, [("d", BV(nbits))]),
-                       ("out", Source, [("d", BV(nbits))]))
-       
-       def get_fragment(self):
-               done = Signal()
-               comb = [
-                       self.busy.eq(~done),
-                       If(done,
-                               self.endpoints["in"].ack.eq(self.endpoints["out"].ack),
-                               self.endpoints["out"].stb.eq(self.endpoints["in"].stb),
-                               self.endpoints["out"].token.d.eq(self.endpoints["in"].token.d)
-                       ).Else(
-                               self.endpoints["in"].ack.eq(0),
-                               self.endpoints["out"].stb.eq(1),
-                               self.endpoints["out"].token.d.eq(1)
-                       )
-               ]
-               sync = [
-                       If(self.endpoints["out"].ack, done.eq(1))
-               ]
-               return Fragment(comb, sync)
-
-def main():
-       nbits = 32
-       
-       # See:
-       # http://www.csse.monash.edu.au/~damian/Idioms/Topics/12.1.DataFlow/html/text.html
-       g = DataFlowGraph()
-       
-       adder = ActorNode(Add(BV(nbits)))
-       bufadd = ActorNode(plumbing.Buffer) # TODO FIXME: deadlocks without this buffer
-       init1 = ActorNode(Init(nbits))
-       buf1 = ActorNode(plumbing.Buffer)
-       init2 = ActorNode(Init(nbits))
-       buf2 = ActorNode(plumbing.Buffer)
-       
-       g.add_connection(adder, bufadd)
-       g.add_connection(bufadd, init1)
-       g.add_connection(init1, buf1)
-       g.add_connection(buf1, adder, sink_subr="a")
-       g.add_connection(buf1, init2)
-       g.add_connection(init2, buf2)
-       g.add_connection(buf2, adder, sink_subr="b")
-       
-       g.add_connection(bufadd, ActorNode(Dumper([("r", BV(nbits))])))
-       
-       c = CompositeActor(g)
-       fragment = c.get_fragment()
-       sim = Simulator(fragment, Runner())
-       sim.run(100)
-       
-main()
index 0aa0854b1e3abd93fcd4621a1efdd0ebe03d8da6..71e0f2486f77238ad8232a555ad8511def9d5696 100644 (file)
@@ -17,9 +17,9 @@ def sink_gen():
                print(t.value["value"])
 
 def main():
-       source = ActorNode(SimActor(source_gen(), ("source", Source, [("value", BV(32))])))
+       source = ActorNode(SimActor(source_gen(), ("source", Source, [("value", 32)])))
        loop = ActorNode(misc.IntSequence(32))
-       sink = ActorNode(SimActor(sink_gen(), ("sink", Sink, [("value", BV(32))])))
+       sink = ActorNode(SimActor(sink_gen(), ("sink", Sink, [("value", 32)])))
        g = DataFlowGraph()
        g.add_connection(source, loop)
        g.add_connection(loop, sink)
index 88c87a3947fae9d750df7e1dc060563ea0e8d26f..fdbc75340cec29f63678d186e7c2e6e9d891976f 100644 (file)
@@ -23,9 +23,9 @@ def sink_gen():
                print(t.value["value"])
 
 def main():
-       base_layout = [("value", BV(32))]
+       base_layout = [("value", 32)]
        packed_layout = structuring.pack_layout(base_layout, pack_factor)
-       rawbits_layout = [("value", BV(32*pack_factor))]
+       rawbits_layout = [("value", 32*pack_factor)]
        
        source = ActorNode(SimActor(source_gen(), ("source", Source, base_layout)))
        sink = ActorNode(SimActor(sink_gen(), ("sink", Sink, base_layout)))
index 40c8e96223c3480ebd49a6f3e3a5e319a641b54c..d2df3df39ed8da576ea8c93d403191099495f11c 100644 (file)
@@ -5,7 +5,7 @@ from migen.sim.generic import Simulator
 from migen.sim.icarus import Runner
 from migen.fhdl import verilog
 
-layout = [("r", BV(32))]
+layout = [("r", 32)]
 
 def number_gen():
        for i in range(10):
index 0cf5b6eb51bd0e598eee820ddbf5091ee1be22ca..ed8e92684ee3c5ec79639c0569ccd02efaebb743 100644 (file)
@@ -9,7 +9,7 @@ from migen.sim.generic import Simulator
 from migen.sim.icarus import Runner
 from migen.fhdl import verilog
 
-layout = [("r", BV(32))]
+layout = [("r", 32)]
 
 def gen():
        ds = Register(32)
index af00d0df009238f2813f0993b6f236dbf111be99..ac3f6fae73288563798b127dcec6fcf4b0cee8db 100644 (file)
@@ -9,7 +9,7 @@ from migen.sim.icarus import Runner
 # and prints its current value in simulation.
 class Counter:
        def __init__(self):
-               self.count = Signal(BV(4))
+               self.count = Signal(4)
        
        # This function will be called at every cycle.
        def do_simulation(self, s):
index a4387f76dded7401b654891d52ea0023eb513c1e..e0227f593d9ae47fb8cabe8cf6aa48011c74a0a2 100644 (file)
@@ -12,7 +12,7 @@ class Counter:
        def __init__(self):
                self.ce = Signal()
                # Demonstrate negative numbers and signals larger than 32 bits.
-               self.count = Signal(BV(37, True), reset=-5)
+               self.count = Signal((37, True), reset=-5)
        
        def do_simulation(self, s):
                # Only assert CE every second cycle.
index 66021ceb6213f4a9367e40f700afc29cf1ce11ab..2137620ffb996add2187092291bde30f89091093 100644 (file)
@@ -17,8 +17,8 @@ def sink_gen():
                print("Received: " + str(t.value["value"]))
 
 def main():
-       source = ActorNode(SimActor(source_gen(), ("source", Source, [("value", BV(32))])))
-       sink = ActorNode(SimActor(sink_gen(), ("sink", Sink, [("value", BV(32))])))
+       source = ActorNode(SimActor(source_gen(), ("source", Source, [("value", 32)])))
+       sink = ActorNode(SimActor(sink_gen(), ("sink", Sink, [("value", 32)])))
        g = DataFlowGraph()
        g.add_connection(source, sink)
        comp = CompositeActor(g)
index 1415fbfddfcbf60a045e34d1fcc46edeaedd3346..218376bc67822909c2427bd75f806285e845a640 100644 (file)
@@ -17,21 +17,20 @@ class FIR:
        def __init__(self, coef, wsize=16):
                self.coef = coef
                self.wsize = wsize
-               self.i = Signal(BV(self.wsize, True))
-               self.o = Signal(BV(self.wsize, True))
+               self.i = Signal((self.wsize, True))
+               self.o = Signal((self.wsize, True))
        
        def get_fragment(self):
                muls = []
                sync = []
                src = self.i
                for c in self.coef:
-                       sreg = Signal(BV(self.wsize, True))
+                       sreg = Signal((self.wsize, True))
                        sync.append(sreg.eq(src))
                        src = sreg
                        c_fp = int(c*2**(self.wsize - 1))
-                       c_e = Constant(c_fp, BV(bits_for(c_fp), True))
-                       muls.append(c_e*sreg)
-               sum_full = Signal(BV(2*self.wsize-1, True))
+                       muls.append(c_fp*sreg)
+               sum_full = Signal((2*self.wsize-1, True))
                sync.append(sum_full.eq(optree("+", muls)))
                comb = [self.o.eq(sum_full[self.wsize-1:])]
                return Fragment(comb, sync)
diff --git a/migen/actorlib/ala.py b/migen/actorlib/ala.py
deleted file mode 100644 (file)
index fe92c88..0000000
+++ /dev/null
@@ -1,143 +0,0 @@
-from migen.fhdl.structure import *
-from migen.fhdl.structure import _Operator
-from migen.flow.actor import *
-from migen.flow.network 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)])
-
-def _create(a, b, actor_class):
-       assert id(a.dfg) == id(b.dfg)
-       dfg = a.dfg
-       
-       bva = a.get_dict()["bv_r"]
-       bvb = b.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 = ComposableNode(dfg, actor_class, {"bv_op": bv_op, "bv_r": bv_r})
-       dfg.add_connection(a, new_actor, "result", "operands", sink_subr=["a"])
-       dfg.add_connection(b, new_actor, "result", "operands", sink_subr=["b"])
-       
-       return new_actor
-
-class ComposableNode(ActorNode):
-       def __init__(self, dfg, actor_class, parameters=dict()):
-               self.dfg = dfg
-               super().__init__(actor_class, parameters)
-       
-       def __hash__(self):
-               return id(self)
-       
-       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)
index 9dad765309c2da1ba0c4dd1d2c27d7c148aa7544..76a2855dbd20de0b65a198d043784df2b63312bd 100644 (file)
@@ -7,13 +7,13 @@ class SequentialReader(Actor):
                self.port = port
                assert(len(self.port.slots) == 1)
                super().__init__(
-                       ("address", Sink, [("a", BV(self.port.hub.aw))]),
-                       ("data", Source, [("d", BV(self.port.hub.dw))]))
+                       ("address", Sink, [("a", self.port.hub.aw)]),
+                       ("data", Source, [("d", self.port.hub.dw)]))
        
        def get_fragment(self):
                sample = Signal()
                data_reg_loaded = Signal()
-               data_reg = Signal(BV(self.port.hub.dw))
+               data_reg = Signal(self.port.hub.dw)
                
                accept_new = Signal()
                
@@ -49,8 +49,8 @@ class OOOReader(Actor):
                self.port = port
                assert(len(self.port.slots) > 1)
                super().__init__(
-                       ("address", Sink, [("a", BV(self.port.hub.aw))]),
-                       ("data", Source, [("d", BV(self.port.hub.dw))]))
+                       ("address", Sink, [("a", self.port.hub.aw)]),
+                       ("data", Source, [("d", self.port.hub.dw)]))
        
        def get_fragment(self):
                tag_width = len(self.port.tag_call)
index ef91a8a4320280449bef3fe4089b5b32f7125ffa..24768825d44155555e1263e81f9c6249012ed2f0 100644 (file)
@@ -6,14 +6,14 @@ class Reader(Actor):
        def __init__(self):
                self.bus = wishbone.Interface()
                super().__init__(
-                       ("address", Sink, [("a", BV(30))]),
-                       ("data", Source, [("d", BV(32))]))
+                       ("address", Sink, [("a", 30)]),
+                       ("data", Source, [("d", 32)]))
        
        def get_fragment(self):
                bus_stb = Signal()
                
                data_reg_loaded = Signal()
-               data_reg = Signal(BV(32))
+               data_reg = Signal(32)
                
                comb = [
                        self.busy.eq(data_reg_loaded),
@@ -42,7 +42,7 @@ class Writer(Actor):
        def __init__(self):
                self.bus = wishbone.Interface()
                super().__init__(
-                       ("address_data", Sink, [("a", BV(30)), ("d", BV(32))]))
+                       ("address_data", Sink, [("a", 30), ("d", 32)]))
 
        def get_fragment(self):
                comb = [
index 1c6a3c79b335b6440c4bae9334783301b336b270..adde77a5312c0834099881115e6ad87ebc5378f8 100644 (file)
@@ -10,23 +10,23 @@ class IntSequence(Actor):
                self.offsetbits = offsetbits
                self.step = step
                
-               parameters_layout = [("maximum", BV(self.nbits))]
+               parameters_layout = [("maximum", self.nbits)]
                if self.offsetbits:
-                       parameters_layout.append(("offset", BV(self.offsetbits)))
+                       parameters_layout.append(("offset", self.offsetbits))
                
                super().__init__(
                        ("parameters", Sink, parameters_layout),
-                       ("source", Source, [("value", BV(max(self.nbits, self.offsetbits)))]))
+                       ("source", Source, [("value", max(self.nbits, self.offsetbits))]))
        
        def get_fragment(self):
                load = Signal()
                ce = Signal()
                last = Signal()
                
-               maximum = Signal(BV(self.nbits))
+               maximum = Signal(self.nbits)
                if self.offsetbits:
-                       offset = Signal(BV(self.offsetbits))
-               counter = Signal(BV(self.nbits))
+                       offset = Signal(self.offsetbits)
+               counter = Signal(self.nbits)
                
                if self.step > 1:
                        comb = [last.eq(counter + self.step >= maximum)]
index bb0ff0bbb36e8b7a38f8c330f2a77745c138bbfb..27b08da572edf7fd398ee057a38b178667a2ee4c 100644 (file)
@@ -3,7 +3,7 @@ from migen.flow.actor import *
 
 def _rawbits_layout(l):
        if isinstance(l, int):
-               return [("rawbits", BV(l))]
+               return [("rawbits", l)]
        else:
                return l
 
@@ -34,7 +34,7 @@ class Unpack(Actor):
        
        def get_fragment(self):
                muxbits = bits_for(self.n-1)
-               mux = Signal(BV(muxbits))
+               mux = Signal(muxbits)
                last = Signal()
                comb = [
                        last.eq(mux == (self.n-1)),
@@ -65,7 +65,7 @@ class Pack(Actor):
        
        def get_fragment(self):
                demuxbits = bits_for(self.n-1)
-               demux = Signal(BV(demuxbits))
+               demux = Signal(demuxbits)
                
                load_part = Signal()
                strobe_all = Signal()
index a7f43925628487407b23550389ee220d19748670..969e30c1f066f9d41f8ac788ebcd60af53916909 100644 (file)
@@ -10,8 +10,8 @@ class RegisterRaw:
                self.name = name
                self.size = size
                self.re = Signal()
-               self.r = Signal(BV(self.size))
-               self.w = Signal(BV(self.size))
+               self.r = Signal(self.size)
+               self.w = Signal(self.size)
 
 (READ_ONLY, WRITE_ONLY, READ_WRITE) = range(3)
 
@@ -21,15 +21,15 @@ class Field:
                self.size = size
                self.access_bus = access_bus
                self.access_dev = access_dev
-               self.storage = Signal(BV(self.size), reset=reset)
+               self.storage = Signal(self.size, reset=reset)
                self.atomic_write = atomic_write
                if self.access_bus == READ_ONLY and self.access_dev == WRITE_ONLY:
-                       self.w = Signal(BV(self.size))
+                       self.w = Signal(self.size)
                else:
                        if self.access_dev == READ_ONLY or self.access_dev == READ_WRITE:
-                               self.r = Signal(BV(self.size))
+                               self.r = Signal(self.size)
                        if self.access_dev == WRITE_ONLY or self.access_dev == READ_WRITE:
-                               self.w = Signal(BV(self.size))
+                               self.w = Signal(self.size)
                                self.we = Signal()
 
 class RegisterFields:
@@ -51,7 +51,7 @@ class FieldAlias:
                self.access_bus = f.access_bus
                self.access_dev = f.access_dev
                if mode == ALIAS_ATOMIC_HOLD:
-                       self.storage = Signal(BV(end-start), name="atomic_hold")
+                       self.storage = Signal(end-start, name="atomic_hold")
                        self.commit_to = f.storage[start:end]
                else:
                        self.storage = f.storage[start:end]
index 1b47a86bd1ff3225efefbda9a3674255c9f5002f..cf7e7977547061a8cc41556ddae5c33653892af0 100644 (file)
@@ -10,17 +10,17 @@ class FinalizeError(Exception):
 
 class Slot:
        def __init__(self, aw, time):
-               self.state = Signal(BV(2))
+               self.state = Signal(2)
                self.we = Signal()
-               self.adr = Signal(BV(aw))
+               self.adr = Signal(aw)
                self.time = time
                if self.time:
-                       self._counter = Signal(BV(bits_for(time)))
+                       self._counter = Signal(bits_for(time))
                        self.mature = Signal()
                
                self.allocate = Signal()
                self.allocate_we = Signal()
-               self.allocate_adr = Signal(BV(aw))
+               self.allocate_adr = Signal(aw)
                self.process = Signal()
                self.call = Signal()
        
@@ -55,7 +55,7 @@ class Port:
                self.finalized = False
                
                # request issuance
-               self.adr = Signal(BV(self.hub.aw))
+               self.adr = Signal(self.hub.aw)
                self.we = Signal()
                self.stb = Signal()
                # tag_issue is created by finalize()
@@ -64,9 +64,9 @@ class Port:
                # request completion
                self.call = Signal()
                # tag_call is created by finalize()
-               self.dat_r = Signal(BV(self.hub.dw))
-               self.dat_w = Signal(BV(self.hub.dw))
-               self.dat_wm = Signal(BV(self.hub.dw//8))
+               self.dat_r = Signal(self.hub.dw)
+               self.dat_w = Signal(self.hub.dw)
+               self.dat_wm = Signal(self.hub.dw//8)
        
        def finalize(self, tagbits, base):
                if self.finalized:
@@ -76,8 +76,8 @@ class Port:
                self.base = base
                nslots = len(self.slots)
                if nslots > 1:
-                       self.tag_issue = Signal(BV(bits_for(nslots-1)))
-               self.tag_call = Signal(BV(tagbits))
+                       self.tag_issue = Signal(bits_for(nslots-1))
+               self.tag_call = Signal(tagbits)
        
        def get_call_expression(self, slotn=0):
                if not self.finalized:
@@ -127,9 +127,9 @@ class Hub:
                
                self.call = Signal()
                # tag_call is created by finalize()
-               self.dat_r = Signal(BV(self.dw))
-               self.dat_w = Signal(BV(self.dw))
-               self.dat_wm = Signal(BV(self.dw//8))
+               self.dat_r = Signal(self.dw)
+               self.dat_w = Signal(self.dw)
+               self.dat_wm = Signal(self.dw//8)
        
        def get_port(self, nslots=1):
                if self.finalized:
@@ -148,7 +148,7 @@ class Hub:
                for port in self.ports:
                        port.finalize(tagbits, base)
                        base += len(port.slots)
-               self.tag_call = Signal(BV(tagbits))
+               self.tag_call = Signal(tagbits)
        
        def get_slots(self):
                if not self.finalized:
index 348e510ce76cc131f54d886491b7a680ad763770..062b9e757f6e0de775dfcbf81835f5eb77d27c67 100644 (file)
@@ -25,7 +25,7 @@ class SimpleInterface:
                busname = modules[len(modules)-1]
                for signal in self.desc.desc:
                        signame = signal[1]
-                       setattr(self, signame, Signal(BV(signal[2]), busname + "_" + signame))
+                       setattr(self, signame, Signal(signal[2], busname + "_" + signame))
 
 def simple_interconnect_stmts(desc, master, slaves):
        s2m = desc.get_names(S_TO_M)
index 1fc699ac246d1028edc65301702c6d87cf2b6aa5..fa3b91c5f6c06d978a759b7ca3b6dad6d0308784 100644 (file)
@@ -74,8 +74,8 @@ class Decoder:
                sync = []
                
                ns = len(self.slaves)
-               slave_sel = Signal(BV(ns))
-               slave_sel_r = Signal(BV(ns))
+               slave_sel = Signal(ns)
+               slave_sel_r = Signal(ns)
                
                # decode slave addresses
                comb += [slave_sel[i].eq(fun(self.master.adr))
index cae09c67f98c7967d6620a2b1abaa60695196875..e19f9f98d62a845a3a6bf6fb17c91cd5c7efb183 100644 (file)
@@ -38,7 +38,7 @@ class WB2ASMI:
                
                write_from_asmi = Signal()
                write_to_asmi = Signal()
-               adr_offset_r = Signal(BV(offsetbits))
+               adr_offset_r = Signal(offsetbits)
                comb += [
                        data_port.adr.eq(adr_line),
                        If(write_from_asmi,
@@ -62,7 +62,7 @@ class WB2ASMI:
                tag_mem = Memory(tagbits+1, 2**linebits)
                tag_port = tag_mem.get_port(write_capable=True)
                
-               tag_layout = [("tag", BV(tagbits)), ("dirty", BV(1))]
+               tag_layout = [("tag", tagbits), ("dirty", 1)]
                tag_do = Record(tag_layout)
                tag_di = Record(tag_layout)
                comb += [
index 96d13affa2879a56ba083df8a602f0d044af0d2a..29cee986bb52bf25aaf8706ade58842885e26b6d 100644 (file)
@@ -4,8 +4,8 @@ class ReorderSlot:
        def __init__(self, tag_width, data_width):
                self.wait_data = Signal()
                self.has_data = Signal()
-               self.tag = Signal(BV(tag_width))
-               self.data = Signal(BV(data_width))
+               self.tag = Signal(tag_width)
+               self.data = Signal(data_width)
 
 class ReorderBuffer:
        def __init__(self, tag_width, data_width, depth):
@@ -14,21 +14,21 @@ class ReorderBuffer:
                # issue
                self.can_issue = Signal()
                self.issue = Signal()
-               self.tag_issue = Signal(BV(tag_width))
+               self.tag_issue = Signal(tag_width)
                
                # call
                self.call = Signal()
-               self.tag_call = Signal(BV(tag_width))
-               self.data_call = Signal(BV(data_width))
+               self.tag_call = Signal(tag_width)
+               self.data_call = Signal(data_width)
                
                # readback
                self.can_read = Signal()
                self.read = Signal()
-               self.data_read = Signal(BV(data_width))
+               self.data_read = Signal(data_width)
                
-               self._empty_count = Signal(BV(bits_for(self.depth)), reset=self.depth)
-               self._produce = Signal(BV(bits_for(self.depth-1)))
-               self._consume = Signal(BV(bits_for(self.depth-1)))
+               self._empty_count = Signal(max=self.depth+1, reset=self.depth)
+               self._produce = Signal(max=self.depth)
+               self._consume = Signal(max=self.depth)
                self._slots = Array(ReorderSlot(tag_width, data_width)
                        for n in range(self.depth))
        
index edac22e835aeeb8e5110759085479e372b5b9231..1c12b8f98c9503ee47a8bb06653969809431111c 100644 (file)
@@ -5,19 +5,19 @@ class Divider:
                self.w = w
                
                self.start_i = Signal()
-               self.dividend_i = Signal(BV(w))
-               self.divisor_i = Signal(BV(w))
+               self.dividend_i = Signal(w)
+               self.divisor_i = Signal(w)
                self.ready_o = Signal()
-               self.quotient_o = Signal(BV(w))
-               self.remainder_o = Signal(BV(w))
+               self.quotient_o = Signal(w)
+               self.remainder_o = Signal(w)
        
        def get_fragment(self):
                w = self.w
                
-               qr = Signal(BV(2*w))
-               counter = Signal(BV(bits_for(w)))
-               divisor_r = Signal(BV(w))
-               diff = Signal(BV(w+1))
+               qr = Signal(2*w)
+               counter = Signal(bits_for(w))
+               divisor_r = Signal(w)
+               diff = Signal(w+1)
                
                comb = [
                        self.quotient_o.eq(qr[:w]),
index cddd4b37b3c45611ac7d8547446472325981f2aa..85f3a401a1dad658cfc9993afd6e17fc246e0097 100644 (file)
@@ -4,9 +4,8 @@ class FSM:
        def __init__(self, *states, delayed_enters=[]):
                nstates = len(states) + sum([d[2] for d in delayed_enters])
                
-               self._state_bv = BV(bits_for(nstates-1))
-               self._state = Signal(self._state_bv)
-               self._next_state = Signal(self._state_bv)
+               self._state = Signal(max=nstates)
+               self._next_state = Signal(max=nstates)
                for n, state in enumerate(states):
                        setattr(self, state, n)
                self.actions = [[] for i in range(len(states))]
index 888941cc2b519fa9e68463ba9cbe5ae206aa0d4e..357271f1f1bcfb6fd13a9ac23d2372e1874693a6 100644 (file)
@@ -54,7 +54,7 @@ def chooser(signal, shift, output, n=None, reverse=False):
 
 def timeline(trigger, events):
        lastevent = max([e[0] for e in events])
-       counter = Signal(BV(bits_for(lastevent)))
+       counter = Signal(bits_for(lastevent))
        
        counterlogic = If(counter != 0,
                counter.eq(counter + 1)
index d8fd82bdd709a926e20caf60e89eb0da4d0bcff5..74bd8303513c59361f8a1ac2d1403f65b10bba0c 100644 (file)
@@ -1,5 +1,5 @@
 from migen.fhdl.structure import *
-from migen.fhdl.tools import value_bv
+from migen.fhdl.tools import value_bits_sign
 
 class Record:
        def __init__(self, layout, name=""):
@@ -11,7 +11,7 @@ class Record:
                        prefix = ""
                for f in layout:
                        if isinstance(f, tuple):
-                               if isinstance(f[1], BV):
+                               if isinstance(f[1], (int, tuple)):
                                        setattr(self, f[0], Signal(f[1], prefix + f[0]))
                                elif isinstance(f[1], Signal) or isinstance(f[1], Record):
                                        setattr(self, f[0], f[1])
@@ -24,7 +24,7 @@ class Record:
                                else:
                                        self.field_order.append((f[0], 1))
                        else:
-                               setattr(self, f, Signal(BV(1), prefix + f))
+                               setattr(self, f, Signal(1, prefix + f))
                                self.field_order.append((f, 1))
 
        def layout(self):
@@ -32,7 +32,7 @@ class Record:
                for key, alignment in self.field_order:
                        e = self.__dict__[key]
                        if isinstance(e, Signal):
-                               l.append((key, e.bv, alignment))
+                               l.append((key, (e.nbits, e.signed), alignment))
                        elif isinstance(e, Record):
                                l.append((key, e.layout(), alignment))
                return l
@@ -88,7 +88,7 @@ class Record:
                        else:
                                raise TypeError
                        for x in added:
-                               offset += value_bv(x).width
+                               offset += value_bits_sign(x)[0]
                        l += added
                if return_offset:
                        return (l, offset)
@@ -97,7 +97,7 @@ class Record:
        
        def to_signal(self, assignment_list, sig_out, align=False):
                flattened, length = self.flatten(align, return_offset=True)
-               raw = Signal(BV(length))
+               raw = Signal(length)
                if sig_out:
                        assignment_list.append(raw.eq(Cat(*flattened)))
                else:
index f2221bb51168bc888a0225ab3555eea2f009a594..204afa7f3423ce97de277d25141ecca6511bc814 100644 (file)
@@ -6,8 +6,8 @@ class RoundRobin:
        def __init__(self, n, switch_policy=SP_WITHDRAW):
                self.n = n
                self.bn = bits_for(self.n-1)
-               self.request = Signal(BV(self.n))
-               self.grant = Signal(BV(self.bn))
+               self.request = Signal(self.n)
+               self.grant = Signal(self.bn)
                self.switch_policy = switch_policy
                if self.switch_policy == SP_CE:
                        self.ce = Signal()
index 906f4ccb9fced33e4c387e3491ffd10078505781..869ed1287bb0d902dc5669711add802fa3d55e26 100644 (file)
@@ -1,5 +1,6 @@
 import inspect
 import re
+import builtins
 from collections import defaultdict
 
 from migen.fhdl import tracer
@@ -24,22 +25,6 @@ def bits_for(n, require_sign_bit=False):
                r += 1
        return r
 
-class BV:
-       def __init__(self, width=1, signed=False):
-               self.width = width
-               self.signed = signed
-       
-       def __repr__(self):
-               r = str(self.width) + "'"
-               if self.signed:
-                       r += "s"
-               r += "d"
-               return r
-       
-       def __eq__(self, other):
-               return self.width == other.width and self.signed == other.signed
-
-
 class HUID:
        __next_uid = 0
        def __init__(self):
@@ -66,13 +51,13 @@ class Value(HUID):
        def __rmul__(self, other):
                return _Operator("*", [other, self])
        def __lshift__(self, other):
-               return _Operator("<<", [self, other])
+               return _Operator("<<<", [self, other])
        def __rlshift__(self, other):
-               return _Operator("<<", [other, self])
+               return _Operator("<<<", [other, self])
        def __rshift__(self, other):
-               return _Operator(">>", [self, other])
+               return _Operator(">>>", [self, other])
        def __rrshift__(self, other):
-               return _Operator(">>", [other, self])
+               return _Operator(">>>", [other, self])
        def __and__(self, other):
                return _Operator("&", [self, other])
        def __rand__(self, other):
@@ -145,17 +130,34 @@ class Replicate(Value):
                self.n = n
 
 class Signal(Value):
-       def __init__(self, bv=BV(), name=None, variable=False, reset=0, name_override=None):
+       def __init__(self, bits_sign=None, name=None, variable=False, reset=0, name_override=None, min=None, max=None):
                super().__init__()
-               assert(isinstance(bv, BV))
-               self.bv = bv
+               
+               # determine number of bits and signedness
+               if bits_sign is None:
+                       if min is None:
+                               min = 0
+                       if max is None:
+                               max = 2
+                       max -= 1 # make both bounds inclusive
+                       assert(min < max)
+                       self.signed = min < 0 or max < 0
+                       self.nbits = builtins.max(bits_for(min, self.signed), bits_for(max, self.signed))
+               else:
+                       assert(min is None and max is None)
+                       if isinstance(bits_sign, tuple):
+                               self.nbits, self.signed = bits_sign
+                       else:
+                               self.nbits, self.signed = bits_sign, False
+               assert(isinstance(self.nbits, int))
+               
                self.variable = variable
                self.reset = reset
                self.name_override = name_override
                self.backtrace = tracer.trace_back(name)
 
-       def __len__(self):
-               return self.bv.width
+       def __len__(self): # TODO: remove (use tools.value_bits_sign instead)
+               return self.nbits
 
        def __repr__(self):
                return "<Signal " + (self.backtrace[-1][0] or "anonymous") + " at " + hex(id(self)) + ">"
@@ -238,9 +240,9 @@ class Instance(HUID):
                self.items = items
        
        class _IO:
-               def __init__(self, name, expr=BV(1)):
+               def __init__(self, name, expr=1):
                        self.name = name
-                       if isinstance(expr, BV):
+                       if isinstance(expr, (int, tuple)):
                                self.expr = Signal(expr, name)
                        else:
                                self.expr = expr
@@ -300,14 +302,14 @@ class Memory(HUID):
          clock_domain="sys"):
                if we_granularity >= self.width:
                        we_granularity = 0
-               adr = Signal(BV(bits_for(self.depth-1)))
-               dat_r = Signal(BV(self.width))
+               adr = Signal(max=self.depth)
+               dat_r = Signal(self.width)
                if write_capable:
                        if we_granularity:
-                               we = Signal(BV(self.width//we_granularity))
+                               we = Signal(self.width//we_granularity)
                        else:
                                we = Signal()
-                       dat_w = Signal(BV(self.width))
+                       dat_w = Signal(self.width)
                else:
                        we = None
                        dat_w = None
index 925e278f6ce9b7c5546cd46f35008bf170115ae2..186dd8e4a3f7130a66b13e2485eb17f12e18f634 100644 (file)
@@ -104,43 +104,77 @@ def insert_reset(rst, sl):
        resetcode = [t.eq(t.reset) for t in sorted(targets, key=lambda x: x.huid)]
        return If(rst, *resetcode).Else(*sl)
 
-def value_bv(v):
+def value_bits_sign(v):
        if isinstance(v, bool):
-               return BV(1, False)
+               return 1, False
        elif isinstance(v, int):
-               return BV(bits_for(v), v < 0)
+               return bits_for(v), v < 0
        elif isinstance(v, Signal):
-               return v.bv
+               return v.nbits, v.signed
        elif isinstance(v, _Operator):
-               obv = list(map(value_bv, v.operands))
+               obs = list(map(value_bits_sign, v.operands))
                if v.op == "+" or v.op == "-":
-                       return BV(max(obv[0].width, obv[1].width) + 1,
-                               obv[0].signed and obv[1].signed)
+                       if not obs[0][1] and not obs[1][1]:
+                               # both operands unsigned
+                               return max(obs[0][0], obs[1][0]) + 1, False
+                       elif obs[0][1] and obs[1][1]:
+                               # both operands signed
+                               return max(obs[0][0], obs[1][0]) + 1, True
+                       elif not obs[0][1] and obs[1][1]:
+                               # first operand unsigned (add sign bit), second operand signed
+                               return max(obs[0][0] + 1, obs[1][0]) + 1, True
+                       else:
+                               # first signed, second operand unsigned (add sign bit)
+                               return max(obs[0][0], obs[1][0] + 1) + 1, True
                elif v.op == "*":
-                       signed = obv[0].signed and obv[1].signed
-                       if signed:
-                               return BV(obv[0].width + obv[1].width - 1, signed)
+                       if not obs[0][1] and not obs[1][1]:
+                               # both operands unsigned
+                               return obs[0][0] + obs[1][0]
+                       elif obs[0][1] and obs[1][1]:
+                               # both operands signed
+                               return obs[0][0] + obs[1][0] - 1
+                       else:
+                               # one operand signed, the other unsigned (add sign bit)
+                               return obs[0][0] + obs[1][0] + 1 - 1
+               elif v.op == "<<<":
+                       if obs[1][1]:
+                               extra = 2**(obs[1][0] - 1) - 1
                        else:
-                               return BV(obv[0].width + obv[1].width, signed)
-               elif v.op == "<<" or v.op == ">>":
-                       return obv[0].bv
+                               extra = 2**obs[1][0] - 1
+                       return obs[0][0] + extra, obs[0][1]
+               elif v.op == ">>>":
+                       if obs[1][1]:
+                               extra = 2**(obs[1][0] - 1)
+                       else:
+                               extra = 0
+                       return obs[0][0] + extra, obs[0][1]
                elif v.op == "&" or v.op == "^" or v.op == "|":
-                       return BV(max(obv[0].width, obv[1].width),
-                               obv[0].signed and obv[1].signed)
+                       if not obs[0][1] and not obs[1][1]:
+                               # both operands unsigned
+                               return max(obs[0][0], obs[1][0]), False
+                       elif obs[0][1] and obs[1][1]:
+                               # both operands signed
+                               return max(obs[0][0], obs[1][0]), True
+                       elif not obs[0][1] and obs[1][1]:
+                               # first operand unsigned (add sign bit), second operand signed
+                               return max(obs[0][0] + 1, obs[1][0]), True
+                       else:
+                               # first signed, second operand unsigned (add sign bit)
+                               return max(obs[0][0], obs[1][0] + 1), True
                elif v.op == "<" or v.op == "<=" or v.op == "==" or v.op == "!=" \
                  or v.op == ">" or v.op == ">=":
-                         return BV(1)
+                         return 1, False
                else:
                        raise TypeError
        elif isinstance(v, _Slice):
-               return BV(v.stop - v.start, value_bv(v.value).signed)
+               return v.stop - v.start, value_bits_sign(v.value)[1]
        elif isinstance(v, Cat):
-               return BV(sum(value_bv(sv).width for sv in v.l))
+               return sum(value_bits_sign(sv)[0] for sv in v.l), False
        elif isinstance(v, Replicate):
-               return BV(value_bv(v.v).width*v.n)
+               return (value_bits_sign(v.v)[0])*v.n, False
        elif isinstance(v, _ArrayProxy):
-               bvc = map(value_bv, v.choices)
-               return BV(max(bv.width for bv in bvc), any(bv.signed for bv in bvc))
+               bsc = map(value_bits_sign, v.choices)
+               return max(bs[0] for bs in bsc), any(bs[1] for bs in bsc)
        else:
                raise TypeError
 
@@ -160,7 +194,7 @@ class _ArrayLowerer(NodeTransformer):
                        return super().visit_Assign(node)
        
        def visit_ArrayProxy(self, node):
-               array_muxed = Signal(value_bv(node))
+               array_muxed = Signal(value_bits_sign(node))
                cases = dict((n, _Assign(array_muxed, self.visit(choice)))
                        for n, choice in enumerate(node.choices))
                self.comb.append(Case(self.visit(node.key), cases).makedefault())
index f9e03ff1426f9907213fa8f1c8ea0f5d57481371..b334762933c5ff121704a0f41a11430a2200ba5f 100644 (file)
@@ -8,7 +8,7 @@ from migen.fhdl.namer import Namespace, build_namespace
 from migen.fhdl import verilog_mem_behavioral
 
 def _printsig(ns, s):
-       if s.bv.signed:
+       if s.signed:
                n = "signed "
        else:
                n = ""
index ac96e68003810743ee2dd463d9378fc64951828a..4fa6acaa6904ed2e7ec6161fc29659ebd6f7d9eb 100644 (file)
@@ -112,7 +112,7 @@ class SequentialActor(BinaryActor):
 
        def get_binary_control_fragment(self, stb_i, ack_o, stb_o, ack_i):
                ready = Signal()
-               timer = Signal(BV(bits_for(self.delay)))
+               timer = Signal(bits_for(self.delay))
                comb = [ready.eq(timer == 0)]
                sync = [
                        If(self.trigger,
@@ -143,7 +143,7 @@ class PipelinedActor(BinaryActor):
                super().__init__(*endpoint_descriptions, **misc)
 
        def get_binary_control_fragment(self, stb_i, ack_o, stb_o, ack_i):
-               valid = Signal(BV(self.latency))
+               valid = Signal(self.latency)
                if self.latency > 1:
                        sync = [If(self.pipe_ce, valid.eq(Cat(stb_i, valid[:self.latency-1])))]
                else:
index 02339d498bec261ab000724e54c33f3e78137b13..611d62d4e0c9749ee09338ee3eb8fc71a545d680 100644 (file)
@@ -23,8 +23,8 @@ class EndpointReporter:
        def get_fragment(self):
                stb = Signal()
                ack = Signal()
-               ack_count = Signal(BV(self.nbits))
-               nack_count = Signal(BV(self.nbits))
+               ack_count = Signal(self.nbits)
+               nack_count = Signal(self.nbits)
                comb = [
                        self._cur_stb.w.eq(stb),
                        self._cur_ack.w.eq(ack)
index 8a6de4d459b3455adffaf529ec4bf98ef2dec11b..699b6fb8637a684a9c44167f8bb65ab922de39be 100644 (file)
@@ -51,7 +51,7 @@ class Splitter(Actor):
                sources = [self.endpoints[e] for e in self.sources()]
                sink = self.endpoints[self.sinks()[0]]
                
-               already_acked = Signal(BV(len(sources)))
+               already_acked = Signal(len(sources))
                sync = [
                        If(sink.stb,
                                already_acked.eq(already_acked | Cat(*[s.ack for s in sources])),
index f54323d560754929fcb1bc41a90aefd6a2b5d58b..0f577fd38d15e6bf24e45da34eceb9f92ed57dc9 100644 (file)
@@ -26,7 +26,7 @@ class LowerAbstractLoad(fhdl.NodeTransformer):
 class ImplRegister:
        def __init__(self, name, nbits):
                self.name = name
-               self.storage = Signal(BV(nbits), name=self.name)
+               self.storage = Signal(nbits, name=self.name)
                self.source_encoding = {}
                self.id_to_source = {}
                self.finalized = False
@@ -40,7 +40,7 @@ class ImplRegister:
        def finalize(self):
                if self.finalized:
                        raise FinalizeError
-               self.sel = Signal(BV(bits_for(len(self.source_encoding) + 1)), name="pl_regsel_"+self.name)
+               self.sel = Signal(max=len(self.source_encoding)+2, name="pl_regsel_"+self.name)
                self.finalized = True
        
        def get_fragment(self):
index 373740eeea86a69da600db1b25438e6d970e0869..2d69a8fedc757fdd985eb21933b10438ca65983c 100644 (file)
@@ -122,7 +122,7 @@ class Simulator:
                        signed = False
                        nbits = item.width
                else:
-                       signed = item.bv.signed
+                       signed = item.signed
                        nbits = len(item)
                value = reply.value & (2**nbits - 1)
                if signed and (value & 2**(nbits - 1)):