Author: Volker Böhm
Date: 08:45:53 06/01/04
Hi,
I am using attack-tables. For some code I whant to know on witch fields the king
could escape. An escape field is a field not attacked by opponent and not
occupied by an own piece.
I am building up an bit array that hold a bit for every adjacent field. The bit
is set if the king can move to this field. For generation of this bit-field I
use 8 compares with 8 jumps and would like to optimize this.
Some years ago I programmed intel assembler and remembered a trick doing this
without any jumps. Now I wonder if it is able add code that makes the compiler
use this trick. Here it is:
Istead of
int bitfield = 0;
if (q8 != 0) bitfield++;
bitfield << 1;
if (q7 != 0) bitfield++;
...
{aternative:
int bitfield = 0;
if (q8 != 0) bitfield += (1 << 7);
if (q7 != 0) bitfield += (1 << 6);
...
}
In assembler I could write (i am not quite sure if my assembler syntax is
correct any more):
XOR AX, AX
CMP Q1, 0
RCL AX, 1
CMP Q2, 0
RCL AX, 1
...
{
alternative:
XOR AX, AX
CMP Q1, 0
ADC AX, 0
SHL AX, 1
CMP Q2, 0
ADC AX, 0
...
}
As the result of a compare sets the carry-flag you can rotate the carry-flag
into your bit-field.
Anybody knows how to "tell" the compiler to use the RCL trick?
Volker
This page took 0.01 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.