Skip to content

Commit

Permalink
Merge branch 'official-stockfish:master' into Main
Browse files Browse the repository at this point in the history
  • Loading branch information
Joachim26 authored Jan 17, 2024
2 parents b0910da + c8bc2ce commit 869f2ba
Show file tree
Hide file tree
Showing 13 changed files with 189 additions and 225 deletions.
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ making contributions to Stockfish.
In case you do not have a C++ compiler installed, you can follow the
instructions from our wiki.

- [Linux][linux-compiling-link]
- [Ubuntu][ubuntu-compiling-link]
- [Windows][windows-compiling-link]
- [macOS][macos-compiling-link]

Expand Down Expand Up @@ -92,6 +92,6 @@ Thank you for contributing to Stockfish and helping us make it even better!
[discussions-link]: https://github.com/official-stockfish/Stockfish/discussions/new
[creating-my-first-test]: https://github.com/official-stockfish/fishtest/wiki/Creating-my-first-test#create-your-test
[issue-tracker-link]: https://github.com/official-stockfish/Stockfish/issues
[linux-compiling-link]: https://github.com/official-stockfish/Stockfish/wiki/Compiling-from-source#linux
[windows-compiling-link]: https://github.com/official-stockfish/Stockfish/wiki/Compiling-from-source#windows
[macos-compiling-link]: https://github.com/official-stockfish/Stockfish/wiki/Compiling-from-source#macos
[ubuntu-compiling-link]: https://github.com/official-stockfish/Stockfish/wiki/Developers#user-content-installing-a-compiler-1
[windows-compiling-link]: https://github.com/official-stockfish/Stockfish/wiki/Developers#user-content-installing-a-compiler
[macos-compiling-link]: https://github.com/official-stockfish/Stockfish/wiki/Developers#user-content-installing-a-compiler-2
2 changes: 1 addition & 1 deletion scripts/get_native_properties.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ case $uname_s in
'aarch64')
file_os='android'
true_arch='armv8'
if check_flags 'dotprod'; then
if check_flags 'asimddp'; then
true_arch="$true_arch-dotprod"
fi
;;
Expand Down
6 changes: 2 additions & 4 deletions src/bitboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ Bitboard BishopTable[0x1480]; // To store bishop attacks

void init_magics(PieceType pt, Bitboard table[], Magic magics[]);

}

// Returns the bitboard of target square for the given step
// from the given square. If the step is off the board, returns empty bitboard.
inline Bitboard safe_destination(Square s, int step) {
Bitboard safe_destination(Square s, int step) {
Square to = Square(s + step);
return is_ok(to) && distance(s, to) <= 2 ? square_bb(to) : Bitboard(0);
}

}

// Returns an ASCII representation of a bitboard suitable
// to be printed to standard output. Useful for debugging.
Expand Down
15 changes: 15 additions & 0 deletions src/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
#ifndef MISC_H_INCLUDED
#define MISC_H_INCLUDED

#include <algorithm>
#include <cassert>
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <iosfwd>
#include <string>
#include <vector>

#define stringify2(x) #x
#define stringify(x) stringify2(x)
Expand Down Expand Up @@ -188,6 +190,19 @@ struct CommandLine {
std::string workingDirectory; // path of the working directory
};

namespace Utility {

template<typename T, typename Predicate>
void move_to_front(std::vector<T>& vec, Predicate pred) {
auto it = std::find_if(vec.begin(), vec.end(), pred);

if (it != vec.end())
{
std::rotate(vec.begin(), it, it + 1);
}
}
}

} // namespace Stockfish

#endif // #ifndef MISC_H_INCLUDED
16 changes: 7 additions & 9 deletions src/movepick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,13 @@ void MovePicker::score() {
: 0;

// malus for putting piece en prise
m.value -=
!(threatenedPieces & from)
? (pt == QUEEN
? bool(to & threatenedByRook) * 50000 + bool(to & threatenedByMinor) * 10000
: pt == ROOK
? bool(to & threatenedByMinor) * 25000 + bool(to & threatenedByPawn) * 10000
: pt != PAWN ? bool(to & threatenedByPawn) * 15000
: 0)
: 0;
m.value -= !(threatenedPieces & from)
? (pt == QUEEN ? bool(to & threatenedByRook) * 50000
+ bool(to & threatenedByMinor) * 10000
: pt == ROOK ? bool(to & threatenedByMinor) * 25000
: pt != PAWN ? bool(to & threatenedByPawn) * 15000
: 0)
: 0;
}

