[pypy-commit] pypy default: Update the comment from CPython's 101bf827611a.

arigo noreply at buildbot.pypy.org
Sun Oct 6 08:44:51 CEST 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r67160:0bb221958198
Date: 2013-10-06 08:44 +0200
http://bitbucket.org/pypy/pypy/changeset/0bb221958198/

Log:	Update the comment from CPython's 101bf827611a.

diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py
--- a/rpython/rlib/rbigint.py
+++ b/rpython/rlib/rbigint.py
@@ -731,11 +731,15 @@
             if c.numdigits() == 1 and c._digits[0] == ONEDIGIT:
                 return NULLRBIGINT
 
-            # if base < 0:
-            #     base = base % modulus
-            # Having the base positive just makes things easier.
-            # As a (very good) optimization, we also reduce 'base' here
-            # if it is much bigger than the modulus.
+            # Reduce base by modulus in some cases:
+            # 1. If base < 0.  Forcing the base non-neg makes things easier.
+            # 2. If base is obviously larger than the modulus.  The "small
+            #    exponent" case later can multiply directly by base repeatedly,
+            #    while the "large exponent" case multiplies directly by base 31
+            #    times.  It can be unboundedly faster to multiply by
+            #    base % modulus instead.
+            # We could _always_ do this reduction, but mod() isn't cheap,
+            # so we only do it when it buys something.
             if a.sign < 0 or a.numdigits() > c.numdigits():
                 a = a.mod(c)
 


More information about the pypy-commit mailing list