Skip to content

Commit

Permalink
Fully qualify memset and memcpy
Browse files Browse the repository at this point in the history
And other trivial touches.

Ispired by Lucas's DiscoCheck

No functional change.
  • Loading branch information
mcostalba committed Jul 13, 2013
1 parent 6960f41 commit 4ede49c
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 22 deletions.
12 changes: 6 additions & 6 deletions src/bitbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/bitboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ namespace {
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.
Expand Down
2 changes: 1 addition & 1 deletion src/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<true>(pos, margin);
Expand Down
2 changes: 1 addition & 1 deletion src/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/movepick.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define MOVEPICK_H_INCLUDED

#include <algorithm> // For std::max
#include <cstring> // For memset
#include <cstring> // For std::memset

#include "movegen.h"
#include "position.h"
Expand All @@ -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) {

Expand Down
8 changes: 4 additions & 4 deletions src/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 1 addition & 3 deletions src/rkiss.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/search.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/tt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}


Expand Down

0 comments on commit 4ede49c

Please sign in to comment.