summaryrefslogtreecommitdiff
path: root/src/searchsup.c
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2026-10-09 14:18:52 -0700
committerScott Gasch <[email protected]>2026-10-09 14:18:52 -0700
commitfbdcb9d76dd2444d8bc631331eaeb9435cc247f8 (patch)
tree602ab360462d6f23188ba51f962c4abb2dc6c7e5 /src/searchsup.c
parent73b4afb12abf7cc442831dea42b41b63a2ce07be (diff)
* Grab bag of eval.c changes.
* Don't bother not hashing when moves are pruned. * Prune moves move librerally with LMP. Inexplicably, this is slightly shallower than HEAD (despite pruning MORE). It may be because it is slightly slower. It consistently beats HEAD in match_play.py though (3x now).
Diffstat (limited to 'src/searchsup.c')
-rw-r--r--src/searchsup.c90
1 files changed, 40 insertions, 50 deletions
diff --git a/src/searchsup.c b/src/searchsup.c
index 726bc9f..69c87a2 100644
--- a/src/searchsup.c
+++ b/src/searchsup.c
@@ -631,7 +631,6 @@ _FlatTableExtraPlies(IN ULONG uRemainingDepth, IN ULONG uMoveNum)
ULONG uMoveIdx = MINU(uMoveNum, LMR_TABLE_MAX_MOVES);
SCORE iTotalTicks = g_iLMRQuietReduction[uDepthIdx][uMoveIdx];
SCORE iExtraTicks = iTotalTicks - ONE_PLY;
-
if (iExtraTicks <= 0)
{
return 0;
@@ -854,10 +853,6 @@ Return value:
ASSERT(!InCheck(&ctx->sPosition, ctx->sPosition.uToMove));
ULONG uExtraPlies = 0;
- if (NULL != puExtraTier)
- {
- *puExtraTier = 0;
- }
#ifdef DISABLE_LMR
// See GNUmakefile's DISABLE_LMR comment. Bail before any signal is
// consulted so the no-LMR arm is a clean control: no reduction, and
@@ -889,37 +884,43 @@ Return value:
}
if (FALSE == fBaseEligible)
{
+ if (NULL != puExtraTier)
+ {
+ *puExtraTier = 0;
+ }
return(0);
}
// We are going to reduce it; let's see if we want to pile on extra
// reduction because we're pretty sure it's "safe".
- uExtraPlies = (fBaseEligible && (FALSE == fDynamicDanger)) ?
+ uExtraPlies = ((FALSE == fDynamicDanger)) ?
_FlatTableExtraPlies(uRemainingDepth, uLegalMoves) : 0;
// Clamp. Combine with the baseline -ONE_PLY and floor the total
// so it never leaves less than JOINT_EXTRA_MIN_REMAINING_DEPTH
// remaining -- never rely on the move loop's own unsigned-
// wraparound clamp to do this implicitly.
- iLocalExtend = iExtend + (-ONE_PLY);
+ //
+ // iExtend is guaranteed 0 here (see routine description; the sole
+ // caller asserts this itself at search.c:1416 right after a
+ // reduction comes back), so iLocalExtend is always exactly
+ // -ONE_PLY -- no need to fold a variable iExtend into it.
+ ASSERT(0 == iExtend);
+ iLocalExtend = -ONE_PLY;
if (uExtraPlies > 0)
{
- INT iMaxExtra =
- ((INT)uRemainingDepth - (INT)ONE_PLY + iLocalExtend -
- (INT)JOINT_EXTRA_MIN_REMAINING_DEPTH) /
- (INT)ONE_PLY;
- if (iMaxExtra < 0)
- {
- iMaxExtra = 0;
- }
- if ((INT)uExtraPlies > iMaxExtra)
- {
- uExtraPlies = (ULONG)iMaxExtra;
- }
- if (uExtraPlies > JOINT_EXTRA_MAX_PLIES)
- {
- uExtraPlies = JOINT_EXTRA_MAX_PLIES;
- }
+ // MAX0 branchlessly floors the numerator at 0 before the
+ // divide (it can go negative when uRemainingDepth is small),
+ // so uMaxExtra is safely non-negative going into MINU -- both
+ // macros need their inputs' high-order bit clear, true here
+ // since none of uRemainingDepth/ONE_PLY/JOINT_EXTRA_MAX_PLIES
+ // come anywhere near 2^31.
+ INT iExtraNumerator =
+ (INT)uRemainingDepth - 2 * (INT)ONE_PLY -
+ (INT)JOINT_EXTRA_MIN_REMAINING_DEPTH;
+ ULONG uMaxExtra = (ULONG)MAX0(iExtraNumerator) / (ULONG)ONE_PLY;
+ uExtraPlies = MINU(uExtraPlies, uMaxExtra);
+ uExtraPlies = MINU(uExtraPlies, (ULONG)JOINT_EXTRA_MAX_PLIES);
iLocalExtend -= (INT)(uExtraPlies * ONE_PLY);
}
if (NULL != puExtraTier)
@@ -929,23 +930,11 @@ Return value:
return(iLocalExtend);
}
-#define LMP_BASE_MOVENUM (12) // never prune before this many
- // legal moves already tried
-#define LMP_PER_PLY_MOVENUM (4) // + this many moves of extra
- // slack per remaining ply
-#define LMP_STATIC_MAX_PCT_THOUSANDTHS JOINT_EXTRA_TIER3_PCT_THOUSANDTHS // the
- // strictest static tier only
- // (~p5 of real traffic)
-#define LMP_DYNAMIC_MIN_SAMPLES (1) // well-evidenced, not a guess
-// 0.100% -- near-zero observed rate. 2026-10-03 unit unification: was
-// (1) in per-mille, i.e. the same nominal 0.1%. Same truncation caveat
-// as LMR_FH_BASELINE_PCT_THOUSANDTHS above (the old `> 1` could only
-// fire at fh/attempts >= 0.002, so the shipped gate behaved like 0.2%);
-// moot in practice since LMP is disabled at its call site
-// (search.c:1228). Note this constant and LMP_STATIC_MAX_PCT_THOUSANDTHS
-// used to be the two reasons this unit mismatch was dangerous: both
-// were literally (1), 100x apart in meaning, four lines apart in this
-// same block.
+#define LMP_BASE_MOVENUM (8) // never prune before this many
+ // legal moves already tried
+#define LMP_PER_PLY_MOVENUM (1) // + this many moves of extra
+ // slack per remaining ply
+#define LMP_DYNAMIC_MIN_SAMPLES (1) // well-evidenced, not a guess
#define LMP_DYNAMIC_MAX_PCT_THOUSANDTHS (1)
@@ -1008,17 +997,22 @@ Return value:
**/
{
- ULONG uMoveNumFloor;
-
+ static ULONG uLMPStaticMaxPctThousandths[] = {
+ 200, 200, 125, 75, 36, 12, 6, 3, 2, 1, 0
+ };
ASSERT(ctx->uPly > 0);
+ ASSERT(IS_VALID_DEPTH(uRemainingDepth));
+ ULONG uRemainingPlies = uRemainingDepth / ONE_PLY;
- // Only consider very late moves.
- uMoveNumFloor = LMP_BASE_MOVENUM +
- (LMP_PER_PLY_MOVENUM * (uRemainingDepth / ONE_PLY));
+#if 0
+ // Only consider very late moves -- removed on the rationale that
+ // the 4D FH% table already takes move lateness into account.
+ ULONG uMoveNumFloor = LMP_BASE_MOVENUM + uRemainingPlies;
if (uLegalMoves <= uMoveNumFloor)
{
return FALSE;
}
+#endif
// Dynamic signal: if there's real, well-evidenced history on this
// exact move identity and it's not essentially zero, don't
@@ -1029,12 +1023,8 @@ Return value:
return FALSE;
}
- // Static signal: must have real data AND be in the strictest
- // (safest) tier -- no data (sentinel) is a reason to NOT gamble
- // on overt pruning, unlike GetLMRReduction's more permissive
- // treatment of that case for mere reduction.
if ((JOINT_TABLE_SENTINEL == uPredictedFH) ||
- (uPredictedFH >= LMP_STATIC_MAX_PCT_THOUSANDTHS))
+ (uPredictedFH >= uLMPStaticMaxPctThousandths[MINU(uRemainingPlies, 10)]))
{
return FALSE;
}