Usenet comp.os.linux.alpha (1997-2013)
 help / color / mirror / Atom feed
From: Craig Burley <burley@tweedledumb.cygnus.com>
Subject: Re: gcc vs Dec Unix c
Date: 1998/01/10	[thread overview]
Message-ID: <y6vhvrhpem.fsf@tweedledumb.cygnus.com> (raw)
In-Reply-To: 884411893.151322629@dejanews.com


[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



  reply	other threads:[~1998-01-10  5:00 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-01-08  5:00 gcc vs Dec Unix c fonte
1998-01-09  5:00 ` Toon Moene
1998-01-09  5:00 ` Toon Moene
1998-01-09  5:00 ` Jaap Schellekens
1998-01-09  5:00   ` cekim
1998-01-09  5:00     ` Peter Mardahl
1998-01-09  5:00       ` Craig Burley
1998-01-10  5:00       ` cekim
1998-01-10  5:00         ` Craig Burley [this message]
1998-01-13  5:00           ` cekim
1998-01-13  5:00             ` Rob Komar
1998-01-13  5:00             ` Yan-Song Chen
1998-01-13  5:00               ` Greg Lindahl
1998-01-15  5:00               ` Lupo LeBoucher
1998-01-15  5:00                 ` Greg Lindahl
1998-01-13  5:00             ` Craig Burley
1998-01-13  5:00               ` [++] x86 FCOS (Was: Re: gcc vs Dec Unix c) Terje Mathisen
1998-01-13  5:00                 ` Andy Glew
1998-01-14  5:00                   ` Terje Mathisen
1998-01-13  5:00               ` gcc vs Dec Unix c James Van Buskirk
1998-01-14  5:00                 ` brianh
1998-01-14  5:00                   ` James Van Buskirk
1998-01-14  5:00             ` bmeyer
1998-01-15  5:00               ` cekim
1998-01-14  5:00     ` Donald K.Sinclair
1998-01-14  5:00       ` Rob Komar
1998-01-16  5:00         ` Torbjorn Lindgren
1998-01-17  5:00           ` Rob Komar
1998-01-14  5:00       ` cekim
1998-01-09  5:00 ` Toon Moene
  -- strict thread matches above, loose matches on Subject: below --
1998-01-13  5:00 Robert Harley
1998-01-14  5:00 ` cekim
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