Make casting styles consistent

Make casting styles consistent with the rest of the code.

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

No functional change
This commit is contained in:
cj5716
2023-09-19 18:06:12 +08:00
committed by Joost VandeVondele
parent 952740b36c
commit fce4cc1829
11 changed files with 56 additions and 56 deletions

View File

@@ -114,7 +114,7 @@ template<typename T, int LE> T number(void* addr)
{
T v;
if ((uintptr_t)addr & (alignof(T) - 1)) // Unaligned pointer (very rare)
if (uintptr_t(addr) & (alignof(T) - 1)) // Unaligned pointer (very rare)
std::memcpy(&v, addr, sizeof(T));
else
v = *((T*)addr);
@@ -263,7 +263,7 @@ public:
exit(EXIT_FAILURE);
}
*mapping = (uint64_t)mmap;
*mapping = uint64_t(mmap);
*baseAddress = MapViewOfFile(mmap, FILE_MAP_READ, 0, 0, 0);
if (!*baseAddress)
@@ -429,7 +429,7 @@ class TBTables {
std::deque<TBTable<DTZ>> dtzTable;
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{ key, wdl, dtz };
// Ensure last element is empty to avoid overflow when looking up
@@ -442,7 +442,7 @@ class TBTables {
// Robin Hood hashing: If we've probed for longer than this element,
// 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) {
std::swap(entry, hashTable[bucket]);
key = otherKey;
@@ -456,7 +456,7 @@ class TBTables {
public:
template<TBType Type>
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 (entry->key == key || !entry->get<Type>())
return entry->get<Type>();
}
@@ -489,7 +489,7 @@ void TBTables::add(const std::vector<PieceType>& pieces) {
file.close();
MaxCardinality = std::max((int)pieces.size(), MaxCardinality);
MaxCardinality = std::max(int(pieces.size()), MaxCardinality);
wdlTable.emplace_back(code);
dtzTable.emplace_back(wdlTable.back());
@@ -560,7 +560,7 @@ int decompress_pairs(PairsData* d, uint64_t idx) {
offset -= d->blockLength[block++] + 1;
// Finally, we find the start address of our block of canonical Huffman symbols
uint32_t* ptr = (uint32_t*)(d->data + ((uint64_t)block * d->sizeofBlock));
uint32_t* ptr = (uint32_t*)(d->data + (uint64_t(block) * d->sizeofBlock));
// Read the first 64 bits in our block, this is a (truncated) sequence of
// unknown number of symbols of unknown length but we know the first one
@@ -600,7 +600,7 @@ int decompress_pairs(PairsData* d, uint64_t idx) {
if (buf64Size <= 32) { // Refill the buffer
buf64Size += 32;
buf64 |= (uint64_t)number<uint32_t, BigEndian>(ptr++) << (64 - buf64Size);
buf64 |= uint64_t(number<uint32_t, BigEndian>(ptr++)) << (64 - buf64Size);
}
}
@@ -1054,22 +1054,22 @@ uint8_t* set_dtz_map(TBTable<DTZ>& e, uint8_t* data, File maxFile) {
auto flags = e.get(0, f)->flags;
if (flags & TBFlag::Mapped) {
if (flags & TBFlag::Wide) {
data += (uintptr_t)data & 1; // Word alignment, we may have a mixed table
data += uintptr_t(data) & 1; // Word alignment, we may have a mixed table
for (int i = 0; i < 4; ++i) { // Sequence like 3,x,x,x,1,x,0,2,x,x
e.get(0, f)->map_idx[i] = (uint16_t)((uint16_t *)data - (uint16_t *)e.map + 1);
e.get(0, f)->map_idx[i] = uint16_t((uint16_t*)data - (uint16_t*)e.map + 1);
data += 2 * number<uint16_t, LittleEndian>(data) + 2;
}
}
else {
for (int i = 0; i < 4; ++i) {
e.get(0, f)->map_idx[i] = (uint16_t)(data - e.map + 1);
e.get(0, f)->map_idx[i] = uint16_t(data - e.map + 1);
data += *data + 1;
}
}
}
}
return data += (uintptr_t)data & 1; // Word alignment
return data += uintptr_t(data) & 1; // Word alignment
}
// Populate entry's PairsData records with data from the just memory mapped file.
@@ -1110,7 +1110,7 @@ void set(T& e, uint8_t* data) {
set_groups(e, e.get(i, f), order[i], f);
}
data += (uintptr_t)data & 1; // Word alignment
data += uintptr_t(data) & 1; // Word alignment
for (File f = FILE_A; f <= maxFile; ++f)
for (int i = 0; i < sides; i++)
@@ -1132,7 +1132,7 @@ void set(T& e, uint8_t* data) {
for (File f = FILE_A; f <= maxFile; ++f)
for (int i = 0; i < sides; i++) {
data = (uint8_t*)(((uintptr_t)data + 0x3F) & ~0x3F); // 64 byte alignment
data = (uint8_t*)((uintptr_t(data) + 0x3F) & ~0x3F); // 64 byte alignment
(d = e.get(i, f))->data = data;
data += d->blocksNum * d->sizeofBlock;
}