1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-07-11 19:49:14 +00:00

Micro optimize copy of new state in do_move()

Instead of copying all, copy only the fields that
are updated incrementally, not the ones that are
recalcuated form scratch anyway.

This reduces copy overhead of 30%.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2009-03-02 17:32:30 +01:00
parent c02613860a
commit 772a37cd54
2 changed files with 14 additions and 6 deletions

View file

@ -707,10 +707,17 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
assert(is_ok()); assert(is_ok());
assert(move_is_ok(m)); assert(move_is_ok(m));
// Copy some fields of old state to our new StateInfo object (except the // Copy some fields of old state to our new StateInfo object except the
// captured piece, which is taken care of later) and switch state pointer // ones which are 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.
newSt = *st; struct ReducedStateInfo {
Key key, pawnKey, materialKey;
int castleRights, rule50;
Square epSquare;
Value mgValue, egValue;
};
memcpy(&newSt, st, sizeof(ReducedStateInfo));
newSt.capture = NO_PIECE_TYPE; newSt.capture = NO_PIECE_TYPE;
newSt.previous = st; newSt.previous = st;
st = &newSt; st = &newSt;

View file

@ -79,14 +79,15 @@ enum CastleRights {
/// must be passed as a parameter. /// must be passed as a parameter.
struct StateInfo { struct StateInfo {
Bitboard checkersBB;
Key key, pawnKey, materialKey; Key key, pawnKey, materialKey;
int castleRights, rule50; int castleRights, rule50;
Square epSquare; Square epSquare;
Value mgValue, egValue; Value mgValue, egValue;
PieceType capture; PieceType capture;
StateInfo* previous; Bitboard checkersBB;
Move lastMove; Move lastMove;
StateInfo* previous;
}; };