Merge commit 'b0287dcb1c436887075962b596cf2068d2ca9ba8' into cluster

This is the last commit before there are more conflicts.
This commit is contained in:
Steinar H. Gunderson
2025-12-24 15:23:14 +01:00
5 changed files with 135 additions and 110 deletions
+11 -11
View File
@@ -46,7 +46,7 @@ int Eval::simple_eval(const Position& pos, Color c) {
bool Eval::use_smallnet(const Position& pos) {
int simpleEval = simple_eval(pos, pos.side_to_move());
return std::abs(simpleEval) > 1018 + 5 * pos.count<PAWN>();
return std::abs(simpleEval) > 992 + 6 * pos.count<PAWN>();
}
// Evaluate is the evaluator for the outer world. It returns a static evaluation
@@ -66,23 +66,23 @@ Value Eval::evaluate(const Eval::NNUE::Networks& networks,
Value nnue = smallNet ? networks.small.evaluate(pos, &caches.small, true, &nnueComplexity)
: networks.big.evaluate(pos, &caches.big, true, &nnueComplexity);
// Re-evaluate the position when higher eval accuracy is worth the time spent
if (smallNet && nnue * simpleEval < 0)
{
nnue = networks.big.evaluate(pos, &caches.big, true, &nnueComplexity);
smallNet = false;
}
// Blend optimism and eval with nnue complexity and material imbalance
optimism += optimism * (nnueComplexity + std::abs(simpleEval - nnue)) / 620;
nnue -= nnue * (nnueComplexity * 5 / 3) / 32082;
// Blend optimism and eval with nnue complexity
optimism += optimism * nnueComplexity / 470;
nnue -= nnue * (nnueComplexity * 5 / 3) / 32621;
v = (nnue
* (32961 + 381 * pos.count<PAWN>() + 349 * pos.count<KNIGHT>()
+ 392 * pos.count<BISHOP>() + 649 * pos.count<ROOK>() + 1211 * pos.count<QUEEN>())
+ optimism
* (4835 + 136 * pos.count<PAWN>() + 375 * pos.count<KNIGHT>()
+ 403 * pos.count<BISHOP>() + 628 * pos.count<ROOK>() + 1124 * pos.count<QUEEN>()))
/ 36860;
int material = 200 * pos.count<PAWN>() + 350 * pos.count<KNIGHT>() + 400 * pos.count<BISHOP>()
+ 640 * pos.count<ROOK>() + 1200 * pos.count<QUEEN>();
v = (nnue * (34000 + material + 135 * pos.count<PAWN>())
+ optimism * (4400 + material + 99 * pos.count<PAWN>()))
/ 35967;
// Damp down the evaluation linearly when shuffling
v = v * (204 - pos.rule50_count()) / 208;
+3 -3
View File
@@ -415,14 +415,14 @@ void start_logger(const std::string& fname) { Logger::start(fname); }
#ifdef NO_PREFETCH
void prefetch(void*) {}
void prefetch(const void*) {}
#else
void prefetch(void* addr) {
void prefetch(const void* addr) {
#if defined(_MSC_VER)
_mm_prefetch((char*) addr, _MM_HINT_T0);
_mm_prefetch((char const*) addr, _MM_HINT_T0);
#else
__builtin_prefetch(addr);
#endif
+1 -1
View File
@@ -40,7 +40,7 @@ std::string compiler_info();
// Preloads the given address in L1/L2 cache. This is a non-blocking
// function that doesn't stall the CPU waiting for data to be loaded from memory,
// which can be quite slow.
void prefetch(void* addr);
void prefetch(const void* addr);
void start_logger(const std::string& fname);
void* std_aligned_alloc(size_t alignment, size_t size);
+54 -26
View File
@@ -55,14 +55,14 @@ using psqt_vec_t = __m256i;
#define vec_store(a, b) _mm512_store_si512(a, b)
#define vec_add_16(a, b) _mm512_add_epi16(a, b)
#define vec_sub_16(a, b) _mm512_sub_epi16(a, b)
#define vec_mul_16(a, b) _mm512_mullo_epi16(a, b)
#define vec_mulhi_16(a, b) _mm512_mulhi_epi16(a, b)
#define vec_zero() _mm512_setzero_epi32()
#define vec_set_16(a) _mm512_set1_epi16(a)
#define vec_max_16(a, b) _mm512_max_epi16(a, b)
#define vec_min_16(a, b) _mm512_min_epi16(a, b)
#define vec_slli_16(a, b) _mm512_slli_epi16(a, b)
// Inverse permuted at load time
#define vec_msb_pack_16(a, b) \
_mm512_packs_epi16(_mm512_srli_epi16(a, 7), _mm512_srli_epi16(b, 7))
#define vec_packus_16(a, b) _mm512_packus_epi16(a, b)
#define vec_load_psqt(a) _mm256_load_si256(a)
#define vec_store_psqt(a, b) _mm256_store_si256(a, b)
#define vec_add_psqt_32(a, b) _mm256_add_epi32(a, b)
@@ -78,14 +78,14 @@ using psqt_vec_t = __m256i;
#define vec_store(a, b) _mm256_store_si256(a, b)
#define vec_add_16(a, b) _mm256_add_epi16(a, b)
#define vec_sub_16(a, b) _mm256_sub_epi16(a, b)
#define vec_mul_16(a, b) _mm256_mullo_epi16(a, b)
#define vec_mulhi_16(a, b) _mm256_mulhi_epi16(a, b)
#define vec_zero() _mm256_setzero_si256()
#define vec_set_16(a) _mm256_set1_epi16(a)
#define vec_max_16(a, b) _mm256_max_epi16(a, b)
#define vec_min_16(a, b) _mm256_min_epi16(a, b)
#define vec_slli_16(a, b) _mm256_slli_epi16(a, b)
// Inverse permuted at load time
#define vec_msb_pack_16(a, b) \
_mm256_packs_epi16(_mm256_srli_epi16(a, 7), _mm256_srli_epi16(b, 7))
#define vec_packus_16(a, b) _mm256_packus_epi16(a, b)
#define vec_load_psqt(a) _mm256_load_si256(a)
#define vec_store_psqt(a, b) _mm256_store_si256(a, b)
#define vec_add_psqt_32(a, b) _mm256_add_epi32(a, b)
@@ -101,12 +101,13 @@ using psqt_vec_t = __m128i;
#define vec_store(a, b) *(a) = (b)
#define vec_add_16(a, b) _mm_add_epi16(a, b)
#define vec_sub_16(a, b) _mm_sub_epi16(a, b)
#define vec_mul_16(a, b) _mm_mullo_epi16(a, b)
#define vec_mulhi_16(a, b) _mm_mulhi_epi16(a, b)
#define vec_zero() _mm_setzero_si128()
#define vec_set_16(a) _mm_set1_epi16(a)
#define vec_max_16(a, b) _mm_max_epi16(a, b)
#define vec_min_16(a, b) _mm_min_epi16(a, b)
#define vec_msb_pack_16(a, b) _mm_packs_epi16(_mm_srli_epi16(a, 7), _mm_srli_epi16(b, 7))
#define vec_slli_16(a, b) _mm_slli_epi16(a, b)
#define vec_packus_16(a, b) _mm_packus_epi16(a, b)
#define vec_load_psqt(a) (*(a))
#define vec_store_psqt(a, b) *(a) = (b)
#define vec_add_psqt_32(a, b) _mm_add_epi32(a, b)
@@ -122,17 +123,13 @@ using psqt_vec_t = int32x4_t;
#define vec_store(a, b) *(a) = (b)
#define vec_add_16(a, b) vaddq_s16(a, b)
#define vec_sub_16(a, b) vsubq_s16(a, b)
#define vec_mul_16(a, b) vmulq_s16(a, b)
#define vec_mulhi_16(a, b) vqdmulhq_s16(a, b)
#define vec_zero() vec_t{0}
#define vec_set_16(a) vdupq_n_s16(a)
#define vec_max_16(a, b) vmaxq_s16(a, b)
#define vec_min_16(a, b) vminq_s16(a, b)
inline vec_t vec_msb_pack_16(vec_t a, vec_t b) {
const int8x8_t shifta = vshrn_n_s16(a, 7);
const int8x8_t shiftb = vshrn_n_s16(b, 7);
const int8x16_t compacted = vcombine_s8(shifta, shiftb);
return *reinterpret_cast<const vec_t*>(&compacted);
}
#define vec_slli_16(a, b) vshlq_s16(a, vec_set_16(b))
#define vec_packus_16(a, b) reinterpret_cast<vec_t>(vcombine_u8(vqmovun_s16(a), vqmovun_s16(b)))
#define vec_load_psqt(a) (*(a))
#define vec_store_psqt(a, b) *(a) = (b)
#define vec_add_psqt_32(a, b) vaddq_s32(a, b)
@@ -279,6 +276,19 @@ class FeatureTransformer {
#endif
}
inline void scale_weights(bool read) const {
for (IndexType j = 0; j < InputDimensions; ++j)
{
WeightType* w = const_cast<WeightType*>(&weights[j * HalfDimensions]);
for (IndexType i = 0; i < HalfDimensions; ++i)
w[i] = read ? w[i] * 2 : w[i] / 2;
}
BiasType* b = const_cast<BiasType*>(biases);
for (IndexType i = 0; i < HalfDimensions; ++i)
b[i] = read ? b[i] * 2 : b[i] / 2;
}
// Read network parameters
bool read_parameters(std::istream& stream) {
@@ -287,6 +297,7 @@ class FeatureTransformer {
read_leb_128<PSQTWeightType>(stream, psqtWeights, PSQTBuckets * InputDimensions);
permute_weights(inverse_order_packs);
scale_weights(true);
return !stream.fail();
}
@@ -294,12 +305,14 @@ class FeatureTransformer {
bool write_parameters(std::ostream& stream) const {
permute_weights(order_packs);
scale_weights(false);
write_leb_128<BiasType>(stream, biases, HalfDimensions);
write_leb_128<WeightType>(stream, weights, HalfDimensions * InputDimensions);
write_leb_128<PSQTWeightType>(stream, psqtWeights, PSQTBuckets * InputDimensions);
permute_weights(inverse_order_packs);
scale_weights(true);
return !stream.fail();
}
@@ -330,7 +343,7 @@ class FeatureTransformer {
constexpr IndexType NumOutputChunks = HalfDimensions / 2 / OutputChunkSize;
const vec_t Zero = vec_zero();
const vec_t One = vec_set_16(127);
const vec_t One = vec_set_16(127 * 2);
const vec_t* in0 = reinterpret_cast<const vec_t*>(&(accumulation[perspectives[p]][0]));
const vec_t* in1 =
@@ -339,15 +352,30 @@ class FeatureTransformer {
for (IndexType j = 0; j < NumOutputChunks; ++j)
{
const vec_t sum0a = vec_max_16(vec_min_16(in0[j * 2 + 0], One), Zero);
const vec_t sum0b = vec_max_16(vec_min_16(in0[j * 2 + 1], One), Zero);
const vec_t sum1a = vec_max_16(vec_min_16(in1[j * 2 + 0], One), Zero);
const vec_t sum1b = vec_max_16(vec_min_16(in1[j * 2 + 1], One), Zero);
// What we want to do is multiply inputs in a pairwise manner (after clipping), and then shift right by 9.
// Instead, we shift left by 7, and use mulhi, stripping the bottom 16 bits, effectively shifting right by 16,
// resulting in a net shift of 9 bits. We use mulhi because it maintains the sign of the multiplication (unlike mullo),
// allowing us to make use of packus to clip 2 of the inputs, resulting in a save of 2 "vec_max_16" calls.
// A special case is when we use NEON, where we shift left by 6 instead, because the instruction "vqdmulhq_s16"
// also doubles the return value after the multiplication, adding an extra shift to the left by 1, so we
// compensate by shifting less before the multiplication.
const vec_t pa = vec_mul_16(sum0a, sum1a);
const vec_t pb = vec_mul_16(sum0b, sum1b);
#if defined(USE_SSE2)
constexpr int shift = 7;
#else
constexpr int shift = 6;
#endif
const vec_t sum0a =
vec_slli_16(vec_max_16(vec_min_16(in0[j * 2 + 0], One), Zero), shift);
const vec_t sum0b =
vec_slli_16(vec_max_16(vec_min_16(in0[j * 2 + 1], One), Zero), shift);
const vec_t sum1a = vec_min_16(in1[j * 2 + 0], One);
const vec_t sum1b = vec_min_16(in1[j * 2 + 1], One);
out[j] = vec_msb_pack_16(pa, pb);
const vec_t pa = vec_mulhi_16(sum0a, sum1a);
const vec_t pb = vec_mulhi_16(sum0b, sum1b);
out[j] = vec_packus_16(pa, pb);
}
#else
@@ -357,9 +385,9 @@ class FeatureTransformer {
BiasType sum0 = accumulation[static_cast<int>(perspectives[p])][j + 0];
BiasType sum1 =
accumulation[static_cast<int>(perspectives[p])][j + HalfDimensions / 2];
sum0 = std::clamp<BiasType>(sum0, 0, 127);
sum1 = std::clamp<BiasType>(sum1, 0, 127);
output[offset + j] = static_cast<OutputType>(unsigned(sum0 * sum1) / 128);
sum0 = std::clamp<BiasType>(sum0, 0, 127 * 2);
sum1 = std::clamp<BiasType>(sum1, 0, 127 * 2);
output[offset + j] = static_cast<OutputType>(unsigned(sum0 * sum1) / 512);
}
#endif
+66 -69
View File
@@ -61,9 +61,9 @@ static constexpr double EvalLevel[10] = {0.981, 0.956, 0.895, 0.949, 0.913,
// Futility margin
Value futility_margin(Depth d, bool noTtCutNode, bool improving, bool oppWorsening) {
Value futilityMult = 127 - 48 * noTtCutNode;
Value improvingDeduction = 65 * improving * futilityMult / 32;
Value worseningDeduction = 334 * oppWorsening * futilityMult / 1024;
Value futilityMult = 129 - 43 * noTtCutNode;
Value improvingDeduction = 56 * improving * futilityMult / 32;
Value worseningDeduction = 336 * oppWorsening * futilityMult / 1024;
return futilityMult * d - improvingDeduction - worseningDeduction;
}
@@ -75,15 +75,15 @@ constexpr int futility_move_count(bool improving, Depth depth) {
// Add correctionHistory value to raw staticEval and guarantee evaluation does not hit the tablebase range
Value to_corrected_static_eval(Value v, const Worker& w, const Position& pos) {
auto cv = w.correctionHistory[pos.side_to_move()][pawn_structure_index<Correction>(pos)];
v += cv * std::abs(cv) / 6047;
v += cv * std::abs(cv) / 5435;
return std::clamp(v, VALUE_TB_LOSS_IN_MAX_PLY + 1, VALUE_TB_WIN_IN_MAX_PLY - 1);
}
// History and stats update bonus, based on depth
int stat_bonus(Depth d) { return std::clamp(187 * d - 288, 17, 1548); }
int stat_bonus(Depth d) { return std::clamp(205 * d - 283, 18, 1544); }
// History and stats update malus, based on depth
int stat_malus(Depth d) { return (d < 4 ? 630 * d - 281 : 1741); }
int stat_malus(Depth d) { return (d < 4 ? 767 * d - 275 : 1911); }
// Add a small random component to draw evaluations to avoid 3-fold blindness
Value value_draw(size_t nodes) { return VALUE_DRAW - 1 + Value(nodes & 0x2); }
@@ -354,12 +354,12 @@ void Search::Worker::iterative_deepening() {
// Reset aspiration window starting size
Value avg = rootMoves[pvIdx].averageScore;
delta = 10 + avg * avg / 9828;
delta = 9 + avg * avg / 10502;
alpha = std::max(avg - delta, -VALUE_INFINITE);
beta = std::min(avg + delta, VALUE_INFINITE);
// Adjust optimism based on root move's averageScore (~4 Elo)
optimism[us] = 116 * avg / (std::abs(avg) + 84);
optimism[us] = 122 * avg / (std::abs(avg) + 92);
optimism[~us] = -optimism[us];
// Start with a small aspiration window and, in the case of a fail
@@ -372,6 +372,7 @@ void Search::Worker::iterative_deepening() {
// for every four searchAgain steps (see issue #2717).
Depth adjustedDepth =
std::max(1, rootDepth - failedHighCnt - 3 * (searchAgainCounter + 1) / 4);
rootDelta = beta - alpha;
bestValue = search<Root>(rootPos, ss, alpha, beta, adjustedDepth, false);
// Bring the best move to the front. It is critical that sorting
@@ -555,7 +556,7 @@ void Search::Worker::clear() {
h->fill(-60);
for (size_t i = 1; i < reductions.size(); ++i)
reductions[i] = int((21.69 + std::log(size_t(options["Threads"])) / 2) * std::log(i));
reductions[i] = int((19.90 + std::log(size_t(options["Threads"])) / 2) * std::log(i));
refreshTable.clear(networks);
}
@@ -638,8 +639,6 @@ Value Search::Worker::search(
if (alpha >= beta)
return alpha;
}
else
thisThread->rootDelta = beta - alpha;
assert(0 <= ss->ply && ss->ply < MAX_PLY);
@@ -686,9 +685,7 @@ Value Search::Worker::search(
// Partial workaround for the graph history interaction problem
// For high rule50 counts don't produce transposition table cutoffs.
if (pos.rule50_count() < 90)
return ttValue >= beta && std::abs(ttValue) < VALUE_TB_WIN_IN_MAX_PLY
? (ttValue * 3 + beta) / 4
: ttValue;
return ttValue;
}
// Step 5. Tablebases probe
@@ -788,7 +785,7 @@ Value Search::Worker::search(
// Use static evaluation difference to improve quiet move ordering (~9 Elo)
if (((ss - 1)->currentMove).is_ok() && !(ss - 1)->inCheck && !priorCapture)
{
int bonus = std::clamp(-11 * int((ss - 1)->staticEval + ss->staticEval), -1729, 1517);
int bonus = std::clamp(-11 * int((ss - 1)->staticEval + ss->staticEval), -1592, 1390);
bonus = bonus > 0 ? 2 * bonus : bonus / 2;
thisThread->mainHistory[~us][((ss - 1)->currentMove).from_to()] << bonus;
if (type_of(pos.piece_on(prevSq)) != PAWN && ((ss - 1)->currentMove).type_of() != PROMOTION)
@@ -810,7 +807,7 @@ Value Search::Worker::search(
// Step 7. Razoring (~1 Elo)
// If eval is really low check with qsearch if it can exceed alpha, if it can't,
// return a fail low.
if (eval < alpha - 474 - 324 * depth * depth)
if (eval < alpha - 501 - 305 * depth * depth)
{
value = qsearch<NonPV>(pos, ss, alpha - 1, alpha);
if (value < alpha)
@@ -819,23 +816,23 @@ Value Search::Worker::search(
// Step 8. Futility pruning: child node (~40 Elo)
// The depth condition is important for mate finding.
if (!ss->ttPv && depth < 11
if (!ss->ttPv && depth < 12
&& eval - futility_margin(depth, cutNode && !ss->ttHit, improving, opponentWorsening)
- (ss - 1)->statScore / 252
- (ss - 1)->statScore / 248
>= beta
&& eval >= beta && eval < VALUE_TB_WIN_IN_MAX_PLY && (!ttMove || ttCapture))
return beta > VALUE_TB_LOSS_IN_MAX_PLY ? (eval + beta) / 2 : eval;
return beta > VALUE_TB_LOSS_IN_MAX_PLY ? beta + (eval - beta) / 3 : eval;
// Step 9. Null move search with verification search (~35 Elo)
if (!PvNode && (ss - 1)->currentMove != Move::null() && (ss - 1)->statScore < 15246
&& eval >= beta && ss->staticEval >= beta - 21 * depth + 366 && !excludedMove
if (!PvNode && (ss - 1)->currentMove != Move::null() && (ss - 1)->statScore < 13999
&& eval >= beta && ss->staticEval >= beta - 21 * depth + 390 && !excludedMove
&& pos.non_pawn_material(us) && ss->ply >= thisThread->nmpMinPly
&& beta > VALUE_TB_LOSS_IN_MAX_PLY)
{
assert(eval - beta >= 0);
// Null move dynamic reduction based on depth and eval
Depth R = std::min(int(eval - beta) / 152, 6) + depth / 3 + 5;
Depth R = std::min(int(eval - beta) / 177, 6) + depth / 3 + 5;
ss->currentMove = Move::null();
ss->continuationHistory = &thisThread->continuationHistory[0][0][NO_PIECE][0];
@@ -881,21 +878,19 @@ Value Search::Worker::search(
if (PvNode && !ttMove)
depth -= 3;
if (!PvNode && ss->ttHit && (tte->bound() & BOUND_UPPER) && ttValue > alpha + 5 * depth)
depth--;
// Use qsearch if depth <= 0.
if (depth <= 0)
return qsearch<PvNode ? PV : NonPV>(pos, ss, alpha, beta);
return qsearch<PV>(pos, ss, alpha, beta);
// For cutNodes without a ttMove, we decrease depth by 2 if depth is high enough.
// For cutNodes, if depth is high enough, decrease depth by 2 if there is no ttMove, or
// by 1 if there is a ttMove with an upper bound.
if (cutNode && depth >= 8 && (!ttMove || tte->bound() == BOUND_UPPER))
depth -= 1 + !ttMove;
// Step 11. ProbCut (~10 Elo)
// If we have a good enough capture (or queen promotion) and a reduced search returns a value
// much above beta, we can (almost) safely prune the previous move.
probCutBeta = beta + 176 - 65 * improving;
probCutBeta = beta + 185 - 60 * improving;
if (
!PvNode && depth > 3
&& std::abs(beta) < VALUE_TB_WIN_IN_MAX_PLY
@@ -952,7 +947,7 @@ Value Search::Worker::search(
moves_loop: // When in check, search starts here
// Step 12. A small Probcut idea, when we are in check (~4 Elo)
probCutBeta = beta + 440;
probCutBeta = beta + 361;
if (ss->inCheck && !PvNode && ttCapture && (tte->bound() & BOUND_LOWER)
&& tte->depth() >= depth - 4 && ttValue >= probCutBeta
&& std::abs(ttValue) < VALUE_TB_WIN_IN_MAX_PLY && std::abs(beta) < VALUE_TB_WIN_IN_MAX_PLY)
@@ -1036,15 +1031,15 @@ moves_loop: // When in check, search starts here
// Futility pruning for captures (~2 Elo)
if (!givesCheck && lmrDepth < 7 && !ss->inCheck)
{
Value futilityValue = ss->staticEval + 276 + 256 * lmrDepth
Value futilityValue = ss->staticEval + 283 + 235 * lmrDepth
+ PieceValue[capturedPiece] + captHist / 7;
if (futilityValue <= alpha)
continue;
}
// SEE based pruning for captures and checks (~11 Elo)
int seeHist = std::clamp(captHist / 32, -177 * depth, 175 * depth);
if (!pos.see_ge(move, -183 * depth - seeHist))
int seeHist = std::clamp(captHist / 32, -183 * depth, 162 * depth);
if (!pos.see_ge(move, -166 * depth - seeHist))
continue;
}
else
@@ -1055,18 +1050,18 @@ moves_loop: // When in check, search starts here
+ thisThread->pawnHistory[pawn_structure_index(pos)][movedPiece][move.to_sq()];
// Continuation history based pruning (~2 Elo)
if (lmrDepth < 6 && history < -4076 * depth)
if (lmrDepth < 6 && history < -4427 * depth)
continue;
history += 2 * thisThread->mainHistory[us][move.from_to()];
lmrDepth += history / 4401;
lmrDepth += history / 3670;
Value futilityValue =
ss->staticEval + (bestValue < ss->staticEval - 53 ? 151 : 57) + 140 * lmrDepth;
ss->staticEval + (bestValue < ss->staticEval - 51 ? 149 : 55) + 141 * lmrDepth;
// Futility pruning: parent node (~13 Elo)
if (!ss->inCheck && lmrDepth < 10 && futilityValue <= alpha)
if (!ss->inCheck && lmrDepth < 11 && futilityValue <= alpha)
{
if (bestValue <= futilityValue && std::abs(bestValue) < VALUE_TB_WIN_IN_MAX_PLY
&& futilityValue < VALUE_TB_WIN_IN_MAX_PLY)
@@ -1091,17 +1086,20 @@ moves_loop: // When in check, search starts here
// then that move is singular and should be extended. To verify this we do
// a reduced search on the position excluding the ttMove and if the result
// is lower than ttValue minus a margin, then we will extend the ttMove.
// Recursive singular search is avoided.
// Note: the depth margin and singularBeta margin are known for having non-linear
// scaling. Their values are optimized to time controls of 180+1.8 and longer
// so changing them requires tests at these types of time controls.
// Recursive singular search is avoided.
// Generally, higher singularBeta (i.e closer to ttValue) and lower extension
// margins scale well.
if (!rootNode && move == ttMove && !excludedMove
&& depth >= 4 - (thisThread->completedDepth > 35) + ss->ttPv
&& depth >= 4 - (thisThread->completedDepth > 38) + ss->ttPv
&& std::abs(ttValue) < VALUE_TB_WIN_IN_MAX_PLY && (tte->bound() & BOUND_LOWER)
&& tte->depth() >= depth - 3)
{
Value singularBeta = ttValue - (57 + 50 * (ss->ttPv && !PvNode)) * depth / 64;
Value singularBeta = ttValue - (58 + 64 * (ss->ttPv && !PvNode)) * depth / 64;
Depth singularDepth = newDepth / 2;
ss->excludedMove = move;
@@ -1111,16 +1109,15 @@ moves_loop: // When in check, search starts here
if (value < singularBeta)
{
int doubleMargin = 298 * PvNode - 209 * !ttCapture;
int tripleMargin =
117 + 252 * PvNode - 270 * !ttCapture + 111 * (ss->ttPv || !ttCapture);
int quadMargin = 471 + 343 * PvNode - 281 * !ttCapture + 217 * ss->ttPv;
int doubleMargin = 304 * PvNode - 203 * !ttCapture;
int tripleMargin = 117 + 259 * PvNode - 296 * !ttCapture + 97 * ss->ttPv;
int quadMargin = 486 + 343 * PvNode - 273 * !ttCapture + 232 * ss->ttPv;
extension = 1 + (value < singularBeta - doubleMargin)
+ (value < singularBeta - tripleMargin)
+ (value < singularBeta - quadMargin);
depth += ((!PvNode) && (depth < 15));
depth += ((!PvNode) && (depth < 16));
}
// Multi-cut pruning
@@ -1129,12 +1126,7 @@ moves_loop: // When in check, search starts here
// we assume this expected cut-node is not singular (multiple moves fail high),
// and we can prune the whole subtree by returning a softbound.
else if (singularBeta >= beta)
{
if (!ttCapture)
update_quiet_histories(pos, ss, *this, ttMove, -stat_malus(depth));
return singularBeta;
}
// Negative extensions
// If other moves failed high over (ttValue - margin) without the ttMove on a reduced search,
@@ -1155,7 +1147,7 @@ moves_loop: // When in check, search starts here
else if (PvNode && move == ttMove && move.to_sq() == prevSq
&& thisThread->captureHistory[movedPiece][move.to_sq()]
[type_of(pos.piece_on(move.to_sq()))]
> 3748)
> 3988)
extension = 1;
}
@@ -1176,25 +1168,30 @@ moves_loop: // When in check, search starts here
thisThread->nodes.fetch_add(1, std::memory_order_relaxed);
pos.do_move(move, st, givesCheck);
// These reduction adjustments have proven non-linear scaling.
// They are optimized to time controls of 180 + 1.8 and longer so
// changing them or adding conditions that are similar
// requires tests at these types of time controls.
// Decrease reduction if position is or has been on the PV (~7 Elo)
if (ss->ttPv)
r -= 1 + (ttValue > alpha) + (tte->depth() >= depth);
else if (cutNode && move != ttMove && move != ss->killers[0])
r++;
// Decrease reduction for PvNodes (~0 Elo on STC, ~2 Elo on LTC)
if (PvNode)
r--;
// These reduction adjustments have no proven non-linear scaling.
// Increase reduction for cut nodes (~4 Elo)
if (cutNode)
r += 2 - (tte->depth() >= depth && ss->ttPv);
r += 2 - (tte->depth() >= depth && ss->ttPv)
+ (!ss->ttPv && move != ttMove && move != ss->killers[0]);
// Increase reduction if ttMove is a capture (~3 Elo)
if (ttCapture)
r++;
// Decrease reduction for PvNodes (~0 Elo on STC, ~2 Elo on LTC)
if (PvNode)
r--;
// Increase reduction if next ply has a lot of fail high (~5 Elo)
if ((ss + 1)->cutoffCnt > 3)
r++;
@@ -1206,10 +1203,10 @@ moves_loop: // When in check, search starts here
ss->statScore = 2 * thisThread->mainHistory[us][move.from_to()]
+ (*contHist[0])[movedPiece][move.to_sq()]
+ (*contHist[1])[movedPiece][move.to_sq()] - 5266;
+ (*contHist[1])[movedPiece][move.to_sq()] - 5169;
// Decrease/increase reduction for moves with a good/bad history (~8 Elo)
r -= ss->statScore / (14519 - std::min(depth, 15) * 103);
r -= ss->statScore / (12219 - std::min(depth, 13) * 120);
// Step 17. Late moves reduction / extension (LMR, ~117 Elo)
if (depth >= 2 && moveCount > 1 + rootNode)
@@ -1228,7 +1225,7 @@ moves_loop: // When in check, search starts here
{
// Adjust full-depth search based on LMR results - if the result
// was good enough search deeper, if it was bad enough search shallower.
const bool doDeeperSearch = value > (bestValue + 40 + 2 * newDepth); // (~1 Elo)
const bool doDeeperSearch = value > (bestValue + 36 + 2 * newDepth); // (~1 Elo)
const bool doShallowerSearch = value < bestValue + newDepth; // (~2 Elo)
newDepth += doDeeperSearch - doShallowerSearch;
@@ -1389,9 +1386,9 @@ moves_loop: // When in check, search starts here
// Bonus for prior countermove that caused the fail low
else if (!priorCapture && prevSq != SQ_NONE)
{
int bonus = (depth > 4) + (depth > 5) + (PvNode || cutNode) + ((ss - 1)->statScore < -13241)
+ ((ss - 1)->moveCount > 10) + (!ss->inCheck && bestValue <= ss->staticEval - 127)
+ (!(ss - 1)->inCheck && bestValue <= -(ss - 1)->staticEval - 74);
int bonus = (depth > 4) + (depth > 5) + (PvNode || cutNode) + ((ss - 1)->statScore < -14144)
+ ((ss - 1)->moveCount > 9) + (!ss->inCheck && bestValue <= ss->staticEval - 115)
+ (!(ss - 1)->inCheck && bestValue <= -(ss - 1)->staticEval - 81);
update_continuation_histories(ss - 1, pos.piece_on(prevSq), prevSq,
stat_bonus(depth) * bonus);
thisThread->mainHistory[~us][((ss - 1)->currentMove).from_to()]
@@ -1564,7 +1561,7 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta,
if (bestValue > alpha)
alpha = bestValue;
futilityBase = ss->staticEval + 264;
futilityBase = ss->staticEval + 279;
}
const PieceToHistory* contHist[] = {(ss - 1)->continuationHistory,
@@ -1636,11 +1633,11 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta,
+ (*contHist[1])[pos.moved_piece(move)][move.to_sq()]
+ thisThread->pawnHistory[pawn_structure_index(pos)][pos.moved_piece(move)]
[move.to_sq()]
<= 4348)
<= 4181)
continue;
// Do not search moves with bad enough SEE values (~5 Elo)
if (!pos.see_ge(move, -63))
if (!pos.see_ge(move, -67))
continue;
}
@@ -1706,7 +1703,7 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta,
Depth Search::Worker::reduction(bool i, Depth d, int mn, int delta) {
int reductionScale = reductions[d] * reductions[mn];
return (reductionScale + 1147 - delta * 755 / rootDelta) / 1024 + (!i && reductionScale > 1125);
return (reductionScale + 1222 - delta * 733 / rootDelta) / 1024 + (!i && reductionScale > 1231);
}
// elapsed() returns the time elapsed since the search started. If the
@@ -1809,7 +1806,7 @@ void update_all_stats(const Position& pos,
if (!pos.capture_stage(bestMove))
{
int bestMoveBonus = bestValue > beta + 165 ? quietMoveBonus // larger bonus
int bestMoveBonus = bestValue > beta + 176 ? quietMoveBonus // larger bonus
: stat_bonus(depth); // smaller bonus
update_quiet_stats(pos, ss, workerThread, bestMove, bestMoveBonus);
@@ -1847,7 +1844,7 @@ void update_all_stats(const Position& pos,
// by moves at ply -1, -2, -3, -4, and -6 with current move.
void update_continuation_histories(Stack* ss, Piece pc, Square to, int bonus) {
bonus = bonus * 45 / 64;
bonus = bonus * 47 / 64;
for (int i : {1, 2, 3, 4, 6})
{