Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nonlinear2 committed Jan 18, 2025
2 parents 264d343 + 8e3e22b commit 0493473
Show file tree
Hide file tree
Showing 15 changed files with 234 additions and 151 deletions.
8 changes: 4 additions & 4 deletions .github/ci/matrix.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"config": [
{
"name": "Ubuntu 20.04 GCC",
"os": "ubuntu-20.04",
"name": "Ubuntu 22.04 GCC",
"os": "ubuntu-22.04",
"simple_name": "ubuntu",
"compiler": "g++",
"comp": "gcc",
Expand Down Expand Up @@ -111,7 +111,7 @@
{
"binaries": "x86-64-avxvnni",
"config": {
"ubuntu-20.04": null
"ubuntu-22.04": null
}
},
{
Expand Down Expand Up @@ -153,7 +153,7 @@
{
"binaries": "apple-silicon",
"config": {
"os": "ubuntu-20.04"
"os": "ubuntu-22.04"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ permissions:
jobs:
Clang-Format:
name: Clang-Format
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ jobs:
fail-fast: false
matrix:
config:
- name: Ubuntu 20.04 GCC
os: ubuntu-20.04
- name: Ubuntu 22.04 GCC
os: ubuntu-22.04
compiler: g++
comp: gcc
run_32bit_tests: true
run_64bit_tests: true
shell: bash
- name: Ubuntu 20.04 Clang
os: ubuntu-20.04
- name: Ubuntu 22.04 Clang
os: ubuntu-22.04
compiler: clang++
comp: clang
run_32bit_tests: true
Expand Down
3 changes: 1 addition & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ further discussion._
- Provide a clear and concise description of the changes in the pull request
description.

_First time contributors should add their name to [AUTHORS](../AUTHORS)._
_First time contributors should add their name to [AUTHORS](./AUTHORS)._

_Stockfish's development is not focused on adding new features. Thus any pull
request introducing new features will potentially be closed without further
Expand Down Expand Up @@ -86,7 +86,6 @@ more details.

Thank you for contributing to Stockfish and helping us make it even better!


[copying-link]: https://github.com/official-stockfish/Stockfish/blob/master/Copying.txt
[discord-link]: https://discord.gg/GWDRS3kU6R
[discussions-link]: https://github.com/official-stockfish/Stockfish/discussions/new
Expand Down
2 changes: 1 addition & 1 deletion scripts/get_native_properties.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ case $uname_s in
case $uname_m in
'arm64')
true_arch='apple-silicon'
file_arch='x86-64-sse41-popcnt' # Supported by Rosetta 2
file_arch='m1-apple-silicon'
;;
'x86_64')
flags=$(sysctl -n machdep.cpu.features machdep.cpu.leaf7_features | tr '\n' ' ' | tr '[:upper:]' '[:lower:]' | tr -d '_.')
Expand Down
4 changes: 2 additions & 2 deletions src/movepick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ void MovePicker::score() {
m.value += (*continuationHistory[1])[pc][to];
m.value += (*continuationHistory[2])[pc][to];
m.value += (*continuationHistory[3])[pc][to];
m.value += (*continuationHistory[4])[pc][to] / 3;
m.value += (*continuationHistory[5])[pc][to];

// bonus for checks
Expand All @@ -186,8 +187,7 @@ void MovePicker::score() {
else // Type == EVASIONS
{
if (pos.capture_stage(m))
m.value =
PieceValue[pos.piece_on(m.to_sq())] - type_of(pos.moved_piece(m)) + (1 << 28);
m.value = PieceValue[pos.piece_on(m.to_sq())] + (1 << 28);
else
m.value = (*mainHistory)[pos.side_to_move()][m.from_to()]
+ (*continuationHistory[0])[pos.moved_piece(m)][m.to_sq()]
Expand Down
110 changes: 98 additions & 12 deletions src/nnue/layers/affine_transform_sparse_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,99 @@
namespace Stockfish::Eval::NNUE::Layers {

#if (USE_SSSE3 | (USE_NEON >= 8))
alignas(CacheLineSize) static inline const
std::array<std::array<std::uint16_t, 8>, 256> lookup_indices = []() {
std::array<std::array<std::uint16_t, 8>, 256> v{};
for (unsigned i = 0; i < 256; ++i)
{
std::uint64_t j = i, k = 0;
while (j)
v[i][k++] = pop_lsb(j);
}
return v;
}();

#if (USE_SSE41)
alignas(CacheLineSize) static constexpr std::uint8_t
#else
alignas(CacheLineSize) static constexpr std::uint16_t
#endif
lookup_indices[256][8] = {
{0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}, {1, 0, 0, 0, 0, 0, 0, 0},
{0, 1, 0, 0, 0, 0, 0, 0}, {2, 0, 0, 0, 0, 0, 0, 0}, {0, 2, 0, 0, 0, 0, 0, 0},
{1, 2, 0, 0, 0, 0, 0, 0}, {0, 1, 2, 0, 0, 0, 0, 0}, {3, 0, 0, 0, 0, 0, 0, 0},
{0, 3, 0, 0, 0, 0, 0, 0}, {1, 3, 0, 0, 0, 0, 0, 0}, {0, 1, 3, 0, 0, 0, 0, 0},
{2, 3, 0, 0, 0, 0, 0, 0}, {0, 2, 3, 0, 0, 0, 0, 0}, {1, 2, 3, 0, 0, 0, 0, 0},
{0, 1, 2, 3, 0, 0, 0, 0}, {4, 0, 0, 0, 0, 0, 0, 0}, {0, 4, 0, 0, 0, 0, 0, 0},
{1, 4, 0, 0, 0, 0, 0, 0}, {0, 1, 4, 0, 0, 0, 0, 0}, {2, 4, 0, 0, 0, 0, 0, 0},
{0, 2, 4, 0, 0, 0, 0, 0}, {1, 2, 4, 0, 0, 0, 0, 0}, {0, 1, 2, 4, 0, 0, 0, 0},
{3, 4, 0, 0, 0, 0, 0, 0}, {0, 3, 4, 0, 0, 0, 0, 0}, {1, 3, 4, 0, 0, 0, 0, 0},
{0, 1, 3, 4, 0, 0, 0, 0}, {2, 3, 4, 0, 0, 0, 0, 0}, {0, 2, 3, 4, 0, 0, 0, 0},
{1, 2, 3, 4, 0, 0, 0, 0}, {0, 1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{2, 3, 5, 6, 7, 0, 0, 0},
{0, 2, 3, 5, 6, 7, 0, 0}, {1, 2, 3, 5, 6, 7, 0, 0}, {0, 1, 2, 3, 5, 6, 7, 0},
{4, 5, 6, 7, 0, 0, 0, 0}, {0, 4, 5, 6, 7, 0, 0, 0}, {1, 4, 5, 6, 7, 0, 0, 0},
{0, 1, 4, 5, 6, 7, 0, 0}, {2, 4, 5, 6, 7, 0, 0, 0}, {0, 2, 4, 5, 6, 7, 0, 0},
{1, 2, 4, 5, 6, 7, 0, 0}, {0, 1, 2, 4, 5, 6, 7, 0}, {3, 4, 5, 6, 7, 0, 0, 0},
{0, 3, 4, 5, 6, 7, 0, 0}, {1, 3, 4, 5, 6, 7, 0, 0}, {0, 1, 3, 4, 5, 6, 7, 0},
{2, 3, 4, 5, 6, 7, 0, 0}, {0, 2, 3, 4, 5, 6, 7, 0}, {1, 2, 3, 4, 5, 6, 7, 0},
{0, 1, 2, 3, 4, 5, 6, 7}};

// Find indices of nonzero numbers in an int32_t array
template<const IndexType InputDimensions>
Expand All @@ -74,7 +156,11 @@ void find_nnz(const std::int32_t* input, std::uint16_t* out, IndexType& count_ou
using vec128_t = __m128i;
#define vec128_zero _mm_setzero_si128()
#define vec128_set_16(a) _mm_set1_epi16(a)
#define vec128_load(a) _mm_load_si128(a)
#if (USE_SSE41)
#define vec128_load(a) _mm_cvtepu8_epi16(_mm_loadl_epi64(a))
#else
#define vec128_load(a) _mm_load_si128(a)
#endif
#define vec128_storeu(a, b) _mm_storeu_si128(a, b)
#define vec128_add(a, b) _mm_add_epi16(a, b)
#elif defined(USE_NEON)
Expand Down
27 changes: 4 additions & 23 deletions src/nnue/nnue_feature_transformer.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,8 @@ class FeatureTransformer {

void hint_common_access(const Position& pos,
AccumulatorCaches::Cache<HalfDimensions>* cache) const {
hint_common_access_for_perspective<WHITE>(pos, cache);
hint_common_access_for_perspective<BLACK>(pos, cache);
update_accumulator<WHITE>(pos, cache);
update_accumulator<BLACK>(pos, cache);
}

private:
Expand Down Expand Up @@ -821,31 +821,12 @@ class FeatureTransformer {
entry.byTypeBB[pt] = pos.pieces(pt);
}

template<Color Perspective>
void hint_common_access_for_perspective(const Position& pos,
AccumulatorCaches::Cache<HalfDimensions>* cache) const {

// Works like update_accumulator, but performs less work.
// Updates ONLY the accumulator for pos.

// Look for a usable accumulator of an earlier position. We keep track
// of the estimated gain in terms of features to be added/subtracted.
// Fast early exit.
if ((pos.state()->*accPtr).computed[Perspective])
return;

StateInfo* oldest = try_find_computed_accumulator<Perspective>(pos);

if ((oldest->*accPtr).computed[Perspective] && oldest != pos.state())
update_accumulator_incremental<Perspective>(pos, oldest);
else
update_accumulator_refresh_cache<Perspective>(pos, cache);
}

template<Color Perspective>
void update_accumulator(const Position& pos,
AccumulatorCaches::Cache<HalfDimensions>* cache) const {

if ((pos.state()->*accPtr).computed[Perspective])
return;
StateInfo* oldest = try_find_computed_accumulator<Perspective>(pos);

if ((oldest->*accPtr).computed[Perspective] && oldest != pos.state())
Expand Down
32 changes: 11 additions & 21 deletions src/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,12 @@ bool Position::gives_check(Move m) const {
// Makes a move, and saves all information necessary
// to a StateInfo object. The move is assumed to be legal. Pseudo-legal
// moves should be filtered out before this function is called.
void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
// If a pointer to the TT table is passed, the entry for the new position
// will be prefetched
void Position::do_move(Move m,
StateInfo& newSt,
bool givesCheck,
const TranspositionTable* tt = nullptr) {

assert(m.is_ok());
assert(&newSt != st);
Expand Down Expand Up @@ -887,11 +892,13 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
st->minorPieceKey ^= Zobrist::psq[pc][from] ^ Zobrist::psq[pc][to];
}

// Set capture piece
st->capturedPiece = captured;

// Update the key with the final value
st->key = k;
if (tt)
prefetch(tt->first_entry(key()));

// Set capture piece
st->capturedPiece = captured;

// Calculate checkers bitboard (if move gives check)
st->checkersBB = givesCheck ? attackers_to(square<KING>(them)) & pieces(us) : 0;
Expand Down Expand Up @@ -1069,23 +1076,6 @@ void Position::undo_null_move() {
}


// Computes the new hash key after the given move. Needed
// for speculative prefetch. It doesn't recognize special moves like castling,
// en passant and promotions.
Key Position::key_after(Move m) const {

Square from = m.from_sq();
Square to = m.to_sq();
Piece pc = piece_on(from);
Piece captured = piece_on(to);
Key k = st->key ^ Zobrist::side;

k ^= Zobrist::psq[captured][to] ^ Zobrist::psq[pc][to] ^ Zobrist::psq[pc][from];

return (captured || type_of(pc) == PAWN) ? k : adjust_key50<true>(k);
}


// Tests if the SEE (Static Exchange Evaluation)
// value of move is greater or equal to the given threshold. We'll use an
// algorithm similar to alpha-beta pruning with a null window.
Expand Down
9 changes: 5 additions & 4 deletions src/position.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ class Position {
Piece captured_piece() const;

// Doing and undoing moves
void do_move(Move m, StateInfo& newSt);
void do_move(Move m, StateInfo& newSt, bool givesCheck);
void do_move(Move m, StateInfo& newSt, const TranspositionTable* tt);
void do_move(Move m, StateInfo& newSt, bool givesCheck, const TranspositionTable* tt);
void undo_move(Move m);
void do_null_move(StateInfo& newSt, const TranspositionTable& tt);
void undo_null_move();
Expand All @@ -152,7 +152,6 @@ class Position {

// Accessing hash keys
Key key() const;
Key key_after(Move m) const;
Key material_key() const;
Key pawn_key() const;
Key major_piece_key() const;
Expand Down Expand Up @@ -369,7 +368,9 @@ inline void Position::move_piece(Square from, Square to) {
board[to] = pc;
}

inline void Position::do_move(Move m, StateInfo& newSt) { do_move(m, newSt, gives_check(m)); }
inline void Position::do_move(Move m, StateInfo& newSt, const TranspositionTable* tt = nullptr) {
do_move(m, newSt, gives_check(m), tt);
}

inline StateInfo* Position::state() const { return st; }

Expand Down
Loading

0 comments on commit 0493473

Please sign in to comment.