This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author h.venev
Recipients christian.heimes, gvanrossum, h.venev, mark.dickinson, tim.peters, vstinner
Date 2014-04-07.10:45:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1396867527.68.0.161435634848.issue1814@psf.upfronthosting.co.za>
In-reply-to
Content
What about using PyVarObject of mp_limb_t and mpn instead of mpz_t? 

Addition:
   - Check signs and allocate.
   - Possibly compare absolute values.
   - Call mpn_(add|sub)_n and possibly mpn_(add|sub)_1 if the integers have different sizes.
   - Overhead for small integers: 1 Python->GMP, 1 if.

Subtraction:
   - Same as addition

Multiplication:
   - Check signs and allocate.
   - Call mpn_mul.
   - Overhead for small integers: 1 Python->GMP, 2 GMP->GMP, 3 if.

Division:
   - Check signs and allocate.
   - Call mpn_div_q.
   - Overhead for small integers: 1 Python->GMP, 1 GMP->GMP, 1 if, maybe a 3 more ifs in mpn_divrem_1.

Pow:
   - Create mpz_t values using MPZ_ROINIT_N(limbs, size) and call mpz_pow(m?). Copy from mpz_limbs_read(result).

* The overhead is after checking if both arguments are integers until going to the right function (mpn_mul -> mpn_mul_n -> mpn_mul_basecase).

Checks for adding integers < 1<<(GMP_NUMB_BITS-1), multiplying < 1<<(GMP_NUMB_BITS/2) and dividing < 1<<GMP_NUMB_BITS can be added.
History
Date User Action Args
2014-04-07 10:45:27h.venevsetrecipients: + h.venev, gvanrossum, tim.peters, mark.dickinson, vstinner, christian.heimes
2014-04-07 10:45:27h.venevsetmessageid: <1396867527.68.0.161435634848.issue1814@psf.upfronthosting.co.za>
2014-04-07 10:45:27h.venevlinkissue1814 messages
2014-04-07 10:45:26h.venevcreate