1
0
Fork 0

Fully qualify memset and memcpy

And other trivial touches.

Ispired by Lucas's DiscoCheck

No functional change.
sf_4_base
Marco Costalba 2013-07-13 17:21:24 +02:00
parent 6960f41e03
commit 4ede49cd85
10 changed files with 20 additions and 22 deletions

View File

@ -39,9 +39,9 @@ namespace {
// bit 6-11: black king square (from SQ_A1 to SQ_H8) // bit 6-11: black king square (from SQ_A1 to SQ_H8)
// bit 12: side to move (WHITE or BLACK) // bit 12: side to move (WHITE or BLACK)
// bit 13-14: white pawn file (from FILE_A to FILE_D) // 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); wksq = Square((idx >> 0) & 0x3F);
bksq = Square((idx >> 6) & 0x3F); bksq = Square((idx >> 6) & 0x3F);
us = Color((idx >> 12) & 0x01); us = Color ((idx >> 12) & 0x01);
psq = File((idx >> 13) & 3) | Rank(6 - (idx >> 15)); 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 // Check if two pieces are on the same square or if a king can be captured
if ( wksq == psq || wksq == bksq || bksq == psq if ( wksq == psq || wksq == bksq || bksq == psq

View File

@ -318,7 +318,7 @@ namespace {
do magics[s] = pick_random(rk, booster); do magics[s] = pick_random(rk, booster);
while (popcount<Max15>((magics[s] * masks[s]) >> 56) < 6); 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 // A good magic must map every possible occupancy to an index that
// looks up the correct sliding attack in the attacks[s] database. // looks up the correct sliding attack in the attacks[s] database.

View File

@ -1142,7 +1142,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
stream.str(""); stream.str("");
stream << std::showpoint << std::showpos << std::fixed << std::setprecision(2); 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; Value margin;
do_evaluate<true>(pos, margin); do_evaluate<true>(pos, margin);

View File

@ -150,7 +150,7 @@ Entry* probe(const Position& pos, Table& entries, Endgames& endgames) {
if (e->key == key) if (e->key == key)
return e; return e;
memset(e, 0, sizeof(Entry)); std::memset(e, 0, sizeof(Entry));
e->key = key; e->key = key;
e->factor[WHITE] = e->factor[BLACK] = (uint8_t)SCALE_FACTOR_NORMAL; e->factor[WHITE] = e->factor[BLACK] = (uint8_t)SCALE_FACTOR_NORMAL;
e->gamePhase = game_phase(pos); e->gamePhase = game_phase(pos);

View File

@ -21,7 +21,7 @@
#define MOVEPICK_H_INCLUDED #define MOVEPICK_H_INCLUDED
#include <algorithm> // For std::max #include <algorithm> // For std::max
#include <cstring> // For memset #include <cstring> // For std::memset
#include "movegen.h" #include "movegen.h"
#include "position.h" #include "position.h"
@ -43,7 +43,7 @@ struct Stats {
static const Value Max = Value(2000); static const Value Max = Value(2000);
const T* operator[](Piece p) const { return table[p]; } 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) {

View 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; startState = *st;
st = &startState; st = &startState;
nodes = 0; 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 // 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 // which are going to be recalculated from scratch anyway, then switch our state
// pointer to point to the new, ready to be updated, 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; newSt.previous = st;
st = &newSt; 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; newSt.previous = st;
st = &newSt; 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; startState.epSquare = SQ_NONE;
st = &startState; st = &startState;

View File

@ -43,14 +43,12 @@
class RKISS { class RKISS {
// Keep variables always together struct S { uint64_t a, b, c, d; } s; // Keep variables always together
struct S { uint64_t a, b, c, d; } s;
uint64_t rotate(uint64_t x, uint64_t k) const { uint64_t rotate(uint64_t x, uint64_t k) const {
return (x << k) | (x >> (64 - k)); return (x << k) | (x >> (64 - k));
} }
// Return 64 bit unsigned integer in between [0, 2^64 - 1]
uint64_t rand64() { uint64_t rand64() {
const uint64_t const uint64_t

View File

@ -298,7 +298,7 @@ namespace {
int depth, prevBestMoveChanges; int depth, prevBestMoveChanges;
Value bestValue, alpha, beta, delta; 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 (ss-1)->currentMove = MOVE_NULL; // Hack to skip update gains
depth = BestMoveChanges = 0; 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) Stack stack[MAX_PLY_PLUS_2], *ss = stack+1; // To allow referencing (ss-1)
Position pos(*sp->pos, this); 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; ss->splitPoint = sp;
sp->mutex.lock(); sp->mutex.lock();

View 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); } 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; int time[COLOR_NB], inc[COLOR_NB], movestogo, depth, nodes, movetime, mate, infinite, ponder;

View 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));
} }