From: Marco Costalba Date: Sat, 13 Jul 2013 15:21:24 +0000 (+0200) Subject: Fully qualify memset and memcpy X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=4ede49cd850392f28bc9da9537c111d2c3f0b297 Fully qualify memset and memcpy And other trivial touches. Ispired by Lucas's DiscoCheck No functional change. --- diff --git a/src/bitbase.cpp b/src/bitbase.cpp index b888d76c..570a9771 100644 --- a/src/bitbase.cpp +++ b/src/bitbase.cpp @@ -39,9 +39,9 @@ namespace { // bit 6-11: black king square (from SQ_A1 to SQ_H8) // bit 12: side to move (WHITE or BLACK) // bit 13-14: white pawn file (from FILE_A to FILE_D) - // bit 15-17: white pawn 6 - rank (from 6 - RANK_7 to 6 - RANK_2) + // bit 15-17: white pawn RANK_7 - rank (from RANK_7 - RANK_7 to RANK_7 - RANK_2) unsigned index(Color us, Square bksq, Square wksq, Square psq) { - return wksq + (bksq << 6) + (us << 12) + (file_of(psq) << 13) + ((6 - rank_of(psq)) << 15); + return wksq + (bksq << 6) + (us << 12) + (file_of(psq) << 13) + ((RANK_7 - rank_of(psq)) << 15); } enum Result { @@ -107,10 +107,10 @@ namespace { Result KPKPosition::classify_leaf(unsigned idx) { - wksq = Square((idx >> 0) & 0x3F); - bksq = Square((idx >> 6) & 0x3F); - us = Color((idx >> 12) & 0x01); - psq = File((idx >> 13) & 3) | Rank(6 - (idx >> 15)); + wksq = Square((idx >> 0) & 0x3F); + bksq = Square((idx >> 6) & 0x3F); + us = Color ((idx >> 12) & 0x01); + psq = File ((idx >> 13) & 0x03) | Rank(RANK_7 - (idx >> 15)); // Check if two pieces are on the same square or if a king can be captured if ( wksq == psq || wksq == bksq || bksq == psq diff --git a/src/bitboard.cpp b/src/bitboard.cpp index 756f0499..3f855c57 100644 --- a/src/bitboard.cpp +++ b/src/bitboard.cpp @@ -318,7 +318,7 @@ namespace { do magics[s] = pick_random(rk, booster); while (popcount((magics[s] * masks[s]) >> 56) < 6); - memset(attacks[s], 0, size * sizeof(Bitboard)); + std::memset(attacks[s], 0, size * sizeof(Bitboard)); // A good magic must map every possible occupancy to an index that // looks up the correct sliding attack in the attacks[s] database. diff --git a/src/evaluate.cpp b/src/evaluate.cpp index d171eb9b..3dbd6dc0 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -1142,7 +1142,7 @@ Value do_evaluate(const Position& pos, Value& margin) { stream.str(""); stream << std::showpoint << std::showpos << std::fixed << std::setprecision(2); - memset(scores, 0, 2 * (TOTAL + 1) * sizeof(Score)); + std::memset(scores, 0, 2 * (TOTAL + 1) * sizeof(Score)); Value margin; do_evaluate(pos, margin); diff --git a/src/material.cpp b/src/material.cpp index ed125dd7..22953cff 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -150,7 +150,7 @@ Entry* probe(const Position& pos, Table& entries, Endgames& endgames) { if (e->key == key) return e; - memset(e, 0, sizeof(Entry)); + std::memset(e, 0, sizeof(Entry)); e->key = key; e->factor[WHITE] = e->factor[BLACK] = (uint8_t)SCALE_FACTOR_NORMAL; e->gamePhase = game_phase(pos); diff --git a/src/movepick.h b/src/movepick.h index 57fe1c0e..37027ace 100644 --- a/src/movepick.h +++ b/src/movepick.h @@ -21,7 +21,7 @@ #define MOVEPICK_H_INCLUDED #include // For std::max -#include // For memset +#include // For std::memset #include "movegen.h" #include "position.h" @@ -43,7 +43,7 @@ struct Stats { static const Value Max = Value(2000); const T* operator[](Piece p) const { return table[p]; } - void clear() { memset(table, 0, sizeof(table)); } + void clear() { std::memset(table, 0, sizeof(table)); } void update(Piece p, Square to, Move m) { diff --git a/src/position.cpp b/src/position.cpp index d58fdec1..1273a62f 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -163,7 +163,7 @@ void Position::init() { Position& Position::operator=(const Position& pos) { - memcpy(this, &pos, sizeof(Position)); + std::memcpy(this, &pos, sizeof(Position)); startState = *st; st = &startState; nodes = 0; @@ -722,7 +722,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI // Copy some fields of old state to our new StateInfo object except the ones // which are going to be recalculated from scratch anyway, then switch our state // pointer to point to the new, ready to be updated, state. - memcpy(&newSt, st, StateCopySize64 * sizeof(uint64_t)); + std::memcpy(&newSt, st, StateCopySize64 * sizeof(uint64_t)); newSt.previous = st; st = &newSt; @@ -1089,7 +1089,7 @@ void Position::do_null_move(StateInfo& newSt) { assert(!checkers()); - memcpy(&newSt, st, sizeof(StateInfo)); // Fully copy here + std::memcpy(&newSt, st, sizeof(StateInfo)); // Fully copy here newSt.previous = st; st = &newSt; @@ -1239,7 +1239,7 @@ int Position::see(Move m, int asymmThreshold) const { void Position::clear() { - memset(this, 0, sizeof(Position)); + std::memset(this, 0, sizeof(Position)); startState.epSquare = SQ_NONE; st = &startState; diff --git a/src/rkiss.h b/src/rkiss.h index 47a3d4cb..86f0599b 100644 --- a/src/rkiss.h +++ b/src/rkiss.h @@ -43,14 +43,12 @@ class RKISS { - // Keep variables always together - struct S { uint64_t a, b, c, d; } s; + struct S { uint64_t a, b, c, d; } s; // Keep variables always together uint64_t rotate(uint64_t x, uint64_t k) const { return (x << k) | (x >> (64 - k)); } - // Return 64 bit unsigned integer in between [0, 2^64 - 1] uint64_t rand64() { const uint64_t diff --git a/src/search.cpp b/src/search.cpp index d36e978b..c98a53da 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -298,7 +298,7 @@ namespace { int depth, prevBestMoveChanges; Value bestValue, alpha, beta, delta; - memset(ss-1, 0, 4 * sizeof(Stack)); + std::memset(ss-1, 0, 4 * sizeof(Stack)); (ss-1)->currentMove = MOVE_NULL; // Hack to skip update gains depth = BestMoveChanges = 0; @@ -1673,7 +1673,7 @@ void Thread::idle_loop() { Stack stack[MAX_PLY_PLUS_2], *ss = stack+1; // To allow referencing (ss-1) Position pos(*sp->pos, this); - memcpy(ss-1, sp->ss-1, 4 * sizeof(Stack)); + std::memcpy(ss-1, sp->ss-1, 4 * sizeof(Stack)); ss->splitPoint = sp; sp->mutex.lock(); diff --git a/src/search.h b/src/search.h index b4fb26ae..37ea9fea 100644 --- a/src/search.h +++ b/src/search.h @@ -79,7 +79,7 @@ struct RootMove { struct LimitsType { - LimitsType() { memset(this, 0, sizeof(LimitsType)); } + LimitsType() { std::memset(this, 0, sizeof(LimitsType)); } bool use_time_management() const { return !(mate | movetime | depth | nodes | infinite); } int time[COLOR_NB], inc[COLOR_NB], movestogo, depth, nodes, movetime, mate, infinite, ponder; diff --git a/src/tt.cpp b/src/tt.cpp index 0d85d030..008439a8 100644 --- a/src/tt.cpp +++ b/src/tt.cpp @@ -60,7 +60,7 @@ void TranspositionTable::set_size(size_t mbSize) { void TranspositionTable::clear() { - memset(table, 0, (hashMask + ClusterSize) * sizeof(TTEntry)); + std::memset(table, 0, (hashMask + ClusterSize) * sizeof(TTEntry)); }