[Python-Dev] 64 bit units in PyLong (original) (raw)
Mark Dickinson dickinsm at gmail.com
Wed Jul 5 15:05:06 EDT 2017
- Previous message (by thread): [Python-Dev] 64 bit units in PyLong
- Next message (by thread): [Python-Dev] 64 bit units in PyLong
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Mon, Jul 3, 2017 at 5:52 AM, Siyuan Ren <netheril96 at gmail.com> wrote:
The current PyLong implementation represents arbitrary precision integers in units of 15 or 30 bits. I presume the purpose is to avoid overflow in addition , subtraction and multiplication. But compilers these days offer intrinsics that allow one to access the overflow flag, and to obtain the result of 64 bit multiplication as a 128 bit number. Or at least on x86-64, which is the dominant platform. Any reason why it is not done?
Portability matters, so any use of these intrinsics would likely also have to be accompanied by fallback code that doesn't depend on them, as well as some buildsystem complexity to figure out whether those intrinsics are supported or not. And then the Objects/longobject.c would suffer in terms of simplicity and readability, so there would have to be some clear gains to offset that. Note that the typical Python workload does not involve thousand-digit integers: what would matter would be performance of smaller integers, and it seems conceivable that 64-bit limbs would speed up those operations simply because so many more integers would become single-limb and so there would be more opportunities to take fast paths, but there would need to be benchmarks demonstrating that.
Oh, and you'd have to rewrite the power algorithm, which currently depends on the size of a limb in bytes being a multiple of 5. :-)
-- Mark
- Previous message (by thread): [Python-Dev] 64 bit units in PyLong
- Next message (by thread): [Python-Dev] 64 bit units in PyLong
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]