]> git.sesse.net Git - stockfish/commitdiff
Use a trivially copyable struct for TBTables::Entry instead of a tuple.
authorTomasz Sobczyk <tomasz.sobczyk1997@gmail.com>
Tue, 12 May 2020 19:41:55 +0000 (21:41 +0200)
committerJoost VandeVondele <Joost.VandeVondele@gmail.com>
Wed, 13 May 2020 17:50:30 +0000 (19:50 +0200)
fixes https://github.com/official-stockfish/Stockfish/issues/2673
which is a warning issued by recent gcc (10.1)

closes https://github.com/official-stockfish/Stockfish/pull/2674

No functional change

AUTHORS
src/syzygy/tbprobe.cpp

diff --git a/AUTHORS b/AUTHORS
index 9fceebf7ee475e93f5dd3601b55e6c450ce2038f..36c2a47b8ada1231d54500956453dc7aa79a00dd 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -151,6 +151,7 @@ thaspel
 theo77186
 Tom Truscott
 Tom Vijlbrief (tomtor)
+Tomasz Sobczyk (Sopel97)
 Torsten Franz (torfranz, tfranzer)
 Tracey Emery (basepr1me)
 Uri Blass (uriblass)
index f1fd695c34a620c3102d048da20b45d92c1b94d6..843f049a58496fae06d1d3bd2dd90710df5cf006 100644 (file)
@@ -60,7 +60,7 @@ namespace {
 constexpr int TBPIECES = 7; // Max number of supported pieces
 
 enum { BigEndian, LittleEndian };
-enum TBType { KEY, WDL, DTZ }; // Used as template parameter
+enum TBType { WDL, DTZ }; // Used as template parameter
 
 // Each table has a set of flags: all of them refer to DTZ tables, the last one to WDL tables
 enum TBFlag { STM = 1, Mapped = 2, WinPlies = 4, LossPlies = 8, Wide = 16, SingleValue = 128 };
@@ -403,7 +403,18 @@ TBTable<DTZ>::TBTable(const TBTable<WDL>& wdl) : TBTable() {
 // at init time, accessed at probe time.
 class TBTables {
 
-    typedef std::tuple<Key, TBTable<WDL>*, TBTable<DTZ>*> Entry;
+    struct Entry
+    {
+        Key key;
+        TBTable<WDL>* wdl;
+        TBTable<DTZ>* dtz;
+
+        template <TBType Type>
+        TBTable<Type>* get() const {
+            return (TBTable<Type>*)(Type == WDL ? (void*)wdl : (void*)dtz);
+        }
+    };
+    static_assert(std::is_trivially_copyable<Entry>::value, "");
 
     static constexpr int Size = 1 << 12; // 4K table, indexed by key's 12 lsb
     static constexpr int Overflow = 1;  // Number of elements allowed to map to the last bucket
@@ -415,12 +426,12 @@ class TBTables {
 
     void insert(Key key, TBTable<WDL>* wdl, TBTable<DTZ>* dtz) {
         uint32_t homeBucket = (uint32_t)key & (Size - 1);
-        Entry entry = std::make_tuple(key, wdl, dtz);
+        Entry entry{ key, wdl, dtz };
 
         // Ensure last element is empty to avoid overflow when looking up
         for (uint32_t bucket = homeBucket; bucket < Size + Overflow - 1; ++bucket) {
-            Key otherKey = std::get<KEY>(hashTable[bucket]);
-            if (otherKey == key || !std::get<WDL>(hashTable[bucket])) {
+            Key otherKey = hashTable[bucket].key;
+            if (otherKey == key || !hashTable[bucket].get<WDL>()) {
                 hashTable[bucket] = entry;
                 return;
             }
@@ -429,7 +440,7 @@ class TBTables {
             // insert here and search for a new spot for the other element instead.
             uint32_t otherHomeBucket = (uint32_t)otherKey & (Size - 1);
             if (otherHomeBucket > homeBucket) {
-                swap(entry, hashTable[bucket]);
+                std::swap(entry, hashTable[bucket]);
                 key = otherKey;
                 homeBucket = otherHomeBucket;
             }
@@ -442,8 +453,8 @@ public:
     template<TBType Type>
     TBTable<Type>* get(Key key) {
         for (const Entry* entry = &hashTable[(uint32_t)key & (Size - 1)]; ; ++entry) {
-            if (std::get<KEY>(*entry) == key || !std::get<Type>(*entry))
-                return std::get<Type>(*entry);
+            if (entry->key == key || !entry->get<Type>())
+                return entry->get<Type>();
         }
     }