Re: Doubled pawns
Posted: Fri May 13, 2016 8:32 am
According to VS profiler, the "if" takes about the same time as the whole loop!stegemma wrote:It is not very efficient but this is what I do now:
(bits8 contains bits count for the first 256 integers)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; }
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;
}
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.