From 6c81c103f5baad90ab497f35e83cc54ee28bee5a Mon Sep 17 00:00:00 2001 From: johndoknjas Date: Sat, 31 Aug 2024 02:54:36 -0700 Subject: [PATCH] Change some post-increments to pre-increments. --- AUTHORS | 1 + src/bitboard.cpp | 2 +- src/nnue/nnue_feature_transformer.h | 4 ++-- src/perft.h | 2 +- src/position.cpp | 2 +- src/search.cpp | 16 ++++++++-------- src/syzygy/tbprobe.cpp | 24 ++++++++++++------------ src/tune.h | 2 +- 8 files changed, 27 insertions(+), 26 deletions(-) diff --git a/AUTHORS b/AUTHORS index 3201e7a8afe..1d21a1273c1 100644 --- a/AUTHORS +++ b/AUTHORS @@ -111,6 +111,7 @@ Jean Gauthier (OuaisBla) Jekaa Jerry Donald Watson (jerrydonaldwatson) jjoshua2 +John Doknjas (johndoknjas) Jonathan Buladas Dumale (SFisGOD) Jonathan Calovski (Mysseno) Jonathan McDermid (jonathanmcdermid) diff --git a/src/bitboard.cpp b/src/bitboard.cpp index c842ca1271e..51ef9d7ac14 100644 --- a/src/bitboard.cpp +++ b/src/bitboard.cpp @@ -180,7 +180,7 @@ void init_magics(PieceType pt, Bitboard table[], Magic magics[]) { if (HasPext) m.attacks[pext(b, m.mask)] = reference[size]; - size++; + ++size; b = (b - m.mask) & m.mask; } while (b); diff --git a/src/nnue/nnue_feature_transformer.h b/src/nnue/nnue_feature_transformer.h index 2f74dcae2ed..87834ec2c86 100644 --- a/src/nnue/nnue_feature_transformer.h +++ b/src/nnue/nnue_feature_transformer.h @@ -779,9 +779,9 @@ class FeatureTransformer { acc[k] = vec_add_16(acc[k], column[k]); } - for (IndexType k = 0; k < NumRegs; k++) + for (IndexType k = 0; k < NumRegs; ++k) vec_store(&entryTile[k], acc[k]); - for (IndexType k = 0; k < NumRegs; k++) + for (IndexType k = 0; k < NumRegs; ++k) vec_store(&accTile[k], acc[k]); } diff --git a/src/perft.h b/src/perft.h index e907742da05..2d231993a87 100644 --- a/src/perft.h +++ b/src/perft.h @@ -42,7 +42,7 @@ uint64_t perft(Position& pos, Depth depth) { for (const auto& m : MoveList(pos)) { if (Root && depth <= 1) - cnt = 1, nodes++; + cnt = 1, ++nodes; else { pos.do_move(m, st); diff --git a/src/position.cpp b/src/position.cpp index d374b1c070a..f0d24a06afc 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -149,7 +149,7 @@ void Position::init() { break; i = (i == H1(key)) ? H2(key) : H1(key); // Push victim to alternative slot } - count++; + ++count; } assert(count == 3668); } diff --git a/src/search.cpp b/src/search.cpp index ad2c35e7708..7300914b427 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -278,7 +278,7 @@ void Search::Worker::iterative_deepening() { pvLast = 0; if (!threads.increaseDepth) - searchAgainCounter++; + ++searchAgainCounter; // MultiPV loop. We perform a full root search for each PV line for (pvIdx = 0; pvIdx < multiPV; ++pvIdx) @@ -286,7 +286,7 @@ void Search::Worker::iterative_deepening() { if (pvIdx == pvLast) { pvFirst = pvLast; - for (pvLast++; pvLast < rootMoves.size(); pvLast++) + for (++pvLast; pvLast < rootMoves.size(); ++pvLast) if (rootMoves[pvLast].tbRank != rootMoves[pvFirst].tbRank) break; } @@ -1128,7 +1128,7 @@ Value Search::Worker::search( // Decrease reduction for PvNodes (~0 Elo on STC, ~2 Elo on LTC) if (PvNode) - r--; + --r; // These reduction adjustments have no proven non-linear scaling @@ -1138,7 +1138,7 @@ Value Search::Worker::search( // Increase reduction if ttMove is a capture (~3 Elo) if (ttCapture) - r++; + ++r; // Increase reduction if next ply has a lot of fail high (~5 Elo) if ((ss + 1)->cutoffCnt > 3) @@ -1545,7 +1545,7 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta) givesCheck = pos.gives_check(move); capture = pos.capture_stage(move); - moveCount++; + ++moveCount; // Step 6. Pruning if (bestValue > VALUE_TB_LOSS_IN_MAX_PLY && pos.non_pawn_material(us)) @@ -1928,7 +1928,7 @@ void syzygy_extend_pv(const OptionsMap& options, if (legalMoves[0].tbRank != rm.tbRank) break; - ply++; + ++ply; auto& st = sts.emplace_back(); pos.do_move(pvMove, st); @@ -1937,7 +1937,7 @@ void syzygy_extend_pv(const OptionsMap& options, if (config.rootInTB && pos.is_draw(ply)) { pos.undo_move(pvMove); - ply--; + --ply; break; } @@ -1988,7 +1988,7 @@ void syzygy_extend_pv(const OptionsMap& options, if (!config.rootInTB || config.cardinality > 0) break; - ply++; + ++ply; Move& pvMove = legalMoves[0].pv[0]; rootMove.pv.push_back(pvMove); diff --git a/src/syzygy/tbprobe.cpp b/src/syzygy/tbprobe.cpp index 9b24e700b18..537131219d2 100644 --- a/src/syzygy/tbprobe.cpp +++ b/src/syzygy/tbprobe.cpp @@ -516,7 +516,7 @@ void TBTables::add(const std::vector& pieces) { if (file_dtz.is_open()) { file_dtz.close(); - foundDTZFiles++; + ++foundDTZFiles; } TBFile file(code + ".rtbw"); // KRK -> KRvK @@ -525,7 +525,7 @@ void TBTables::add(const std::vector& pieces) { return; file.close(); - foundWDLFiles++; + ++foundWDLFiles; MaxCardinality = std::max(int(pieces.size()), MaxCardinality); @@ -1148,7 +1148,7 @@ void set(T& e, uint8_t* data) { assert(e.hasPawns == bool(*data & HasPawns)); assert((e.key != e.key2) == bool(*data & Split)); - data++; // First byte stores flags + ++data; // First byte stores flags const int sides = T::Sides == 2 && (e.key != e.key2) ? 2 : 1; const File maxFile = e.hasPawns ? FILE_D : FILE_A; @@ -1160,7 +1160,7 @@ void set(T& e, uint8_t* data) { for (File f = FILE_A; f <= maxFile; ++f) { - for (int i = 0; i < sides; i++) + for (int i = 0; i < sides; ++i) *e.get(i, f) = PairsData(); int order[][2] = {{*data & 0xF, pp ? *(data + 1) & 0xF : 0xF}, @@ -1168,7 +1168,7 @@ void set(T& e, uint8_t* data) { data += 1 + pp; for (int k = 0; k < e.pieceCount; ++k, ++data) - for (int i = 0; i < sides; i++) + for (int i = 0; i < sides; ++i) e.get(i, f)->pieces[k] = Piece(i ? *data >> 4 : *data & 0xF); for (int i = 0; i < sides; ++i) @@ -1178,27 +1178,27 @@ void set(T& e, uint8_t* data) { data += uintptr_t(data) & 1; // Word alignment for (File f = FILE_A; f <= maxFile; ++f) - for (int i = 0; i < sides; i++) + for (int i = 0; i < sides; ++i) data = set_sizes(e.get(i, f), data); data = set_dtz_map(e, data, maxFile); for (File f = FILE_A; f <= maxFile; ++f) - for (int i = 0; i < sides; i++) + for (int i = 0; i < sides; ++i) { (d = e.get(i, f))->sparseIndex = (SparseEntry*) data; data += d->sparseIndexSize * sizeof(SparseEntry); } for (File f = FILE_A; f <= maxFile; ++f) - for (int i = 0; i < sides; i++) + for (int i = 0; i < sides; ++i) { (d = e.get(i, f))->blockLength = (uint16_t*) data; data += d->blockLengthSize * sizeof(uint16_t); } for (File f = FILE_A; f <= maxFile; ++f) - for (int i = 0; i < sides; i++) + for (int i = 0; i < sides; ++i) { data = (uint8_t*) ((uintptr_t(data) + 0x3F) & ~0x3F); // 64 byte alignment (d = e.get(i, f))->data = data; @@ -1286,7 +1286,7 @@ WDLScore search(Position& pos, ProbeState* result) { if (!pos.capture(move) && (!CheckZeroingMoves || type_of(pos.moved_piece(move)) != PAWN)) continue; - moveCount++; + ++moveCount; pos.do_move(move, st); value = -search(pos, result); @@ -1372,7 +1372,7 @@ void Tablebases::init(const std::string& paths) { // diagonal, the other one shall not be above the a1-h8 diagonal. std::vector> bothOnDiagonal; code = 0; - for (int idx = 0; idx < 10; idx++) + for (int idx = 0; idx < 10; ++idx) for (Square s1 = SQ_A1; s1 <= SQ_D4; ++s1) if (MapA1D1D4[s1] == idx && (idx || s1 == SQ_B1)) // SQ_B1 is mapped to 0 { @@ -1398,7 +1398,7 @@ void Tablebases::init(const std::string& paths) { // are Binomial[k][n] ways to choose k elements from a set of n elements. Binomial[0][0] = 1; - for (int n = 1; n < 64; n++) // Squares + for (int n = 1; n < 64; ++n) // Squares for (int k = 0; k < 6 && k <= n; ++k) // Pieces Binomial[k][n] = (k > 0 ? Binomial[k - 1][n - 1] : 0) + (k < n ? Binomial[k][n - 1] : 0); diff --git a/src/tune.h b/src/tune.h index ed4738cdc47..a648e02d299 100644 --- a/src/tune.h +++ b/src/tune.h @@ -134,7 +134,7 @@ class Tune { // Template specialization for arrays: recursively handle multi-dimensional arrays template int add(const SetRange& range, std::string&& names, T (&value)[N], Args&&... args) { - for (size_t i = 0; i < N; i++) + for (size_t i = 0; i < N; ++i) add(range, next(names, i == N - 1) + "[" + std::to_string(i) + "]", value[i]); return add(range, std::move(names), args...); }