Skip to content

Commit

Permalink
Support negative values in ConcatSignal contributors
Browse files Browse the repository at this point in the history
  • Loading branch information
jandecaluwe committed Oct 10, 2015
1 parent bd0cfba commit 385e82d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
10 changes: 7 additions & 3 deletions myhdl/_ShadowSignal.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file is part of the myhdl library, a Python package for using
# Python as a Hardware Description Language.
#
# Copyright (C) 2003-2011 Jan Decaluwe
# Copyright (C) 2003-2015 Jan Decaluwe
#
# The myhdl library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License as
Expand Down Expand Up @@ -172,8 +172,12 @@ def genfunc(self):
else:
w = len(a)
lo = hi - w
if a in sigargs:
newval[hi:lo] = a
# note: 'a in sigargs' is equivalence check, not identity
if isinstance(a, _Signal):
if isinstance(a._val, intbv):
newval[hi:lo] = a[w:]
else:
newval[hi:lo] = a
hi = lo
set_next(self, newval)
yield sigargs
Expand Down
35 changes: 35 additions & 0 deletions myhdl/test/core/test_ShadowSignal.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,41 @@ def check():
def test_ConcatSignalWithConsts():
Simulation(bench_ConcatSignalWithConsts()).run()

def bench_ConcatSignalWithNegs():

Am = 2**(5-1)
Cm = 2**(3-1)
Dm = 2**(4-1)

a = Signal(intbv(-1, min=-Am, max=Am))
b = Signal(bool(0))
c = Signal(intbv(-1, min=-Cm, max=Cm))
d = Signal(intbv(-1, min=-Dm, max=Dm))

s = ConcatSignal(a, b, c, d)

@instance
def check():
for i in range(-Am, Am):
for j in (0, 1):
for k in range(-Cm, Cm):
for m in range(-Dm, Dm):
a.next = i
b.next = j
c.next = k
d.next = m
yield delay(10)

assert s[13:8] == a[len(a):]
assert s[7] == b
assert s[7:4] == c[len(c):]
assert s[4:] == d[len(d):]

return check

def test_ConcatSignalWithNegs():
Simulation(bench_ConcatSignalWithNegs()).run()


def bench_TristateSignal():
s = TristateSignal(intbv(0)[8:])
Expand Down

0 comments on commit 385e82d

Please sign in to comment.