Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ddugovic committed Jun 15, 2023
2 parents 0c39dd7 + 32d3284 commit a6d752b
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/stockfish_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ jobs:

- name: Extract the bench number from the commit history
run: |
git log HEAD | grep "\b[Bb]ench[ :]\+[0-9]\{7\}" | head -n 1 | sed "s/[^0-9]*\([0-9]*\).*/\1/g" > git_sig
git log HEAD | grep -o "\b[Bb]ench[ :]\+[1-9][0-9]\{5,9\}\b" | head -n 1 | sed "s/[^0-9]//g" > git_sig
[ -s git_sig ] && echo "benchref=$(cat git_sig)" >> $GITHUB_ENV && echo "Reference bench:" $(cat git_sig) || echo "No bench found"
- name: Check compiler
Expand Down
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Alexander Kure
Alexander Pagel (Lolligerhans)
Alfredo Menezes (lonfom169)
Ali AlZhrani (Cooffe)
Andreas Matthies (Matthies)
Andrei Vetrov (proukornew)
Andrew Grant (AndyGrant)
Andrey Neporada (nepal)
Expand Down Expand Up @@ -216,6 +217,7 @@ tttak
Unai Corzo (unaiic)
Uri Blass (uriblass)
Vince Negri (cuddlestmonkey)
Viren
windfishballad
xefoci7612
zz4032
Expand Down
2 changes: 1 addition & 1 deletion src/evaluate.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace Eval {
// The default net name MUST follow the format nn-[SHA256 first 12 digits].nnue
// for the build process (profile-build and fishtest) to work. Do not change the
// name of the macro, as it is used in the Makefile.
#define EvalFileDefaultName "nn-fdc1d0fe6455.nnue"
#define EvalFileDefaultName "nn-cd2ff4716c34.nnue"

namespace NNUE {

Expand Down
4 changes: 2 additions & 2 deletions src/nnue/layers/affine_transform_sparse_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ namespace Stockfish::Eval::NNUE::Layers {
#define vec_nnz(a) _mm512_cmpgt_epi32_mask(a, _mm512_setzero_si512())
#elif defined (USE_AVX2)
using vec_t = __m256i;
#define vec_nnz(a) _mm256_movemask_ps((__m256)_mm256_cmpgt_epi32(a, _mm256_setzero_si256()))
#define vec_nnz(a) _mm256_movemask_ps(_mm256_castsi256_ps(_mm256_cmpgt_epi32(a, _mm256_setzero_si256())))
#elif defined (USE_SSSE3)
using vec_t = __m128i;
#define vec_nnz(a) _mm_movemask_ps((__m128)_mm_cmpgt_epi32(a, _mm_setzero_si128()))
#define vec_nnz(a) _mm_movemask_ps(_mm_castsi128_ps(_mm_cmpgt_epi32(a, _mm_setzero_si128())))
#endif
constexpr IndexType InputSimdWidth = sizeof(vec_t) / sizeof(std::int32_t);
// Inputs are processed InputSimdWidth at a time and outputs are processed 8 at a time so we process in chunks of max(InputSimdWidth, 8)
Expand Down
175 changes: 88 additions & 87 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1591,7 +1591,6 @@ namespace {
// Step 4. Static evaluation of the position
if (ss->inCheck)
{
ss->staticEval = VALUE_NONE;
bestValue = futilityBase = -VALUE_INFINITE;
}
else
Expand All @@ -1608,10 +1607,11 @@ namespace {
bestValue = ttValue;
}
else
{
// In case of null move search use previous static eval with a different sign
ss->staticEval = bestValue =
(ss-1)->currentMove != MOVE_NULL ? evaluate(pos)
: -(ss-1)->staticEval;
ss->staticEval = bestValue = (ss-1)->currentMove != MOVE_NULL ? evaluate(pos)
: -(ss-1)->staticEval;
}

// Stand pat. Return immediately if static value is at least beta
if (bestValue >= beta)
Expand Down Expand Up @@ -1650,120 +1650,121 @@ namespace {
// or a beta cutoff occurs.
while ((move = mp.next_move()) != MOVE_NONE)
{
assert(is_ok(move));
assert(is_ok(move));

// Check for legality
if (!pos.legal(move))
continue;
// Check for legality
if (!pos.legal(move))
continue;

givesCheck = pos.gives_check(move);
capture = pos.capture_stage(move);
givesCheck = pos.gives_check(move);
capture = pos.capture_stage(move);

moveCount++;
moveCount++;

// Step 6. Pruning.
if (bestValue > VALUE_TB_LOSS_IN_MAX_PLY)
{
// Futility pruning and moveCount pruning (~10 Elo)
if ( !givesCheck
// Step 6. Pruning.
if (bestValue > VALUE_TB_LOSS_IN_MAX_PLY)
{
// Futility pruning and moveCount pruning (~10 Elo)
if ( !givesCheck
#ifdef EXTINCTION
&& !pos.is_extinction()
&& !pos.is_extinction()
#endif
#ifdef RACE
&& !(pos.is_race() && type_of(pos.piece_on(from_sq(move))) == KING && rank_of(to_sq(move)) == RANK_8)
&& !(pos.is_race() && type_of(pos.piece_on(from_sq(move))) == KING && rank_of(to_sq(move)) == RANK_8)
#endif
#ifdef HELPMATE
&& !pos.is_helpmate()
&& !pos.is_helpmate()
#endif
&& to_sq(move) != prevSq
&& futilityBase > -VALUE_KNOWN_WIN
&& type_of(move) != PROMOTION)
{
if (moveCount > 2)
continue;
&& to_sq(move) != prevSq
&& futilityBase > -VALUE_KNOWN_WIN
&& type_of(move) != PROMOTION)
{
if (moveCount > 2)
continue;

#ifdef ATOMIC
if (pos.is_atomic())
futilityValue = futilityBase + pos.see<ATOMIC_VARIANT>(move);
else
if (pos.is_atomic())
futilityValue = futilityBase + pos.see<ATOMIC_VARIANT>(move);
else
#endif
#ifdef CRAZYHOUSE
if (pos.is_house())
futilityValue = futilityBase + 2 * PieceValue[CRAZYHOUSE_VARIANT][EG][pos.piece_on(to_sq(move))];
else
if (pos.is_house())
futilityValue = futilityBase + 2 * PieceValue[CRAZYHOUSE_VARIANT][EG][pos.piece_on(to_sq(move))];
else
#endif
futilityValue = futilityBase + PieceValue[pos.variant()][EG][pos.piece_on(to_sq(move))];
futilityValue = futilityBase + PieceValue[pos.variant()][EG][pos.piece_on(to_sq(move))];

if (futilityValue <= alpha)
{
bestValue = std::max(bestValue, futilityValue);
continue;
}
if (futilityValue <= alpha)
{
bestValue = std::max(bestValue, futilityValue);
continue;
}

if (futilityBase <= alpha && !pos.see_ge(move, VALUE_ZERO + 1))
{
bestValue = std::max(bestValue, futilityBase);
continue;
}
}
if (futilityBase <= alpha && !pos.see_ge(move, VALUE_ZERO + 1))
{
bestValue = std::max(bestValue, futilityBase);
continue;
}
}

// We prune after 2nd quiet check evasion where being 'in check' is implicitly checked through the counter
// and being a 'quiet' apart from being a tt move is assumed after an increment because captures are pushed ahead.
if (quietCheckEvasions > 1)
break;
// We prune after the second quiet check evasion move, where being 'in check' is
// implicitly checked through the counter, and being a 'quiet move' apart from
// being a tt move is assumed after an increment because captures are pushed ahead.
if (quietCheckEvasions > 1)
break;

// Continuation history based pruning (~3 Elo)
if ( !capture
&& (*contHist[0])[pos.moved_piece(move)][to_sq(move)] < 0
&& (*contHist[1])[pos.moved_piece(move)][to_sq(move)] < 0)
continue;
// Continuation history based pruning (~3 Elo)
if ( !capture
&& (*contHist[0])[pos.moved_piece(move)][to_sq(move)] < 0
&& (*contHist[1])[pos.moved_piece(move)][to_sq(move)] < 0)
continue;

// Do not search moves with bad enough SEE values (~5 Elo)
if (!pos.see_ge(move, Value(-95)))
continue;
}
// Do not search moves with bad enough SEE values (~5 Elo)
if (!pos.see_ge(move, Value(-95)))
continue;
}

// Speculative prefetch as early as possible
prefetch(TT.first_entry(pos.key_after(move)));
// Speculative prefetch as early as possible
prefetch(TT.first_entry(pos.key_after(move)));

// Update the current move
ss->currentMove = move;
ss->continuationHistory = &thisThread->continuationHistory[ss->inCheck]
[capture]
[pos.moved_piece(move)]
[to_sq(move)];
// Update the current move
ss->currentMove = move;
ss->continuationHistory = &thisThread->continuationHistory[ss->inCheck]
[capture]
[pos.moved_piece(move)]
[to_sq(move)];

quietCheckEvasions += !capture && ss->inCheck;
quietCheckEvasions += !capture && ss->inCheck;

// Step 7. Make and search the move
pos.do_move(move, st, givesCheck);
value = -qsearch<nodeType>(pos, ss+1, -beta, -alpha, depth - 1);
// Step 7. Make and search the move
pos.do_move(move, st, givesCheck);
value = -qsearch<nodeType>(pos, ss+1, -beta, -alpha, depth - 1);
#ifdef HELPMATE
if (pos.is_helpmate())
value = -value;
if (pos.is_helpmate())
value = -value;
#endif
pos.undo_move(move);
pos.undo_move(move);

assert(value > -VALUE_INFINITE && value < VALUE_INFINITE);
assert(value > -VALUE_INFINITE && value < VALUE_INFINITE);

// Step 8. Check for a new best move
if (value > bestValue)
{
bestValue = value;
// Step 8. Check for a new best move
if (value > bestValue)
{
bestValue = value;

if (value > alpha)
{
bestMove = move;
if (value > alpha)
{
bestMove = move;

if (PvNode) // Update pv even in fail-high case
update_pv(ss->pv, move, (ss+1)->pv);
if (PvNode) // Update pv even in fail-high case
update_pv(ss->pv, move, (ss+1)->pv);

if (PvNode && value < beta) // Update alpha here!
alpha = value;
else
break; // Fail high
}
}
if (PvNode && value < beta) // Update alpha here!
alpha = value;
else
break; // Fail high
}
}
}

// Step 9. Check for mate
Expand Down

0 comments on commit a6d752b

Please sign in to comment.