Discussion of chess software programming and technical issues.
Moderators: hgm, Dann Corbit, Harvey Williamson
Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
-
stegemma
- Posts: 859
- Joined: Mon Aug 10, 2009 8:05 pm
- Location: Italy
- Full name: Stefano Gemma
-
Contact:
Post
by stegemma » Fri May 13, 2016 6:32 am
stegemma wrote:It is not very efficient but this is what I do now:
Code: Select all
inline int CountDoubled(uint64_t boPawns)
{
int n = 0;
if((boPawns & ~(boPawns * BOARD_H_COL)) != boEmpty)
{
boPawns >>= 8;
uint64_t k = boEmpty;
for(int i = 0; i < 6; i++)
{
k |= (boPawns & BOARD_1_ROW); // accumula i bit dei pedoni sulla prima riga
uint64_t dbl = k & (boPawns >>= 8);
n += bits8[dbl];
}
}
return n;
}
(bits8 contains bits count for the first 256 integers)
According to VS profiler, the "if" takes about the same time as the whole loop!
This version seems to be faster:
Code: Select all
inline int CountDoubled(uint64_t boPawns)
{
int n = 0;
boPawns >>= 8;
uint64_t k = boEmpty;
for(int i = 0; i < 6; i++)
{
k |= (boPawns & BOARD_1_ROW); // accumulates pawn bits on first row
uint64_t dbl = k & (boPawns >>= 8);
n += bits8[dbl];
}
return n;
}
Of course removing any test on pawns if there are no more one of them must be done in the caller.
The compiler is smart enough to avoid the "& BOARD_1_ROW" and it uses a single 8 bit register (r8b, in my test). An improvement using less smart compilers could be to use uint8_t variables for dbl and k.
-
stegemma
- Posts: 859
- Joined: Mon Aug 10, 2009 8:05 pm
- Location: Italy
- Full name: Stefano Gemma
-
Contact:
Post
by stegemma » Mon May 16, 2016 5:35 pm
hgm wrote:Normally this info would come from your Pawn hash, meaning that speed is irrelevant.
I've found a simpler way to do it: because I've a node array, I simply store the value of current pawn structure in the current node, so that I can use it avoiding re-computing any time:
Code: Select all
if(pNode->boMyPawns == boMyPawns && pNode->boOtherPawns == boOtherPawns)
{
++kSamePawns; // to test efficiency
eval += pNode->vPawnValue;
} else
{
++kNoSamePawns; // to test efficiency
pNode->boMyPawns = boMyPawns;
pNode->boOtherPawns = boOtherPawns;
pNode->vPawnValue = 0;
// pedoni doppiati
int nMyDoubled = CountDoubled(boMyPawns);
int nOtherDoubled = CountDoubled(boOtherPawns);
pNode->vPawnValue += iiValues[nOtherDoubled - nMyDoubled];
...
}
This very simple code gives me a "pawns hit" of about 50% and a little speed-up (more than +5 Knps).
Now I'll try to extend this idea to other evaluation parameters.
PS: I don't need to separate my/other pawns because you can't exchange a pawn structure inside a single node!!!