[Libre-soc-bugs] [Bug 324] create POWER9 DIV pipeline

bugzilla-daemon at libre-soc.org bugzilla-daemon at libre-soc.org
Fri Jun 19 15:51:13 BST 2020


--- Comment #24 from Jacob Lifshay <programmerjake at gmail.com> ---
(In reply to Luke Kenneth Casson Leighton from comment #23)
> (In reply to Jacob Lifshay from comment #21)
> > I was thinking SelectableInt and other custom classes would implement the
> > trunc_div and rtrunc_div member functions, which is the trunc_div version of
> > __sub__ and __rsub__. Similarly for trunc_rem and rtrunc_rem.
> the problem is that if we do that, SelectableInt behaves unpredictably.
> SelectableInt is designed not to be a "POWER9 compliant integer arithmetic"
> class, it's designed to be a direct one-to-one and onto map of the behaviour
> of the python *int* class - just one that happens to have a bitlength
> associated
> with it.
> thus we genuinely expect SelectableInt's floordiv and truncdiv behaviour to
> be exactly that of int, and consequently if in any code anywhere we need to
> perform a div (or mod), we expect it to actually work.

they behave the same as int even if the trunc_div and trunc_rem member
functions are overridden with a custom implementation that calculates the same

The member functions are designed to work for classes like Signal or other
special classes that are sufficiently unlike int that they needs to be manually

the trunc_div free function calls the member functions if they exist -- just
like abs(a) calls a.__abs__()

there's no reason trunc_div should or would match __floor_div__ -- they're
different operations.

I was thinking about implementing trunc_div as a monkey-patched member function
of int, but was not sure that was a good idea or if int can even be

> here's the thing: although you may not have been aware of it, trunc_div and
> trunc_rem are *behaving as expected* despite the fact that you wrote them
> assuming that they would take python ints as arguments!

that's mostly expected.

> and that's *exactly* why SelectableInt.__floordiv__ and
> SelectableInt.__truncdiv__
> should not implement POWER9 div behaviour :)

__floor_div__ is a flooring-division operator, of course it shouldn't be
truncating division, that's what trunc_div is for :)

You are receiving this mail because:
You are on the CC list for the bug.

More information about the libre-soc-bugs mailing list