From: Jacob Lifshay Date: Wed, 7 Oct 2020 02:33:07 +0000 (-0700) Subject: format code X-Git-Tag: 24jan2021_ls180~12 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b639fbc22a90e68360482f49c9a779a8be109a86;p=nmutil.git format code --- diff --git a/src/nmutil/divmod.py b/src/nmutil/divmod.py index f827d53..af5d214 100644 --- a/src/nmutil/divmod.py +++ b/src/nmutil/divmod.py @@ -1,6 +1,8 @@ from copy import copy # this is a POWER ISA 3.0B compatible *signed* div function # however it is also the c, c++, rust, java *and* x86 way of doing things + + def trunc_divs(n, d): abs_n = abs(n.to_signed_int()) abs_d = abs(d.to_signed_int()) @@ -9,9 +11,9 @@ def trunc_divs(n, d): abs_q = abs_n // abs_d sign_n = n.value & (1 << (n.bits - 1)) != 0 sign_d = d.value & (1 << (d.bits - 1)) != 0 - print ("trunc_div", hex(n.value), hex(d.value), - hex(abs_n), hex(abs_d), hex(abs_q), - sign_n, sign_d) + print("trunc_div", hex(n.value), hex(d.value), + hex(abs_n), hex(abs_d), hex(abs_q), + sign_n, sign_d) res = copy(n) if (sign_n == sign_d): res.value = abs_q @@ -26,7 +28,7 @@ def trunc_divs(n, d): # however it is also the c, c++, rust, java *and* x86 way of doing things def trunc_rems(n, d): m = d * trunc_divs(n, d) - m.bits = n.bits # cheat - really shouldn't do this. mul returns full length - return n - m - + # cheat - really shouldn't do this. mul returns full length + m.bits = n.bits + return n - m