Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it really efficient to use Karatsuba algorithm in 64-bit x 64-bit multiplication?

I work on AVX2 and need to calculate 64-bit x64-bit -> 128-bit widening multiplication and got 64-bit high part in the fastest manner. Since AVX2 has not such an instruction, is it reasonable for me to use Karatsuba algorithm for efficiency and gaining speed?

like image 968
Yigit Demirag Avatar asked Jun 26 '15 09:06

Yigit Demirag


People also ask

How much faster is Karatsuba multiplication?

single-digit products. For example, the traditional algorithm requires (210)2 = 1,048,576 single-digit multiplications to multiply two 1024-digit numbers (n = 1024 = 210), whereas the Karatsuba algorithm requires 310 = 59,049 thus being ~17.758 times faster.

Why Karatsuba algorithm is used?

In Karatsuba algorithm, 2-digit multiplication operation can be performed with three multiplications (Dwivedi, 2013). Karatsuba algorithm is used by Intel and other companies to perform faster multiplication, because it requires less number of steps (Madke and Zafar, 2014).

What is the time complexity of Karatsuba algorithm?

The traditional Karatsuba algorithm for the multiplication of polynomials and multi-precision integers has a time complexity of O(n^{1.59}) and a space complexity of O(n).

What is the fastest time complexity to multiply two numbers of n length each using Karatsuba algorithm?

This algorithm takes O(n^2) time.


1 Answers

No. On modern architectures the crossover at which Karatsuba beats schoolbook multiplication is usually somewhere between 8 and 24 machine words (e.g. between 512 and 1536 bits on x86_64). For fixed sizes, the threshold is at the smaller end of that range, and the new ADCX/ADOX instructions likely bring it in somewhat further for scalar code, but 64x64 is still too small to benefit from Karatsuba.

like image 157
Stephen Canon Avatar answered Nov 15 '22 12:11

Stephen Canon