From: Luke Kenneth Casson Leighton Date: Mon, 6 Jul 2020 19:19:58 +0000 (+0100) Subject: add MULS (signed) version of multiply X-Git-Tag: div_pipeline~162^2~24 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a1fc933c3dd4581f2994b6e720fad332a4b56b68;p=soc.git add MULS (signed) version of multiply --- 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):