mirror of
https://github.com/official-stockfish/Stockfish.git
synced 2026-07-22 20:57:10 +00:00
Add intrinsics for LSX and LASX
This adds actual intrinsics of SIMD on loongarch64, with considerable performance improvements. Benchmark on `Loongson-3A6000-HV Not Specified CPU @ 2.5GHz` Baseline GCC 14 (debian trixie): ``` =========================== Total time (ms) : 17816 Nodes searched : 2336177 Nodes/second : 131128 ``` With this PR: GCC 16 (debian sid): ``` ./stockfish compiler Stockfish dev-20260516-52e8d9ef by the Stockfish developers (see AUTHORS file) Compiled by : g++ (GNUC) 16.1.0 on Linux Compilation architecture : loongarch64-lasx Compilation settings : 64bit LASX LSX Compiler __VERSION__ macro : 16.1.0 =========================== Total time (ms) : 3518 Nodes searched : 2336177 Nodes/second : 664063 ``` ``` ./stockfish compiler Stockfish dev-20260516-52e8d9ef by the Stockfish developers (see AUTHORS file) Compiled by : g++ (GNUC) 16.1.0 on Linux Compilation architecture : loongarch64-lsx Compilation settings : 64bit LSX Compiler __VERSION__ macro : 16.1.0 =========================== Total time (ms) : 4944 Nodes searched : 2336177 Nodes/second : 472527 ``` clang 22 (debian sid): ``` ./stockfish compiler Stockfish dev-20260516-52e8d9ef by the Stockfish developers (see AUTHORS file) Compiled by : clang++ 22.1.5 on Linux Compilation architecture : loongarch64-lasx Compilation settings : 64bit LASX LSX Compiler __VERSION__ macro : Debian Clang 22.1.5 (1) =========================== Total time (ms) : 3401 Nodes searched : 2336177 Nodes/second : 686908 ``` ``` ./stockfish compiler Stockfish dev-20260516-52e8d9ef by the Stockfish developers (see AUTHORS file) Compiled by : clang++ 22.1.5 on Linux Compilation architecture : loongarch64-lsx Compilation settings : 64bit LSX Compiler __VERSION__ macro : Debian Clang 22.1.5 (1) =========================== Total time (ms) : 5501 Nodes searched : 2336177 Nodes/second : 424682 ``` GCC 14 (debian trixie): ``` ./stockfish compiler Stockfish dev-20260516-52e8d9ef by the Stockfish developers (see AUTHORS file) Compiled by : g++ (GNUC) 14.2.0 on Linux Compilation architecture : loongarch64-lasx Compilation settings : 64bit LASX LSX Compiler __VERSION__ macro : 14.2.0 =========================== Total time (ms) : 3559 Nodes searched : 2336177 Nodes/second : 656413 ``` ``` ./stockfish compiler Stockfish dev-20260516-52e8d9ef by the Stockfish developers (see AUTHORS file) Compiled by : g++ (GNUC) 14.2.0 on Linux Compilation architecture : loongarch64-lsx Compilation settings : 64bit LSX Compiler __VERSION__ macro : 14.2.0 =========================== Total time (ms) : 5212 Nodes searched : 2336177 Nodes/second : 448230 ``` clang 19 (debian trixie): ``` ./stockfish compiler Stockfish dev-20260516-52e8d9ef by the Stockfish developers (see AUTHORS file) Compiled by : clang++ 19.1.7 on Linux Compilation architecture : loongarch64-lasx Compilation settings : 64bit LASX LSX Compiler __VERSION__ macro : Debian Clang 19.1.7 (3+b1) =========================== Total time (ms) : 4830 Nodes searched : 2336177 Nodes/second : 483680 ``` ``` ./stockfish compiler Stockfish dev-20260516-52e8d9ef by the Stockfish developers (see AUTHORS file) Compiled by : clang++ 19.1.7 on Linux Compilation architecture : loongarch64-lsx Compilation settings : 64bit LSX Compiler __VERSION__ macro : Debian Clang 19.1.7 (3+b1) =========================== Total time (ms) : 5568 Nodes searched : 2336177 Nodes/second : 419572 ``` closes https://github.com/official-stockfish/Stockfish/pull/6815 No functional change
This commit is contained in:
committed by
Joost VandeVondele
parent
0366d092a8
commit
ffffe1bdb5
@@ -516,6 +516,41 @@ Bitboard get_changed_pieces(const std::array<Piece, SQUARE_NB>& oldPieces,
|
||||
sameBB |= static_cast<Bitboard>(equalMask) << i;
|
||||
}
|
||||
return ~sameBB;
|
||||
#elif defined(USE_LASX)
|
||||
static_assert(sizeof(Piece) == 1);
|
||||
|
||||
Bitboard changed = 0;
|
||||
|
||||
for (int i = 0; i < 64; i += 32)
|
||||
{
|
||||
const __m256i old_v = __lasx_xvld(reinterpret_cast<const void*>(&oldPieces[i]), 0);
|
||||
const __m256i new_v = __lasx_xvld(reinterpret_cast<const void*>(&newPieces[i]), 0);
|
||||
const __m256i diff = __lasx_xvxor_v(old_v, new_v);
|
||||
const __m256i mask = __lasx_xvmsknz_b(diff);
|
||||
const auto lo = static_cast<std::uint16_t>(__lasx_xvpickve2gr_d(mask, 0));
|
||||
const auto hi = static_cast<std::uint16_t>(__lasx_xvpickve2gr_d(mask, 2));
|
||||
|
||||
changed |= (static_cast<Bitboard>(lo) | (static_cast<Bitboard>(hi) << 16)) << i;
|
||||
}
|
||||
|
||||
return changed;
|
||||
#elif defined(USE_LSX)
|
||||
static_assert(sizeof(Piece) == 1);
|
||||
|
||||
Bitboard changed = 0;
|
||||
|
||||
for (int i = 0; i < 64; i += 16)
|
||||
{
|
||||
const __m128i old_v = __lsx_vld(reinterpret_cast<const void*>(&oldPieces[i]), 0);
|
||||
const __m128i new_v = __lsx_vld(reinterpret_cast<const void*>(&newPieces[i]), 0);
|
||||
const __m128i diff = __lsx_vxor_v(old_v, new_v);
|
||||
const __m128i mask = __lsx_vmsknz_b(diff);
|
||||
|
||||
changed |= static_cast<Bitboard>(static_cast<std::uint16_t>(__lsx_vpickve2gr_d(mask, 0)))
|
||||
<< i;
|
||||
}
|
||||
|
||||
return changed;
|
||||
#elif defined(USE_NEON)
|
||||
uint8x16x4_t old_v = vld4q_u8(reinterpret_cast<const uint8_t*>(oldPieces.data()));
|
||||
uint8x16x4_t new_v = vld4q_u8(reinterpret_cast<const uint8_t*>(newPieces.data()));
|
||||
|
||||
Reference in New Issue
Block a user