mirror of
https://github.com/sockspls/badfish
synced 2025-05-01 09:13:08 +00:00
Delay sorting of negative scored non-captures
We can do this only when needed, if we get a cut-off before we skip sorting entirely. This reduces sorting time of about 20%. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
69644d3f73
commit
c7866a4215
3 changed files with 10 additions and 5 deletions
|
@ -89,7 +89,7 @@ inline void insertion_sort(T* firstMove, T* lastMove)
|
||||||
// Our dedicated sort in range [firstMove, lastMove), first splits
|
// Our dedicated sort in range [firstMove, lastMove), first splits
|
||||||
// positive scores from ramining then order seaprately the two sets.
|
// positive scores from ramining then order seaprately the two sets.
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline void sort_moves(T* firstMove, T* lastMove)
|
inline void sort_moves(T* firstMove, T* lastMove, T** lastPositive)
|
||||||
{
|
{
|
||||||
T tmp;
|
T tmp;
|
||||||
T *p, *d;
|
T *p, *d;
|
||||||
|
@ -114,9 +114,9 @@ inline void sort_moves(T* firstMove, T* lastMove)
|
||||||
|
|
||||||
} while (p != d);
|
} while (p != d);
|
||||||
|
|
||||||
// Sort positives and non-positives separately
|
// Sort just positive scored moves, remaining only when we get there
|
||||||
insertion_sort<T>(firstMove, p);
|
insertion_sort<T>(firstMove, p);
|
||||||
insertion_sort<T>(p, lastMove);
|
*lastPositive = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Picks up the best move in range [curMove, lastMove), one per cycle.
|
// Picks up the best move in range [curMove, lastMove), one per cycle.
|
||||||
|
|
|
@ -136,7 +136,7 @@ void MovePicker::go_next_phase() {
|
||||||
case PH_NONCAPTURES:
|
case PH_NONCAPTURES:
|
||||||
lastMove = generate_noncaptures(pos, moves);
|
lastMove = generate_noncaptures(pos, moves);
|
||||||
score_noncaptures();
|
score_noncaptures();
|
||||||
sort_moves(moves, lastMove);
|
sort_moves(moves, lastMove, &lastGoodNonCapture);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case PH_BAD_CAPTURES:
|
case PH_BAD_CAPTURES:
|
||||||
|
@ -305,6 +305,11 @@ Move MovePicker::get_next_move() {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PH_NONCAPTURES:
|
case PH_NONCAPTURES:
|
||||||
|
|
||||||
|
// Sort negative scored moves only when we get there
|
||||||
|
if (curMove == lastGoodNonCapture)
|
||||||
|
insertion_sort(lastGoodNonCapture, lastMove);
|
||||||
|
|
||||||
move = (curMove++)->move;
|
move = (curMove++)->move;
|
||||||
if ( move != ttMoves[0].move
|
if ( move != ttMoves[0].move
|
||||||
&& move != ttMoves[1].move
|
&& move != ttMoves[1].move
|
||||||
|
|
|
@ -64,7 +64,7 @@ private:
|
||||||
MoveStack ttMoves[2], killers[2];
|
MoveStack ttMoves[2], killers[2];
|
||||||
int phase;
|
int phase;
|
||||||
const uint8_t* phasePtr;
|
const uint8_t* phasePtr;
|
||||||
MoveStack *curMove, *lastMove, *lastBadCapture;
|
MoveStack *curMove, *lastMove, *lastGoodNonCapture, *lastBadCapture;
|
||||||
Bitboard pinned;
|
Bitboard pinned;
|
||||||
MoveStack moves[256], badCaptures[64];
|
MoveStack moves[256], badCaptures[64];
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue