&& tte
&& tte->depth() >= depth
&& ttValue != VALUE_NONE // Only in case of TT access race
- && ( PvNode ? tte->type() == BOUND_EXACT
- : ttValue >= beta ? (tte->type() & BOUND_LOWER)
- : (tte->type() & BOUND_UPPER)))
+ && ( PvNode ? tte->bound() == BOUND_EXACT
+ : ttValue >= beta ? (tte->bound() & BOUND_LOWER)
+ : (tte->bound() & BOUND_UPPER)))
{
TT.refresh(tte);
ss->currentMove = ttMove; // Can be MOVE_NONE
// Can ttValue be used as a better position evaluation?
if (ttValue != VALUE_NONE)
- if ( ((tte->type() & BOUND_LOWER) && ttValue > eval)
- || ((tte->type() & BOUND_UPPER) && ttValue < eval))
+ if ( ((tte->bound() & BOUND_LOWER) && ttValue > eval)
+ || ((tte->bound() & BOUND_UPPER) && ttValue < eval))
eval = ttValue;
}
else
&& depth >= (PvNode ? 6 * ONE_PLY : 8 * ONE_PLY)
&& ttMove != MOVE_NONE
&& !excludedMove // Recursive singular search is not allowed
- && (tte->type() & BOUND_LOWER)
+ && (tte->bound() & BOUND_LOWER)
&& tte->depth() >= depth - 3 * ONE_PLY;
// Step 11. Loop through moves
if ( tte
&& tte->depth() >= ttDepth
&& ttValue != VALUE_NONE // Only in case of TT access race
- && ( PvNode ? tte->type() == BOUND_EXACT
- : ttValue >= beta ? (tte->type() & BOUND_LOWER)
- : (tte->type() & BOUND_UPPER)))
+ && ( PvNode ? tte->bound() == BOUND_EXACT
+ : ttValue >= beta ? (tte->bound() & BOUND_LOWER)
+ : (tte->bound() & BOUND_UPPER)))
{
ss->currentMove = ttMove; // Can be MOVE_NONE
return ttValue;
void RootMove::extract_pv_from_tt(Position& pos) {
StateInfo state[MAX_PLY_PLUS_2], *st = state;
- TTEntry* tte;
+ const TTEntry* tte;
int ply = 0;
Move m = pv[0];
void RootMove::insert_pv_in_tt(Position& pos) {
StateInfo state[MAX_PLY_PLUS_2], *st = state;
- TTEntry* tte;
+ const TTEntry* tte;
int ply = 0;
do {
hashMask = size - ClusterSize;
free(mem);
- mem = malloc(size * sizeof(TTEntry) + CACHE_LINE_SIZE - 1);
+ mem = calloc(size * sizeof(TTEntry) + CACHE_LINE_SIZE - 1, 1);
if (!mem)
{
}
table = (TTEntry*)((uintptr_t(mem) + CACHE_LINE_SIZE - 1) & ~(CACHE_LINE_SIZE - 1));
- clear(); // Operator new is not guaranteed to initialize memory to zero
}
}
+/// TranspositionTable::probe() looks up the current position in the
+/// transposition table. Returns a pointer to the TTEntry or NULL if
+/// position is not found.
+
+const TTEntry* TranspositionTable::probe(const Key key) const {
+
+ const TTEntry* tte = first_entry(key);
+ uint32_t key32 = key >> 32;
+
+ for (unsigned i = 0; i < ClusterSize; i++, tte++)
+ if (tte->key() == key32)
+ return tte;
+
+ return NULL;
+}
+
+
/// TranspositionTable::store() writes a new entry containing position key and
/// valuable information of current position. The lowest order bits of position
/// key are used to decide on which cluster the position will be placed.
{
if (!tte->key() || tte->key() == key32) // Empty or overwrite old
{
- // Preserve any existing ttMove
- if (m == MOVE_NONE)
- m = tte->move();
+ if (!m)
+ m = tte->move(); // Preserve any existing ttMove
- tte->save(key32, v, t, d, m, generation, statV, kingD);
- return;
+ replace = tte;
+ break;
}
// Implement replace strategy
c1 = (replace->generation() == generation ? 2 : 0);
- c2 = (tte->generation() == generation || tte->type() == BOUND_EXACT ? -2 : 0);
+ c2 = (tte->generation() == generation || tte->bound() == BOUND_EXACT ? -2 : 0);
c3 = (tte->depth() < replace->depth() ? 1 : 0);
if (c1 + c2 + c3 > 0)
replace = tte;
}
- replace->save(key32, v, t, d, m, generation, statV, kingD);
-}
-
-
-/// TranspositionTable::probe() looks up the current position in the
-/// transposition table. Returns a pointer to the TTEntry or NULL if
-/// position is not found.
-
-TTEntry* TranspositionTable::probe(const Key key) const {
- TTEntry* tte = first_entry(key);
- uint32_t key32 = key >> 32;
-
- for (unsigned i = 0; i < ClusterSize; i++, tte++)
- if (tte->key() == key32)
- return tte;
-
- return NULL;
+ replace->save(key32, v, t, d, m, generation, statV, kingD);
}
/// static value: 16 bit
/// static margin: 16 bit
-class TTEntry {
+struct TTEntry {
-public:
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;
+ bound8 = (uint8_t)b;
generation8 = (uint8_t)g;
value16 = (int16_t)v;
depth16 = (int16_t)d;
evalValue = (int16_t)ev;
evalMargin = (int16_t)em;
}
- void set_generation(int g) { generation8 = (uint8_t)g; }
+ void set_generation(uint8_t g) { generation8 = g; }
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; }
+ Bound bound() const { return (Bound)bound8; }
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;
+ uint8_t bound8, generation8;
int16_t value16, depth16, evalValue, evalMargin;
};
~TranspositionTable() { free(mem); }
void new_search() { generation++; }
- TTEntry* probe(const Key key) const;
+ const 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);
uint32_t hashMask;
TTEntry* table;
void* mem;
- uint8_t generation; // Size must be not bigger then TTEntry::generation8
+ uint8_t generation; // Size must be not bigger than TTEntry::generation8
};
extern TranspositionTable TT;