Skip to content

Commit 734315f

Browse files
stousetvondele
authored andcommitted
Remove precomputed SquareBB
Bit-shifting is a single instruction, and should be faster than an array lookup on supported architectures. Besides (ever so slightly) speeding up the conversion of a square into a bitboard, we may see minor general performance improvements due to preserving more of the CPU's existing cache. passed STC: LLR: 2.95 (-2.94,2.94) <-1.75,0.25> Total: 47280 W: 12469 L: 12271 D: 22540 Ptnml(0-2): 128, 4893, 13402, 5087, 130 https://tests.stockfishchess.org/tests/view/63c5cfe618c20f4929c5fe46 Small speedup locally: ``` Result of 20 runs ================== base (./stockfish.master ) = 1752135 +/- 10943 test (./stockfish.patch ) = 1763939 +/- 10818 diff = +11804 +/- 4731 speedup = +0.0067 P(speedup > 0) = 1.0000 CPU: 16 x AMD Ryzen 9 3950X 16-Core Processor ``` Closes #4343 Bench: 4106793
1 parent a08b8d4 commit 734315f

File tree

2 files changed

+1
-6
lines changed

2 files changed

+1
-6
lines changed

src/bitboard.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ namespace Stockfish {
2727
uint8_t PopCnt16[1 << 16];
2828
uint8_t SquareDistance[SQUARE_NB][SQUARE_NB];
2929

30-
Bitboard SquareBB[SQUARE_NB];
3130
Bitboard LineBB[SQUARE_NB][SQUARE_NB];
3231
Bitboard BetweenBB[SQUARE_NB][SQUARE_NB];
3332
Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
@@ -82,9 +81,6 @@ void Bitboards::init() {
8281
for (unsigned i = 0; i < (1 << 16); ++i)
8382
PopCnt16[i] = uint8_t(std::bitset<16>(i).count());
8483

85-
for (Square s = SQ_A1; s <= SQ_H8; ++s)
86-
SquareBB[s] = (1ULL << s);
87-
8884
for (Square s1 = SQ_A1; s1 <= SQ_H8; ++s1)
8985
for (Square s2 = SQ_A1; s2 <= SQ_H8; ++s2)
9086
SquareDistance[s1][s2] = std::max(distance<File>(s1, s2), distance<Rank>(s1, s2));

src/bitboard.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ constexpr Bitboard KingFlank[FILE_NB] = {
7474
extern uint8_t PopCnt16[1 << 16];
7575
extern uint8_t SquareDistance[SQUARE_NB][SQUARE_NB];
7676

77-
extern Bitboard SquareBB[SQUARE_NB];
7877
extern Bitboard BetweenBB[SQUARE_NB][SQUARE_NB];
7978
extern Bitboard LineBB[SQUARE_NB][SQUARE_NB];
8079
extern Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
@@ -108,7 +107,7 @@ extern Magic BishopMagics[SQUARE_NB];
108107

109108
inline Bitboard square_bb(Square s) {
110109
assert(is_ok(s));
111-
return SquareBB[s];
110+
return (1ULL << s);
112111
}
113112

114113

0 commit comments

Comments
 (0)