Skip to content

Commit 4ede49c

Browse files
committed
Fully qualify memset and memcpy
And other trivial touches. Ispired by Lucas's DiscoCheck No functional change.
1 parent 6960f41 commit 4ede49c

File tree

10 files changed

+20
-22
lines changed

10 files changed

+20
-22
lines changed

src/bitbase.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ namespace {
3939
// bit 6-11: black king square (from SQ_A1 to SQ_H8)
4040
// bit 12: side to move (WHITE or BLACK)
4141
// bit 13-14: white pawn file (from FILE_A to FILE_D)
42-
// bit 15-17: white pawn 6 - rank (from 6 - RANK_7 to 6 - RANK_2)
42+
// bit 15-17: white pawn RANK_7 - rank (from RANK_7 - RANK_7 to RANK_7 - RANK_2)
4343
unsigned index(Color us, Square bksq, Square wksq, Square psq) {
44-
return wksq + (bksq << 6) + (us << 12) + (file_of(psq) << 13) + ((6 - rank_of(psq)) << 15);
44+
return wksq + (bksq << 6) + (us << 12) + (file_of(psq) << 13) + ((RANK_7 - rank_of(psq)) << 15);
4545
}
4646

4747
enum Result {
@@ -107,10 +107,10 @@ namespace {
107107

108108
Result KPKPosition::classify_leaf(unsigned idx) {
109109

110-
wksq = Square((idx >> 0) & 0x3F);
111-
bksq = Square((idx >> 6) & 0x3F);
112-
us = Color((idx >> 12) & 0x01);
113-
psq = File((idx >> 13) & 3) | Rank(6 - (idx >> 15));
110+
wksq = Square((idx >> 0) & 0x3F);
111+
bksq = Square((idx >> 6) & 0x3F);
112+
us = Color ((idx >> 12) & 0x01);
113+
psq = File ((idx >> 13) & 0x03) | Rank(RANK_7 - (idx >> 15));
114114

115115
// Check if two pieces are on the same square or if a king can be captured
116116
if ( wksq == psq || wksq == bksq || bksq == psq

src/bitboard.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ namespace {
318318
do magics[s] = pick_random(rk, booster);
319319
while (popcount<Max15>((magics[s] * masks[s]) >> 56) < 6);
320320

321-
memset(attacks[s], 0, size * sizeof(Bitboard));
321+
std::memset(attacks[s], 0, size * sizeof(Bitboard));
322322

323323
// A good magic must map every possible occupancy to an index that
324324
// looks up the correct sliding attack in the attacks[s] database.

src/evaluate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
11421142

11431143
stream.str("");
11441144
stream << std::showpoint << std::showpos << std::fixed << std::setprecision(2);
1145-
memset(scores, 0, 2 * (TOTAL + 1) * sizeof(Score));
1145+
std::memset(scores, 0, 2 * (TOTAL + 1) * sizeof(Score));
11461146

11471147
Value margin;
11481148
do_evaluate<true>(pos, margin);

src/material.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ Entry* probe(const Position& pos, Table& entries, Endgames& endgames) {
150150
if (e->key == key)
151151
return e;
152152

153-
memset(e, 0, sizeof(Entry));
153+
std::memset(e, 0, sizeof(Entry));
154154
e->key = key;
155155
e->factor[WHITE] = e->factor[BLACK] = (uint8_t)SCALE_FACTOR_NORMAL;
156156
e->gamePhase = game_phase(pos);

src/movepick.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#define MOVEPICK_H_INCLUDED
2222

2323
#include <algorithm> // For std::max
24-
#include <cstring> // For memset
24+
#include <cstring> // For std::memset
2525

2626
#include "movegen.h"
2727
#include "position.h"
@@ -43,7 +43,7 @@ struct Stats {
4343
static const Value Max = Value(2000);
4444

4545
const T* operator[](Piece p) const { return table[p]; }
46-
void clear() { memset(table, 0, sizeof(table)); }
46+
void clear() { std::memset(table, 0, sizeof(table)); }
4747

4848
void update(Piece p, Square to, Move m) {
4949

src/position.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ void Position::init() {
163163

164164
Position& Position::operator=(const Position& pos) {
165165

166-
memcpy(this, &pos, sizeof(Position));
166+
std::memcpy(this, &pos, sizeof(Position));
167167
startState = *st;
168168
st = &startState;
169169
nodes = 0;
@@ -722,7 +722,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
722722
// Copy some fields of old state to our new StateInfo object except the ones
723723
// which are going to be recalculated from scratch anyway, then switch our state
724724
// pointer to point to the new, ready to be updated, state.
725-
memcpy(&newSt, st, StateCopySize64 * sizeof(uint64_t));
725+
std::memcpy(&newSt, st, StateCopySize64 * sizeof(uint64_t));
726726

727727
newSt.previous = st;
728728
st = &newSt;
@@ -1089,7 +1089,7 @@ void Position::do_null_move(StateInfo& newSt) {
10891089

10901090
assert(!checkers());
10911091

1092-
memcpy(&newSt, st, sizeof(StateInfo)); // Fully copy here
1092+
std::memcpy(&newSt, st, sizeof(StateInfo)); // Fully copy here
10931093

10941094
newSt.previous = st;
10951095
st = &newSt;
@@ -1239,7 +1239,7 @@ int Position::see(Move m, int asymmThreshold) const {
12391239

12401240
void Position::clear() {
12411241

1242-
memset(this, 0, sizeof(Position));
1242+
std::memset(this, 0, sizeof(Position));
12431243
startState.epSquare = SQ_NONE;
12441244
st = &startState;
12451245

src/rkiss.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,12 @@
4343

4444
class RKISS {
4545

46-
// Keep variables always together
47-
struct S { uint64_t a, b, c, d; } s;
46+
struct S { uint64_t a, b, c, d; } s; // Keep variables always together
4847

4948
uint64_t rotate(uint64_t x, uint64_t k) const {
5049
return (x << k) | (x >> (64 - k));
5150
}
5251

53-
// Return 64 bit unsigned integer in between [0, 2^64 - 1]
5452
uint64_t rand64() {
5553

5654
const uint64_t

src/search.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ namespace {
298298
int depth, prevBestMoveChanges;
299299
Value bestValue, alpha, beta, delta;
300300

301-
memset(ss-1, 0, 4 * sizeof(Stack));
301+
std::memset(ss-1, 0, 4 * sizeof(Stack));
302302
(ss-1)->currentMove = MOVE_NULL; // Hack to skip update gains
303303

304304
depth = BestMoveChanges = 0;
@@ -1673,7 +1673,7 @@ void Thread::idle_loop() {
16731673
Stack stack[MAX_PLY_PLUS_2], *ss = stack+1; // To allow referencing (ss-1)
16741674
Position pos(*sp->pos, this);
16751675

1676-
memcpy(ss-1, sp->ss-1, 4 * sizeof(Stack));
1676+
std::memcpy(ss-1, sp->ss-1, 4 * sizeof(Stack));
16771677
ss->splitPoint = sp;
16781678

16791679
sp->mutex.lock();

src/search.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ struct RootMove {
7979

8080
struct LimitsType {
8181

82-
LimitsType() { memset(this, 0, sizeof(LimitsType)); }
82+
LimitsType() { std::memset(this, 0, sizeof(LimitsType)); }
8383
bool use_time_management() const { return !(mate | movetime | depth | nodes | infinite); }
8484

8585
int time[COLOR_NB], inc[COLOR_NB], movestogo, depth, nodes, movetime, mate, infinite, ponder;

src/tt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void TranspositionTable::set_size(size_t mbSize) {
6060

6161
void TranspositionTable::clear() {
6262

63-
memset(table, 0, (hashMask + ClusterSize) * sizeof(TTEntry));
63+
std::memset(table, 0, (hashMask + ClusterSize) * sizeof(TTEntry));
6464
}
6565

6666

0 commit comments

Comments
 (0)