X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Ftt.h;h=c7c39e90cc9918d3cddb8611a12d8e66ffbf63a8;hp=6c7caf75fce19bbab5c55886a26e6d75f27f47c1;hb=293c44bc09587259818a82e1d2afb511e552badd;hpb=feeafb0a50556654e345a09d16529a5eb7715dc0 diff --git a/src/tt.h b/src/tt.h index 6c7caf75..c7c39e90 100644 --- a/src/tt.h +++ b/src/tt.h @@ -1,7 +1,7 @@ /* Stockfish, a UCI chess playing engine derived from Glaurung 2.1 Copyright (C) 2004-2008 Tord Romstad (Glaurung author) - Copyright (C) 2008-2012 Marco Costalba, Joona Kiiski, Tord Romstad + Copyright (C) 2008-2013 Marco Costalba, Joona Kiiski, Tord Romstad Stockfish is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -44,91 +44,60 @@ class TTEntry { public: - void save(uint32_t k, Value v, Bound b, Depth d, Move m, int g) { - - key32 = (uint32_t)k; - move16 = (uint16_t)m; - bound = (uint8_t)b; - generation8 = (uint8_t)g; - valueUpper = (int16_t)(b & BOUND_UPPER ? v : VALUE_NONE); - depthUpper = (int16_t)(b & BOUND_UPPER ? d : DEPTH_NONE); - valueLower = (int16_t)(b & BOUND_LOWER ? v : VALUE_NONE); - depthLower = (int16_t)(b & BOUND_LOWER ? d : DEPTH_NONE); + void save(uint32_t k, Value v, Bound b, Depth d, Move m, int g, Value ev, Value em) { + + key32 = (uint32_t)k; + move16 = (uint16_t)m; + bound = (uint8_t)b; + generation8 = (uint8_t)g; + value16 = (int16_t)v; + depth16 = (int16_t)d; + evalValue = (int16_t)ev; + evalMargin = (int16_t)em; } - - void update(Value v, Bound b, Depth d, Move m, int g) { - - move16 = (uint16_t)m; - bound |= (uint8_t)b; - generation8 = (uint8_t)g; - - if (b & BOUND_UPPER) - { - valueUpper = (int16_t)v; - depthUpper = (int16_t)d; - } - - if (b & BOUND_LOWER) - { - valueLower = (int16_t)v; - depthLower = (int16_t)d; - } - } - void set_generation(int g) { generation8 = (uint8_t)g; } - uint32_t key() const { return key32; } - Depth depth() const { return (Depth)depthLower; } - Depth depth_upper() const { return (Depth)depthUpper; } - Move move() const { return (Move)move16; } - Value value() const { return (Value)valueLower; } - Value value_upper() const { return (Value)valueUpper; } - Bound type() const { return (Bound)bound; } - int generation() const { return (int)generation8; } + uint32_t key() const { return key32; } + Depth depth() const { return (Depth)depth16; } + Move move() const { return (Move)move16; } + Value value() const { return (Value)value16; } + Bound type() const { return (Bound)bound; } + int generation() const { return (int)generation8; } + Value eval_value() const { return (Value)evalValue; } + Value eval_margin() const { return (Value)evalMargin; } private: uint32_t key32; uint16_t move16; uint8_t bound, generation8; - int16_t valueLower, depthLower, valueUpper, depthUpper; + int16_t value16, depth16, evalValue, evalMargin; }; -/// This is the number of TTEntry slots for each cluster -const int ClusterSize = 4; - - -/// TTCluster consists of ClusterSize number of TTEntries. Size of TTCluster -/// must not be bigger than a cache line size. In case it is less, it should -/// be padded to guarantee always aligned accesses. - -struct TTCluster { - TTEntry data[ClusterSize]; -}; - - -/// The transposition table class. This is basically just a huge array containing -/// TTCluster objects, and a few methods for writing and reading entries. +/// A TranspositionTable consists of a power of 2 number of clusters and each +/// cluster consists of ClusterSize number of TTEntry. Each non-empty entry +/// contains information of exactly one position. Size of a cluster shall not be +/// bigger than a cache line size. In case it is less, it should be padded to +/// guarantee always aligned accesses. class TranspositionTable { - TranspositionTable(const TranspositionTable&); - TranspositionTable& operator=(const TranspositionTable&); + static const unsigned ClusterSize = 4; // A cluster is 64 Bytes public: - TranspositionTable(); - ~TranspositionTable(); + ~TranspositionTable() { delete [] table; } + void new_search() { generation++; } + + TTEntry* probe(const Key key) const; + TTEntry* first_entry(const Key key) const; + void refresh(const TTEntry* tte) const; void set_size(size_t mbSize); void clear(); - void store(const Key posKey, Value v, Bound b, Depth d, Move m); - TTEntry* probe(const Key posKey) const; - void new_search(); - TTEntry* first_entry(const Key posKey) const; - void refresh(const TTEntry* tte) const; + void store(const Key key, Value v, Bound type, Depth d, Move m, Value statV, Value kingD); private: - size_t size; - TTCluster* entries; + uint32_t hashMask; + TTEntry* table; uint8_t generation; // Size must be not bigger then TTEntry::generation8 }; @@ -139,9 +108,9 @@ extern TranspositionTable TT; /// a cluster given a position. The lowest order bits of the key are used to /// get the index of the cluster. -inline TTEntry* TranspositionTable::first_entry(const Key posKey) const { +inline TTEntry* TranspositionTable::first_entry(const Key key) const { - return entries[((uint32_t)posKey) & (size - 1)].data; + return table + ((uint32_t)key & hashMask); }