Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/nmigen
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e58d9ec74d1b
Choose a base ref
...
head repository: m-labs/nmigen
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 48d13e47ec08
Choose a head ref
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on Dec 21, 2018

  1. hdl.mem: use different naming for array signals.

    It looks like [] is confusing gtkwave somehow.
    whitequark committed Dec 21, 2018
    Copy the full SHA
    af7db88 View commit details
  2. Copy the full SHA
    7ae7683 View commit details
  3. back.pysim: handle out of bounds ArrayProxy indexes.

    whitequark committed Dec 21, 2018
    Copy the full SHA
    48d13e4 View commit details
Showing with 31 additions and 5 deletions.
  1. +15 −4 nmigen/back/pysim.py
  2. +1 −1 nmigen/hdl/mem.py
  3. +15 −0 nmigen/test/test_sim.py
19 changes: 15 additions & 4 deletions nmigen/back/pysim.py
Original file line number Diff line number Diff line change
@@ -193,7 +193,12 @@ def on_ArrayProxy(self, value):
shape = value.shape()
elems = list(map(self, value.elems))
index = self(value.index)
return lambda state: normalize(elems[index(state)](state), shape)
def eval(state):
index_value = index(state)
if index_value >= len(elems):
index_value = len(elems) - 1
return normalize(elems[index_value](state), shape)
return eval


class _LHSValueCompiler(AbstractValueTransformer):
@@ -263,7 +268,10 @@ def on_ArrayProxy(self, value):
elems = list(map(self, value.elems))
index = self.rhs_compiler(value.index)
def eval(state, rhs):
elems[index(state)](state, rhs)
index_value = index(state)
if index_value >= len(elems):
index_value = len(elems) - 1
elems[index_value](state, rhs)
return eval


@@ -417,8 +425,11 @@ def __enter__(self):
hierarchy = {}
def add_fragment(fragment, scope=()):
hierarchy[fragment] = scope
for subfragment, name in fragment.subfragments:
add_fragment(subfragment, (*scope, name))
for index, (subfragment, name) in enumerate(fragment.subfragments):
if name is None:
add_fragment(subfragment, (*scope, "#{}".format(index)))
else:
add_fragment(subfragment, (*scope, name))
add_fragment(root_fragment)

def add_signal(signal):
2 changes: 1 addition & 1 deletion nmigen/hdl/mem.py
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ def __init__(self, width, depth, init=None, name=None):
# Array of signals for simulation.
self._array = Array()
for addr, data in enumerate(self.init + [0 for _ in range(self.depth - len(self.init))]):
self._array.append(Signal(self.width, reset=data, name="{}[{}]".format(name, addr)))
self._array.append(Signal(self.width, reset=data, name="{}({})".format(name, addr)))

def read_port(self, domain="sync", synchronous=True, transparent=True):
if not synchronous and not transparent:
15 changes: 15 additions & 0 deletions nmigen/test/test_sim.py
Original file line number Diff line number Diff line change
@@ -184,6 +184,12 @@ def test_array(self):
self.assertStatement(stmt, [C(1)], C(4))
self.assertStatement(stmt, [C(2)], C(10))

def test_array_oob(self):
array = Array([1, 4, 10])
stmt = lambda y, a: y.eq(array[a])
self.assertStatement(stmt, [C(3)], C(10))
self.assertStatement(stmt, [C(4)], C(10))

def test_array_lhs(self):
l = Signal(3, reset=1)
m = Signal(3, reset=4)
@@ -194,6 +200,15 @@ def test_array_lhs(self):
self.assertStatement(stmt, [C(1), C(0b010)], C(0b111010001))
self.assertStatement(stmt, [C(2), C(0b100)], C(0b100100001))

def test_array_lhs_oob(self):
l = Signal(3)
m = Signal(3)
n = Signal(3)
array = Array([l, m, n])
stmt = lambda y, a, b: [array[a].eq(b), y.eq(Cat(*array))]
self.assertStatement(stmt, [C(3), C(0b001)], C(0b001000000))
self.assertStatement(stmt, [C(4), C(0b010)], C(0b010000000))

def test_array_index(self):
array = Array(Array(x * y for y in range(10)) for x in range(10))
stmt = lambda y, a, b: y.eq(array[a][b])