Line data Source code
1 : #pragma once
2 :
3 : #include "definition.hpp"
4 :
5 : struct Position;
6 : struct Searcher;
7 :
8 : /*!
9 : * TT in Minic is a very classic 1 entry per bucket cache,
10 : * It stores a 32 bits hash and thus move from TT must be validating before being used
11 : * An entry is storing both static and evaluation score
12 : * as well as move, bound and depth.
13 : * ///@todo test using aging !
14 : */
15 : namespace TT {
16 :
17 : // curGen is coded inside Bound using only 3bits, shifted by 5 (224 = 0x111)
18 : extern GenerationType curGen;
19 :
20 : enum Bound : uint8_t {
21 : B_none = 0,
22 : B_alpha = 1,
23 : B_beta = 2,
24 : B_exact = 3,
25 : B_ttPVFlag = 4,
26 : B_isCheckFlag = 8,
27 : B_isInCheckFlag = 16,
28 : B_gen = 224,
29 : B_allFlags = B_ttPVFlag | B_isCheckFlag | B_isInCheckFlag | B_gen,
30 : };
31 :
32 : #if defined(__GNUC__)
33 : #pragma GCC diagnostic push
34 : #pragma GCC diagnostic ignored "-Wpedantic"
35 : #pragma GCC diagnostic ignored "-Wignored-qualifiers"
36 : #endif // defined(__GNUC__)
37 : #if defined(__clang__)
38 : #pragma clang diagnostic push
39 : #pragma clang diagnostic ignored "-Wpedantic"
40 : #pragma clang diagnostic ignored "-Wignored-qualifiers"
41 : #endif // defined(__clang__)
42 : struct Entry {
43 6726008 : Entry(): m(INVALIDMINIMOVE), h(nullHash), s(0), e(0), b(B_none), d(-2) {}
44 5706276 : Entry(Hash _h, Move _m, ScoreType _s, ScoreType _e, Bound _b, DepthType _d):
45 5706276 : h(Hash64to32(_h)), m(Move2MiniMove(_m)), s(_s), e(_e), b(static_cast<TT::Bound>(_b | (curGen << 5))), d(_d) {}
46 : MiniHash h; //32
47 : union {
48 : MiniHash _data1; //32
49 : struct {
50 : ScoreType s; //16
51 : ScoreType e; //16
52 : };
53 : };
54 : union {
55 : MiniHash _data2; //32
56 : struct {
57 : MiniMove m; //16
58 : Bound b; //8
59 : DepthType d; //8
60 : };
61 : };
62 : };
63 : #if defined(__clang__)
64 : #pragma clang diagnostic pop
65 : #endif // defined(__clang__)
66 : #if defined(__GNUC__)
67 : #pragma GCC diagnostic pop
68 : #endif // defined(__GNUC__)
69 :
70 : [[nodiscard]] ScoreType createHashScore(ScoreType score, DepthType height);
71 :
72 : [[nodiscard]] ScoreType adjustHashScore(ScoreType score, DepthType height);
73 :
74 : void getPV(const Position& p, Searcher& context, PVList& pv);
75 :
76 : // TT
77 :
78 : void initTable();
79 :
80 : void clearTT();
81 :
82 : [[nodiscard]] int hashFull();
83 :
84 : void age();
85 :
86 : void prefetch(Hash h);
87 :
88 : bool getEntry(Searcher& context, const Position& p, Hash h, DepthType d, Entry& e);
89 :
90 : void setEntry(Searcher& context, Hash h, Move m, ScoreType s, ScoreType eval, Bound b, DepthType d, bool distribute = false);
91 :
92 : void _setEntry(Hash h, const Entry& e);
93 :
94 : } // namespace TT
|