Skip to content

Commit 6f10137

Browse files
protonspringsnicolet
authored andcommitted
Use a std::bitset for KPKBitbase
This is a non-functional simplification. Looks like std::bitset works good for the KPKBitbase. Thanks for Jorg Oster for helping get the speed up (the [] accessor is faster than test()). Speed testing: 10k calls to probe: master 9.8 sec patch 9.8 sec. STC LLR: 2.94 (-2.94,2.94) {-1.50,0.50} Total: 100154 W: 19025 L: 18992 D: 62137 Ptnml(0-2): 1397, 11376, 24572, 11254, 1473 http://tests.stockfishchess.org/tests/view/5e21e601346e35ac603b7d2b Closes #2502 No functional change
1 parent f3c83ed commit 6f10137

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/bitbase.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <cassert>
2222
#include <numeric>
2323
#include <vector>
24+
#include <bitset>
2425

2526
#include "bitboard.h"
2627
#include "types.h"
@@ -31,8 +32,7 @@ namespace {
3132
// Positions with the pawn on files E to H will be mirrored before probing.
3233
constexpr unsigned MAX_INDEX = 2*24*64*64; // stm * psq * wksq * bksq = 196608
3334

34-
// Each uint32_t stores results of 32 positions, one per bit
35-
uint32_t KPKBitbase[MAX_INDEX / 32];
35+
std::bitset<MAX_INDEX> KPKBitbase;
3636

3737
// A KPK bitbase index is an integer in [0, IndexMax] range
3838
//
@@ -74,8 +74,7 @@ bool Bitbases::probe(Square wksq, Square wpsq, Square bksq, Color stm) {
7474

7575
assert(file_of(wpsq) <= FILE_D);
7676

77-
unsigned idx = index(stm, bksq, wksq, wpsq);
78-
return KPKBitbase[idx / 32] & (1 << (idx & 0x1F));
77+
return KPKBitbase[index(stm, bksq, wksq, wpsq)];
7978
}
8079

8180

@@ -94,10 +93,10 @@ void Bitbases::init() {
9493
for (repeat = idx = 0; idx < MAX_INDEX; ++idx)
9594
repeat |= (db[idx] == UNKNOWN && db[idx].classify(db) != UNKNOWN);
9695

97-
// Map 32 results into one KPKBitbase[] entry
96+
// Fill the bitbase with the decisive results
9897
for (idx = 0; idx < MAX_INDEX; ++idx)
9998
if (db[idx] == WIN)
100-
KPKBitbase[idx / 32] |= 1 << (idx & 0x1F);
99+
KPKBitbase.set(idx);
101100
}
102101

103102

0 commit comments

Comments
 (0)