Code: Select all
# define AttacksBishop(square, occ) \
(plus7dir[square] ^ plus7dir[LSB(plus7dir[square] & (occ))] | \
plus9dir[square] ^ plus9dir[LSB(plus9dir[square] & (occ))] | \
minus7dir[square] ^ minus7dir[MSB(minus7dir[square] & (occ))] | \
minus9dir[square] ^ minus9dir[MSB(minus9dir[square] & (occ))])
Code: Select all
/*As mentioned by Robert Hyatt [2], instead of fetching four ray-attacks on the otherwise empty board, one may already use the rook- or bishop attacks to reset outer squares from that union set.
A further improvement was suggested by Michael Sherwin [3], to union the occupancy with the outer bits 0 and 63. Together with appropriate bits set in separate ray-masks, this yields to an efficient branchless solution with 13 64-bit operations in total and 4.5 KByte for the lookup tables for both rooks and bishops each.*/
struct {
U64 bitsN; // bits North, including MSB (bit 63)
U64 bitsE; // bits East, including MSB
U64 bitsS; // bits South, including LSB (bit 0 == 1)
U64 bitsW; // bits West, including LSB
} CACHE_ALIGN rayWstop[64];
U64 attacksEmpty[64];
U64 rayN[64];
U64 rayE[64];
U64 rayS[64];
U64 rayW[64];
U64 rookAttacks(U64 occ, unsigned int sq) {
unsigned long ulN, ulE, ulS, ulW;
occ |= C64(0x8000000000000001);
_BitScanForward64(&ulN, occ & rayWstop[sq].bitsN);
_BitScanForward64(&ulE, occ & rayWstop[sq].bitsE);
_BitScanReverse64(&ulS, occ & rayWstop[sq].bitsS);
_BitScanReverse64(&ulW, occ & rayWstop[sq].bitsW);
return attacksEmpty[sq]^rayN[ulN]^rayE[ulE]^rayS[ulS]^rayW[ulW];
}
Code: Select all
u64 allPieces = pieces[WHITE] | pieces[BLACK] | 0x8000000000000001;
u32 NW, NN, NE, EE, SE, SS, SW, WW;
case WB:
_BitScanForward64(&NW, ray[fs].NW & allPieces);
_BitScanForward64(&NE, ray[fs].NE & allPieces);
_BitScanReverse64(&SE, ray[fs].SE & allPieces);
_BitScanReverse64(&SW, ray[fs].SW & allPieces);
bb[ply][fs] = (
(ray[fs].NW ^ ray[NW].NW) |
(ray[fs].NE ^ ray[NE].NE) |
(ray[fs].SE ^ ray[SE].SE) |
(ray[fs].SW ^ ray[SW].SW))
& ~pieces[WHITE];
captures |= bb[ply][fs];
break;
I'm just doing this to compare with my SISSY bitboards. Whichever one is faster will be good enough for me!