[Python-Dev] Optionally using GMP to implement long if available

Gregory P. Smith greg at krypto.org
Mon Nov 3 23:26:21 CET 2008

On Mon, Nov 3, 2008 at 12:41 PM, Victor Stinner
<victor.stinner at haypocalc.com> wrote:
> Hi,
> Le Monday 03 November 2008 18:56:37 Paul Miller, vous avez écrit :
>> I've read some of the past discussion about including GMP into the
>> python core and understand the reasons for not doing so.
> Please, check this issue: http://bugs.python.org/issue1814
> I patched Python3 to use GMP because I thaugh that GMP is much faster than
> Python for integer computation. The "problem" is that GMP target are integers
> much bigger than 10**100. As I remember, GMP has a special hack for very
> small integer: integer which can be stored in one CPU word, but it's not
> enough to speed up Python.
> With my last patch, with GMP, Python is 2% *slower*.
> My patch can be improved, but I expected +20% to +100% to no -2% :-/

One optimization that could be done to the existing Python longobject
code is to allow it to use larger digits.  Currently it is hardcoded
to use 15bit digits.

The most common desktop+server CPUs in the world (x86) all support
efficient 32bit*32bit -> 64bit multiply so there is no good reason to
limit python itself to 15bit digits when on either x86 or x86_64.  30
or 31bit digits would be more efficient as more numbers would then be
a single digit shortcutting their computations and the number of
digits for others would be half.

The ability to use 15bit digits is good for other cpus but is wasteful
when the hardware supports more (32bit x86 and all 64bit archs).

> And there is also the license issue...
> --
> Victor Stinner aka haypo
> http://www.haypocalc.com/blog/
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/greg%40krypto.org

More information about the Python-Dev mailing list