Skip to content

Commit

Permalink
Removed unnecessary assignments
Browse files Browse the repository at this point in the history
In both search and qsearch, there are instances where we do unadjustedStaticEval = ss->staticEval = eval/bestValue = tte->eval(), but immediately after re-assign ss-static and eval/bestValue to some new value. Change is to just remove the initial assignment to ss-staticEval and eval/bestValue. One consideration, although very minor is to use the ternary operator to immediately assign unadjustedStaticEval but unsure if there is a significant performance difference between that and an if block. Also when I ran 'make format', it suggested ss-staticEval some alignment whitespace to the above line = bestValue =, but I think looks worse than just ss-staticEval = bestValue = .
  • Loading branch information
PikaCat-OuO committed Feb 11, 2024
1 parent a60e200 commit 710db7f
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,9 +597,9 @@ Value Search::Worker::search(
else if (ss->ttHit)
{
// Never assume anything about values stored in TT
unadjustedStaticEval = ss->staticEval = eval = tte->eval();
if (eval == VALUE_NONE)
unadjustedStaticEval = ss->staticEval = eval = evaluate(pos, thisThread->optimism[us]);
unadjustedStaticEval = tte->eval();
if (unadjustedStaticEval == VALUE_NONE)
unadjustedStaticEval = evaluate(pos, thisThread->optimism[us]);
else if (PvNode)
Eval::NNUE::hint_common_parent_position(pos);

Expand All @@ -611,7 +611,7 @@ Value Search::Worker::search(
}
else
{
unadjustedStaticEval = ss->staticEval = eval = evaluate(pos, thisThread->optimism[us]);
unadjustedStaticEval = evaluate(pos, thisThread->optimism[us]);
ss->staticEval = eval = to_corrected_static_eval(unadjustedStaticEval, *thisThread, pos);

// Static evaluation is saved as it was before adjustment by correction history
Expand Down Expand Up @@ -1329,9 +1329,9 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta,
if (ss->ttHit)
{
// Never assume anything about values stored in TT
if ((unadjustedStaticEval = ss->staticEval = bestValue = tte->eval()) == VALUE_NONE)
unadjustedStaticEval = ss->staticEval = bestValue =
evaluate(pos, thisThread->optimism[us]);
unadjustedStaticEval = tte->eval();
if (unadjustedStaticEval == VALUE_NONE)
unadjustedStaticEval = evaluate(pos, thisThread->optimism[us]);
ss->staticEval = bestValue =
to_corrected_static_eval(unadjustedStaticEval, *thisThread, pos);

Expand All @@ -1343,10 +1343,10 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta,
else
{
// In case of null move search, use previous static eval with a different sign
unadjustedStaticEval = ss->staticEval = bestValue =
(ss - 1)->currentMove != Move::null() ? evaluate(pos, thisThread->optimism[us])
: -(ss - 1)->staticEval;
ss->staticEval = bestValue =
unadjustedStaticEval = (ss - 1)->currentMove != Move::null()
? evaluate(pos, thisThread->optimism[us])
: -(ss - 1)->staticEval;
ss->staticEval = bestValue =
to_corrected_static_eval(unadjustedStaticEval, *thisThread, pos);
}

Expand Down

0 comments on commit 710db7f

Please sign in to comment.