Usenet comp.os.linux.alpha (1997-2013)
 help / color / mirror / Atom feed
From: Alex Rhomberg <rhomberg@ife.ee.ethz.ch>
Subject: Re: fast array calculation in C
Date: 1999/10/11	[thread overview]
Message-ID: <3801A6BC.21E8653E@ife.ee.ethz.ch> (raw)
In-Reply-To: 7tockg$230o@news2.newsguy.com

Greg Lindahl wrote:
> > I've found that the biggest difference in code efficience comes if the
> > compiler thinks that lvalue and rvalue accesses could be the same
> > address or not.
> 
> This is usually known as the "aliasing problem" -- the compiler isn't
> sure if a given pointer store is the same as a different pointer load,
> so it doesn't re-use values in variables.

exactly. The next part follows from this. As the compiler doesn't dare
reordering loads and stores, it will produce bad code.

> > By feeding the produced assembler into a short Perl
> > script, I was able to identify ugly code, optimize it and shave 30% of
> > the execution time of a 700 line function by optimizing 4 lines.
> >
> > I'll post the perl-script for those who are interested.
> > It finds the lines where the target of a ldt/addt/mult/subt function
> > appears in the following line, which means pipeline stalls:
> 
> .. but this is a different problem, an instruction scheduling
> problem. What I am saying, mostly, is that I obviously don't
> understand what you are saying.

Just enter some test code and look at the produced assembler. 
E.g. a vector addition:
If the compiler is unsure about aliasing, it will produce stalling code:
ldt $f1, 8(a1)
ldt $f2, 16(a2)
addt $f1,$f2,$f1    #STALL, wait for $f2
stt $f1             #STALL, wait for $f1

If the compiler knows there is no such problem (e.g. by using
temporaries or local arrays), it can reorder the instructions and
produce much much faster code.
The scheduling problem follows from the aliasing prob.

> In addition, is this savings in gcc or in ccc?

The savings are in ccc. After I entered all hints to remove aliasing
problems, the ccc produces no more "ugly" code, gcc still does. ccc's
code is about three times as fast.

> Are you using a 21264 or a 21164? The 21264 has enough out-of-order
> execution stuff that the above problem doesn't always cause a stall.

The stuff we are talking about are stores and loads. Does the 21264
analyze those to see that they don't access the same location so they
can be reordered? Still, I would expect no more than a factor of 2
improvement due to ooo execution. The code is still bad. E.g. for matric
multiplication (of small matrices), the good code also uses register
much better and contains only a fraction of the loads and stores.
I'm using EV56, I'm buying EV67

> If you are interested in this from a computer-science research side,
> you can look at the Atlas and FFTW projects, which do a more
> complicated version of what you have done.

I was interested to improve my times of 20us per Finite Element. I'm now
running at 2.8us per FE with 345 MFLOPS, which is more than a third of
peak. That's OK for me. There is not much room for improvement (except
increasing clock frequency)

- Alex



  reply	other threads:[~1999-10-11  4:00 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-10-07  4:00 fast array calculation in C Alex Rhomberg
1999-10-09  4:00 ` Greg Lindahl
1999-10-11  4:00   ` Alex Rhomberg [this message]
1999-10-11  4:00     ` Greg Lindahl
1999-10-11  4:00       ` memore0
1999-10-11  4:00         ` Greg Lindahl
1999-10-12  4:00         ` Alex Rhomberg
1999-10-12  4:00           ` memore0
1999-10-12  4:00             ` Alex Rhomberg
1999-10-12  4:00           ` Eberhard Burr
1999-10-13  4:00             ` Alex Rhomberg
1999-10-13  4:00               ` Robert Harley
1999-10-12  4:00       ` Alex Rhomberg
     [not found] <3809E64D.85BDCAFC@ife.ee.ethz.ch>
     [not found] ` <7ud6gc$2o94@news2.newsguy.com>
1999-10-18  4:00   ` Emil Briggs
1999-10-18  4:00     ` Greg Lindahl
1999-10-18  4:00   ` Alex Rhomberg
1999-10-18  4:00     ` Greg Lindahl
1999-10-18  4:00       ` Alex Rhomberg
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