mirror of
https://github.com/official-stockfish/Stockfish.git
synced 2026-07-22 12:47:08 +00:00
Simplify HalfKAv2_hm::write_indices()
https://tests.stockfishchess.org/tests/view/69bb1fafd7d60419badf31a3 LLR: 2.95 (-2.94,2.94) <-1.75,0.25> Total: 116544 W: 30024 L: 29895 D: 56625 Ptnml(0-2): 317, 12875, 31729, 13064, 287 closes https://github.com/official-stockfish/Stockfish/pull/6677 No functional change
This commit is contained in:
@@ -40,6 +40,15 @@ std::string pretty(Bitboard b);
|
|||||||
|
|
||||||
} // namespace Stockfish::Bitboards
|
} // namespace Stockfish::Bitboards
|
||||||
|
|
||||||
|
#ifdef USE_AVX512
|
||||||
|
// clang-format off
|
||||||
|
inline const __m512i AllSquares = _mm512_set_epi8(
|
||||||
|
63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41,
|
||||||
|
40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18,
|
||||||
|
17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
|
||||||
|
// clang-format on
|
||||||
|
#endif
|
||||||
|
|
||||||
constexpr Bitboard FileABB = 0x0101010101010101ULL;
|
constexpr Bitboard FileABB = 0x0101010101010101ULL;
|
||||||
constexpr Bitboard FileBBB = FileABB << 1;
|
constexpr Bitboard FileBBB = FileABB << 1;
|
||||||
constexpr Bitboard FileCBB = FileABB << 2;
|
constexpr Bitboard FileCBB = FileABB << 2;
|
||||||
|
|||||||
@@ -36,13 +36,6 @@ namespace {
|
|||||||
|
|
||||||
#if defined(USE_AVX512ICL)
|
#if defined(USE_AVX512ICL)
|
||||||
|
|
||||||
// clang-format off
|
|
||||||
const __m512i AllSquares = _mm512_set_epi8(
|
|
||||||
63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41,
|
|
||||||
40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18,
|
|
||||||
17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
|
|
||||||
// clang-format on
|
|
||||||
|
|
||||||
template<Direction offset>
|
template<Direction offset>
|
||||||
inline Move* splat_pawn_moves(Move* moveList, Bitboard to_bb) {
|
inline Move* splat_pawn_moves(Move* moveList, Bitboard to_bb) {
|
||||||
assert(popcount(to_bb) <= 8); // <= 8 pawns per side
|
assert(popcount(to_bb) <= 8); // <= 8 pawns per side
|
||||||
|
|||||||
@@ -43,56 +43,43 @@ void HalfKAv2_hm::write_indices(const std::array<Piece, SQUARE_NB>& oldPieces,
|
|||||||
const __m512i vecOldPieces = _mm512_loadu_si512(oldPieces.data());
|
const __m512i vecOldPieces = _mm512_loadu_si512(oldPieces.data());
|
||||||
const __m512i vecNewPieces = _mm512_loadu_si512(newPieces.data());
|
const __m512i vecNewPieces = _mm512_loadu_si512(newPieces.data());
|
||||||
|
|
||||||
static constexpr uint16_t psiTable[COLOR_NB][32] = {
|
alignas(64) static constexpr uint16_t psiTable[COLOR_NB][16] = {
|
||||||
{PS_NONE, PS_W_PAWN, PS_W_KNIGHT, PS_W_BISHOP, PS_W_ROOK, PS_W_QUEEN, PS_KING, PS_NONE,
|
{PS_NONE, PS_W_PAWN, PS_W_KNIGHT, PS_W_BISHOP, PS_W_ROOK, PS_W_QUEEN, PS_KING, PS_NONE,
|
||||||
PS_NONE, PS_B_PAWN, PS_B_KNIGHT, PS_B_BISHOP, PS_B_ROOK, PS_B_QUEEN, PS_KING, PS_NONE,
|
PS_NONE, PS_B_PAWN, PS_B_KNIGHT, PS_B_BISHOP, PS_B_ROOK, PS_B_QUEEN, PS_KING, PS_NONE},
|
||||||
PS_NONE, PS_NONE, PS_NONE, PS_NONE, PS_NONE, PS_NONE, PS_NONE, PS_NONE,
|
|
||||||
PS_NONE, PS_NONE, PS_NONE, PS_NONE, PS_NONE, PS_NONE, PS_NONE, PS_NONE},
|
|
||||||
|
|
||||||
{PS_NONE, PS_B_PAWN, PS_B_KNIGHT, PS_B_BISHOP, PS_B_ROOK, PS_B_QUEEN, PS_KING, PS_NONE,
|
{PS_NONE, PS_B_PAWN, PS_B_KNIGHT, PS_B_BISHOP, PS_B_ROOK, PS_B_QUEEN, PS_KING, PS_NONE,
|
||||||
PS_NONE, PS_W_PAWN, PS_W_KNIGHT, PS_W_BISHOP, PS_W_ROOK, PS_W_QUEEN, PS_KING, PS_NONE,
|
PS_NONE, PS_W_PAWN, PS_W_KNIGHT, PS_W_BISHOP, PS_W_ROOK, PS_W_QUEEN, PS_KING, PS_NONE}};
|
||||||
PS_NONE, PS_NONE, PS_NONE, PS_NONE, PS_NONE, PS_NONE, PS_NONE, PS_NONE,
|
|
||||||
PS_NONE, PS_NONE, PS_NONE, PS_NONE, PS_NONE, PS_NONE, PS_NONE, PS_NONE}};
|
|
||||||
const __m512i psi = _mm512_loadu_si512(psiTable[perspective]);
|
|
||||||
|
|
||||||
const __m512i allSquares = _mm512_set_epi8(
|
|
||||||
63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41,
|
|
||||||
40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18,
|
|
||||||
17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
|
|
||||||
|
|
||||||
const uint16_t flip = 56 * perspective;
|
const uint16_t flip = 56 * perspective;
|
||||||
const __m512i orient = _mm512_set1_epi16((uint16_t) OrientTBL[ksq] ^ flip);
|
const __m512i orient = _mm512_set1_epi16((uint16_t) OrientTBL[ksq] ^ flip);
|
||||||
const __m512i bucket = _mm512_set1_epi16((uint16_t) KingBuckets[int(ksq) ^ flip]);
|
const __m512i psi =
|
||||||
|
_mm512_zextsi256_si512(_mm256_loadu_si256((const __m256i*) psiTable[perspective]));
|
||||||
|
const __m512i psi_plus_bucket =
|
||||||
|
_mm512_add_epi16(psi, _mm512_set1_epi16((uint16_t) KingBuckets[int(ksq) ^ flip]));
|
||||||
|
|
||||||
|
__m512i removed_squares = _mm512_maskz_compress_epi8(removedBB, AllSquares);
|
||||||
|
__m512i added_squares = _mm512_maskz_compress_epi8(addedBB, AllSquares);
|
||||||
|
__m512i removed_pieces = _mm512_maskz_compress_epi8(removedBB, vecOldPieces);
|
||||||
|
__m512i added_pieces = _mm512_maskz_compress_epi8(addedBB, vecNewPieces);
|
||||||
|
|
||||||
__m512i removed_squares = _mm512_maskz_compress_epi8(removedBB, allSquares);
|
|
||||||
__m512i removed_pieces = _mm512_permutexvar_epi8(removed_squares, vecOldPieces);
|
|
||||||
removed_squares = _mm512_cvtepi8_epi16(_mm512_castsi512_si256(removed_squares));
|
removed_squares = _mm512_cvtepi8_epi16(_mm512_castsi512_si256(removed_squares));
|
||||||
removed_pieces = _mm512_cvtepi8_epi16(_mm512_castsi512_si256(removed_pieces));
|
|
||||||
const __m512i removed_psi = _mm512_permutexvar_epi16(removed_pieces, psi);
|
|
||||||
__m512i removed_indices = _mm512_xor_si512(removed_squares, orient);
|
|
||||||
removed_indices = _mm512_add_epi16(removed_indices, removed_psi);
|
|
||||||
removed_indices = _mm512_add_epi16(removed_indices, bucket);
|
|
||||||
|
|
||||||
__m512i added_squares = _mm512_maskz_compress_epi8(addedBB, allSquares);
|
|
||||||
__m512i added_pieces = _mm512_permutexvar_epi8(added_squares, vecNewPieces);
|
|
||||||
added_squares = _mm512_cvtepi8_epi16(_mm512_castsi512_si256(added_squares));
|
added_squares = _mm512_cvtepi8_epi16(_mm512_castsi512_si256(added_squares));
|
||||||
|
removed_pieces = _mm512_cvtepi8_epi16(_mm512_castsi512_si256(removed_pieces));
|
||||||
added_pieces = _mm512_cvtepi8_epi16(_mm512_castsi512_si256(added_pieces));
|
added_pieces = _mm512_cvtepi8_epi16(_mm512_castsi512_si256(added_pieces));
|
||||||
const __m512i added_psi = _mm512_permutexvar_epi16(added_pieces, psi);
|
|
||||||
__m512i added_indices = _mm512_xor_si512(added_squares, orient);
|
|
||||||
added_indices = _mm512_add_epi16(added_indices, added_psi);
|
|
||||||
added_indices = _mm512_add_epi16(added_indices, bucket);
|
|
||||||
|
|
||||||
const __m512i removed_indices0 = _mm512_cvtepi16_epi32(_mm512_castsi512_si256(removed_indices));
|
const __m512i removed_indices =
|
||||||
const __m512i removed_indices1 =
|
_mm512_or_si512(_mm512_xor_si512(removed_squares, orient),
|
||||||
_mm512_cvtepi16_epi32(_mm512_extracti64x4_epi64(removed_indices, 1));
|
_mm512_permutexvar_epi16(removed_pieces, psi_plus_bucket));
|
||||||
_mm512_storeu_si512(write_removed, removed_indices0);
|
const __m512i added_indices =
|
||||||
_mm512_storeu_si512(write_removed + 16, removed_indices1);
|
_mm512_or_si512(_mm512_xor_si512(added_squares, orient),
|
||||||
|
_mm512_permutexvar_epi16(added_pieces, psi_plus_bucket));
|
||||||
|
|
||||||
const __m512i added_indices0 = _mm512_cvtepi16_epi32(_mm512_castsi512_si256(added_indices));
|
_mm512_storeu_si512(write_removed,
|
||||||
const __m512i added_indices1 =
|
_mm512_cvtepu16_epi32(_mm512_castsi512_si256(removed_indices)));
|
||||||
_mm512_cvtepi16_epi32(_mm512_extracti64x4_epi64(added_indices, 1));
|
_mm512_storeu_si512(write_removed + 16,
|
||||||
_mm512_storeu_si512(write_added, added_indices0);
|
_mm512_cvtepu16_epi32(_mm512_extracti64x4_epi64(removed_indices, 1)));
|
||||||
_mm512_storeu_si512(write_added + 16, added_indices1);
|
_mm512_storeu_si512(write_added, _mm512_cvtepu16_epi32(_mm512_castsi512_si256(added_indices)));
|
||||||
|
_mm512_storeu_si512(write_added + 16,
|
||||||
|
_mm512_cvtepu16_epi32(_mm512_extracti64x4_epi64(added_indices, 1)));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -1185,11 +1185,6 @@ void write_multiple_dirties(const Position& p,
|
|||||||
static_assert(sizeof(DirtyThreat) == 4);
|
static_assert(sizeof(DirtyThreat) == 4);
|
||||||
|
|
||||||
const __m512i board = _mm512_loadu_si512(p.piece_array().data());
|
const __m512i board = _mm512_loadu_si512(p.piece_array().data());
|
||||||
const __m512i AllSquares = _mm512_set_epi8(
|
|
||||||
63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41,
|
|
||||||
40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18,
|
|
||||||
17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
|
|
||||||
|
|
||||||
const int dt_count = popcount(mask);
|
const int dt_count = popcount(mask);
|
||||||
assert(dt_count <= 16);
|
assert(dt_count <= 16);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user