From 30d70888160a45ec0562b3610d35d06145447102 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Mon, 6 Jul 2020 19:44:58 +0100 Subject: [PATCH] SelectableInt: make __mul__ return enough space to fit the result --- src/soc/decoder/selectable_int.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/soc/decoder/selectable_int.py b/src/soc/decoder/selectable_int.py index 0c5e560c..3036b6f6 100644 --- a/src/soc/decoder/selectable_int.py +++ b/src/soc/decoder/selectable_int.py @@ -178,7 +178,12 @@ class SelectableInt: def __sub__(self, b): return self._op(sub, b) def __mul__(self, b): - return self._op(mul, b) + # different case: mul result needs to fit the total bitsize + if isinstance(b, int): + b = SelectableInt(b, self.bits) + print ("SelectableInt mul", hex(self.value), hex(b.value), + self.bits, b.bits) + return SelectableInt(self.value * b.value, self.bits + b.bits) def __floordiv__(self, b): return self._op(floordiv, b) def __truediv__(self, b): -- 2.30.2