1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-07-16 05:49:14 +00:00

Use a trivially copyable struct for TBTables::Entry instead of a tuple.

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
This commit is contained in:
Tomasz Sobczyk 2020-05-12 21:41:55 +02:00 committed by Joost VandeVondele
parent 66ed8b6c47
commit 86ee4eb84d
2 changed files with 20 additions and 8 deletions

View file

@ -151,6 +151,7 @@ thaspel
theo77186 theo77186
Tom Truscott Tom Truscott
Tom Vijlbrief (tomtor) Tom Vijlbrief (tomtor)
Tomasz Sobczyk (Sopel97)
Torsten Franz (torfranz, tfranzer) Torsten Franz (torfranz, tfranzer)
Tracey Emery (basepr1me) Tracey Emery (basepr1me)
Uri Blass (uriblass) Uri Blass (uriblass)

View file

@ -60,7 +60,7 @@ namespace {
constexpr int TBPIECES = 7; // Max number of supported pieces constexpr int TBPIECES = 7; // Max number of supported pieces
enum { BigEndian, LittleEndian }; 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 // 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 }; 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. // at init time, accessed at probe time.
class TBTables { 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 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 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) { void insert(Key key, TBTable<WDL>* wdl, TBTable<DTZ>* dtz) {
uint32_t homeBucket = (uint32_t)key & (Size - 1); 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 // Ensure last element is empty to avoid overflow when looking up
for (uint32_t bucket = homeBucket; bucket < Size + Overflow - 1; ++bucket) { for (uint32_t bucket = homeBucket; bucket < Size + Overflow - 1; ++bucket) {
Key otherKey = std::get<KEY>(hashTable[bucket]); Key otherKey = hashTable[bucket].key;
if (otherKey == key || !std::get<WDL>(hashTable[bucket])) { if (otherKey == key || !hashTable[bucket].get<WDL>()) {
hashTable[bucket] = entry; hashTable[bucket] = entry;
return; return;
} }
@ -429,7 +440,7 @@ class TBTables {
// insert here and search for a new spot for the other element instead. // insert here and search for a new spot for the other element instead.
uint32_t otherHomeBucket = (uint32_t)otherKey & (Size - 1); uint32_t otherHomeBucket = (uint32_t)otherKey & (Size - 1);
if (otherHomeBucket > homeBucket) { if (otherHomeBucket > homeBucket) {
swap(entry, hashTable[bucket]); std::swap(entry, hashTable[bucket]);
key = otherKey; key = otherKey;
homeBucket = otherHomeBucket; homeBucket = otherHomeBucket;
} }
@ -442,8 +453,8 @@ public:
template<TBType Type> template<TBType Type>
TBTable<Type>* get(Key key) { TBTable<Type>* get(Key key) {
for (const Entry* entry = &hashTable[(uint32_t)key & (Size - 1)]; ; ++entry) { for (const Entry* entry = &hashTable[(uint32_t)key & (Size - 1)]; ; ++entry) {
if (std::get<KEY>(*entry) == key || !std::get<Type>(*entry)) if (entry->key == key || !entry->get<Type>())
return std::get<Type>(*entry); return entry->get<Type>();
} }
} }