Message215690
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. |
|
Date |
User |
Action |
Args |
2014-04-07 10:45:27 | h.venev | set | recipients:
+ h.venev, gvanrossum, tim.peters, mark.dickinson, vstinner, christian.heimes |
2014-04-07 10:45:27 | h.venev | set | messageid: <1396867527.68.0.161435634848.issue1814@psf.upfronthosting.co.za> |
2014-04-07 10:45:27 | h.venev | link | issue1814 messages |
2014-04-07 10:45:26 | h.venev | create | |
|