[Libre-soc-bugs] [Bug 324] create POWER9 DIV pipeline
bugzilla-daemon at libre-soc.org
bugzilla-daemon at libre-soc.org
Fri Jun 19 14:05:33 BST 2020
https://bugs.libre-soc.org/show_bug.cgi?id=324
--- Comment #13 from Jacob Lifshay <programmerjake at gmail.com> ---
The spec pseudo-code doesn't contain all the required information to implement
any of the div or mod operations since only the prose states the conditions for
overflow (which *DO* show up in the overflow flags when div*o is used).
Additionally, only the prose states if the division is to be interpreted as
signed or unsigned.
All divisions are truncating division, not floor division, so we should
translate them to function calls to custom trunc_div and trunc_rem functions
rather than python's // and % operators (since the mod* instructions implement
the mathematical remainder of truncating division operation rather than the
mathematical modulo operation).
Code not tested:
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
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)
--
You are receiving this mail because:
You are on the CC list for the bug.
More information about the libre-soc-bugs
mailing list