diff --git a/src/nnue/features/full_threats.cpp b/src/nnue/features/full_threats.cpp index 4e3ba81cf..47a5f8f0d 100644 --- a/src/nnue/features/full_threats.cpp +++ b/src/nnue/features/full_threats.cpp @@ -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(data); } - - constexpr IndexType feature_index_base() const { return static_cast(data >> 8); } -}; - constexpr std::array 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, PIECE_NB> indices{}; + std::array, 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