hdl.ast: avoid unnecessary sign padding in ArrayProxy.
Before this commit, ArrayProxy would add sign padding (an extra bit) a homogeneous array of signed values, or an array where all unsigned values are smaller than the largest signed one. After this commit, ArrayProxy would only add padding in arrays with mixed signedness where all signed values are smaller or equal in size to the largest unsigned value. Fixes #476. Co-authored-by: Pepijn de Vos <pepijndevos@gmail.com>
This commit is contained in:
parent
cb81618c28
commit
00026c6e4a
2 changed files with 43 additions and 5 deletions
|
|
@ -806,7 +806,29 @@ class ArrayProxyTestCase(FHDLTestCase):
|
|||
s = Signal(range(len(a)))
|
||||
v = a[s]
|
||||
self.assertEqual(v.p.shape(), unsigned(4))
|
||||
self.assertEqual(v.n.shape(), signed(6))
|
||||
self.assertEqual(v.n.shape(), signed(5))
|
||||
|
||||
def test_attr_shape_signed(self):
|
||||
# [unsigned(1), unsigned(1)] → unsigned(1)
|
||||
a1 = Array([1, 1])
|
||||
v1 = a1[Const(0)]
|
||||
self.assertEqual(v1.shape(), unsigned(1))
|
||||
# [signed(1), signed(1)] → signed(1)
|
||||
a2 = Array([-1, -1])
|
||||
v2 = a2[Const(0)]
|
||||
self.assertEqual(v2.shape(), signed(1))
|
||||
# [unsigned(1), signed(2)] → signed(2)
|
||||
a3 = Array([1, -2])
|
||||
v3 = a3[Const(0)]
|
||||
self.assertEqual(v3.shape(), signed(2))
|
||||
# [unsigned(1), signed(1)] → signed(2); 1st operand padded with sign bit!
|
||||
a4 = Array([1, -1])
|
||||
v4 = a4[Const(0)]
|
||||
self.assertEqual(v4.shape(), signed(2))
|
||||
# [unsigned(2), signed(1)] → signed(3); 1st operand padded with sign bit!
|
||||
a5 = Array([1, -1])
|
||||
v5 = a5[Const(0)]
|
||||
self.assertEqual(v5.shape(), signed(2))
|
||||
|
||||
def test_repr(self):
|
||||
a = Array([1, 2, 3])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue