* sqrt performance
@ 1999-03-03 2:26 esci
1999-03-03 9:27 ` Andrei A. Dergatchev
0 siblings, 1 reply; 9+ messages in thread
From: esci @ 1999-03-03 2:26 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 6314 bytes --]
The following uuencoded compressed tar file contains several
variations on coding the double square root equation from
reflection seismology. The times are rather counterintuitive.
The run_"n" files contain data which may be plotted w/ the gnuplot
script, "plt" enclosed.
All examples were run using DU 4.0E and the software development
tools from the most recent ASAP SDK.
In particular, the Digipaq Extended Math Library vsqrt() has
the poorest performance of all. (run_2 & run_5 using sub2.f
and sub5.f respectively)
Interestingly, the straight forward loop unrolled twice w/
explicit temporaries matches the 25 cycles per result given
by Cray in "The Benchmarker's Guide to Single-processor
Optimization for CRAY T3E Systems" for the Cray vector libm
routines.
I am unable to assemble either of the sqrt routines posted
by Kazushige Goto <goto@statabo.rim.or.jp>. Some pathetic
attempts on my part to modify the code for the DU assembler
succeeded in producing a .o file w/o any error messages, but
a simple "nm -og sqrt.o" causes nm(1) to dump core. I have
a Linux box waiting to be assembled, but am trying to get some
programming done first.
Reducing the cycle count per result by even a little bit would
be of great value to me. The 12 cycles quoted by Goto for his
code would be staggering. Using Linux would be even better :-)
Reginald Beardsley
------------------------------------------------------------------------
Exploration Software Consultants Inc.
Voice: 972-379-0557 email: rhb@acm.org
Fax: 972-379-0558
------------------------------------------------------------------------
begin 644 tst.tar.gz
M'XL("#&7W#8``W1S="YT87(`[9UM<]NX$8#[]?0KT#0SD11'QCO`FW-G;JZ7
M?FF;F6NG7V](6]8ID257HG/VO^^"!"A*%I9V8MG'###CE0PL`1`M?FF;F6NG7V](6]8ID257HG/VO^^"!"A*%I9V8MG'###CE0PL`1`OSRX@4/IG
M_FEZ.5],_W3$0"G54A+W*IBH7BDS]:M["X%0K;6!-XII0AE71D'Z,2L5PLVF
MS-=0E?5O18?>=+U!TJM;@4ISPQG4GSQI)8\7WK__QX]__S<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NU8;=GZET99"BFD
MD$(*CPCI_%\Z_T=ZNO^3SO]]?4CG_]+YO[[._W3^+YW_2^'K0CK_E\[_]97_
DZ?Q?.O^7PM>%=/XOG?\C/>)_.O^7SO^E\'3A_VMYG/<`H```
`
end
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: sqrt performance
1999-03-03 2:26 sqrt performance esci
@ 1999-03-03 9:27 ` Andrei A. Dergatchev
1999-03-03 11:59 ` Kazushige Goto
0 siblings, 1 reply; 9+ messages in thread
From: Andrei A. Dergatchev @ 1999-03-03 9:27 UTC (permalink / raw)
Hi,
> [snip]
> I am unable to assemble either of the sqrt routines posted
> by Kazushige Goto <goto@statabo.rim.or.jp>. Some pathetic
> attempts on my part to modify the code for the DU assembler
Just curious, is DU assembler so substantially different from
Alpha-Linux one ?? I downloaded DU4.0 "Assembly Language
Programmer's Guide" and thought that it's the same with gas
for my Alpha :-( Or maybe it is just nm (linker) problems -
something with offsets etc ? And what about posted C program -
do you have C compiler to test it ? I'm not by any mean ANSI C
expert but at a first glance I can't believe any ANSI C compatable
compiler will have any problems with it.
BTW, thanks for your code.
> [snip]
Regards,
Andrei
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: sqrt performance
1999-03-03 9:27 ` Andrei A. Dergatchev
@ 1999-03-03 11:59 ` Kazushige Goto
0 siblings, 0 replies; 9+ messages in thread
From: Kazushige Goto @ 1999-03-03 11:59 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1100 bytes --]
Hi,
From: "Andrei A. Dergatchev" <A.Dergatchev@tn.utwente.nl>
Subject: Re: sqrt performance
A.Dergatchev> Just curious, is DU assembler so substantially different from
A.Dergatchev> Alpha-Linux one ?? I downloaded DU4.0 "Assembly Language
It's a just bit different the handling of read only area.
I atached patch, it may work fine on DU.
Thanks,
goto@statabo.rim.or.jp
diff -ru sqrt-test.old/sqrt.S sqrt-test/sqrt.S
--- sqrt-test.old/sqrt.S Tue Feb 23 17:06:38 1999
+++ sqrt-test/sqrt.S Wed Mar 3 20:55:31 1999
@@ -37,7 +37,11 @@
.set noat
.set noreorder
-.section .rodata
+#ifdef __ELF__
+ .section .rodata
+#else
+ .rdata
+#endif
.align 5
$table:
diff -ru sqrt-test.old/sqrtv.S sqrt-test/sqrtv.S
--- sqrt-test.old/sqrtv.S Tue Oct 6 13:36:04 1998
+++ sqrt-test/sqrtv.S Wed Mar 3 20:55:32 1999
@@ -43,7 +43,11 @@
.set noat
.set noreorder
-.section .rodata
+#ifdef __ELF__
+ .section .rodata
+#else
+ .rdata
+#endif
.align 5
table:
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: sqrt performance
@ 1999-03-03 13:21 esci
1999-03-03 18:51 ` Andrei A. Dergatchev
0 siblings, 1 reply; 9+ messages in thread
From: esci @ 1999-03-03 13:21 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1109 bytes --]
[ snip]
>-.section .rodata
>+#ifdef __ELF__
>+ .section .rodata
>+#else
>+ .rdata
>+#endif
[ snip]
Unfortunately this is exactly what I did ( I left off the #ifdef ). I
never tried linking after nm(1) core dumped. It was late when I posted
my notes yesterday and I was getting pretty befuddled. The examples I
sent were rewrites of a kernel extracted from an application I'm working
on. The results of my tuning efforts were so confusing I decided to
build new test environment (complete w/ its own bugs :-(
I plan to compile the C code as well as a FORTRAN translation today and
compare them. I will also generate assembly using the C and FORTRAN codes
and see if I can figure out what to do to write assembly code that will
work both places.
Reginald Beardsley
------------------------------------------------------------------------
Exploration Software Consultants Inc.
Voice: 972-379-0557 email: rhb@acm.org
Fax: 972-379-0558
------------------------------------------------------------------------
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: sqrt performance
1999-03-03 13:21 esci
@ 1999-03-03 18:51 ` Andrei A. Dergatchev
0 siblings, 0 replies; 9+ messages in thread
From: Andrei A. Dergatchev @ 1999-03-03 18:51 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1262 bytes --]
Hi,
> [snip]
> I plan to compile the C code as well as a FORTRAN translation today and
> compare them. I will also generate assembly using the C and FORTRAN codes
> and see if I can figure out what to do to write assembly code that will
> work both places.
>
sub1.f:
...
do i=1 ,n
t2 = i*dt
t2 = t2*t2
ts = sqrt( rs2*s(i) + t2 )
tg = sqrt( rg2*s(i) + t2 )
j(i) = ts + tg
end do
...
Looking at the structure of your code I think it *should* be possible
to get some acceleration exploiting regulatiry of sqrt argument:
some_value*constant_for_this_cycle+delta^2*(i++)^2
for i=1,N
I'm thinking about division of one argument over other.
Can you expect any relation of general nature like
some_value*constant_for_this_cycle<<delta^2*(i++)^2
or vice versa or anything in this style ?
>
> Reginald Beardsley
>
> ------------------------------------------------------------------------
> Exploration Software Consultants Inc.
>
> Voice: 972-379-0557 email: rhb@acm.org
> Fax: 972-379-0558
> ------------------------------------------------------------------------
Regards,
Andrei
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: sqrt performance
@ 1999-03-03 20:53 esci
1999-03-03 21:40 ` Andrei A. Dergatchev
1999-03-04 5:15 ` Michal Jaegermann
0 siblings, 2 replies; 9+ messages in thread
From: esci @ 1999-03-03 20:53 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1929 bytes --]
[snip]
>Looking at the structure of your code I think it *should* be possible
>to get some acceleration exploiting regulatiry of sqrt argument:
>some_value*constant_for_this_cycle+delta^2*(i++)^2
>for i=1,N
>
>I'm thinking about division of one argument over other.
>Can you expect any relation of general nature like
>some_value*constant_for_this_cycle<<delta^2*(i++)^2
>or vice versa or anything in this style ?
All the values are monotonic, so you can speed things up a good bit by using
the previous result as the starting point in a Newtonian iteration. It gives
a factor of 3 speed up w/ g77 or NDP, but is slightly slower than the DU
library routine. This was with 2 steps hard coded w/o conditional logic.
I only need 13 bits of accuracy as the result is an index into an array.
One of the things that is slowly sinking in is that my loop is too short,
typically under 100 iterations. From what I'm seeing, I should be able to
get faster results by chaining a number of loops together.
BTW can anyone provide good references on sqrt() methods? I looked in
Knuth and quite a few other math references but found little other than very
basic stuff (i.e. Newton's method) Knuth has one algorithm posed as an
exercise (M40 == Mathematical, term project difficulty :-(
I'm currently looking into using a table driven Taylor's series expansion.
Hint's and suggestions *very* welcome. I need to do this over the range
from 0 to 100,000,000 w/ the roots off by less than 1 (I actually need
integer roots for the indexing). There ought to be a way to get this going
a lot faster.
Reginald Beardsley
------------------------------------------------------------------------
Exploration Software Consultants Inc.
Voice: 972-379-0557 email: rhb@acm.org
Fax: 972-379-0558
------------------------------------------------------------------------
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: sqrt performance
1999-03-03 20:53 esci
@ 1999-03-03 21:40 ` Andrei A. Dergatchev
1999-03-04 5:15 ` Michal Jaegermann
1 sibling, 0 replies; 9+ messages in thread
From: Andrei A. Dergatchev @ 1999-03-03 21:40 UTC (permalink / raw)
Hi,
[snip]
> All the values are monotonic, so you can speed things up a good bit by using
> the previous result as the starting point in a Newtonian iteration. It gives
> a factor of 3 speed up w/ g77 or NDP, but is slightly slower than the DU
> library routine. This was with 2 steps hard coded w/o conditional logic.
> I only need 13 bits of accuracy as the result is an index into an array.
Well, 3x speed up is already quite a lot, do you want to calculate sqrt at
one clock :-) ? Ok, just kidding. I believe requiring only 13 bits (out of 64
of input ?) we have plenty of room to optimise. Can you provide some
code using this optimisation to start with ?
> One of the things that is slowly sinking in is that my loop is too short,
> typically under 100 iterations. From what I'm seeing, I should be able to
> get faster results by chaining a number of loops together.
Yeah, for longer loops it might be possible to keep larger tables in cach.
> BTW can anyone provide good references on sqrt() methods? I looked in
> Knuth and quite a few other math references but found little other than very
> basic stuff (i.e. Newton's method) Knuth has one algorithm posed as an
> exercise (M40 == Mathematical, term project difficulty :-(
During somewhere in between Sep 1 1997 and Dec 1 1998 Dann Corbit
discussed optimum sqrt routines several times in comp.lang.c and
sci.math.num-analysis
This entiry thread was *very* useful for my background in applied math :-)
http://x11.dejanews.com/[ST_rn=ps]/dnquery.xp?&search=thread&svcclass=dnserver&ST=PS&CONTEXT=920496754.1956577512&HIT_CONTEXT=920496754.1956577512&HIT_NUM=0&recnum=%3c1998051405135800.BAA02391@ladder03.news.aol.com%3e%231/1
> I'm currently looking into using a table driven Taylor's series expansion.
You may want to search dejanews for ~a(Dann Corbit), ~g(comp.lang.c)
and "sqrt" :-) I'll steal just a few from what I was given.
http://x11.dejanews.com/[ST_rn=ps]/getdoc.xp?AN=324191203&CONTEXT=920497028.1963655168&hitnum=43
ftp://ftp.cs.umd.edu/pub/papers/papers/2990/2990.ps.Z
http://www.astro.virginia.edu/~eww6n/math/SquareRoot.html
> Hint's and suggestions *very* welcome. I need to do this over the range
> from 0 to 100,000,000 w/ the roots off by less than 1 (I actually need
> integer roots for the indexing). There ought to be a way to get this going
> a lot faster.
Do you need only roots of integers ?? Once more:
http://www.dejanews.com/[ST_rn=ps]/dnquery.xp?ST=PS&QRY=sqrt&defaultOp=AND&DBS=1&format=terse&showsort=date&maxhits=100&LNG=ALL&subjects=&groups=&authors=user923005%40aol.com&fromdate=&todate=
"I have different algorithms for each. For integer, go look at comp.lang.c for
a posting by Dann Corbit."
>
>
> Reginald Beardsley
>
> ------------------------------------------------------------------------
> Exploration Software Consultants Inc.
>
> Voice: 972-379-0557 email: rhb@acm.org
> Fax: 972-379-0558
> ------------------------------------------------------------------------
Good luck,
Andrei
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: sqrt performance
1999-03-03 20:53 esci
1999-03-03 21:40 ` Andrei A. Dergatchev
@ 1999-03-04 5:15 ` Michal Jaegermann
1999-03-04 18:30 ` Joachim Wesner
1 sibling, 1 reply; 9+ messages in thread
From: Michal Jaegermann @ 1999-03-04 5:15 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 446 bytes --]
esci wrote:
>
> I'm currently looking into using a table driven Taylor's series expansion.
> Hint's and suggestions *very* welcome. I need to do this over the range
> from 0 to 100,000,000 w/ the roots off by less than 1
If you reduce that to an interval [0,1) this would mean that you
need 10 decimal places. A decent polynomial approximation plus one
step of a Newton iteration should bring you in that range, I think.
Michal
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: sqrt performance
1999-03-04 5:15 ` Michal Jaegermann
@ 1999-03-04 18:30 ` Joachim Wesner
0 siblings, 0 replies; 9+ messages in thread
From: Joachim Wesner @ 1999-03-04 18:30 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3296 bytes --]
Michal Jaegermann wrote:
>
> esci wrote:
> >
> > I'm currently looking into using a table driven Taylor's series expansion.
> > Hint's and suggestions *very* welcome. I need to do this over the range
> > from 0 to 100,000,000 w/ the roots off by less than 1
>
> If you reduce that to an interval [0,1) this would mean that you
> need 10 decimal places. A decent polynomial approximation plus one
> step of a Newton iteration should bring you in that range, I think.
Not necessarily, at least not for high (aka. full 16 digits). There is a
reason that there is no polynomial based approximation for sqrt in
libffm.
First, you want uniform *relative* precision for the function over the
full range, so 0..1 won't work. However, you can take acount of the
floating point format and only operate on the mantissa and 0.25..1 or
0.5..1 using frexp and ldexp (which however, are notoriously ineffective
when using the C lib routine, clearly, you NEED assembler here).
Unfortunatelly, sqrt is notoriusly ugly in approximating even for small
intervalls, you need much higher orders (and large coefficients for the
high orders, i.e. bad with respect to numerical stability) compared to
say sin(), which is much more well behaved.
However, assuming you go for 0.5..1 where you probably need to adjust
the result by sqrt(0.5) (further slowdown, you need to test it and
decide) and you want 1e-10 final *relative* precision, you need better
1e-5 rel. precision before the final Newton step.
If anybody wants to give it a try, here are the coefficients for a
(nearly) minimax relative prec. polynomial:
For better 1e-5 rel. precision from 0.5..1 you already need a 5th order
polynomial with the coefficients
A 0:
2.07200449623728886e-001
A 1:
1.45700060266363978e+000
A 2:
-1.34960056099104825e+000
A 3:
1.11173630566745442e+000
A 4:
-5.38779078465377500e-001
A 5:
1.12443059720350031e-001
(i.e. A0 + x*A1 + x*x*A2 ...)
which gives you better than ~ 1.4e-6 rel. precision.
If you go for only forth order, you get
A 0:
2.30280650419599074e-001
A 1:
1.29379894493964541e+000
A 2:
-8.94996784387289337e-001
A 3:
4.88028708781137845e-001
A 4:
-1.17117604514064883e-001
however, max. rel. error here is just above the range, i.e. 1.1e-5
Compared to that, for 1e-8 or better 1e-9 initial rel. precision for a
full prec. version, you need >= 9th order, slow to evaluate on a machine
with pipled floating point unit. You can "vectorize" it by some tricks,
that are actually usued in libffm, but you have to further sacrifice
some precision for that.
I would be interested in the result you get, however, I fear, you won't
be able to beat the new libcpml speed !?
Best wishes,
Joachim
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~1999-03-04 18:30 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1999-03-03 2:26 sqrt performance esci
1999-03-03 9:27 ` Andrei A. Dergatchev
1999-03-03 11:59 ` Kazushige Goto
-- strict thread matches above, loose matches on Subject: below --
1999-03-03 13:21 esci
1999-03-03 18:51 ` Andrei A. Dergatchev
1999-03-03 20:53 esci
1999-03-03 21:40 ` Andrei A. Dergatchev
1999-03-04 5:15 ` Michal Jaegermann
1999-03-04 18:30 ` Joachim Wesner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox