From: Kojirion Date: Sun, 15 Sep 2013 07:11:29 +0000 (+0200) Subject: Use pre-increment also for native types X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=a71209868bdd8361d0607acf7725f70e9d1f2019 Use pre-increment also for native types Now that we use pre-increment on enums, it make sense, for code style uniformity, to swith to pre-increment also for native types, although there is no speed difference. No functional change. --- diff --git a/src/benchmark.cpp b/src/benchmark.cpp index f22ea6da..a0dab27b 100644 --- a/src/benchmark.cpp +++ b/src/benchmark.cpp @@ -116,7 +116,7 @@ void benchmark(const Position& current, istream& is) { Search::StateStackPtr st; Time::point elapsed = Time::now(); - for (size_t i = 0; i < fens.size(); i++) + for (size_t i = 0; i < fens.size(); ++i) { Position pos(fens[i], Options["UCI_Chess960"], Threads.main()); diff --git a/src/bitboard.cpp b/src/bitboard.cpp index a377703b..cbece63c 100644 --- a/src/bitboard.cpp +++ b/src/bitboard.cpp @@ -150,11 +150,11 @@ void Bitboards::print(Bitboard b) { void Bitboards::init() { - for (int k = 0, i = 0; i < 8; i++) + for (int k = 0, i = 0; i < 8; ++i) while (k < (2 << i)) MS1BTable[k++] = i; - for (int i = 0; i < 64; i++) + for (int i = 0; i < 64; ++i) BSFTable[bsf_index(1ULL << i)] = Square(i); for (Square s = SQ_A1; s <= SQ_H8; ++s) @@ -163,7 +163,7 @@ void Bitboards::init() { FileBB[FILE_A] = FileABB; RankBB[RANK_1] = Rank1BB; - for (int i = 1; i < 8; i++) + for (int i = 1; i < 8; ++i) { FileBB[i] = FileBB[i - 1] << 1; RankBB[i] = RankBB[i - 1] << 8; @@ -235,7 +235,7 @@ namespace { Bitboard attack = 0; - for (int i = 0; i < 4; i++) + for (int i = 0; i < 4; ++i) for (Square s = sq + deltas[i]; is_ok(s) && square_distance(s, s - deltas[i]) == 1; s += deltas[i]) @@ -322,7 +322,7 @@ namespace { // looks up the correct sliding attack in the attacks[s] database. // Note that we build up the database for square 's' as a side // effect of verifying the magic. - for (i = 0; i < size; i++) + for (i = 0; i < size; ++i) { Bitboard& attack = attacks[s][index(s, occupancy[i])]; diff --git a/src/book.cpp b/src/book.cpp index caf2b066..c5c40dde 100644 --- a/src/book.cpp +++ b/src/book.cpp @@ -361,7 +361,7 @@ PolyglotBook::~PolyglotBook() { if (is_open()) close(); } template PolyglotBook& PolyglotBook::operator>>(T& n) { n = 0; - for (size_t i = 0; i < sizeof(T); i++) + for (size_t i = 0; i < sizeof(T); ++i) n = T((n << 8) + ifstream::get()); return *this; diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 912c05fc..fbde9d11 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -288,7 +288,7 @@ namespace Eval { const int MaxSlope = 30; const int Peak = 1280; - for (int t = 0, i = 1; i < 100; i++) + for (int t = 0, i = 1; i < 100; ++i) { t = std::min(Peak, std::min(int(0.4 * i * i), t + MaxSlope)); diff --git a/src/main.cpp b/src/main.cpp index 3d26b63a..74483a87 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -43,7 +43,7 @@ int main(int argc, char* argv[]) { std::string args; - for (int i = 1; i < argc; i++) + for (int i = 1; i < argc; ++i) args += std::string(argv[i]) + " "; UCI::loop(args); diff --git a/src/movepick.cpp b/src/movepick.cpp index 4f2fa01e..643c8368 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -231,7 +231,7 @@ void MovePicker::generate_next() { killers[2].move = killers[3].move = MOVE_NONE; // Be sure countermoves are different from killers - for (int i = 0; i < 2; i++) + for (int i = 0; i < 2; ++i) if (countermoves[i] != cur->move && countermoves[i] != (cur+1)->move) (end++)->move = countermoves[i]; diff --git a/src/position.cpp b/src/position.cpp index 2266f2a5..4cb7e306 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -1149,7 +1149,7 @@ void Position::clear() { startState.epSquare = SQ_NONE; st = &startState; - for (int i = 0; i < PIECE_TYPE_NB; i++) + for (int i = 0; i < PIECE_TYPE_NB; ++i) for (int j = 0; j < 16; j++) pieceList[WHITE][i][j] = pieceList[BLACK][i][j] = SQ_NONE; } @@ -1428,7 +1428,7 @@ bool Position::pos_is_ok(int* failedStep) const { if ((*step)++, debugPieceList) for (Color c = WHITE; c <= BLACK; ++c) for (PieceType pt = PAWN; pt <= KING; ++pt) - for (int i = 0; i < pieceCount[c][pt]; i++) + for (int i = 0; i < pieceCount[c][pt]; ++i) if ( board[pieceList[c][pt][i]] != make_piece(c, pt) || index[pieceList[c][pt][i]] != i) return false; diff --git a/src/rkiss.h b/src/rkiss.h index 9564253b..18c1d4f6 100644 --- a/src/rkiss.h +++ b/src/rkiss.h @@ -64,7 +64,7 @@ public: s.a = 0xf1ea5eed; s.b = s.c = s.d = 0xd4e12c77; - for (int i = 0; i < seed; i++) // Scramble a few rounds + for (int i = 0; i < seed; ++i) // Scramble a few rounds rand64(); } diff --git a/src/search.cpp b/src/search.cpp index e29f5449..4ab17fd8 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -236,7 +236,7 @@ void Search::think() { } // Reset the threads, still sleeping: will be wake up at split time - for (size_t i = 0; i < Threads.size(); i++) + for (size_t i = 0; i < Threads.size(); ++i) Threads[i]->maxPly = 0; Threads.sleepWhileIdle = Options["Idle Threads Sleep"]; @@ -337,7 +337,7 @@ namespace { // Save last iteration's scores before first PV line is searched and all // the move scores but the (new) PV are set to -VALUE_INFINITE. - for (size_t i = 0; i < RootMoves.size(); i++) + for (size_t i = 0; i < RootMoves.size(); ++i) RootMoves[i].prevScore = RootMoves[i].score; // MultiPV loop. We perform a full root search for each PV line @@ -367,7 +367,7 @@ namespace { // Write PV back to transposition table in case the relevant // entries have been overwritten during the search. - for (size_t i = 0; i <= PVIdx; i++) + for (size_t i = 0; i <= PVIdx; ++i) RootMoves[i].insert_pv_in_tt(pos); // If search has been stopped return immediately. Sorting and @@ -1102,7 +1102,7 @@ moves_loop: // When in check and at SpNode search starts from here // played non-capture moves. Value bonus = Value(int(depth) * int(depth)); History.update(pos.piece_moved(bestMove), to_sq(bestMove), bonus); - for (int i = 0; i < quietCount - 1; i++) + for (int i = 0; i < quietCount - 1; ++i) { Move m = quietsSearched[i]; History.update(pos.piece_moved(m), to_sq(m), -bonus); @@ -1456,7 +1456,7 @@ moves_loop: // When in check and at SpNode search starts from here // Choose best move. For each move score we add two terms both dependent on // weakness, one deterministic and bigger for weaker moves, and one random, // then we choose the move with the resulting highest score. - for (size_t i = 0; i < PVSize; i++) + for (size_t i = 0; i < PVSize; ++i) { int s = RootMoves[i].score; @@ -1489,11 +1489,11 @@ moves_loop: // When in check and at SpNode search starts from here size_t uciPVSize = std::min((size_t)Options["MultiPV"], RootMoves.size()); int selDepth = 0; - for (size_t i = 0; i < Threads.size(); i++) + for (size_t i = 0; i < Threads.size(); ++i) if (Threads[i]->maxPly > selDepth) selDepth = Threads[i]->maxPly; - for (size_t i = 0; i < uciPVSize; i++) + for (size_t i = 0; i < uciPVSize; ++i) { bool updated = (i <= PVIdx); @@ -1730,7 +1730,7 @@ void check_time() { // Loop across all split points and sum accumulated SplitPoint nodes plus // all the currently active positions nodes. - for (size_t i = 0; i < Threads.size(); i++) + for (size_t i = 0; i < Threads.size(); ++i) for (int j = 0; j < Threads[i]->splitPointsSize; j++) { SplitPoint& sp = Threads[i]->splitPoints[j]; diff --git a/src/timeman.cpp b/src/timeman.cpp index 3bc9a317..8bda4f25 100644 --- a/src/timeman.cpp +++ b/src/timeman.cpp @@ -155,7 +155,7 @@ namespace { int thisMoveImportance = move_importance(currentPly) * slowMover / 100; int otherMovesImportance = 0; - for (int i = 1; i < movesToGo; i++) + for (int i = 1; i < movesToGo; ++i) otherMovesImportance += move_importance(currentPly + 2 * i); float ratio1 = (TMaxRatio * thisMoveImportance) / float(TMaxRatio * thisMoveImportance + otherMovesImportance); diff --git a/src/tt.cpp b/src/tt.cpp index 9774a233..11173e0a 100644 --- a/src/tt.cpp +++ b/src/tt.cpp @@ -73,7 +73,7 @@ const TTEntry* TranspositionTable::probe(const Key key) const { const TTEntry* tte = first_entry(key); uint32_t key32 = key >> 32; - for (unsigned i = 0; i < ClusterSize; i++, tte++) + for (unsigned i = 0; i < ClusterSize; ++i, tte++) if (tte->key() == key32) return tte; @@ -97,7 +97,7 @@ void TranspositionTable::store(const Key key, Value v, Bound b, Depth d, Move m, tte = replace = first_entry(key); - for (unsigned i = 0; i < ClusterSize; i++, tte++) + for (unsigned i = 0; i < ClusterSize; ++i, tte++) { if (!tte->key() || tte->key() == key32) // Empty or overwrite old {