X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fbitboard.cpp;h=c4d34aeb1737b6513b527794a793da545dfe97fd;hp=dd12dd3ad509775276ebee5345836b9b194ce35b;hb=d9113d127b491db0a427a416217d55d3d298c25e;hpb=59c85346d28f96ae69e172ff7187ccfbbf78d180 diff --git a/src/bitboard.cpp b/src/bitboard.cpp index dd12dd3a..c4d34aeb 100644 --- a/src/bitboard.cpp +++ b/src/bitboard.cpp @@ -214,7 +214,7 @@ Bitboard BAttacks[0x1480]; Bitboard SetMaskBB[65]; Bitboard ClearMaskBB[65]; -Bitboard NonSlidingAttacksBB[16][64]; +Bitboard StepAttacksBB[16][64]; Bitboard BetweenBB[64][64]; Bitboard SquaresInFrontMask[2][64]; @@ -231,7 +231,7 @@ uint8_t BitCount8Bit[256]; namespace { void init_masks(); - void init_non_sliding_attacks(); + void init_step_attacks(); void init_pseudo_attacks(); void init_between_bitboards(); Bitboard index_to_bitboard(int index, Bitboard mask); @@ -347,7 +347,7 @@ void init_bitboards() { int bishopDeltas[4][2] = {{1,1},{-1,1},{1,-1},{-1,-1}}; init_masks(); - init_non_sliding_attacks(); + init_step_attacks(); init_sliding_attacks(RAttacks, RAttackIndex, RMask, RShift, RMult, rookDeltas); init_sliding_attacks(BAttacks, BAttackIndex, BMask, BShift, BMult, bishopDeltas); init_pseudo_attacks(); @@ -384,7 +384,7 @@ namespace { BitCount8Bit[b] = (uint8_t)count_1s(b); } - void init_non_sliding_attacks() { + void init_step_attacks() { const int step[][9] = { {0}, @@ -401,7 +401,7 @@ namespace { Square to = s + Square(step[pc][k]); if (square_is_ok(to) && square_distance(s, to) < 3) - set_bit(&NonSlidingAttacksBB[pc][s], to); + set_bit(&StepAttacksBB[pc][s], to); } } @@ -451,27 +451,19 @@ namespace { void init_sliding_attacks(Bitboard attacks[], int attackIndex[], Bitboard mask[], const int shift[], const Bitboard mult[], int deltas[][2]) { + Bitboard b, v; + int i, j, index; - for (int i = 0, index = 0; i < 64; i++) + for (i = index = 0; i < 64; i++) { attackIndex[i] = index; mask[i] = sliding_attacks(i, 0, deltas, 1, 6, 1, 6); - -#if defined(IS_64BIT) - int j = (1 << (64 - shift[i])); -#else - int j = (1 << (32 - shift[i])); -#endif + j = 1 << ((CpuIs64Bit ? 64 : 32) - shift[i]); for (int k = 0; k < j; k++) { - Bitboard b = index_to_bitboard(k, mask[i]); - -#if defined(IS_64BIT) - Bitboard v = b * mult[i]; -#else - unsigned v = int(b) * int(mult[i]) ^ int(b >> 32) * int(mult[i] >> 32); -#endif + b = index_to_bitboard(k, mask[i]); + v = CpuIs64Bit ? b * mult[i] : unsigned(b * mult[i] ^ (b >> 32) * (mult[i] >> 32)); attacks[index + (v >> shift[i])] = sliding_attacks(i, b, deltas, 0, 7, 0, 7); } index += j; @@ -490,8 +482,7 @@ namespace { void init_between_bitboards() { - Square s1, s2, s3; - SquareDelta d; + Square s1, s2, s3, d; int f, r; for (s1 = SQ_A1; s1 <= SQ_H8; s1++) @@ -501,7 +492,7 @@ namespace { f = file_distance(s1, s2); r = rank_distance(s1, s2); - d = SquareDelta(s2 - s1) / Max(f, r); + d = (s2 - s1) / Max(f, r); for (s3 = s1 + d; s3 != s2; s3 += d) set_bit(&(BetweenBB[s1][s2]), s3);