From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 102b75,7b37ae94a49a9eec,start X-Google-Attributes: gid102b75,public X-Google-Thread: 111c93,b79a29863eb727e7 X-Google-Attributes: gid111c93,public From: Craig Burley Subject: Re: gcc vs Dec Unix c Date: 1998/01/10 Message-ID: X-Deja-AN: 314791223 References: <884291935.1575288842@dejanews.com> <694nm1$74c$1@news2.xs4all.nl> <884364975.2133262340@dejanews.com> <695t9e$kft$1@agate.berkeley.edu> <884411893.151322629@dejanews.com> Organization: Cygnus Support Newsgroups: comp.os.linux.alpha,comp.arch [I'm cross-posting this to comp.arch, since it's definitely got architecture-relevant content.] cekim@ix.netcom.com writes: > In article <695t9e$kft$1@agate.berkeley.edu>, > peterm@landau.EECS.Berkeley.EDU (Peter Mardahl) wrote: > > > > I believe that x86 implements cos in HARDWARE, while Alpha does NOT. > > > > Therefore, if you're doing cos() quite a lot, the x86 will stomp > > alpha, and most other RISC. > > You are quite correct(FCOS in TASM), I completely forgot about > that(hardware implimentation in x86). I never worked too much with x86 fp > at assembly level and certainly not recently. I should have realized > such a gap could have only come from hard vs soft code. Never expected > such a thing in a RISC, of course. Whether an operation is done "in hardware" or "in software" has *little* relevance to its performance, in practice, and that's most certainly true in this particular case. > One thing that threw me off of that trail is that the ".s" assembly dump > has "call cos" instead of the TASM or AT&T equivalent "FCOS". I assume > Gcc just replaces this with the appropriate code or macro according to > the host architecture. Nope. At least, I challenge you to prove your theory -- to my knowledge, gcc *can't*, and gas *doesn't*, replace "call cos" in assembly code with "fcos". However, gcc might (and g77 should, since I wrote that code myself) recognize COS() in a program and, when optimization (maybe -ffast-math too?) is suitably enabled, implement that via "fcos" in assembler on the x86 architecture. (I'm pretty sure it replaces SQRT() with "fsqrt", anyway.) If gas *does* replace "call cos" with "fcos", let us know -- I'd love to know, but have never noticed this while debugging (and disassembling) x86 code. (Maybe gdb replaces "fcos" with "call cos"? ;-) So, you can probably tweak-up the performance of your x86 program by ensuring theat "fcos" is used in-line, one way or the other. (Another optimization Glen Clark asked me for about a year ago is to have g77 recognize SIN(X) and COS(X) being needed around the same "time" and thus use the Pentium's ability to deliver both more quickly than one followed by the other...something I haven't gotten around to yet, and would guess egcs would be more likely to address in the near future than I.) Probably *the* biggest reason for the observations of bad performance of cos() on an Alpha that, otherwise, would be considered somewhat faster than a particular Pentium configuration, is simply that the *software* is slow. And we already *know* GNU/Linux, g77, and gcc generate slow code on Alphas, including calls to some libm.a procedures that also are slow (and are fairly Linux-specific). Don't assume the Alpha *hardware* is slow until you've used the fastest *software* available on it. And, for FP performance, including stuff like cos(), I believe that *usually* means Digital UNIX, C, and Fortran. Even then, you might not be looking at the *fastest* achievable on the Alpha -- or, conceivably, on the Pentium, though I'd have a hard time believing there was lots more performance headroom available on a cos()-heavy benchmark by avoiding the Pentium's cos() instruction, simply because of the Pentium being register-starved (though, for all I know, it has register renaming, OOO, and other clever stuff that mitigates this problem sufficiently to make a *software* replacement for "fcos", that also is substantially faster, a distinct possibility). In my experience, somewhat encouraged by people who do actual *hardware* design (of CPUs), complicated hardware instructions often should be *avoided*, for maximum performance, in favor of a software solution employing the *exact same CPU*'s lower-level instructions (which they've had more time to thoroughly optimize). Since I've actually both followed, and gone against, the advice of hardware designers on such issues, I've learned that they are, often, right, but not always. (E.g. on Prime machines I actually *hugely* sped up some code by using the "deplored" LDC/STC [LoaD Character/STore Character] instructions for a printf()-type routine used throughout the system, called IOA$. It's unlikely this could have been made any faster by avoiding LDC/STC, but I don't recall how hard I tried. Though, the huge speed-up was really obtained by rewriting the original Fortran code into assembler. How huge a speed-up? Well, the PRIMOS [rough] equivalent of GNU/Linux "ps aux", called "usage", literally used *half* the CPU time, as measured by itself of course, when my IOA$ was linked in. Given how much of "usage" was devoted to calling PRIMOS kernel routines and such to collect, and compute, data, only to print roughly a 25x80 screenful of text via IOA$, that suggests at least one, possibly nearly two, orders of magnitude improvement for IOA$ itself. But that was mostly due to *not* using *other* hardware instructions, namely, not using the fancier string instructions, which we generally knew to avoid when we cared about performance.) -- "Practice random senselessness and act kind of beautiful." James Craig Burley, Software Craftsperson burley@gnu.org