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

[Freeciv-Dev] Re: map_adjust_x()

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: map_adjust_x()
From: Falk Hueffner <falk.hueffner@xxxxxxxxxxxxxxxxxxxxxxxx>
Date: 15 Mar 2001 04:19:15 +0100

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 ;)


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