Ciao,
Il Ven, 12 Giugno 2015 9:04 am, Torbjörn Granlund ha scritto:
We might want to look into the plain division-free sqrt(A) = A*sqrt(1/A)
approach before implementing a tricky division sqrt(A).
We can try improving the current implementation, before implementing any
other algorithm :-)
I wrote a simple patch (it touches very few lines) that allows skipping
the final squaring when mpn_sqrtrem is called with a NULL argument and the
approximation computed so far can not change.
It exploits the spurious half-a-limb that current code adds to the result
when the size is odd, i.e. it changes the timings only for odd sizes.
Before the patch:
$ tune/speed -rp1 -s21-110 -f15 mpn_sqrt mpn_root.2
mpn_rootrem.2 mpn_sqrtrem
overhead 0.2 secs, precision 1 units of 2.86e-10 secs, CPU
freq 3500.08 MHz
mpn_sqrtmpn_root.2 mpn_rootrem.2 mpn_sqrtrem
210.013801.61551.5569 #0.9996
315 #0.153741.12221.54261.1521
4725 0.000918521 #0.90001.24581.0004
70875 0.029574741 #0.96121.21921.0007
10631250.741147157 #0.97181.21470.
Sometimes mpn_root.2 is faster than the other functios in a wide range
With the patch applied:
$ tune/speed.nsqrt -rp1 -s21-110 -f15 mpn_sqrt mpn_root.2
mpn_rootrem.2 mpn_sqrtrem
overhead 0.2 secs, precision 1 units of 2.86e-10 secs, CPU
freq 3500.08 MHz
mpn_sqrtmpn_root.2 mpn_rootrem.2 mpn_sqrtrem
21 #0.013391.64961.60891.0244
315 #0.129241.33181.84321.3701
4725 #0.0007996071.03491.43121.1495
70875#0.0263216531.08041.36981.1253
1063125 #0.6563897051.09821.37361.1296
mpn_rot.2 is the faster
--
http://bodrato.it/
___
gmp-devel mailing list
gmp-devel@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-devel