1
0
Fork 0

Movepicker: take move's loop out of switch statement

This not only cleans up the code but gives another
speed boost of 1.8%

From revision 595a90dfd0 we have increased pgo compiled binary
speed of a whopping +5.2% without any functional change !!

This is really awsome considering that we have also
cut line count by 25 lines.

Sometime we spend days for getting an extra 1% from move
generation while instead the biggest optimizations come
from anonymous and apparently dull parts of the code.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
sf_2.3.1_base
Marco Costalba 2009-08-30 09:42:55 +01:00
parent e9de96f0e4
commit 607ac0687a
1 changed files with 29 additions and 43 deletions

View File

@ -150,6 +150,7 @@ void MovePicker::go_next_phase() {
return;
case PH_STOP:
lastMove = curMove + 1; // hack to be friendly for get_next_move()
return;
default:
@ -247,24 +248,23 @@ Move MovePicker::get_next_move() {
assert(!pos.is_check() || *phasePtr == PH_EVASIONS || *phasePtr == PH_STOP);
assert( pos.is_check() || *phasePtr != PH_EVASIONS);
Move move;
while (true)
{
switch (phase) {
while (curMove != lastMove)
{
move = (curMove++)->move;
case PH_TT_MOVES:
while (curMove != lastMove)
{
Move move = (curMove++)->move;
switch (phase) {
case PH_TT_MOVES:
if ( move != MOVE_NONE
&& move_is_legal(pos, move, pinned))
return move;
}
break;
break;
case PH_GOOD_CAPTURES:
while (curMove != lastMove)
{
Move move = (curMove++)->move;
case PH_GOOD_CAPTURES:
if ( move != ttMoves[0].move
&& move != ttMoves[1].move
&& pos.pl_move_is_legal(move, pinned))
@ -280,59 +280,45 @@ Move MovePicker::get_next_move() {
badCaptures[numOfBadCaptures].move = move;
badCaptures[numOfBadCaptures++].score = seeValue;
}
}
break;
break;
case PH_KILLERS:
while (curMove != lastMove)
{
Move move = (curMove++)->move;
case PH_KILLERS:
if ( move != MOVE_NONE
&& move != ttMoves[0].move
&& move != ttMoves[1].move
&& move_is_legal(pos, move, pinned)
&& !pos.move_is_capture(move))
return move;
}
break;
break;
case PH_NONCAPTURES:
while (curMove != lastMove)
{
Move move = (curMove++)->move;
case PH_NONCAPTURES:
if ( move != ttMoves[0].move
&& move != ttMoves[1].move
&& move != killers[0].move
&& move != killers[1].move
&& pos.pl_move_is_legal(move, pinned))
return move;
}
break;
break;
case PH_EVASIONS:
case PH_BAD_CAPTURES:
if (curMove != lastMove)
return (curMove++)->move;
break;
case PH_EVASIONS:
case PH_BAD_CAPTURES:
return move;
case PH_QCAPTURES:
case PH_QCHECKS:
while (curMove != lastMove)
{
Move move = (curMove++)->move;
case PH_QCAPTURES:
case PH_QCHECKS:
// Maybe postpone the legality check until after futility pruning?
if ( move != ttMoves[0].move
&& pos.pl_move_is_legal(move, pinned))
return move;
break;
case PH_STOP:
return MOVE_NONE;
default:
assert(false);
break;
}
break;
case PH_STOP:
return MOVE_NONE;
default:
assert(false);
break;
}
go_next_phase();
}