usage of mpz_mul function for squaring
Gašper Močnik
mocnik.gasper2 at gmail.com
Mon Nov 29 18:50:49 UTC 2021
Hello,
I have a question regarding mpz_t integer multiplication and squaring.
While reading the GNU Manual 15.1 Multiplication section I noticed that
described algorithms use different procedure when squaring a N limb operand
compared to multiplying two different N limb operands.
My question is: Does the mpz_mul function detect when you want to square a
number i.e. you input the same mpz_t variable for both the op1 and op2 or
is there a separate function you need to call for squaring to achieve
faster calculation?
The other question I have is about the speed of squaring a N limb operand
compared to multiplying two different N limb operands. In the Basecase
Multiplication section of Manual it is stated that squaring is about 1.5x
faster than multiplying. I'm assuming squaring is also faster than
multiplication when other algorithms are used (Karatsuba, Toom, FFT, ...)
since they rely on basecase multiplication and also use a different
calculation procedure for squaring. Is my assumption correct?
Thanks for the answer and kind regards,
Gasper Mocnik
More information about the gmp-discuss
mailing list