Skip to content

Commit

Permalink
Change some post-increments to pre-increments and += 1.
Browse files Browse the repository at this point in the history
  • Loading branch information
johndoknjas committed Sep 1, 2024
1 parent 4510442 commit 60f5938
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 26 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/bitboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 += 1;
b = (b - m.mask) & m.mask;
} while (b);

Expand Down
4 changes: 2 additions & 2 deletions src/nnue/nnue_feature_transformer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/perft.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ uint64_t perft(Position& pos, Depth depth) {
for (const auto& m : MoveList<LEGAL>(pos))
{
if (Root && depth <= 1)
cnt = 1, nodes++;
cnt = 1, nodes += 1;
else
{
pos.do_move(m, st);
Expand Down
2 changes: 1 addition & 1 deletion src/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void Position::init() {
break;
i = (i == H1(key)) ? H2(key) : H1(key); // Push victim to alternative slot
}
count++;
count += 1;
}
assert(count == 3668);
}
Expand Down
16 changes: 8 additions & 8 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,15 @@ void Search::Worker::iterative_deepening() {
pvLast = 0;

if (!threads.increaseDepth)
searchAgainCounter++;
searchAgainCounter += 1;

// MultiPV loop. We perform a full root search for each PV line
for (pvIdx = 0; pvIdx < multiPV; ++pvIdx)
{
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;
}
Expand Down Expand Up @@ -1128,7 +1128,7 @@ Value Search::Worker::search(

// Decrease reduction for PvNodes (~0 Elo on STC, ~2 Elo on LTC)
if (PvNode)
r--;
r -= 1;

// These reduction adjustments have no proven non-linear scaling

Expand All @@ -1138,7 +1138,7 @@ Value Search::Worker::search(

// Increase reduction if ttMove is a capture (~3 Elo)
if (ttCapture)
r++;
r += 1;

// Increase reduction if next ply has a lot of fail high (~5 Elo)
if ((ss + 1)->cutoffCnt > 3)
Expand Down Expand Up @@ -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 += 1;

// Step 6. Pruning
if (bestValue > VALUE_TB_LOSS_IN_MAX_PLY && pos.non_pawn_material(us))
Expand Down Expand Up @@ -1928,7 +1928,7 @@ void syzygy_extend_pv(const OptionsMap& options,
if (legalMoves[0].tbRank != rm.tbRank)
break;

ply++;
ply += 1;

auto& st = sts.emplace_back();
pos.do_move(pvMove, st);
Expand All @@ -1937,7 +1937,7 @@ void syzygy_extend_pv(const OptionsMap& options,
if (config.rootInTB && pos.is_draw(ply))
{
pos.undo_move(pvMove);
ply--;
ply -= 1;
break;
}

Expand Down Expand Up @@ -1988,7 +1988,7 @@ void syzygy_extend_pv(const OptionsMap& options,
if (!config.rootInTB || config.cardinality > 0)
break;

ply++;
ply += 1;

Move& pvMove = legalMoves[0].pv[0];
rootMove.pv.push_back(pvMove);
Expand Down
24 changes: 12 additions & 12 deletions src/syzygy/tbprobe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ void TBTables::add(const std::vector<PieceType>& pieces) {
if (file_dtz.is_open())
{
file_dtz.close();
foundDTZFiles++;
foundDTZFiles += 1;
}

TBFile file(code + ".rtbw"); // KRK -> KRvK
Expand All @@ -525,7 +525,7 @@ void TBTables::add(const std::vector<PieceType>& pieces) {
return;

file.close();
foundWDLFiles++;
++foundWDLFiles;

MaxCardinality = std::max(int(pieces.size()), MaxCardinality);

Expand Down Expand Up @@ -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 += 1; // 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;
Expand All @@ -1160,15 +1160,15 @@ 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},
{*data >> 4, pp ? *(data + 1) >> 4 : 0xF}};
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)
Expand All @@ -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;
Expand Down Expand Up @@ -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 += 1;

pos.do_move(move, st);
value = -search<false>(pos, result);
Expand Down Expand Up @@ -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<std::pair<int, Square>> 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
{
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/tune.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class Tune {
// Template specialization for arrays: recursively handle multi-dimensional arrays
template<typename T, size_t N, typename... Args>
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...);
}
Expand Down

0 comments on commit 60f5938

Please sign in to comment.