]> git.sesse.net Git - stockfish/commitdiff
Further simplify first_entry()
authorMarco Costalba <mcostalba@gmail.com>
Sat, 9 Feb 2013 15:22:47 +0000 (16:22 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 9 Feb 2013 15:37:20 +0000 (16:37 +0100)
We can encode the ClusterSize directly in the
hashMask, this allows to skip the left shift.

There is no real change, but bench number is now
different because instead of using the lowest order
bits of the key to index the start of the cluster,
now we don't use the last two lsb bits that are
always set to zero (cluster size is 4). So for
instance, if 10 bits are used to index the cluster,
instead of bits [9..0] now we use bits [11..2].
This changes the positions that end up in the same
cluster affecting TT hits and so bench is different.

Also some renaming while there.

bench: 5383795

src/tt.cpp
src/tt.h

index fa0d39de00db423202eab55e5d2e82d0f94ebd4a..f4e5535430d85a47246b3921196171ac1af7dd14 100644 (file)
@@ -34,16 +34,16 @@ void TranspositionTable::set_size(size_t mbSize) {
 
   assert(msb((mbSize << 20) / sizeof(TTEntry)) < 32);
 
-  uint32_t size = 1 << msb((mbSize << 20) / sizeof(TTEntry[ClusterSize]));
+  uint32_t size = ClusterSize << msb((mbSize << 20) / sizeof(TTEntry[ClusterSize]));
 
-  if (clusterMask == size - 1)
+  if (hashMask == size - ClusterSize)
       return;
 
-  clusterMask = size - 1;
-  delete [] entries;
-  entries = new (std::nothrow) TTEntry[size * ClusterSize];
+  hashMask = size - ClusterSize;
+  delete [] table;
+  table = new (std::nothrow) TTEntry[size];
 
-  if (!entries)
+  if (!table)
   {
       std::cerr << "Failed to allocate " << mbSize
                 << "MB for transposition table." << std::endl;
@@ -60,7 +60,7 @@ void TranspositionTable::set_size(size_t mbSize) {
 
 void TranspositionTable::clear() {
 
-  memset(entries, 0, (clusterMask + 1) * sizeof(TTEntry[ClusterSize]));
+  memset(table, 0, (hashMask + ClusterSize) * sizeof(TTEntry));
 }
 
 
index 81bfd3b267385c2d50951c02d3736f5cf1601a32..2db19c89aab0e13610fd21f3fc27b21bc7b40b0b 100644 (file)
--- a/src/tt.h
+++ b/src/tt.h
@@ -85,7 +85,7 @@ class TranspositionTable {
   static const unsigned ClusterSize = 4; // A cluster is 64 Bytes
 
 public:
- ~TranspositionTable() { delete [] entries; }
+ ~TranspositionTable() { delete [] table; }
   void new_search() { generation++; }
 
   TTEntry* probe(const Key key) const;
@@ -96,8 +96,8 @@ public:
   void store(const Key key, Value v, Bound type, Depth d, Move m, Value statV, Value kingD);
 
 private:
-  uint32_t clusterMask;
-  TTEntry* entries;
+  uint32_t hashMask;
+  TTEntry* table;
   uint8_t generation; // Size must be not bigger then TTEntry::generation8
 };
 
@@ -110,7 +110,7 @@ extern TranspositionTable TT;
 
 inline TTEntry* TranspositionTable::first_entry(const Key key) const {
 
-  return entries + ((uint32_t)key & clusterMask) * ClusterSize;
+  return table + ((uint32_t)key & hashMask);
 }