A Faster Magic Move Bitboard Generator?
Posted: 15 Dec 2006, 01:11
Hi all
For those of you that are using Pradu's magic move bitboard generator (or understand how it works) and have a 32-bit computer, you'll be using code that looks something like this to retrieve your attackboards:-
I picked up on a recent post by H.G Muller and substituted the code above with:-
This modification requires a new set of two 32-bit keys per square (or like me you could join them into one 64-bit key) and only uses two 32-bit multiplies instead of three, and a 32-bit shift, and is probably more suited to a 32-bit machine.
I have implemented this into my program and, for me, I got an increased perft speed of 1.5 million nps.
My thanks to H.G Muller
Grant
For those of you that are using Pradu's magic move bitboard generator (or understand how it works) and have a 32-bit computer, you'll be using code that looks something like this to retrieve your attackboards:-
- Code: Select all
U64 Bmagic(unsigned int square) {
return *(bIndecies[square] + (((Occupied & bishopMask[square]) * bishopMagic[square]) >> bishopShift[square]));
}
U64 Rmagic(unsigned int square) {
return *(rIndecies[square] + (((Occupied & rookMask[square]) * rookMagic[square]) >> rookShift[square]));
}
I picked up on a recent post by H.G Muller and substituted the code above with:-
- Code: Select all
U64 Bmagic(unsigned int square) {
unsigned int lo = bishopMagicLo[square] * (int) Occupied;
unsigned int hi = bishopMagicHi[square] * (int) (Occupied>>32);
return *(bIndecies[square] + ((lo ^ hi) >> bishopShift[square]));
}
U64 Rmagic(unsigned int square) {
unsigned int lo = rookMagicLo[square] * (int) Occupied;
unsigned int hi = rookMagicHi[square] * (int) (Occupied>>32);
return *(rIndecies[square] + ((lo ^ hi) >> rookShift[square]));
}
This modification requires a new set of two 32-bit keys per square (or like me you could join them into one 64-bit key) and only uses two 32-bit multiplies instead of three, and a 32-bit shift, and is probably more suited to a 32-bit machine.
I have implemented this into my program and, for me, I got an increased perft speed of 1.5 million nps.
My thanks to H.G Muller
Grant