From: Luke Kenneth Casson Leighton Date: Fri, 19 Jun 2020 21:16:55 +0000 (+0100) Subject: move trunc_div and trunc_rem to nmutil X-Git-Tag: div_pipeline~306 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a56985dfb4fb3197700417f480fd214aa7d1e84e;p=soc.git move trunc_div and trunc_rem to nmutil --- diff --git a/src/soc/decoder/helpers.py b/src/soc/decoder/helpers.py index 6b61ffca..d920b920 100644 --- a/src/soc/decoder/helpers.py +++ b/src/soc/decoder/helpers.py @@ -1,5 +1,6 @@ import unittest from soc.decoder.selectable_int import SelectableInt +from nmutil.divmod import trunc_div, trunc_rem """ Links: @@ -11,33 +12,6 @@ def exts(value, bits): return (value & (sign - 1)) - (value & sign) -# this is a POWER ISA 3.0B compatible div function -def trunc_div(n, d): - f = getattr(n, "trunc_div", None) - if f is not None: - return f(d) - fr = getattr(d, "rtrunc_div", None) - if fr is not None: - return fr(n) - abs_n = abs(n) - abs_d = abs(d) - abs_q = n // d - if (n < 0) == (d < 0): - return abs_q - return -abs_q - - -# this is a POWER ISA 3.0B compatible mod / remainder function -def trunc_rem(n, d): - f = getattr(n, "trunc_rem", None) - if f is not None: - return f(d) - fr = getattr(d, "rtrunc_rem", None) - if fr is not None: - return fr(n) - return n - d * trunc_div(n, d) - - def EXTS(value): """ extends sign bit out from current MSB to all 256 bits """