else // Type == EVASIONS
Expand Down
19 changes: 5 additions & 14 deletions src/nnue/layers/affine_transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,18 @@ class AffineTransform {
#define vec_setzero _mm512_setzero_si512
#define vec_set_32 _mm512_set1_epi32
#define vec_add_dpbusd_32 Simd::m512_add_dpbusd_epi32
#define vec_add_dpbusd_32x2 Simd::m512_add_dpbusd_epi32x2
#define vec_hadd Simd::m512_hadd
#elif defined(USE_AVX2)
using vec_t = __m256i;
#define vec_setzero _mm256_setzero_si256
#define vec_set_32 _mm256_set1_epi32
#define vec_add_dpbusd_32 Simd::m256_add_dpbusd_epi32
#define vec_add_dpbusd_32x2 Simd::m256_add_dpbusd_epi32x2
#define vec_hadd Simd::m256_hadd
#elif defined(USE_SSSE3)
using vec_t = __m128i;
#define vec_setzero _mm_setzero_si128
#define vec_set_32 _mm_set1_epi32
#define vec_add_dpbusd_32 Simd::m128_add_dpbusd_epi32
#define vec_add_dpbusd_32x2 Simd::m128_add_dpbusd_epi32x2
#define vec_hadd Simd::m128_hadd
#endif

Expand All @@ -231,16 +228,14 @@ class AffineTransform {
for (IndexType k = 0; k < NumRegs; ++k)
acc[k] = biasvec[k];

for (IndexType i = 0; i < NumChunks; i += 2)
for (IndexType i = 0; i < NumChunks; ++i)
{
const vec_t in0 = vec_set_32(input32[i + 0]);
const vec_t in1 = vec_set_32(input32[i + 1]);
const vec_t in0 = vec_set_32(input32[i]);
const auto col0 =
reinterpret_cast<const vec_t*>(&weights[(i + 0) * OutputDimensions * 4]);
const auto col1 =
reinterpret_cast<const vec_t*>(&weights[(i + 1) * OutputDimensions * 4]);
reinterpret_cast<const vec_t*>(&weights[i * OutputDimensions * 4]);

for (IndexType k = 0; k < NumRegs; ++k)
vec_add_dpbusd_32x2(acc[k], in0, col0[k], in1, col1[k]);
vec_add_dpbusd_32(acc[k], in0, col0[k]);
}

vec_t* outptr = reinterpret_cast<vec_t*>(output);
Expand All @@ -250,7 +245,6 @@ class AffineTransform {
#undef vec_setzero
#undef vec_set_32
#undef vec_add_dpbusd_32
#undef vec_add_dpbusd_32x2
#undef vec_hadd
}
else if constexpr (OutputDimensions == 1)
Expand All @@ -263,14 +257,12 @@ class AffineTransform {
#define vec_setzero _mm256_setzero_si256
#define vec_set_32 _mm256_set1_epi32
#define vec_add_dpbusd_32 Simd::m256_add_dpbusd_epi32
#define vec_add_dpbusd_32x2 Simd::m256_add_dpbusd_epi32x2
#define vec_hadd Simd::m256_hadd
#elif defined(USE_SSSE3)
using vec_t = __m128i;
#define vec_setzero _mm_setzero_si128
#define vec_set_32 _mm_set1_epi32
#define vec_add_dpbusd_32 Simd::m128_add_dpbusd_epi32
#define vec_add_dpbusd_32x2 Simd::m128_add_dpbusd_epi32x2
#define vec_hadd Simd::m128_hadd
#endif

Expand All @@ -294,7 +286,6 @@ class AffineTransform {
#undef vec_setzero
#undef vec_set_32
#undef vec_add_dpbusd_32
#undef vec_add_dpbusd_32x2
#undef vec_hadd
}
#else
Expand Down
54 changes: 0 additions & 54 deletions src/nnue/layers/simd.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,6 @@ m512_hadd128x16_interleave(__m512i sum0, __m512i sum1, __m512i sum2, __m512i sum
#endif
}

[[maybe_unused]] static void
m512_add_dpbusd_epi32x2(__m512i& acc, __m512i a0, __m512i b0, __m512i a1, __m512i b1) {

#if defined(USE_VNNI)
acc = _mm512_dpbusd_epi32(acc, a0, b0);
acc = _mm512_dpbusd_epi32(acc, a1, b1);
#else
__m512i product0 = _mm512_maddubs_epi16(a0, b0);
__m512i product1 = _mm512_maddubs_epi16(a1, b1);
product0 = _mm512_madd_epi16(product0, _mm512_set1_epi16(1));
product1 = _mm512_madd_epi16(product1, _mm512_set1_epi16(1));
acc = _mm512_add_epi32(acc, _mm512_add_epi32(product0, product1));
#endif
}

#endif

#if defined(USE_AVX2)
Expand All @@ -124,21 +109,6 @@ m512_add_dpbusd_epi32x2(__m512i& acc, __m512i a0, __m512i b0, __m512i a1, __m512
#endif
}

[[maybe_unused]] static void
m256_add_dpbusd_epi32x2(__m256i& acc, __m256i a0, __m256i b0, __m256i a1, __m256i b1) {

#if defined(USE_VNNI)
acc = _mm256_dpbusd_epi32(acc, a0, b0);
acc = _mm256_dpbusd_epi32(acc, a1, b1);
#else
__m256i product0 = _mm256_maddubs_epi16(a0, b0);
__m256i product1 = _mm256_maddubs_epi16(a1, b1);
product0 = _mm256_madd_epi16(product0, _mm256_set1_epi16(1));
product1 = _mm256_madd_epi16(product1, _mm256_set1_epi16(1));
acc = _mm256_add_epi32(acc, _mm256_add_epi32(product0, product1));
#endif
}

#endif

#if defined(USE_SSSE3)
Expand All @@ -156,27 +126,10 @@ m256_add_dpbusd_epi32x2(__m256i& acc, __m256i a0, __m256i b0, __m256i a1, __m256
acc = _mm_add_epi32(acc, product0);
}

[[maybe_unused]] static void
m128_add_dpbusd_epi32x2(__m128i& acc, __m128i a0, __m128i b0, __m128i a1, __m128i b1) {

__m128i product0 = _mm_maddubs_epi16(a0, b0);
__m128i product1 = _mm_maddubs_epi16(a1, b1);
product0 = _mm_madd_epi16(product0, _mm_set1_epi16(1));
product1 = _mm_madd_epi16(product1, _mm_set1_epi16(1));
acc = _mm_add_epi32(acc, _mm_add_epi32(product0, product1));
}

#endif

#if defined(USE_NEON_DOTPROD)

[[maybe_unused]] static void dotprod_m128_add_dpbusd_epi32x2(
int32x4_t& acc, int8x16_t a0, int8x16_t b0, int8x16_t a1, int8x16_t b1) {

acc = vdotq_s32(acc, a0, b0);
acc = vdotq_s32(acc, a1, b1);
}

[[maybe_unused]] static void
dotprod_m128_add_dpbusd_epi32(int32x4_t& acc, int8x16_t a, int8x16_t b) {

Expand All @@ -198,13 +151,6 @@ dotprod_m128_add_dpbusd_epi32(int32x4_t& acc, int8x16_t a, int8x16_t b) {
return neon_m128_reduce_add_epi32(sum) + bias;
}

[[maybe_unused]] static void
neon_m128_add_dpbusd_epi32x2(int32x4_t& acc, int8x8_t a0, int8x8_t b0, int8x8_t a1, int8x8_t b1) {

int16x8_t product = vmull_s8(a0, b0);
product = vmlal_s8(product, a1, b1);
acc = vpadalq_s16(acc, product);
}
#endif

#if USE_NEON >= 8
Expand Down
Loading

0 comments on commit 869f2ba

Please sign in to comment.