Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2001:
[Freeciv-Dev] Re: map_adjust_x()
Home

[Freeciv-Dev] Re: map_adjust_x()

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Falk Hueffner <falk.hueffner@xxxxxxxxxxxxxxxxxxxxxxxx>, freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: map_adjust_x()
From: Thue <thue@xxxxxxx>
Date: Tue, 20 Mar 2001 13:39:46 +0100

On Thursday 15 March 2001 04:19, Falk Hueffner wrote:
> Thue <thue@xxxxxxx> writes:
> > On Friday 09 March 2001 00:08, Falk Hueffner wrote:
> > > Thue <thue@xxxxxxx> writes:
> > > > Right now map_adjust_x only adjusts values in the range
> > > > [-map.xsize;map.xsize*2], but values outside that range are possible
> > > > as input (though rare).
> > > >
> > > > So the correct thing to do is to use modulus.
> > >
> > > Please do some timings with this change. Integer modulo is about the
> > > slowest opcode modern CPUS have, it often takes 10-20 cycles. (Not to
> > > mention older Alphas, which have no modulo opcode at all...)
> > >
> > >   Falk
> >
> > But on the other hand we do away with a conditional if; might not be
> > that big a penalty.
> > You could do it without the modulo with a
> >    while (x >= map.xsize) x -= map.xsize;
> > Those two should be benchmarked.
>
> Hmm, the while thingie is likely not really faster than the modulo,
> since theres at least one mispredicted branch. What was the reason a
> simple if wouldn't work? It would be by far the fastest (Uhm... unless
> you have no conditional move instruction...) Oh well, somebody should
> just benchmark it ;)
>
>         Falk

The current one contains an "if" so the "while" should be very similar. In 
far most cases both would have one conditional, with the while one containing 
one jmp instruction extra in the case of a positive.

-Thue



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