mirror of
https://github.com/official-stockfish/Stockfish.git
synced 2026-07-22 12:47:08 +00:00
Simplify make_index
Refactor index LUT construction to simplify make_index. Passed STC Non-Regression: LLR: 2.93 (-2.94,2.94) <-1.75,0.25> Total: 62432 W: 16193 L: 16006 D: 30233 Ptnml(0-2): 189, 6950, 16764, 7111, 202 https://tests.stockfishchess.org/tests/view/6959985ad844c1ce7cc7eac8 closes https://github.com/official-stockfish/Stockfish/pull/6522 No functional change.
This commit is contained in:
committed by
Joost VandeVondele
parent
d852a9195e
commit
e9b2864579
@@ -37,26 +37,6 @@ struct HelperOffsets {
|
||||
int cumulativePieceOffset, cumulativeOffset;
|
||||
};
|
||||
|
||||
// Information on a particular pair of pieces and whether they should be excluded
|
||||
struct PiecePairData {
|
||||
// Layout: bits 8..31 are the index contribution of this piece pair, bits 0 and 1 are exclusion info
|
||||
uint32_t data;
|
||||
|
||||
constexpr PiecePairData() :
|
||||
data(0) {}
|
||||
|
||||
constexpr PiecePairData(bool excluded_pair,
|
||||
bool semi_excluded_pair,
|
||||
IndexType feature_index_base) :
|
||||
data((uint32_t(excluded_pair) << 1) | (uint32_t(semi_excluded_pair && !excluded_pair))
|
||||
| (uint32_t(feature_index_base) << 8)) {}
|
||||
|
||||
// lsb: excluded if from < to; 2nd lsb: always excluded
|
||||
constexpr uint8_t excluded_pair_info() const { return static_cast<uint8_t>(data); }
|
||||
|
||||
constexpr IndexType feature_index_base() const { return static_cast<IndexType>(data >> 8); }
|
||||
};
|
||||
|
||||
constexpr std::array<Piece, 12> AllPieces = {
|
||||
W_PAWN, W_KNIGHT, W_BISHOP, W_ROOK, W_QUEEN, W_KING,
|
||||
B_PAWN, B_KNIGHT, B_BISHOP, B_ROOK, B_QUEEN, B_KING,
|
||||
@@ -173,7 +153,7 @@ constexpr auto helper_offsets = init_threat_offsets().first;
|
||||
constexpr auto offsets = init_threat_offsets().second;
|
||||
|
||||
constexpr auto init_index_luts() {
|
||||
std::array<std::array<PiecePairData, PIECE_NB>, PIECE_NB> indices{};
|
||||
std::array<std::array<std::array<uint32_t, 2>, PIECE_NB>, PIECE_NB> indices{};
|
||||
|
||||
for (Piece attacker : AllPieces)
|
||||
{
|
||||
@@ -189,8 +169,10 @@ constexpr auto init_index_luts() {
|
||||
+ (color_of(attacked) * (numValidTargets[attacker] / 2) + map)
|
||||
* helper_offsets[attacker].cumulativePieceOffset;
|
||||
|
||||
bool excluded = map < 0;
|
||||
indices[attacker][attacked] = PiecePairData(excluded, semi_excluded, feature);
|
||||
bool excluded = map < 0;
|
||||
indices[attacker][attacked][0] = excluded ? FullThreats::Dimensions : feature;
|
||||
indices[attacker][attacked][1] =
|
||||
excluded || semi_excluded ? FullThreats::Dimensions : feature;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,7 +182,7 @@ constexpr auto init_index_luts() {
|
||||
// The final index is calculated from summing data found in these two LUTs, as well
|
||||
// as offsets[attacker][from]
|
||||
|
||||
// [attacker][attacked]
|
||||
// [attacker][attacked][from < to]
|
||||
constexpr auto index_lut1 = init_index_luts();
|
||||
// [attacker][from][to]
|
||||
constexpr auto index_lut2 = index_lut2_array();
|
||||
@@ -216,17 +198,9 @@ inline sf_always_inline IndexType FullThreats::make_index(
|
||||
unsigned attacker_oriented = attacker ^ swap;
|
||||
unsigned attacked_oriented = attacked ^ swap;
|
||||
|
||||
const auto piecePairData = index_lut1[attacker_oriented][attacked_oriented];
|
||||
|
||||
const bool less_than = from_oriented < to_oriented;
|
||||
if ((piecePairData.excluded_pair_info() + less_than) & 2)
|
||||
return FullThreats::Dimensions;
|
||||
|
||||
const IndexType index = piecePairData.feature_index_base()
|
||||
+ offsets[attacker_oriented][from_oriented]
|
||||
+ index_lut2[attacker_oriented][from_oriented][to_oriented];
|
||||
sf_assume(index < Dimensions);
|
||||
return index;
|
||||
return index_lut1[attacker_oriented][attacked_oriented][from_oriented < to_oriented]
|
||||
+ offsets[attacker_oriented][from_oriented]
|
||||
+ index_lut2[attacker_oriented][from_oriented][to_oriented];
|
||||
}
|
||||
|
||||
// Get a list of indices for active features in ascending order
|
||||
|
||||
Reference in New Issue
Block a user