Skip to content

Commit 26327f5

Browse files
committed
Merge Upstream
Bench: 15585909
2 parents d4eee7c + 678d503 commit 26327f5

File tree

12 files changed

+205
-155
lines changed

12 files changed

+205
-155
lines changed

.github/ci/matrix.json

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"comp": "gcc",
99
"shell": "bash",
1010
"archive_ext": "tar",
11-
"sde": "/home/runner/work/Stockfish/Stockfish/.output/sde-temp-files/sde-external-9.27.0-2023-09-13-lin/sde -future --"
11+
"sde": "/home/runner/work/Stockfish/Stockfish/.output/sde-temp-files/sde-external-9.33.0-2024-01-07-lin/sde -future --"
1212
},
1313
{
1414
"name": "MacOS 13 Apple Clang",
@@ -38,7 +38,7 @@
3838
"msys_env": "x86_64-gcc",
3939
"shell": "msys2 {0}",
4040
"ext": ".exe",
41-
"sde": "/d/a/Stockfish/Stockfish/.output/sde-temp-files/sde-external-9.27.0-2023-09-13-win/sde.exe -future --",
41+
"sde": "/d/a/Stockfish/Stockfish/.output/sde-temp-files/sde-external-9.33.0-2024-01-07-win/sde.exe -future --",
4242
"archive_ext": "zip"
4343
},
4444
{
@@ -63,6 +63,7 @@
6363
"x86-64-avx512",
6464
"x86-64-vnni256",
6565
"x86-64-vnni512",
66+
"x86-64-avx512icl",
6667
"apple-silicon",
6768
"armv8",
6869
"armv8-dotprod"
@@ -116,6 +117,12 @@
116117
"os": "macos-14"
117118
}
118119
},
120+
{
121+
"binaries": "x86-64-avx512icl",
122+
"config": {
123+
"os": "macos-14"
124+
}
125+
},
119126
{
120127
"binaries": "x86-64-avxvnni",
121128
"config": {
@@ -140,6 +147,12 @@
140147
"os": "macos-13"
141148
}
142149
},
150+
{
151+
"binaries": "x86-64-avx512icl",
152+
"config": {
153+
"os": "macos-13"
154+
}
155+
},
143156
{
144157
"binaries": "x86-64",
145158
"config": {
@@ -188,6 +201,12 @@
188201
"os": "windows-11-arm"
189202
}
190203
},
204+
{
205+
"binaries": "x86-64-avx512icl",
206+
"config": {
207+
"os": "windows-11-arm"
208+
}
209+
},
191210
{
192211
"binaries": "apple-silicon",
193212
"config": {

.github/workflows/compilation.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ jobs:
4343

4444
- name: Download SDE package
4545
if: runner.os == 'Linux' || runner.os == 'Windows'
46-
uses: petarpetrovt/setup-sde@91a1a03434384e064706634125a15f7446d2aafb # @v2.3
46+
uses: petarpetrovt/setup-sde@f0fa5971dc275704531e94264dd23250c442aa41 # @v2.4
4747
with:
4848
environmentVariableName: SDE_DIR
49-
sdeVersion: 9.27.0
49+
sdeVersion: 9.33.0
5050

5151
- name: Download the used network from the fishtest framework
5252
run: make net

.github/workflows/sanitizers.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
- name: Run with glibcxx assertions
4343
make_option: ""
4444
cxx_extra_flags: -D_GLIBCXX_ASSERTIONS
45-
instrumented_option: non
45+
instrumented_option: none
4646
defaults:
4747
run:
4848
working-directory: src

AUTHORS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,15 @@ Jonathan McDermid (jonathanmcdermid)
125125
Joost VandeVondele (vondele)
126126
Joseph Ellis (jhellis3)
127127
Joseph R. Prostko
128+
Jost Triller (tsoj)
128129
Jörg Oster (joergoster)
129130
Julian Willemer (NightlyKing)
130131
jundery
131132
Justin Blanchard (UncombedCoconut)
132133
Kelly Wilson
133134
Ken Takusagawa
134135
Kenneth Lee (kennethlee33)
136+
kevlu8
135137
Kian E (KJE-98)
136138
kinderchocolate
137139
Kiran Panditrao (Krgp)
@@ -232,6 +234,7 @@ Stefano Di Martino (StefanoD)
232234
Steinar Gunderson (sesse)
233235
Stéphane Nicolet (snicolet)
234236
Stephen Touset (stouset)
237+
Stockfisher69
235238
Styx (styxdoto)
236239
Syine Mineta (MinetaS)
237240
Taras Vuk (TarasVuk)

src/Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,10 @@ endif
590590
# Locate the version in the same directory as the compiler used,
591591
# with fallback to a generic one if it can't be located
592592
LLVM_PROFDATA := $(dir $(realpath $(shell which $(CXX) 2> /dev/null)))llvm-profdata
593+
# for icx
594+
ifeq ($(wildcard $(LLVM_PROFDATA)),)
595+
LLVM_PROFDATA := $(dir $(realpath $(shell which $(CXX) 2> /dev/null)))/compiler/llvm-profdata
596+
endif
593597
ifeq ($(wildcard $(LLVM_PROFDATA)),)
594598
LLVM_PROFDATA := llvm-profdata
595599
endif
@@ -899,7 +903,7 @@ help:
899903
echo "Supported archs:" && \
900904
echo "" && \
901905
echo "native > select the best architecture for the host processor (default)" && \
902-
echo "x86-64-avx512icl > x86 64-bit with minimum avx512 support of Intel Ice Lane or AMD Zen 4" && \
906+
echo "x86-64-avx512icl > x86 64-bit with minimum avx512 support of Intel Ice Lake or AMD Zen 4" && \
903907
echo "x86-64-vnni512 > x86 64-bit with vnni 512bit support" && \
904908
echo "x86-64-vnni256 > x86 64-bit with vnni 512bit support, limit operands to 256bit wide" && \
905909
echo "x86-64-avx512 > x86 64-bit with avx512 support" && \
@@ -1137,7 +1141,7 @@ icx-profile-make:
11371141
all
11381142

11391143
icx-profile-use:
1140-
$(XCRUN) llvm-profdata merge -output=$(EXE).profdata *.profraw
1144+
$(XCRUN) $(LLVM_PROFDATA) merge -output=$(EXE).profdata *.profraw
11411145
$(MAKE) ARCH=$(ARCH) COMP=$(COMP) \
11421146
EXTRACXXFLAGS='-fprofile-instr-use=$(EXE).profdata' \
11431147
EXTRALDFLAGS='-fprofile-use ' \

src/history.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,12 @@ static_assert((PAWN_HISTORY_SIZE & (PAWN_HISTORY_SIZE - 1)) == 0,
4444
static_assert((CORRECTION_HISTORY_SIZE & (CORRECTION_HISTORY_SIZE - 1)) == 0,
4545
"CORRECTION_HISTORY_SIZE has to be a power of 2");
4646

47-
enum PawnHistoryType {
48-
Normal,
49-
Correction
50-
};
47+
inline int pawn_history_index(const Position& pos) {
48+
return pos.pawn_key() & (PAWN_HISTORY_SIZE - 1);
49+
}
5150

52-
template<PawnHistoryType T = Normal>
53-
inline int pawn_structure_index(const Position& pos) {
54-
return pos.pawn_key() & ((T == Normal ? PAWN_HISTORY_SIZE : CORRECTION_HISTORY_SIZE) - 1);
51+
inline int pawn_correction_history_index(const Position& pos) {
52+
return pos.pawn_key() & (CORRECTION_HISTORY_SIZE - 1);
5553
}
5654

5755
inline int minor_piece_index(const Position& pos) {
@@ -103,7 +101,7 @@ using Stats = MultiArray<StatsEntry<T, D>, Sizes...>;
103101
// ButterflyHistory records how often quiet moves have been successful or unsuccessful
104102
// during the current search, and is used for reduction and move ordering decisions.
105103
// It uses 2 tables (one for each color) indexed by the move's from and to squares,
106-
// see https://www.chessprogramming.org/Butterfly_Boards (~11 elo)
104+
// see https://www.chessprogramming.org/Butterfly_Boards
107105
using ButterflyHistory = Stats<std::int16_t, 7183, COLOR_NB, int(SQUARE_NB) * int(SQUARE_NB)>;
108106

109107
// LowPlyHistory is adressed by play and move's from and to squares, used
@@ -120,7 +118,6 @@ using PieceToHistory = Stats<std::int16_t, 30000, PIECE_NB, SQUARE_NB>;
120118
// ContinuationHistory is the combined history of a given pair of moves, usually
121119
// the current one given a previous one. The nested history table is based on
122120
// PieceToHistory instead of ButterflyBoards.
123-
// (~63 elo)
124121
using ContinuationHistory = MultiArray<PieceToHistory, PIECE_NB, SQUARE_NB>;
125122

126123
// PawnHistory is addressed by the pawn structure and a move's [piece][to]

src/movegen.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ namespace {
3737
#if defined(USE_AVX512ICL)
3838

3939
inline Move* write_moves(Move* moveList, uint32_t mask, __m512i vector) {
40+
// Avoid _mm512_mask_compressstoreu_epi16() as it's 256 uOps on Zen4
4041
_mm512_storeu_si512(reinterpret_cast<__m512i*>(moveList),
4142
_mm512_maskz_compress_epi16(mask, vector));
4243
return moveList + popcount(mask);

src/movepick.cpp

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, int th, const CapturePieceTo
115115
threshold(th) {
116116
assert(!pos.checkers());
117117

118-
stage = PROBCUT_TT
119-
+ !(ttm && pos.capture_stage(ttm) && pos.pseudo_legal(ttm) && pos.see_ge(ttm, threshold));
118+
stage = PROBCUT_TT + !(ttm && pos.capture_stage(ttm) && pos.pseudo_legal(ttm));
120119
}
121120

122121
// Assigns a numerical value to each move in a list, used for sorting.
@@ -129,13 +128,15 @@ ExtMove* MovePicker::score(MoveList<Type>& ml) {
129128

130129
Color us = pos.side_to_move();
131130

132-
[[maybe_unused]] Bitboard threatByLesser[QUEEN + 1];
131+
[[maybe_unused]] Bitboard threatByLesser[KING + 1];
133132
if constexpr (Type == QUIETS)
134133
{
134+
threatByLesser[PAWN] = 0;
135135
threatByLesser[KNIGHT] = threatByLesser[BISHOP] = pos.attacks_by<PAWN>(~us);
136136
threatByLesser[ROOK] =
137137
pos.attacks_by<KNIGHT>(~us) | pos.attacks_by<BISHOP>(~us) | threatByLesser[KNIGHT];
138138
threatByLesser[QUEEN] = pos.attacks_by<ROOK>(~us) | threatByLesser[ROOK];
139+
threatByLesser[KING] = pos.attacks_by<QUEEN>(~us) | threatByLesser[QUEEN];
139140
}
140141

141142
ExtMove* it = cur;
@@ -158,7 +159,7 @@ ExtMove* MovePicker::score(MoveList<Type>& ml) {
158159
{
159160
// histories
160161
m.value = 2 * (*mainHistory)[us][m.from_to()];
161-
m.value += 2 * (*pawnHistory)[pawn_structure_index(pos)][pc][to];
162+
m.value += 2 * (*pawnHistory)[pawn_history_index(pos)][pc][to];
162163
m.value += (*continuationHistory[0])[pc][to];
163164
m.value += (*continuationHistory[1])[pc][to];
164165
m.value += (*continuationHistory[2])[pc][to];
@@ -170,12 +171,10 @@ ExtMove* MovePicker::score(MoveList<Type>& ml) {
170171

171172
// penalty for moving to a square threatened by a lesser piece
172173
// or bonus for escaping an attack by a lesser piece.
173-
if (KNIGHT <= pt && pt <= QUEEN)
174-
{
175-
static constexpr int bonus[QUEEN + 1] = {0, 0, 144, 144, 256, 517};
176-
int v = threatByLesser[pt] & to ? -95 : 100 * bool(threatByLesser[pt] & from);
177-
m.value += bonus[pt] * v;
178-
}
174+
static constexpr int bonus[KING + 1] = {0, 0, 144, 144, 256, 517, 10000};
175+
int v = threatByLesser[pt] & to ? -95 : 100 * bool(threatByLesser[pt] & from);
176+
m.value += bonus[pt] * v;
177+
179178

180179
if (ply < LOW_PLY_HISTORY_SIZE)
181180
m.value += 8 * (*lowPlyHistory)[ply][m.from_to()] / (1 + ply);
@@ -316,18 +315,4 @@ Move MovePicker::next_move() {
316315

317316
void MovePicker::skip_quiet_moves() { skipQuiets = true; }
318317

319-
// this function must be called after all quiet moves and captures have been generated
320-
bool MovePicker::can_move_king_or_pawn() const {
321-
// SEE negative captures shouldn't be returned in GOOD_CAPTURE stage
322-
assert(stage > GOOD_CAPTURE && stage != EVASION_INIT);
323-
324-
for (const ExtMove* m = moves; m < endGenerated; ++m)
325-
{
326-
PieceType movedPieceType = type_of(pos.moved_piece(*m));
327-
if ((movedPieceType == PAWN || movedPieceType == KING))
328-
return true;
329-
}
330-
return false;
331-
}
332-
333318
} // namespace Stockfish

src/movepick.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class MovePicker {
5050
MovePicker(const Position&, Move, int, const CapturePieceToHistory*);
5151
Move next_move();
5252
void skip_quiet_moves();
53-
bool can_move_king_or_pawn() const;
5453

5554
private:
5655
template<typename Pred>
@@ -67,7 +66,7 @@ class MovePicker {
6766
const PieceToHistory** continuationHistory;
6867
const PawnHistory* pawnHistory;
6968
Move ttMove;
70-
ExtMove * cur, *endCur, *endBadCaptures, *endCaptures, *endGenerated;
69+
ExtMove * cur, *endCur, *endBadCaptures, *endCaptures, *endGenerated = moves;
7170
int stage;
7271
int threshold;
7372
Depth depth;

src/nnue/layers/affine_transform_sparse_input.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ void find_nnz(const std::int32_t* RESTRICT input,
8888
constexpr IndexType SimdWidthOut = 32; // 512 bits / 16 bits
8989
constexpr IndexType NumChunks = InputDimensions / SimdWidthOut;
9090
const __m512i increment = _mm512_set1_epi16(SimdWidthOut);
91-
__m512i base = _mm512_set_epi16(31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16,
92-
15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
91+
__m512i base = _mm512_set_epi16( // Same permute order as _mm512_packus_epi32()
92+
31, 30, 29, 28, 15, 14, 13, 12, 27, 26, 25, 24, 11, 10, 9, 8, 23, 22, 21, 20, 7, 6, 5, 4, 19,
93+
18, 17, 16, 3, 2, 1, 0);
9394

9495
IndexType count = 0;
9596
for (IndexType i = 0; i < NumChunks; ++i)
@@ -98,12 +99,12 @@ void find_nnz(const std::int32_t* RESTRICT input,
9899
const __m512i inputV1 = _mm512_load_si512(input + i * 2 * SimdWidthIn + SimdWidthIn);
99100

100101
// Get a bitmask and gather non zero indices
101-
const __mmask32 nnzMask = _mm512_kunpackw(_mm512_test_epi32_mask(inputV1, inputV1),
102-
_mm512_test_epi32_mask(inputV0, inputV0));
102+
const __m512i inputV01 = _mm512_packus_epi32(inputV0, inputV1);
103+
const __mmask32 nnzMask = _mm512_test_epi16_mask(inputV01, inputV01);
103104

104105
// Avoid _mm512_mask_compressstoreu_epi16() as it's 256 uOps on Zen4
105106
__m512i nnz = _mm512_maskz_compress_epi16(nnzMask, base);
106-
_mm512_storeu_epi16(out + count, nnz);
107+
_mm512_storeu_si512(out + count, nnz);
107108

108109
count += popcount(nnzMask);
109110
base = _mm512_add_epi16(base, increment);

0 commit comments

Comments
 (0)