Better nonpawn indexing

Improves indexing scheme, by noting that both sides are likely to access the same non_pawn_index nearby.

LLR: 2.93 (-2.94,2.94) <0.00,2.00>
Total: 75936 W: 19905 L: 19554 D: 36477
Ptnml(0-2): 190, 7863, 21554, 8128, 233
https://tests.stockfishchess.org/tests/view/67904d0cfc8c306ba6cea332

closes https://github.com/official-stockfish/Stockfish/pull/5816

No functional change

Co-authored-by: Andrew Grant <andrew.github@grantnet.us>
This commit is contained in:
Shawn Xu
2025-01-21 17:41:33 -08:00
committed by Joost VandeVondele
parent 435ba3dbb5
commit 889fed448c
2 changed files with 10 additions and 5 deletions

View File

@@ -138,7 +138,7 @@ enum CorrHistType {
Pawn, // By color and pawn structure Pawn, // By color and pawn structure
Major, // By color and positions of major pieces (Queen, Rook) and King Major, // By color and positions of major pieces (Queen, Rook) and King
Minor, // By color and positions of minor pieces (Knight, Bishop) and King Minor, // By color and positions of minor pieces (Knight, Bishop) and King
NonPawn, // By color and non-pawn material positions NonPawn, // By Non-pawn material positions and color
PieceTo, // By [piece][to] move PieceTo, // By [piece][to] move
Continuation, // Combined history of move pairs Continuation, // Combined history of move pairs
}; };
@@ -150,6 +150,11 @@ struct CorrHistTypedef {
using type = Stats<std::int16_t, CORRECTION_HISTORY_LIMIT, COLOR_NB, CORRECTION_HISTORY_SIZE>; using type = Stats<std::int16_t, CORRECTION_HISTORY_LIMIT, COLOR_NB, CORRECTION_HISTORY_SIZE>;
}; };
template<>
struct CorrHistTypedef<NonPawn> {
using type = Stats<std::int16_t, CORRECTION_HISTORY_LIMIT, CORRECTION_HISTORY_SIZE, COLOR_NB>;
};
template<> template<>
struct CorrHistTypedef<PieceTo> { struct CorrHistTypedef<PieceTo> {
using type = Stats<std::int16_t, CORRECTION_HISTORY_LIMIT, PIECE_NB, SQUARE_NB>; using type = Stats<std::int16_t, CORRECTION_HISTORY_LIMIT, PIECE_NB, SQUARE_NB>;

View File

@@ -89,8 +89,8 @@ int correction_value(const Worker& w, const Position& pos, const Stack* ss) {
const auto pcv = w.pawnCorrectionHistory[us][pawn_structure_index<Correction>(pos)]; const auto pcv = w.pawnCorrectionHistory[us][pawn_structure_index<Correction>(pos)];
const auto macv = w.majorPieceCorrectionHistory[us][major_piece_index(pos)]; const auto macv = w.majorPieceCorrectionHistory[us][major_piece_index(pos)];
const auto micv = w.minorPieceCorrectionHistory[us][minor_piece_index(pos)]; const auto micv = w.minorPieceCorrectionHistory[us][minor_piece_index(pos)];
const auto wnpcv = w.nonPawnCorrectionHistory[WHITE][us][non_pawn_index<WHITE>(pos)]; const auto wnpcv = w.nonPawnCorrectionHistory[WHITE][non_pawn_index<WHITE>(pos)][us];
const auto bnpcv = w.nonPawnCorrectionHistory[BLACK][us][non_pawn_index<BLACK>(pos)]; const auto bnpcv = w.nonPawnCorrectionHistory[BLACK][non_pawn_index<BLACK>(pos)][us];
const auto cntcv = const auto cntcv =
m.is_ok() ? (*(ss - 2)->continuationCorrectionHistory)[pos.piece_on(m.to_sq())][m.to_sq()] m.is_ok() ? (*(ss - 2)->continuationCorrectionHistory)[pos.piece_on(m.to_sq())][m.to_sq()]
: 0; : 0;
@@ -1442,9 +1442,9 @@ moves_loop: // When in check, search starts here
<< bonus * 114 / 128; << bonus * 114 / 128;
thisThread->majorPieceCorrectionHistory[us][major_piece_index(pos)] << bonus * 163 / 128; thisThread->majorPieceCorrectionHistory[us][major_piece_index(pos)] << bonus * 163 / 128;
thisThread->minorPieceCorrectionHistory[us][minor_piece_index(pos)] << bonus * 146 / 128; thisThread->minorPieceCorrectionHistory[us][minor_piece_index(pos)] << bonus * 146 / 128;
thisThread->nonPawnCorrectionHistory[WHITE][us][non_pawn_index<WHITE>(pos)] thisThread->nonPawnCorrectionHistory[WHITE][non_pawn_index<WHITE>(pos)][us]
<< bonus * nonPawnWeight / 128; << bonus * nonPawnWeight / 128;
thisThread->nonPawnCorrectionHistory[BLACK][us][non_pawn_index<BLACK>(pos)] thisThread->nonPawnCorrectionHistory[BLACK][non_pawn_index<BLACK>(pos)][us]
<< bonus * nonPawnWeight / 128; << bonus * nonPawnWeight / 128;
if (m.is_ok()) if (m.is_ok())