mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
SF patch 936813: fast modular exponentiation
This checkin is adapted from part 1 (of 3) of Trevor Perrin's patch set. x_mul() - sped a little by optimizing the C - sped a lot (~2X) if it's doing a square; note that long_pow() squares often k_mul() - more cache-friendly now if it's doing a square KARATSUBA_CUTOFF - boosted; gradeschool mult is quicker now, and it may have been too low for many platforms anyway KARATSUBA_SQUARE_CUTOFF - new - since x_mul is a lot faster at squaring now, the point at which Karatsuba pays for squaring is much higher than for general mult
This commit is contained in:
parent
afb5f94217
commit
0973b99e1c
4 changed files with 91 additions and 22 deletions
|
@ -12,7 +12,7 @@ extern "C" {
|
|||
contains at least 16 bits, but it's made changeable anyway.
|
||||
Note: 'digit' should be able to hold 2*MASK+1, and 'twodigits'
|
||||
should be able to hold the intermediate results in 'mul'
|
||||
(at most MASK << SHIFT).
|
||||
(at most (BASE-1)*(2*BASE+1) == MASK*(2*MASK+3)).
|
||||
Also, x_sub assumes that 'digit' is an unsigned type, and overflow
|
||||
is handled by taking the result mod 2**N for some N > SHIFT.
|
||||
And, at some places it is assumed that MASK fits in an int, as well. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue