- excluded = ((Rank1BB | Rank8BB) & ~rank_bb(s)) | ((FileABB | FileHBB) & ~file_bb(s));
-
- attack[s] = &attTabl[offset];
- mask[s] = sliding_attacks(s, EmptyBoardBB, deltas, excluded);
- shift[s] = (CpuIs64Bit ? 64 : 32) - count_1s<CNT64>(mask[s]);
+ // Board edges are not considered in the relevant occupancies
+ edges = ((Rank1BB | Rank8BB) & ~rank_bb(s)) | ((FileABB | FileHBB) & ~file_bb(s));
+
+ // Given a square 's', the mask is the bitboard of sliding attacks from
+ // 's' computed on an empty board. The index must be big enough to contain
+ // all the attacks for each possible subset of the mask and so is 2 power
+ // the number of 1s of the mask. Hence we deduce the size of the shift to
+ // apply to the 64 or 32 bits word to get the index.
+ masks[s] = sliding_attack(deltas, s, 0) & ~edges;
+ shifts[s] = (Is64Bit ? 64 : 32) - popcount<Max15>(masks[s]);
+
+ // Use Carry-Rippler trick to enumerate all subsets of masks[s] and
+ // store the corresponding sliding attack bitboard in reference[].
+ b = size = 0;
+ do {
+ occupancy[size] = b;
+ reference[size++] = sliding_attack(deltas, s, b);
+ b = (b - masks[s]) & masks[s];
+ } while (b);