Subtraction based Attack Mask Generation
Posted: Wed Nov 16, 2016 2:25 pm
Hello!
You guys remember SBAMG: Subtraction based Attack Mask Generation? Matthew Brades has pointed out that it invokes undefined behaviour by calling msb(0) sometimes. So here is the fix, in a more concise way than before.
...where
You guys remember SBAMG: Subtraction based Attack Mask Generation? Matthew Brades has pointed out that it invokes undefined behaviour by calling msb(0) sometimes. So here is the fix, in a more concise way than before.
Code: Select all
uint64_t rank_attacks(int sq, uint64_t occ)
{
occ = (occ & RankMaskEx[sq]) | RankOuterSquares[sq];
return ((occ - ThisAndNextSq[msb(occ & PrevSquares[sq])]) ^ occ) & RankMaskEx[sq];
}
uint64_t file_attacks(int sq, uint64_t occ)
{
occ = (occ & FileMaskEx[sq]) | FileOuterSquares[sq];
return ((occ - ThisAndNextSq[msb(occ & PrevSquares[sq])]) ^ occ) & FileMaskEx[sq];
}
Code: Select all
RankMaskEx[sq] = Bitboard of the rank mask excluding the bitboard of square 'sq' (same for FileMaskEx[sq]);
ThisAndNextSq[sq] = 3ULL << sq;
PrevSquares[0] = 1;
PrevSquares[sq] = (1ULL << sq) - 1 (sq != 0)
RankOuterSquares[sq] = ((0x81ULL << (sq & 56)) & ~(1ULL << sq)) | 1;
FileOuterSquares[sq] = ((0x100000000000001ULL << (sq & 7)) & ~(1ULL << sq)) | 1;