]> git.sesse.net Git - stockfish/commitdiff
Fully qualify memset and memcpy
authorMarco Costalba <mcostalba@gmail.com>
Sat, 13 Jul 2013 15:21:24 +0000 (17:21 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 13 Jul 2013 16:01:13 +0000 (18:01 +0200)
And other trivial touches.

Ispired by Lucas's DiscoCheck

No functional change.

src/bitbase.cpp
src/bitboard.cpp
src/evaluate.cpp
src/material.cpp
src/movepick.h
src/position.cpp
src/rkiss.h
src/search.cpp
src/search.h
src/tt.cpp

index b888d76c780ecc79f17ca5f69bd2f5504c2652e3..570a9771419099aec3bc929b469a1b0b598e61dd 100644 (file)
@@ -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  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) {
   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 {
   }
 
   enum Result {
@@ -107,10 +107,10 @@ namespace {
 
   Result KPKPosition::classify_leaf(unsigned idx) {
 
 
   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
 
     // Check if two pieces are on the same square or if a king can be captured
     if (   wksq == psq || wksq == bksq || bksq == psq
index 756f049987db38e7dbad37e52831f055d1a7589d..3f855c574e6c0e0cc4377820218559f9bbf331e8 100644 (file)
@@ -318,7 +318,7 @@ namespace {
             do magics[s] = pick_random(rk, booster);
             while (popcount<Max15>((magics[s] * masks[s]) >> 56) < 6);
 
             do magics[s] = pick_random(rk, booster);
             while (popcount<Max15>((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.
 
             // A good magic must map every possible occupancy to an index that
             // looks up the correct sliding attack in the attacks[s] database.
index d171eb9b27cca2a8df66cf273320c579dc2c7ba5..3dbd6dc03a8db98b1da7501432296f99187d00a4 100644 (file)
@@ -1142,7 +1142,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
 
     stream.str("");
     stream << std::showpoint << std::showpos << std::fixed << std::setprecision(2);
 
     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<true>(pos, margin);
 
     Value margin;
     do_evaluate<true>(pos, margin);
index ed125dd7ce9eaef663e495d3c49b04fba1ba7cd6..22953cff6d8d4328706cb1ffe4299d46214d2c05 100644 (file)
@@ -150,7 +150,7 @@ Entry* probe(const Position& pos, Table& entries, Endgames& endgames) {
   if (e->key == key)
       return e;
 
   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);
   e->key = key;
   e->factor[WHITE] = e->factor[BLACK] = (uint8_t)SCALE_FACTOR_NORMAL;
   e->gamePhase = game_phase(pos);
index 57fe1c0ec304a76fd2542e97876c811eac92b6d2..37027ace23153d1dff36b88446df58d5b4be495d 100644 (file)
@@ -21,7 +21,7 @@
 #define MOVEPICK_H_INCLUDED
 
 #include <algorithm> // For std::max
 #define MOVEPICK_H_INCLUDED
 
 #include <algorithm> // For std::max
-#include <cstring>   // For memset
+#include <cstring>   // For std::memset
 
 #include "movegen.h"
 #include "position.h"
 
 #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]; }
   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) {
 
 
   void update(Piece p, Square to, Move m) {
 
index d58fdec1339cfffec3665c3830003824875ac310..1273a62fb3d0a0e975e2d06cdbf590359d9c473d 100644 (file)
@@ -163,7 +163,7 @@ void Position::init() {
 
 Position& Position::operator=(const Position& pos) {
 
 
 Position& Position::operator=(const Position& pos) {
 
-  memcpy(this, &pos, sizeof(Position));
+  std::memcpy(this, &pos, sizeof(Position));
   startState = *st;
   st = &startState;
   nodes = 0;
   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.
   // 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;
 
   newSt.previous = st;
   st = &newSt;
@@ -1089,7 +1089,7 @@ void Position::do_null_move(StateInfo& newSt) {
 
   assert(!checkers());
 
 
   assert(!checkers());
 
-  memcpy(&newSt, st, sizeof(StateInfo)); // Fully copy here
+  std::memcpy(&newSt, st, sizeof(StateInfo)); // Fully copy here
 
   newSt.previous = st;
   st = &newSt;
 
   newSt.previous = st;
   st = &newSt;
@@ -1239,7 +1239,7 @@ int Position::see(Move m, int asymmThreshold) const {
 
 void Position::clear() {
 
 
 void Position::clear() {
 
-  memset(this, 0, sizeof(Position));
+  std::memset(this, 0, sizeof(Position));
   startState.epSquare = SQ_NONE;
   st = &startState;
 
   startState.epSquare = SQ_NONE;
   st = &startState;
 
index 47a3d4cbd6bee9affaab2a8e9508f6a8923328c7..86f0599b6a4e606defb6ee6c0789c4136242e6c2 100644 (file)
 
 class RKISS {
 
 
 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));
   }
 
 
   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
   uint64_t rand64() {
 
     const uint64_t
index d36e978bbbbe6a725c1c9a0d59806a2e767dc438..c98a53dac207e915bf1c691edbfca43ba73706f2 100644 (file)
@@ -298,7 +298,7 @@ namespace {
     int depth, prevBestMoveChanges;
     Value bestValue, alpha, beta, delta;
 
     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;
     (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);
 
           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();
           ss->splitPoint = sp;
 
           sp->mutex.lock();
index b4fb26ae72b9bee3b1bd80f1bfd225e12e654518..37ea9feaefa76fa981d2a4052064b76fa50196fa 100644 (file)
@@ -79,7 +79,7 @@ struct RootMove {
 
 struct LimitsType {
 
 
 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;
   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;
index 0d85d03006b26bd1cedc54c881b0f890dc2a252f..008439a82cac8861bbc83eecd29f91e621b45480 100644 (file)
@@ -60,7 +60,7 @@ void TranspositionTable::set_size(size_t mbSize) {
 
 void TranspositionTable::clear() {
 
 
 void TranspositionTable::clear() {
 
-  memset(table, 0, (hashMask + ClusterSize) * sizeof(TTEntry));
+  std::memset(table, 0, (hashMask + ClusterSize) * sizeof(TTEntry));
 }
 
 
 }