+ // 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_attacks(s, EmptyBoardBB, deltas) & ~edges;
+ shifts[s] = (CpuIs64Bit ? 64 : 32) - count_1s<CNT32_MAX15>(masks[s]);
+
+ // Use Carry-Rippler trick to enumerate all subsets of masks[s] and
+ // store the corresponding sliding attacks in reference[].
+ b = maxKey = 0;
+ do {
+ occupancy[maxKey] = b;
+ reference[maxKey++] = sliding_attacks(s, b, deltas);
+ b = (b - masks[s]) & masks[s];
+ } while (b);