From a1fc933c3dd4581f2994b6e720fad332a4b56b68 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Mon, 6 Jul 2020 20:19:58 +0100 Subject: [PATCH] add MULS (signed) version of multiply --- src/soc/decoder/helpers.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/soc/decoder/helpers.py b/src/soc/decoder/helpers.py index 53edaca2..8cab8d50 100644 --- a/src/soc/decoder/helpers.py +++ b/src/soc/decoder/helpers.py @@ -27,6 +27,17 @@ def EXTS64(value): return SelectableInt(exts(value.value, value.bits) & ((1 << 64)-1), 64) +# signed version of MUL +def MULS(a, b): + a_s = a.value & (1<<(a.bits-1)) != 0 + b_s = b.value & (1<<(b.bits-1)) != 0 + result = abs(a) * abs(b) + print ("MULS", result, a_s, b_s) + if a_s == b_s: + return result + return -result + + # XXX should this explicitly extend from 32 to 64? def EXTZ64(value): if isinstance(value, SelectableInt): -- 2.30.2