mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 00:33:09 +00:00
Move file name setup inside init()
This commit is contained in:
parent
ac136ea72b
commit
107750279d
1 changed files with 18 additions and 15 deletions
|
@ -1118,9 +1118,13 @@ void do_init(Entry& e, T& p, uint8_t* data)
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Entry>
|
template<typename Entry>
|
||||||
bool init(Entry& e, const std::string& fname)
|
bool init(Entry& e, const Position& pos)
|
||||||
{
|
{
|
||||||
const uint8_t* MAGIC = std::is_same<Entry, DTZEntry>::value ? DTZ_MAGIC : WDL_MAGIC;
|
const bool IsWDL = std::is_same<Entry, WDLEntry>::value;
|
||||||
|
const uint8_t* MAGIC = IsWDL ? WDL_MAGIC : DTZ_MAGIC;
|
||||||
|
|
||||||
|
std::string fname = pos_code(pos, e.key != pos.material_key())
|
||||||
|
+ (IsWDL ? ".rtbw" : ".rtbz");
|
||||||
|
|
||||||
uint8_t* data = TBFile(fname).map(&e.baseAddress, &e.mapping, MAGIC);
|
uint8_t* data = TBFile(fname).map(&e.baseAddress, &e.mapping, MAGIC);
|
||||||
if (!data)
|
if (!data)
|
||||||
|
@ -1130,8 +1134,8 @@ bool init(Entry& e, const std::string& fname)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
WDLScore probe_wdl_table(Position& pos, ProbeState* result)
|
WDLScore probe_wdl_table(Position& pos, ProbeState* result) {
|
||||||
{
|
|
||||||
Key key = pos.material_key();
|
Key key = pos.material_key();
|
||||||
|
|
||||||
if (!(pos.pieces() ^ pos.pieces(KING)))
|
if (!(pos.pieces() ^ pos.pieces(KING)))
|
||||||
|
@ -1143,14 +1147,13 @@ WDLScore probe_wdl_table(Position& pos, ProbeState* result)
|
||||||
return WDLDraw;
|
return WDLDraw;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init table at first access attempt. Special care to avoid
|
// Init table at first access attempt. Special care should be taken to avoid
|
||||||
// one thread reads ready == 1 while the other is still in
|
// one thread reads ready == 1 while the other is still in init(), this could
|
||||||
// init(), this could happen due to compiler reordering.
|
// happen due to compiler reordering.
|
||||||
if (!entry->ready.load(std::memory_order_acquire)) {
|
if (!entry->ready.load(std::memory_order_acquire)) {
|
||||||
std::unique_lock<Mutex> lk(TB_mutex);
|
std::unique_lock<Mutex> lk(TB_mutex);
|
||||||
if (!entry->ready.load(std::memory_order_relaxed)) {
|
if (!entry->ready.load(std::memory_order_relaxed)) {
|
||||||
std::string fname = pos_code(pos, entry->key != key) + ".rtbw";
|
if (!init(*entry, pos)) {
|
||||||
if (!init(*entry, fname)) {
|
|
||||||
// Was ptr2->key = 0ULL; Just leave !ptr->ready condition
|
// Was ptr2->key = 0ULL; Just leave !ptr->ready condition
|
||||||
*result = FAIL;
|
*result = FAIL;
|
||||||
return WDLDraw;
|
return WDLDraw;
|
||||||
|
@ -1162,8 +1165,8 @@ WDLScore probe_wdl_table(Position& pos, ProbeState* result)
|
||||||
return (WDLScore)probe_table(pos, entry);
|
return (WDLScore)probe_table(pos, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
int probe_dtz_table(const Position& pos, WDLScore wdl, ProbeState* result)
|
int probe_dtz_table(const Position& pos, WDLScore wdl, ProbeState* result) {
|
||||||
{
|
|
||||||
Key key = pos.material_key();
|
Key key = pos.material_key();
|
||||||
|
|
||||||
if (DTZTable.front().key != key && DTZTable.front().key2 != key) {
|
if (DTZTable.front().key != key && DTZTable.front().key2 != key) {
|
||||||
|
@ -1187,8 +1190,7 @@ int probe_dtz_table(const Position& pos, WDLScore wdl, ProbeState* result)
|
||||||
|
|
||||||
DTZTable.push_front(DTZEntry(*wdlEntry));
|
DTZTable.push_front(DTZEntry(*wdlEntry));
|
||||||
|
|
||||||
std::string fname = pos_code(pos, wdlEntry->key != key) + ".rtbz";
|
if (!init(DTZTable.front(), pos)) {
|
||||||
if (!init(DTZTable.front(), fname)) {
|
|
||||||
// In case file is not found init() fails, but we leave
|
// In case file is not found init() fails, but we leave
|
||||||
// the entry so to avoid rechecking at every probe (same
|
// the entry so to avoid rechecking at every probe (same
|
||||||
// functionality as WDL case).
|
// functionality as WDL case).
|
||||||
|
@ -1198,8 +1200,9 @@ int probe_dtz_table(const Position& pos, WDLScore wdl, ProbeState* result)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep list size within 64 entries
|
// Keep list size within 64 entries to avoid huge mapped memory.
|
||||||
// FIXME remove it when we will know what we are doing
|
// DTZ are huge and probed only at root, so normally we have only
|
||||||
|
// few of them mapped in real games.
|
||||||
if (DTZTable.size() > 64)
|
if (DTZTable.size() > 64)
|
||||||
DTZTable.pop_back();
|
DTZTable.pop_back();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue