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

bugzilla-daemon at libre-soc.org bugzilla-daemon at libre-soc.org
Fri Jun 19 21:08:24 BST 2020


https://bugs.libre-soc.org/show_bug.cgi?id=324

--- Comment #28 from Jacob Lifshay <programmerjake at gmail.com> ---
(In reply to Luke Kenneth Casson Leighton from comment #27)
> (In reply to Jacob Lifshay from comment #26)
> 
> > The standalone functions tries to call the member functions if they exist,
> > this is to emulate python's behavior where a - b calls a.__sub__(b) or
> > b.__rsub__(a).
> > 
> > So, if I had a custom class:
> > 
> > class MyClass:
> >     def trunc_div(self, d):
> >         print("trunc_div:", self, "/", d)
> >         return 0
> >     def rtrunc_div(self, n):
> >         print("rtrunc_div:", n, "/", self)
> >         return 0
> >     def __repr__(self):
> >         return "MyClass"
> > 
> > trunc_div(MyClass(), 123)
> > trunc_div(MyClass(), MyClass())
> > trunc_div(456, MyClass())
> > 
> > outputs:
> > trunc_div: MyClass / 123
> > trunc_div: MyClass / MyClass
> > rtrunc_div: 456 / MyClass
> 
> only the functions in the operator module work this way.  the above is not
> how python works.  or, if it is, it's literally the first time i've heard
> about it in 20 years!

no, what I posted is exactly how python works, assuming the trunc_div function
which you copied to soc.git earlier today is in scope (apparently that wasn't
obvious):
https://git.libre-soc.org/?p=soc.git;a=blob;f=src/soc/decoder/helpers.py;h=ef6610e5c89d7d0e0316c216bf51faf8486f46df;hb=HEAD#l13


result from python repl:

...
>>> trunc_div(MyClass(), 123)
trunc_div: MyClass / 123
0
>>> trunc_div(MyClass(), MyClass())
trunc_div: MyClass / MyClass
0
>>> trunc_div(456, MyClass())
rtrunc_div: 456 / MyClass
0
>>>

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


More information about the libre-soc-bugs mailing list