Usenet comp.os.linux.alpha (1997-2013)
 help / color / mirror / Atom feed
From: Joachim Wesner <joachim.wesner@frankfurt.netsurf.de>
Subject: Re: sin() on alpha / Cray libm
Date: 1998/05/24	[thread overview]
Message-ID: <356750BC.67934043@frankfurt.netsurf.de> (raw)
In-Reply-To: 6k6t8g$2jd@news3.newsguy.com


Greg Lindahl wrote:
> 
> torvalds@transmeta.com (Linus Torvalds) writes:
> 
> > Remember: if you can make a small and simple routine that avoids one
> > cache miss, that one cache miss is often more costly than the cost of
> > the whole routine. This is less true of more complex functions like
> > sin() and cos(), but it's still something that is easily overlooked,
> 
> This is very true. I would suspect that the Cray "vector" sin() cos()
> and other library functions might have completely different
> implementations for this reason; when you know you are computing with
> a warm cache, you can use different algorithms... so if your compiler
> is already doing vector analysis, you can get a big win.

Actually, their fast *scalar* routines (did not yet look at the vector
routines) seem to use a pretty good balance between a table-based
approach and an polynomial approximation, some functions use tables with
up to 100 double prec constants, so some cache space will be needed :-((
I do not yet understand the exact algorithm, because all the constant
are coded als big integer numbers, originally in a fortran block data
subroutine !!! However, I got the stuff running in a prelim. form on
linux/axp. The latest results are:

My measured execution time on a LX 533 (1 tick ~ 2 ns) (all routines
were tested with random arguments from 0 to x)

0..x            0..0.3          0..10           0..300

actual libm:

sin             0.18 us         0.45 us         0.51 us
cos             0.20 us         0.46 us         0.52 us
tan             0.30 us         0.63 us         0.69 us
log		0.45 us		0.45 us		0.45 us
log10		0.62 us		0.61 us		0.61 us
sqrt		0.19 us		0.19 us		0.19 us

New converted CRAY routines:

sin             0.20 us         0.20 us         0.20 us
cos             0.22 us         0.22 us         0.22 us
sin+cos
(simultaneous!) 0.24 us         0.24 us         0.24 us
tan
(derived)       0.27 us         0.27 us         0.27 us
log		0.16 us		0.16 us		0.16 us
log10		0.19 us		0.19 us		0.19 us
exp		0.20 us		0.20 us		0.20 us
sqrt		0.16 us		0.15 us		0.15 us

These results are for a "hot" cache in a tight loop, the random #
generation and the looping/calling overhad removed !

All those sacrifice a bit of accuracy, often the last bit and sometimes
the second last bit will be wrong, as oposed to libm that often gets the
last bit (rounded) correctly. There's still a fast cubic root and some
reduced precision (~ 32 bits) routine. I will add a good (derived) pow 
soon (hey, it's not always as easy as exp(log(x)*y)). HOWEVER, there are
no inverse trig and no hyperbolic functions in the cray lib.

Some cleaning up work will still have to follow before it would be ready
for general use (if copyright permits), as it uses temporary storage in
a *static* data segment (just where also the *constants* where stored,
this is a 100% typical good old fortran approach), so it could not be
interrupted and shared in the actual form, but those changes seem pretty
trivial.

Joachim



  reply	other threads:[~1998-05-24  4:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-05-22  4:00 sin() on alpha Dong-Woon Park
1998-05-22  4:00 ` Bruce Allen
1998-05-22  4:00   ` Greg Lindahl
1998-05-23  4:00   ` Dong-Woon Park
1998-05-23  4:00     ` Bruce Allen
1998-05-24  4:00       ` Joachim Wesner
1998-05-24  4:00     ` Joachim Wesner
1998-05-23  4:00   ` Christopher Browne
1998-05-23  4:00     ` Michal Jaegermann
1998-05-23  4:00     ` Linus Torvalds
1998-05-23  4:00       ` Greg Lindahl
1998-05-24  4:00         ` Joachim Wesner [this message]
1998-05-23  4:00       ` Andi Kleen
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox