Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2001:
[Freeciv-Dev] Re: the directional system
Home

[Freeciv-Dev] Re: the directional system

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Gaute B Strokkenes <gs234@xxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: the directional system
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 12 Sep 2001 08:52:57 +0200
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

On Tue, Sep 11, 2001 at 09:43:24PM +0200, Gaute B Strokkenes wrote:
> On Sat, 8 Sep 2001, hawk@xxxxxxxxxxxxxxxxxxxxxxx wrote:
> > On Fri, Sep 07, 2001 at 08:33:02PM -0400, Greg Wooledge wrote:
> >> Raimar Falke (hawk@xxxxxxxxxxxxxxxxxxxxxxx) wrote:
> >> > On Fri, Sep 07, 2001 at 04:51:36AM -0700, Trent Piepho wrote:
> >> > > +#define DIR_REVERSE(dir) (((dir) + 4) % 8)
> >> > > +#define DIR_REVERSE(dir) (((dir) + 4) & 7)
> >> 
> >> > $ gcc -S -O2 a.c
> >> > $ cat a.s
> >> 
> >> Nice demonstration, but it only shows that your version of gcc can
> >> handle this optimization
> > 
> > This is correct.
> > 
> >> -- there may be other compilers out there that don't.
> > 
> > Than please state the compiler and the version. I don't know what
> > compiler are used to compile freeciv. I also don't know which
> > compiler supports such optimization. However I think all compilers
> > used today are able to perform the optimization since it is a very
> > easy transformation IMHO.
> 
> This transformation is only safe when dir is an unsigned type, or when
> the compiler can prove that a negative value for dir can not occur.

This point was: the compiler is capable of doing the transformation
"/8" -> "&7". And yes in the signed case the compiler has to emit an
extra branch.

> In most cases Freeciv uses plain ints, and it is usually very hard to
> prove that a given variable can not be negative.  Therefore the
> compiler will not be able to make this tranformation in the general
> case.
> 
> > Please do the work and compile the small test program with various
> > compilers. This will give you, me and the freeciv community a better
> > understanding of how capable various compilers are.
> > 
> >> It's safer to use the bitwise AND operation.
> > 
> > Yes it would be safer for performance. However if performance would
> > be the primary goal freeciv would use X11 directly.
> 
> I can't see what you're worried about; the "&" version is hardly any
> less readable.

Let me restate: I'm only accepting "performance improvement fixes" if:
 - there is a problem (profiling data for example) in the tree and
 - the patch reduces the time used by a reasonable amount (i.e. this
 depends on the patch size)

Yes I know even without testing the compiler that "&7" isn't slower
than "%8". But is has to be proven that it is faster. The autogame
feature makes it really easy to do such test runs.

Please take a look at the top of the profile I recently posted if you
try to make freeciv faster. It looks like a new "real" hashtable would
be a nice project.

        Raimar

P.S.: And yes the signature was randomly choosen.

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "Premature optimization is the root of all evil."
    -- D. E. Knuth in "Structured Programming with go to Statements"


[Prev in Thread] Current Thread [Next in Thread]