Make casting styles consistent with the rest of the code.
closes https://github.com/official-stockfish/Stockfish/pull/4793
No functional change
#elif defined(_MSC_VER)
- return (int)_mm_popcnt_u64(b);
+ return int(_mm_popcnt_u64(b));
#else // Assumed gcc or compatible compiler
Tie(std::streambuf* b, std::streambuf* l) : buf(b), logBuf(l) {}
int sync() override { return logBuf->pubsync(), buf->pubsync(); }
- int overflow(int c) override { return log(buf->sputc((char)c), "<< "); }
+ int overflow(int c) override { return log(buf->sputc(char(c)), "<< "); }
int underflow() override { return buf->sgetc(); }
int uflow() override { return log(buf->sbumpc(), ">> "); }
if (last == '\n')
logBuf->sputn(prefix, 3);
- return last = logBuf->sputc((char)c);
+ return last = logBuf->sputc(char(c));
}
};
compiler += ")";
#elif defined(__e2k__) && defined(__LCC__)
#define dot_ver2(n) \
- compiler += (char)'.'; \
- compiler += (char)('0' + (n) / 10); \
- compiler += (char)('0' + (n) % 10);
+ compiler += char('.'); \
+ compiler += char('0' + (n) / 10); \
+ compiler += char('0' + (n) % 10);
compiler += "MCST LCC ";
compiler += "(version ";
if (!hAdvapi32)
hAdvapi32 = LoadLibrary(TEXT("advapi32.dll"));
- auto fun6 = (fun6_t)(void(*)())GetProcAddress(hAdvapi32, "OpenProcessToken");
+ auto fun6 = fun6_t((void(*)())GetProcAddress(hAdvapi32, "OpenProcessToken"));
if (!fun6)
return nullptr;
- auto fun7 = (fun7_t)(void(*)())GetProcAddress(hAdvapi32, "LookupPrivilegeValueA");
+ auto fun7 = fun7_t((void(*)())GetProcAddress(hAdvapi32, "LookupPrivilegeValueA"));
if (!fun7)
return nullptr;
- auto fun8 = (fun8_t)(void(*)())GetProcAddress(hAdvapi32, "AdjustTokenPrivileges");
+ auto fun8 = fun8_t((void(*)())GetProcAddress(hAdvapi32, "AdjustTokenPrivileges"));
if (!fun8)
return nullptr;
// Early exit if the needed API are not available at runtime
HMODULE k32 = GetModuleHandle(TEXT("Kernel32.dll"));
- auto fun2 = (fun2_t)(void(*)())GetProcAddress(k32, "GetNumaNodeProcessorMaskEx");
- auto fun3 = (fun3_t)(void(*)())GetProcAddress(k32, "SetThreadGroupAffinity");
- auto fun4 = (fun4_t)(void(*)())GetProcAddress(k32, "GetNumaNodeProcessorMask2");
- auto fun5 = (fun5_t)(void(*)())GetProcAddress(k32, "GetMaximumProcessorGroupCount");
+ auto fun2 = fun2_t((void(*)())GetProcAddress(k32, "GetNumaNodeProcessorMaskEx"));
+ auto fun3 = fun3_t((void(*)())GetProcAddress(k32, "SetThreadGroupAffinity"));
+ auto fun4 = fun4_t((void(*)())GetProcAddress(k32, "GetNumaNodeProcessorMask2"));
+ auto fun5 = fun5_t((void(*)())GetProcAddress(k32, "GetMaximumProcessorGroupCount"));
if (!fun2 || !fun3)
return;
inline uint64_t mul_hi64(uint64_t a, uint64_t b) {
#if defined(__GNUC__) && defined(IS_64BIT)
__extension__ using uint128 = unsigned __int128;
- return ((uint128)a * (uint128)b) >> 64;
+ return (uint128(a) * uint128(b)) >> 64;
#else
- uint64_t aL = (uint32_t)a, aH = a >> 32;
- uint64_t bL = (uint32_t)b, bH = b >> 32;
+ uint64_t aL = uint32_t(a), aH = a >> 32;
+ uint64_t bL = uint32_t(b), bH = b >> 32;
uint64_t c1 = (aL * bL) >> 32;
uint64_t c2 = aH * bL + c1;
- uint64_t c3 = aL * bH + (uint32_t)c2;
+ uint64_t c3 = aL * bH + uint32_t(c2);
return aH * bH + (c2 >> 32) + (c3 >> 32);
#endif
}
ExtMove* generate(const Position& pos, ExtMove* moveList) {
static_assert(Type != LEGAL, "Unsupported type in generate()");
- assert((Type == EVASIONS) == (bool)pos.checkers());
+ assert((Type == EVASIONS) == bool(pos.checkers()));
Color us = pos.side_to_move();
if (!Detail::write_parameters(stream, *featureTransformer)) return false;
for (std::size_t i = 0; i < LayerStacks; ++i)
if (!Detail::write_parameters(stream, *(network[i]))) return false;
- return (bool)stream;
+ return bool(stream);
}
void hint_common_parent_position(const Position& pos) {
// A lambda to output one box of the board
auto writeSquare = [&board](File file, Rank rank, Piece pc, Value value) {
- const int x = ((int)file) * 8;
- const int y = (7 - (int)rank) * 3;
+ const int x = int(file) * 8;
+ const int y = (7 - int(rank)) * 3;
for (int i = 1; i < 8; ++i)
board[y][x+i] = board[y+3][x+i] = '-';
for (int i = 1; i < 3; ++i)
vec_t sum0 = vec_setzero();
const auto row0 = reinterpret_cast<const vec_t*>(&weights[0]);
- for (int j = 0; j < (int)NumChunks; ++j)
+ for (int j = 0; j < int(NumChunks); ++j)
{
const vec_t in = inputVector[j];
vec_add_dpbusd_32(sum0, in, row0[j]);
for (IndexType j = 0; j < InputsPerChunk; ++j)
{
const vec_t inputChunk = inputVector[i * InputsPerChunk + j];
- nnz |= (unsigned)vec_nnz(inputChunk) << (j * InputSimdWidth);
+ nnz |= unsigned(vec_nnz(inputChunk)) << (j * InputSimdWidth);
}
for (IndexType j = 0; j < OutputsPerChunk; ++j)
{
// When playing with strength handicap enable MultiPV search that we will
// use behind-the-scenes to retrieve a set of possible moves.
if (skill.enabled())
- multiPV = std::max(multiPV, (size_t)4);
+ multiPV = std::max(multiPV, size_t(4));
multiPV = std::min(multiPV, rootMoves.size());
if ( (Limits.use_time_management() && (elapsed > Time.maximum() || stopOnPonderhit))
|| (Limits.movetime && elapsed >= Limits.movetime)
- || (Limits.nodes && Threads.nodes_searched() >= (uint64_t)Limits.nodes))
+ || (Limits.nodes && Threads.nodes_searched() >= uint64_t(Limits.nodes)))
Threads.stop = true;
}
TimePoint elapsed = Time.elapsed() + 1;
const RootMoves& rootMoves = pos.this_thread()->rootMoves;
size_t pvIdx = pos.this_thread()->pvIdx;
- size_t multiPV = std::min((size_t)Options["MultiPV"], rootMoves.size());
+ size_t multiPV = std::min(size_t(Options["MultiPV"]), rootMoves.size());
uint64_t nodesSearched = Threads.nodes_searched();
uint64_t tbHits = Threads.tb_hits() + (TB::RootInTB ? rootMoves.size() : 0);
{
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);
exit(EXIT_FAILURE);
}
- *mapping = (uint64_t)mmap;
+ *mapping = uint64_t(mmap);
*baseAddress = MapViewOfFile(mmap, FILE_MAP_READ, 0, 0, 0);
if (!*baseAddress)
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
// 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;
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>();
}
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());
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
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);
}
}
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.
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++)
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;
}
void TTEntry::save(Key k, Value v, bool pv, Bound b, Depth d, Move m, Value ev) {
// Preserve any existing move for the same position
- if (m || (uint16_t)k != key16)
- move16 = (uint16_t)m;
+ if (m || uint16_t(k) != key16)
+ move16 = uint16_t(m);
// Overwrite less valuable entries (cheapest checks first)
if ( b == BOUND_EXACT
- || (uint16_t)k != key16
+ || uint16_t(k) != key16
|| d - DEPTH_OFFSET + 2 * pv > depth8 - 4)
{
assert(d > DEPTH_OFFSET);
assert(d < 256 + DEPTH_OFFSET);
- key16 = (uint16_t)k;
- depth8 = (uint8_t)(d - DEPTH_OFFSET);
- genBound8 = (uint8_t)(TT.generation8 | uint8_t(pv) << 2 | b);
- value16 = (int16_t)v;
- eval16 = (int16_t)ev;
+ key16 = uint16_t(k);
+ depth8 = uint8_t(d - DEPTH_OFFSET);
+ genBound8 = uint8_t(TT.generation8 | uint8_t(pv) << 2 | b);
+ value16 = int16_t(v);
+ eval16 = int16_t(ev);
}
}
TTEntry* TranspositionTable::probe(const Key key, bool& found) const {
TTEntry* const tte = first_entry(key);
- const uint16_t key16 = (uint16_t)key; // Use the low 16 bits as key inside the cluster
+ const uint16_t key16 = uint16_t(key); // Use the low 16 bits as key inside the cluster
for (int i = 0; i < ClusterSize; ++i)
if (tte[i].key16 == key16 || !tte[i].depth8)
{
tte[i].genBound8 = uint8_t(generation8 | (tte[i].genBound8 & (GENERATION_DELTA - 1))); // Refresh
- return found = (bool)tte[i].depth8, &tte[i];
+ return found = bool(tte[i].depth8), &tte[i];
}
// Find an entry to be replaced according to the replacement strategy
struct TTEntry {
- Move move() const { return (Move )move16; }
- Value value() const { return (Value)value16; }
- Value eval() const { return (Value)eval16; }
- Depth depth() const { return (Depth)depth8 + DEPTH_OFFSET; }
- bool is_pv() const { return (bool)(genBound8 & 0x4); }
- Bound bound() const { return (Bound)(genBound8 & 0x3); }
+ Move move() const { return Move (move16); }
+ Value value() const { return Value(value16); }
+ Value eval() const { return Value(eval16); }
+ Depth depth() const { return Depth(depth8 + DEPTH_OFFSET); }
+ bool is_pv() const { return bool (genBound8 & 0x4); }
+ Bound bound() const { return Bound(genBound8 & 0x3); }
void save(Key k, Value v, bool pv, Bound b, Depth d, Move m, Value ev);
private: