Skip to content

Commit

Permalink
Changed to more performant architecture.
Browse files Browse the repository at this point in the history
  • Loading branch information
dpldgr committed Nov 28, 2024
1 parent bdb353e commit ba51e00
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 45 deletions.
12 changes: 6 additions & 6 deletions src/movegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Stockfish {
class Position;
class movelist_buf;

movelist_buf* get_thread_mlb( const Position& pos );
movelist_buf& get_mlb( const Position& pos );

enum GenType {
CAPTURES,
Expand Down Expand Up @@ -147,15 +147,15 @@ template<GenType T>
struct MoveList {

explicit MoveList(const Position& pos)
:mlb(get_mlb(pos))
{
this->mlb = pos.get_mlb();
this->moveList = this->mlb->acquire();
this->last = generate<T>(pos, this->moveList);
moveList = mlb.acquire();
last = generate<T>(pos, moveList);
}

~MoveList()
{
this->mlb->release(this->moveList);
mlb.release(moveList);
}

const ExtMove* begin() const { return moveList; }
Expand All @@ -166,7 +166,7 @@ struct MoveList {
}

private:
movelist_buf* mlb;
movelist_buf& mlb;
ExtMove* last;
ExtMove* moveList = nullptr;
};
Expand Down
20 changes: 7 additions & 13 deletions src/movepick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,23 @@ namespace {
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh, const GateHistory* dh, const LowPlyHistory* lp,
const CapturePieceToHistory* cph, const PieceToHistory** ch, Move cm, const Move* killers, int pl)
: pos(p), mainHistory(mh), gateHistory(dh), lowPlyHistory(lp), captureHistory(cph), continuationHistory(ch),
ttMove(ttm), refutations{{killers[0], 0}, {killers[1], 0}, {cm, 0}}, depth(d), ply(pl) {
ttMove(ttm), refutations{{killers[0], 0}, {killers[1], 0}, {cm, 0}}, depth(d), ply(pl), mlb(get_mlb(p)) {

assert(d > 0);

this->mlb = pos.get_mlb();
this->moves = this->mlb->acquire();

moves = mlb.acquire();
stage = (pos.checkers() ? EVASION_TT : MAIN_TT) +
!(ttm && pos.pseudo_legal(ttm));
}

/// MovePicker constructor for quiescence search
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh, const GateHistory* dh,
const CapturePieceToHistory* cph, const PieceToHistory** ch, Square rs)
: pos(p), mainHistory(mh), gateHistory(dh), captureHistory(cph), continuationHistory(ch), ttMove(ttm), recaptureSquare(rs), depth(d) {
: pos(p), mainHistory(mh), gateHistory(dh), captureHistory(cph), continuationHistory(ch), ttMove(ttm), recaptureSquare(rs), depth(d), mlb(get_mlb(p)) {

assert(d <= 0);

this->mlb = pos.get_mlb();
this->moves = this->mlb->acquire();

moves = mlb.acquire();
stage = (pos.checkers() ? EVASION_TT : QSEARCH_TT) +
!( ttm
&& (pos.checkers() || depth > DEPTH_QS_RECAPTURES || to_sq(ttm) == recaptureSquare)
Expand All @@ -96,21 +92,19 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHist
/// MovePicker constructor for ProbCut: we generate captures with SEE greater
/// than or equal to the given threshold.
MovePicker::MovePicker(const Position& p, Move ttm, Value th, const GateHistory* dh, const CapturePieceToHistory* cph)
: pos(p), gateHistory(dh), captureHistory(cph), ttMove(ttm), threshold(th) {
: pos(p), gateHistory(dh), captureHistory(cph), ttMove(ttm), threshold(th), mlb(get_mlb(p)) {

assert(!pos.checkers());

this->mlb = pos.get_mlb();
this->moves = this->mlb->acquire();

moves = mlb.acquire();
stage = PROBCUT_TT + !(ttm && pos.capture(ttm)
&& pos.pseudo_legal(ttm)
&& pos.see_ge(ttm, threshold));
}

MovePicker::~MovePicker()
{
this->mlb->release(this->moves);
mlb.release(moves);
}

/// MovePicker::score() assigns a numerical value to each move in a list, used
Expand Down
2 changes: 1 addition & 1 deletion src/movepick.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class MovePicker {
Value threshold;
Depth depth;
int ply;
movelist_buf* mlb;
movelist_buf& mlb;
ExtMove* moves;
};

Expand Down
6 changes: 3 additions & 3 deletions src/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,12 +532,12 @@ Position& Position::set(const Variant* v, const string& fenStr, bool isChess960,
if ( thisThread )
{
this->thread_id = thisThread->id();
this->bind_mlb();
//this->bind_mlb();
}
else
{
this->thread_id = -1;
this->mlb = nullptr;
//this->mlb = nullptr;
}

set_state(st);
Expand Down Expand Up @@ -2859,7 +2859,7 @@ bool Position::is_immediate_game_end(Value& result, int ply) const {
current |= newBitboard;
}
}

if (connect_nxn())
{
Bitboard connectors = connectPieces;
Expand Down
36 changes: 14 additions & 22 deletions src/position.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ namespace Stockfish {

class movelist_buf;

movelist_buf* get_thread_mlb( const Position& pos );

/// StateInfo struct stores information needed to restore a Position object to
/// its previous state when we retract a move. Whenever a move is made on the
/// board (by calling Position::do_move), a StateInfo object must be passed.
Expand Down Expand Up @@ -346,8 +344,7 @@ class Position {
int thread_id;
movelist_buf* mlb;

void bind_mlb();
movelist_buf* get_mlb() const;
//void bind_mlb();

private:
// Initialization helpers (used while setting up a position)
Expand Down Expand Up @@ -1002,11 +999,11 @@ inline bool Position::flag_move() const {

inline bool Position::flag_reached(Color c) const {
assert(var != nullptr);
bool simpleResult =
bool simpleResult =
(flag_region(c) & pieces(c, flag_piece(c)))
&& ( popcount(flag_region(c) & pieces(c, flag_piece(c))) >= var->flagPieceCount
|| (var->flagPieceBlockedWin && !(flag_region(c) & ~pieces())));

if (simpleResult&&var->flagPieceSafe)
{
Bitboard piecesInFlagZone = flag_region(c) & pieces(c, flag_piece(c));
Expand All @@ -1016,7 +1013,7 @@ inline bool Position::flag_reached(Color c) const {
pieces in the flag zone and they need to be safe: If I have 3 pieces there, but one is under
threat, I don't think I can declare victory. If I have 4 there, but one is under threat, I
think that's victory.
*/
*/
while (piecesInFlagZone)
{
Square sr = pop_lsb(piecesInFlagZone);
Expand Down Expand Up @@ -1577,25 +1574,20 @@ inline bool Position::can_drop(Color c, PieceType pt) const {
return variant()->freeDrops || count_in_hand(c, pt) > 0;
}

inline void set_thread_mlb(Position& pos)
{
pos.mlb = &mlb_pool[pos.thread_id];
}
//inline void set_thread_mlb(Position& pos)
//{
// pos.mlb = &mlb_pool[pos.thread_id];
//}

inline movelist_buf* get_thread_mlb(const Position& pos)
inline movelist_buf& get_mlb(const Position& pos)
{
return &mlb_pool[pos.thread_id];
return mlb_pool[pos.thread_id];
}

inline void Position::bind_mlb()
{
this->mlb = &mlb_pool[this->thread_id];
}

inline movelist_buf* Position::get_mlb() const
{
return this->mlb;
}
//inline void Position::bind_mlb()
//{
// this->mlb = &mlb_pool[this->thread_id];
//}

} // namespace Stockfish

Expand Down

0 comments on commit ba51e00

Please sign in to comment.