hdl.ast: fix shape calculation for *.
This was carried over from Migen, and is wrong there too. Counterexample: 1'sd-1 * 4'sd-4 = 4'sd-4 (but should be 5'sd4).
This commit is contained in:
parent
7b25665fde
commit
f71e0fffbb
|
@ -333,14 +333,7 @@ class Operator(Value):
|
|||
bits, sign = self._bitwise_binary_shape(*op_shapes)
|
||||
return bits + 1, sign
|
||||
if self.op == "*":
|
||||
if not a_sign and not b_sign:
|
||||
# both operands unsigned
|
||||
return a_bits + b_bits, False
|
||||
if a_sign and b_sign:
|
||||
# both operands signed
|
||||
return a_bits + b_bits - 1, True
|
||||
# one operand signed, the other unsigned (add sign bit)
|
||||
return a_bits + b_bits + 1 - 1, True
|
||||
return a_bits + b_bits, a_sign or b_sign
|
||||
if self.op == "%":
|
||||
return a_bits, a_sign
|
||||
if self.op in ("<", "<=", "==", "!=", ">", ">=", "b"):
|
||||
|
|
|
@ -137,7 +137,7 @@ class OperatorTestCase(FHDLTestCase):
|
|||
self.assertEqual(repr(v1), "(* (const 4'd0) (const 6'd0))")
|
||||
self.assertEqual(v1.shape(), (10, False))
|
||||
v2 = Const(0, (4, True)) * Const(0, (6, True))
|
||||
self.assertEqual(v2.shape(), (9, True))
|
||||
self.assertEqual(v2.shape(), (10, True))
|
||||
v3 = Const(0, (4, True)) * Const(0, (4, False))
|
||||
self.assertEqual(v3.shape(), (8, True))
|
||||
v5 = 10 * Const(0, 4)
|
||||
|
|
Loading…
Reference in a new issue