From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111c93,2cb1c7dcdf4349e1 X-Google-Attributes: gid111c93,public From: Joachim Wesner Subject: Re: sin() on alpha / Cray libm Date: 1998/05/24 Message-ID: <356750BC.67934043@frankfurt.netsurf.de>#1/1 X-Deja-AN: 355934222 Content-Transfer-Encoding: 7bit References: <6k5od1$1b7$1@palladium.transmeta.com> <6k6t8g$2jd@news3.newsguy.com> Content-Type: text/plain; charset=us-ascii Organization: OMNILINK -- your link to the Net MIME-Version: 1.0 Newsgroups: comp.os.linux.alpha 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