Obviously you do this twice during generation of quiet pawn moves: once for all pawns on rank 2-6 (for white) that can advance one rank, with increment=8, and once for all pawns on rank 2 that can advance two ranks, with increment=16. So your modification adds two calls to popcount(). How can it still be faster than the "standard" implementation (example below) that does not need any popcount (and also no "goto")?cdani wrote:Sure someone can improve this, but I think is really fast.
Code: Select all
b = bitboard of pawns increment = 8 or 16 uint8_t cas; uint8_t casd; switch (popcount(b)) { case 8: cas = lsb(b); b &= b - 1; casd = cas + increment; ml->moviment = MakeMove(cas, casd); ml++; // ... case 2: cas = lsb(b); b &= b - 1; casd = cas + increment; ml->moviment = MakeMove(cas, casd); ml++; case 1: cas = lsb(b); casd = cas + increment; ml->moviment = MakeMove(cas, casd); ml++; case 0: return ml; default: //> 8 pawns for strange games or positions altremovpeo2 : if (b == 0) return ml; cas = lsb(b); casd = cas + increment; ml->moviment = MakeMove(cas, casd); ml++; b &= b - 1; goto altremovpeo2; }
Code: Select all
while (b) {
uint8_t cas = lsb(b);
b &= b - 1;
(ml++)->moviment = MakeMove(cas, cas + increment);
}
return ml;
1) About how many positions did you use to test the performance difference? 10, 100, 1000, ...?cdani wrote:Of course minimal, something like 1100000 n/s to 1100500 n/s to give an idea. Is more for fun than for anything other, and also is interesting to share and to have other ideas.mar wrote:What was the performance gain versus a loop? (and overall speed gain?)
2) What was the previous solution to compare against (the one with 1100000 n/s): a loop similar to my example above, or something different?
Certainly correct. However, accumulating micro-optimizations can sometimes also turn out to be neutral (in terms of speed and/or rating difference) if at least one of the micro-optimizations is somehow "unclear", can sometimes help and sometimes hurt, etc.cdani wrote:Any elo gain is due to accumulating a few of those things.