1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-01 01:03:09 +00:00

Get rid of ReducedStateInfo struct

ReducedStateInfo is a redundant struct that is also
prone to errors, indeed must be updated any time is
updated StateInfo. It is a trick to partial copy a
StateInfo object in do_move().

This patch takes advantage of builtin macro offsetof()
to directly calculate the number of quad words to copy.
Note that we still use memcpy to do the actual job of
copying the (48 bytes) of data.

Idea by Richard Vida.

No functional and no performance change.
This commit is contained in:
Marco Costalba 2012-10-28 17:12:40 +01:00
parent ad1941fd00
commit 13f90a30ef
2 changed files with 9 additions and 11 deletions

View file

@ -770,9 +770,9 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
Key k = st->key; Key k = st->key;
// 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 recalculated from scratch anyway, then switch our state pointer // which are going to be recalculated from scratch anyway, then switch our state
// to point to the new, ready to be updated, state. // pointer to point to the new, ready to be updated, state.
memcpy(&newSt, st, sizeof(ReducedStateInfo)); memcpy(&newSt, st, StateCopySize64 * sizeof(uint64_t));
newSt.previous = st; newSt.previous = st;
st = &newSt; st = &newSt;

View file

@ -21,6 +21,7 @@
#define POSITION_H_INCLUDED #define POSITION_H_INCLUDED
#include <cassert> #include <cassert>
#include <cstddef>
#include "bitboard.h" #include "bitboard.h"
#include "types.h" #include "types.h"
@ -44,7 +45,7 @@ struct CheckInfo {
/// The StateInfo struct stores information we need to restore a Position /// The StateInfo struct stores information we need to restore a Position
/// object to its previous state when we retract a move. Whenever a move /// object to its previous state when we retract a move. Whenever a move
/// is made on the board (by calling Position::do_move), an StateInfo object /// is made on the board (by calling Position::do_move), a StateInfo object
/// must be passed as a parameter. /// must be passed as a parameter.
struct StateInfo { struct StateInfo {
@ -60,13 +61,10 @@ struct StateInfo {
StateInfo* previous; StateInfo* previous;
}; };
struct ReducedStateInfo {
Key pawnKey, materialKey; /// When making a move the current StateInfo up to 'key' excluded is copied to
Value npMaterial[COLOR_NB]; /// the new one. Here we calculate the quad words (64bits) needed to be copied.
int castleRights, rule50, pliesFromNull; const size_t StateCopySize64 = offsetof(StateInfo, key) / sizeof(uint64_t) + 1;
Score psqScore;
Square epSquare;
};
/// The position data structure. A position consists of the following data: /// The position data structure. A position consists of the following data: