[myhdl-list] myhdl.concat
Brought to you by:
jandecaluwe
From: Thomas H. <th...@ct...> - 2014-08-09 08:17:38
|
I expected myhdl.concat to return a bit-wise concatenation of the arguments. However, when I use concat(unsigned, signed) this is not the case. The following program prints '7FFFFFFD' instead of '8FFFFFFD': <code> #!/usr/bin/python2.7-32 # -*- coding: utf-8 -*- import myhdl def unsigned(width, value=0, cls=myhdl.intbv): """Create an unsigned signal based on a bitvector with the specified width and initial value. """ return myhdl.Signal(cls(value, 0, 2**width)) def signed(width, value=0, cls=myhdl.intbv): """Create an signed signal based on a bitvector with the specified width and initial value. """ return myhdl.Signal(cls(value, -2**(width-1), 2**(width-1))) a = unsigned(4, 8) b = signed(28, -3) print "%08X" % myhdl.concat(a, b) </code> Is this correct? Changing (in myhdl 0.8, module _concat.py) this line gives the result that I expected: --- _concat.py~ Mon Aug 4 12:20:26 2014 +++ _concat.py Sat Aug 9 10:15:05 2014 @@ -65,7 +65,7 @@ if not w: raise TypeError, "concat: arg on pos %d should have length" % (i+1) width += w - val = val*(2**w) + v + val = val*(2**w) | (v % 2**len(v)) if basewidth: return intbv(val, _nrbits=basewidth + width) Thomas |