Author: Ricardo Gibert
Date: 11:04:23 01/03/03
Go up one level in this thread
On January 03, 2003 at 12:03:45, Uri Blass wrote:
>code B is slightly faster than code A.
>I know that side can get only 0 or 1(something that the compiler does not know)
>and B is eqvivalent to A if you assume that side gets only 0 or 1.
>
>Is it possible to write a third code that will be even faster than B?
>
>I think that if the compiler can know that side is or 0 or 1 it can do B even
>faster.
>
>code A:
>
>if (side==LIGHT)
>{
> if (to>=56)
> {
> gen_promote(from,to,bits);
> return;
> }
>}
>else
>{
> if (to<=7)
> {
> gen_promote(from,to,bits);
> return;
> }
>}
Try something like this:
if ((to<=7) || (to>=56))
{
gen_promote(from,to,bits);
return;
}
Note: Above is untested.
I've assumed from "gen_promote(from,to,bits)" that this code is executed for
pawn moves only and is intended to test whether promotions should be generated.
The test "side==LIGHT" is not neccessary since, the test "to>=56" can only be
true if it is Whites move (white pawns can't move to the squares 0 thru 7) and
for "to<=7" the reasoning is analogous.
I've also assumed that "to<=7" is false even more often than "to>=56", so I
placed it first. White has the advantage of the first move after all!
>
>code B:
>if ((to+side*(63-2*to))>=56)
>{
> gen_promote(from,to,bits);
> return;
>}
Even if code B proves faster, I would not use it. This kind of code should be
avoided IMHO.
>
>Uri
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.