mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Microptimize first_entry() for 32bits
Do a 32bit bitwise 'and' instead of a 64bit subtract and bitwise 'and'. This is possible because even in the biggest hash table case (8GB) the number of entries is 2^29 so storable in an unsigned int. No functional change.
This commit is contained in:
parent
fe3352665b
commit
c698362680
2 changed files with 8 additions and 6 deletions
10
src/tt.cpp
10
src/tt.cpp
|
@ -32,12 +32,14 @@ TranspositionTable TT; // Our global transposition table
|
|||
|
||||
void TranspositionTable::set_size(size_t mbSize) {
|
||||
|
||||
size_t newSize = 1ULL << msb((mbSize << 20) / sizeof(TTEntry[ClusterSize]));
|
||||
assert(msb((mbSize << 20) / sizeof(TTEntry)) < 32);
|
||||
|
||||
if (newSize == size)
|
||||
uint32_t size = 1 << msb((mbSize << 20) / sizeof(TTEntry[ClusterSize]));
|
||||
|
||||
if (clusterMask == size - 1)
|
||||
return;
|
||||
|
||||
size = newSize;
|
||||
clusterMask = size - 1;
|
||||
delete [] entries;
|
||||
entries = new (std::nothrow) TTEntry[size * ClusterSize];
|
||||
|
||||
|
@ -58,7 +60,7 @@ void TranspositionTable::set_size(size_t mbSize) {
|
|||
|
||||
void TranspositionTable::clear() {
|
||||
|
||||
memset(entries, 0, size * sizeof(TTEntry[ClusterSize]));
|
||||
memset(entries, 0, (clusterMask + 1) * sizeof(TTEntry[ClusterSize]));
|
||||
}
|
||||
|
||||
|
||||
|
|
4
src/tt.h
4
src/tt.h
|
@ -96,7 +96,7 @@ public:
|
|||
void store(const Key key, Value v, Bound type, Depth d, Move m, Value statV, Value kingD);
|
||||
|
||||
private:
|
||||
size_t size;
|
||||
uint32_t clusterMask;
|
||||
TTEntry* entries;
|
||||
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 & (size - 1)) * ClusterSize;
|
||||
return entries + ((uint32_t)key & clusterMask) * ClusterSize;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue