[Python-Dev] Memory size overflows

Gerald S. Williams gsw@agere.com
2002年10月21日 18:09:29 -0400


Tim Peters wrote:
> Python assumes 2's comp in several places already.

Yeah, I just noticed that.
> I thought you were going to time this <wink>?

I am.
If you assume that, for the vast majority of multiplications, both
multiplicands are in the range -sqrt(sys.maxint):sqrt(sys.maxint),
the following gives a 15% performance improvement for me:
 unsigned long sa = (a < 0L);
 unsigned long sb = (b < 0L);
 unsigned long ua = sa ? -a : a;
 unsigned long ub = sb ? -b : b;
 if ((ua | ub) & OVERFLOW_POSSIBLE_MASK)
 {
 <CURRENT IMPLEMENTATION, AS IS>
 }
If both numbers are evenly distributed from -sys.maxint:sys.maxint,
this yields about a 3% slowdown, though. These numbers are just for
the core multiply path, since I pulled it out in order to compare
algorithms better.
I'm looking into improving the rest, but it's difficult.
-Jerry

AltStyle によって変換されたページ (->オリジナル) /