From a56985dfb4fb3197700417f480fd214aa7d1e84e Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Fri, 19 Jun 2020 22:16:55 +0100 Subject: [PATCH] move trunc_div and trunc_rem to nmutil --- src/soc/decoder/helpers.py | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) 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 """ -- 2.30.2