mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-19 00:26:33 +08:00
Lookup square distance instead of calculate on the fly
Microptimization that gives a +0.7% speed increase. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
@@ -56,6 +56,7 @@ Bitboard RookPseudoAttacks[64];
|
|||||||
Bitboard QueenPseudoAttacks[64];
|
Bitboard QueenPseudoAttacks[64];
|
||||||
|
|
||||||
uint8_t BitCount8Bit[256];
|
uint8_t BitCount8Bit[256];
|
||||||
|
int SquareDistance[64][64];
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@@ -154,6 +155,13 @@ Square pop_1st_bit(Bitboard* bb) {
|
|||||||
|
|
||||||
void init_bitboards() {
|
void init_bitboards() {
|
||||||
|
|
||||||
|
for (Bitboard b = 0; b < 256; b++)
|
||||||
|
BitCount8Bit[b] = (uint8_t)count_1s<CNT32_MAX15>(b);
|
||||||
|
|
||||||
|
for (Square s1 = SQ_A1; s1 <= SQ_H8; s1++)
|
||||||
|
for (Square s2 = SQ_A1; s2 <= SQ_H8; s2++)
|
||||||
|
SquareDistance[s1][s2] = Max(file_distance(s1, s2), rank_distance(s1, s2));
|
||||||
|
|
||||||
SquaresByColorBB[DARK] = 0xAA55AA55AA55AA55ULL;
|
SquaresByColorBB[DARK] = 0xAA55AA55AA55AA55ULL;
|
||||||
SquaresByColorBB[LIGHT] = ~SquaresByColorBB[DARK];
|
SquaresByColorBB[LIGHT] = ~SquaresByColorBB[DARK];
|
||||||
|
|
||||||
@@ -194,9 +202,6 @@ void init_bitboards() {
|
|||||||
AttackSpanMask[c][s] = in_front_bb(c, s) & neighboring_files_bb(s);
|
AttackSpanMask[c][s] = in_front_bb(c, s) & neighboring_files_bb(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Bitboard b = 0; b < 256; b++)
|
|
||||||
BitCount8Bit[b] = (uint8_t)count_1s<CNT32_MAX15>(b);
|
|
||||||
|
|
||||||
for (int i = 0; i < 64; i++)
|
for (int i = 0; i < 64; i++)
|
||||||
if (!CpuIs64Bit) // Matt Taylor's folding trick for 32 bit systems
|
if (!CpuIs64Bit) // Matt Taylor's folding trick for 32 bit systems
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -348,6 +348,7 @@ const Value QueenValueEndgame = Value(0x9FE);
|
|||||||
|
|
||||||
extern const Value PieceValueMidgame[17];
|
extern const Value PieceValueMidgame[17];
|
||||||
extern const Value PieceValueEndgame[17];
|
extern const Value PieceValueEndgame[17];
|
||||||
|
extern int SquareDistance[64][64];
|
||||||
|
|
||||||
inline Value piece_value_midgame(Piece p) {
|
inline Value piece_value_midgame(Piece p) {
|
||||||
return PieceValueMidgame[p];
|
return PieceValueMidgame[p];
|
||||||
@@ -440,7 +441,7 @@ inline int rank_distance(Square s1, Square s2) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline int square_distance(Square s1, Square s2) {
|
inline int square_distance(Square s1, Square s2) {
|
||||||
return Max(file_distance(s1, s2), rank_distance(s1, s2));
|
return SquareDistance[s1][s2];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline char file_to_char(File f) {
|
inline char file_to_char(File f) {
|
||||||
|
|||||||
Reference in New Issue
Block a user