2 Stockfish, a UCI chess playing engine derived from Glaurung 2.1
3 Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
5 Stockfish is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 Stockfish is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 /// TTEntry struct is the 10 bytes transposition table entry, defined as below:
38 Move move() const { return (Move )move16; }
39 Value value() const { return (Value)value16; }
40 Value eval() const { return (Value)eval16; }
41 Depth depth() const { return (Depth)depth8 + DEPTH_OFFSET; }
42 bool is_pv() const { return (bool)(genBound8 & 0x4); }
43 Bound bound() const { return (Bound)(genBound8 & 0x3); }
44 void save(Key k, Value v, bool pv, Bound b, Depth d, Move m, Value ev);
47 friend class TranspositionTable;
58 /// A TranspositionTable is an array of Cluster, of size clusterCount. Each
59 /// cluster consists of ClusterSize number of TTEntry. Each non-empty TTEntry
60 /// contains information on exactly one position. The size of a Cluster should
61 /// divide the size of a cache line for best performance, as the cacheline is
62 /// prefetched when possible.
64 class TranspositionTable {
66 static constexpr int ClusterSize = 3;
69 TTEntry entry[ClusterSize];
70 char padding[2]; // Pad to 32 bytes
73 static_assert(sizeof(Cluster) == 32, "Unexpected Cluster size");
76 ~TranspositionTable() { aligned_ttmem_free(mem); }
77 void new_search() { generation8 += 8; } // Lower 3 bits are used by PV flag and Bound
78 TTEntry* probe(const Key key, bool& found) const;
80 void resize(size_t mbSize);
83 TTEntry* first_entry(const Key key) const {
84 return &table[mul_hi64(key, clusterCount)].entry[0];
88 friend struct TTEntry;
93 uint8_t generation8; // Size must be not bigger than TTEntry::genBound8
96 extern TranspositionTable TT;
98 #endif // #ifndef TT_H_INCLUDED