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>
// Our dedicated sort in range [firstMove, lastMove), first splits
// positive scores from ramining then order seaprately the two sets.
template<typename T>
// Our dedicated sort in range [firstMove, lastMove), first splits
// positive scores from ramining then order seaprately the two sets.
template<typename T>
-inline void sort_moves(T* firstMove, T* lastMove)
+inline void sort_moves(T* firstMove, T* lastMove, T** lastPositive)
- // 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);
}
// Picks up the best move in range [curMove, lastMove), one per cycle.
}
// Picks up the best move in range [curMove, lastMove), one per cycle.
case PH_NONCAPTURES:
lastMove = generate_noncaptures(pos, moves);
score_noncaptures();
case PH_NONCAPTURES:
lastMove = generate_noncaptures(pos, moves);
score_noncaptures();
- sort_moves(moves, lastMove);
+ sort_moves(moves, lastMove, &lastGoodNonCapture);
return;
case PH_BAD_CAPTURES:
return;
case PH_BAD_CAPTURES:
break;
case PH_NONCAPTURES:
break;
case PH_NONCAPTURES:
+
+ // Sort negative scored moves only when we get there
+ if (curMove == lastGoodNonCapture)
+ insertion_sort(lastGoodNonCapture, lastMove);
+
move = (curMove++)->move;
if ( move != ttMoves[0].move
&& move != ttMoves[1].move
move = (curMove++)->move;
if ( move != ttMoves[0].move
&& move != ttMoves[1].move
MoveStack ttMoves[2], killers[2];
int phase;
const uint8_t* phasePtr;
MoveStack ttMoves[2], killers[2];
int phase;
const uint8_t* phasePtr;
- MoveStack *curMove, *lastMove, *lastBadCapture;
+ MoveStack *curMove, *lastMove, *lastGoodNonCapture, *lastBadCapture;
Bitboard pinned;
MoveStack moves[256], badCaptures[64];
};
Bitboard pinned;
MoveStack moves[256], badCaptures[64];
};