diff --git a/source/graphics/ColladaManager.cpp b/source/graphics/ColladaManager.cpp index 98a6503e9a..5f4b12b003 100644 --- a/source/graphics/ColladaManager.cpp +++ b/source/graphics/ColladaManager.cpp @@ -25,7 +25,6 @@ #include "lib/file/vfs/vfs_util.h" #include "lib/path.h" #include "lib/status.h" -#include "lib/types.h" #include "maths/MD5.h" #include "ps/CLogger.h" #include "ps/CStr.h" @@ -300,8 +299,8 @@ public: } else { - m_skeletonHashes.push_back((u64)fileInfo.MTime() & ~1); //skip lowest bit, since zip and FAT don't preserve it - m_skeletonHashes.push_back((u64)fileInfo.Size()); + m_skeletonHashes.push_back(static_cast(fileInfo.MTime()) & ~1); //skip lowest bit, since zip and FAT don't preserve it + m_skeletonHashes.push_back(static_cast(fileInfo.Size())); } } @@ -313,14 +312,14 @@ public: m_skeletonHashInvalidated = false; } - for (const u64& h : m_skeletonHashes) + for (const std::uint64_t& h : m_skeletonHashes) hash.Update(reinterpret_cast(&h), sizeof(h)); } private: PIVFS m_VFS; bool m_skeletonHashInvalidated; - std::vector m_skeletonHashes; + std::vector m_skeletonHashes; }; CColladaManager::CColladaManager(const PIVFS& vfs) diff --git a/source/graphics/SkeletonAnimDef.cpp b/source/graphics/SkeletonAnimDef.cpp index 5e544127f8..239c09c61d 100644 --- a/source/graphics/SkeletonAnimDef.cpp +++ b/source/graphics/SkeletonAnimDef.cpp @@ -39,7 +39,8 @@ std::uint32_t g_NextSkeletonDefUID = 1; CSkeletonAnimDef::CSkeletonAnimDef() : m_FrameTime(0), m_NumKeys(0), m_NumFrames(0) { m_UID = g_NextSkeletonDefUID++; - // Log a warning if we ever overflow. Should that not result from a bug, bumping to u64 ought to suffice. + // Log a warning if we ever overflow. Should that not result from a bug, bumping to std::uint64_t + // ought to suffice. if (g_NextSkeletonDefUID == 0) { // Reset to 1. diff --git a/source/lib/byte_order.cpp b/source/lib/byte_order.cpp index 93c6e3754f..70e14c7dca 100644 --- a/source/lib/byte_order.cpp +++ b/source/lib/byte_order.cpp @@ -51,13 +51,13 @@ std::uint32_t swap32(const std::uint32_t x) #endif #ifndef swap64 -u64 swap64(const u64 x) +std::uint64_t swap64(const std::uint64_t x) { const std::uint32_t lo = static_cast(x & 0xFFFFFFFF); const std::uint32_t hi = static_cast(x >> 32); - u64 ret = swap32(lo); + std::uint64_t ret = swap32(lo); ret <<= 32; - // careful: must shift var of type u64, not std::uint32_t + // careful: must shift var of type std::uint64_t, not std::uint32_t ret |= swap32(hi); return ret; } @@ -81,9 +81,9 @@ std::uint32_t read_le32(const void* p) return to_le32(n); } -u64 read_le64(const void* p) +std::uint64_t read_le64(const void* p) { - u64 n; + std::uint64_t n; memcpy(&n, p, sizeof(n)); return to_le64(n); } @@ -103,9 +103,9 @@ std::uint32_t read_be32(const void* p) return to_be32(n); } -u64 read_be64(const void* p) +std::uint64_t read_be64(const void* p) { - u64 n; + std::uint64_t n; memcpy(&n, p, sizeof(n)); return to_be64(n); } @@ -123,9 +123,9 @@ void write_le32(void* p, std::uint32_t x) memcpy(p, &n, sizeof(n)); } -void write_le64(void* p, u64 x) +void write_le64(void* p, std::uint64_t x) { - u64 n = to_le64(x); + std::uint64_t n = to_le64(x); memcpy(p, &n, sizeof(n)); } @@ -142,25 +142,25 @@ void write_be32(void* p, std::uint32_t x) memcpy(p, &n, sizeof(n)); } -void write_be64(void* p, u64 x) +void write_be64(void* p, std::uint64_t x) { - u64 n = to_be64(x); + std::uint64_t n = to_be64(x); memcpy(p, &n, sizeof(n)); } -u64 movzx_le64(const std::uint8_t* p, size_t size_bytes) +std::uint64_t movzx_le64(const std::uint8_t* p, size_t size_bytes) { - u64 number = 0; + std::uint64_t number = 0; for(size_t i = 0; i < std::min(size_bytes, (size_t)8u); i++) - number |= ((u64)p[i]) << (i*8); + number |= static_cast(p[i]) << (i*8); return number; } -u64 movzx_be64(const std::uint8_t* p, size_t size_bytes) +std::uint64_t movzx_be64(const std::uint8_t* p, size_t size_bytes) { - u64 number = 0; + std::uint64_t number = 0; for(size_t i = 0; i < std::min(size_bytes, (size_t)8u); i++) { number <<= 8; @@ -171,18 +171,18 @@ u64 movzx_be64(const std::uint8_t* p, size_t size_bytes) } -static inline std::int64_t SignExtend(u64 bits, size_t size_bytes) +static inline std::int64_t SignExtend(std::uint64_t bits, size_t size_bytes) { // no point in sign-extending if >= 8 bytes were requested if(size_bytes < 8) { - const u64 sign_bit = Bit((size_bytes*8)-1); + const std::uint64_t sign_bit = Bit((size_bytes*8)-1); // number would be negative in the smaller type, // so sign-extend, i.e. set all more significant bits. if(bits & sign_bit) { - const u64 valid_bit_mask = (sign_bit+sign_bit)-1; + const std::uint64_t valid_bit_mask = (sign_bit+sign_bit)-1; bits |= ~valid_bit_mask; } } @@ -193,12 +193,12 @@ static inline std::int64_t SignExtend(u64 bits, size_t size_bytes) std::int64_t movsx_le64(const std::uint8_t* p, size_t size_bytes) { - const u64 number = movzx_le64(p, size_bytes); + const std::uint64_t number = movzx_le64(p, size_bytes); return SignExtend(number, size_bytes); } std::int64_t movsx_be64(const std::uint8_t* p, size_t size_bytes) { - const u64 number = movzx_be64(p, size_bytes); + const std::uint64_t number = movzx_be64(p, size_bytes); return SignExtend(number, size_bytes); } diff --git a/source/lib/byte_order.h b/source/lib/byte_order.h index 5f52ef86a5..c632a337ae 100644 --- a/source/lib/byte_order.h +++ b/source/lib/byte_order.h @@ -28,7 +28,6 @@ #define INCLUDED_BYTE_ORDER #include "lib/sysdep/compiler.h" -#include "lib/types.h" #include @@ -102,29 +101,29 @@ /// read a little-endian number from memory into native byte order. std::uint16_t read_le16(const void* p); std::uint32_t read_le32(const void* p); /// see read_le16 -u64 read_le64(const void* p); /// see read_le16 +std::uint64_t read_le64(const void* p); /// see read_le16 /// read a big-endian number from memory into native byte order. std::uint16_t read_be16(const void* p); std::uint32_t read_be32(const void* p); /// see read_be16 -u64 read_be64(const void* p); /// see read_be16 +std::uint64_t read_be64(const void* p); /// see read_be16 /// write a little-endian number to memory in native byte order. void write_le16(void* p, std::uint16_t x); void write_le32(void* p, std::uint32_t x); /// see write_le16 -void write_le64(void* p, u64 x); /// see write_le16 +void write_le64(void* p, std::uint64_t x); /// see write_le16 /// write a big-endian number to memory in native byte order. void write_be16(void* p, std::uint16_t x); void write_be32(void* p, std::uint32_t x); /// see write_be16 -void write_be64(void* p, u64 x); /// see write_be16 +void write_be64(void* p, std::uint64_t x); /// see write_be16 /** - * zero-extend \ (truncated to 8) bytes of little-endian data to u64, - * starting at address \ (need not be aligned). + * zero-extend \ (truncated to 8) bytes of little-endian data to + * std::uint64_t, starting at address \ (need not be aligned). **/ -u64 movzx_le64(const std::uint8_t* p, size_t size); -u64 movzx_be64(const std::uint8_t* p, size_t size); +std::uint64_t movzx_le64(const std::uint8_t* p, size_t size); +std::uint64_t movzx_be64(const std::uint8_t* p, size_t size); /** * sign-extend \ (truncated to 8) bytes of little-endian data to @@ -164,7 +163,7 @@ std::uint16_t swap16(const std::uint16_t x); std::uint32_t swap32(const std::uint32_t x); #endif #ifndef swap64 -u64 swap64(const u64 x); +std::uint64_t swap64(const std::uint64_t x); #endif #endif // #ifndef INCLUDED_BYTE_ORDER diff --git a/source/lib/file/file_system.cpp b/source/lib/file/file_system.cpp index 7545b66050..6363638125 100644 --- a/source/lib/file/file_system.cpp +++ b/source/lib/file/file_system.cpp @@ -53,7 +53,8 @@ Status GetFileInfo(const OsPath& pathname, CFileInfo* pPtrInfo) try { const std::filesystem::path path{pathname.string()}; - *pPtrInfo = CFileInfo(path.filename().wstring(), static_cast(std::filesystem::file_size(path)), + *pPtrInfo = CFileInfo(path.filename().wstring(), + static_cast(std::filesystem::file_size(path)), static_cast(std::chrono::duration_cast(std::filesystem::last_write_time(path).time_since_epoch()).count())); } catch (std::filesystem::filesystem_error& err) @@ -76,7 +77,8 @@ Status GetDirectoryEntries(const OsPath& path, CFileInfos* files, DirectoryNames } else if (entry.is_regular_file() && files) { - files->emplace_back(entry.path().filename().wstring(), static_cast(entry.file_size()), + files->emplace_back(entry.path().filename().wstring(), + static_cast(entry.file_size()), static_cast(std::chrono::duration_cast(entry.last_write_time().time_since_epoch()).count())); } } diff --git a/source/lib/fnv_hash.cpp b/source/lib/fnv_hash.cpp index b55d7e8450..c24e491389 100644 --- a/source/lib/fnv_hash.cpp +++ b/source/lib/fnv_hash.cpp @@ -62,9 +62,9 @@ std::uint32_t fnv_hash(const void* buf, size_t len) // FNV1-A hash - good for strings. // if len = 0 (default), treat buf as a C-string; // otherwise, hash bytes of buf. -u64 fnv_hash64(const void* buf, size_t len) +std::uint64_t fnv_hash64(const void* buf, size_t len) { - u64 h = 0xCBF29CE484222325ull; + std::uint64_t h = 0xCBF29CE484222325ull; // give distinct values for different length 0 buffers. // value taken from FNV; it has no special significance. diff --git a/source/lib/fnv_hash.h b/source/lib/fnv_hash.h index 357f411057..2ecaf8a004 100644 --- a/source/lib/fnv_hash.h +++ b/source/lib/fnv_hash.h @@ -27,8 +27,6 @@ #ifndef INCLUDED_FNV_HASH #define INCLUDED_FNV_HASH -#include "lib/types.h" - #include /** @@ -48,6 +46,6 @@ **/ extern std::uint32_t fnv_hash(const void* buf, size_t len = 0); /// 64-bit version of fnv_hash. -extern u64 fnv_hash64(const void* buf, size_t len = 0); +extern std::uint64_t fnv_hash64(const void* buf, size_t len = 0); #endif // INCLUDED_FNV_HASH diff --git a/source/lib/lib.cpp b/source/lib/lib.cpp index eea505a882..1e77261532 100644 --- a/source/lib/lib.cpp +++ b/source/lib/lib.cpp @@ -36,12 +36,12 @@ // these avoid a common mistake in using >> (ANSI requires shift count be // less than the bit width of the type). -std::uint32_t u64_hi(u64 x) +std::uint32_t u64_hi(std::uint64_t x) { return static_cast(x >> 32); } -std::uint32_t u64_lo(u64 x) +std::uint32_t u64_lo(std::uint64_t x) { return static_cast(x & 0xFFFFFFFF); } @@ -57,9 +57,9 @@ std::uint16_t u32_lo(std::uint32_t x) } -u64 u64_from_u32(std::uint32_t hi, std::uint32_t lo) +std::uint64_t u64_from_u32(std::uint32_t hi, std::uint32_t lo) { - u64 x = (u64)hi; + std::uint64_t x = static_cast(hi); x <<= 32; x |= lo; return x; diff --git a/source/lib/lib.h b/source/lib/lib.h index f532bb0c19..032362d069 100644 --- a/source/lib/lib.h +++ b/source/lib/lib.h @@ -61,7 +61,6 @@ scope #define INCLUDED_LIB #include "lib/debug.h" -#include "lib/types.h" #include // fabsf #include // numeric_limits @@ -113,12 +112,12 @@ inline bool IsSimilarMagnitude(double d1, double d2, const double relativeErrorT // note: these avoid a common mistake in using >> (ANSI requires // shift count be less than the bit width of the type). -extern std::uint32_t u64_hi(u64 x); /// return upper 32-bits -extern std::uint32_t u64_lo(u64 x); /// return lower 32-bits +extern std::uint32_t u64_hi(std::uint64_t x); /// return upper 32-bits +extern std::uint32_t u64_lo(std::uint64_t x); /// return lower 32-bits extern std::uint16_t u32_hi(std::uint32_t x); /// return upper 16-bits extern std::uint16_t u32_lo(std::uint32_t x); /// return lower 16-bits -extern u64 u64_from_u32(std::uint32_t hi, std::uint32_t lo); /// assemble u64 from std::uint32_t +extern std::uint64_t u64_from_u32(std::uint32_t hi, std::uint32_t lo); /// assemble std::uint64_t from std::uint32_t extern std::uint32_t u32_from_u16(std::uint16_t hi, std::uint16_t lo); /// assemble std::uint32_t from std::uint16_t // safe downcasters: cast from any integral type to std::uint32_t or @@ -134,7 +133,7 @@ extern std::uint32_t u32_from_u16(std::uint16_t hi, std::uint16_t lo); /// assem template std::uint8_t u8_from_larger(T x) { const std::uint8_t max = std::numeric_limits::max(); - if((u64)x > (u64)max) + if(static_cast(x) > static_cast(max)) throw std::out_of_range("u8_from_larger"); return static_cast(x & max); } @@ -142,7 +141,7 @@ template std::uint8_t u8_from_larger(T x) template std::uint16_t u16_from_larger(T x) { const std::uint16_t max = std::numeric_limits::max(); - if((u64)x > (u64)max) + if(static_cast(x) > static_cast(max)) throw std::out_of_range("u16_from_larger"); return static_cast(x & max); } @@ -150,7 +149,7 @@ template std::uint16_t u16_from_larger(T x) template std::uint32_t u32_from_larger(T x) { const std::uint32_t max = std::numeric_limits::max(); - if((u64)x > (u64)max) + if(static_cast(x) > static_cast(max)) throw std::out_of_range("u32_from_larger"); return static_cast(x & max); } diff --git a/source/lib/sysdep/arch/x86_x64/x86_x64.cpp b/source/lib/sysdep/arch/x86_x64/x86_x64.cpp index 0aa32fe0b8..3b0d8e6961 100644 --- a/source/lib/sysdep/arch/x86_x64/x86_x64.cpp +++ b/source/lib/sysdep/arch/x86_x64/x86_x64.cpp @@ -373,7 +373,7 @@ static const char* IdentifierString() // miscellaneous stateless functions #if !MSC_VERSION // ensure not already defined in header -u64 rdtsc() +std::uint64_t rdtsc() { #if GCC_VERSION // GCC supports "portable" assembly for both x86 and x64 @@ -458,12 +458,12 @@ double ClockFrequency() for(size_t i = 0; i < numSamples; i++) { double dt; - std::int64_t dc; // (std::int64_t instead of u64 for faster conversion to double) + std::int64_t dc; // (std::int64_t instead of std::uint64_t for faster conversion to double) // count # of clocks in max{1 tick, 1 ms}: // .. wait for start of tick. const double t0 = timer_Time(); - u64 c1; double t1; + std::uint64_t c1; double t1; do { // note: timer_Time effectively has a long delay (up to 5 us) @@ -480,7 +480,7 @@ double ClockFrequency() do { const double t2 = timer_Time(); - const u64 c2 = rdtsc(); + const std::uint64_t c2 = rdtsc(); dc = static_cast(c2 - c1); dt = t2 - t1; } diff --git a/source/lib/sysdep/arch/x86_x64/x86_x64.h b/source/lib/sysdep/arch/x86_x64/x86_x64.h index 8193a87610..5a58824cf5 100644 --- a/source/lib/sysdep/arch/x86_x64/x86_x64.h +++ b/source/lib/sysdep/arch/x86_x64/x86_x64.h @@ -29,7 +29,6 @@ #include "lib/sysdep/arch.h" #include "lib/sysdep/compiler.h" -#include "lib/types.h" #include @@ -163,9 +162,9 @@ void GetCapBits(std::uint32_t* d0, std::uint32_t* d1, std::uint32_t* d2, std::ui * - x64 RDTSC writes to edx:eax and clears the upper halves of rdx and rax. **/ #if MSC_VERSION -static inline u64 rdtsc() { return __rdtsc(); } +static inline std::uint64_t rdtsc() { return __rdtsc(); } #else -u64 rdtsc(); +std::uint64_t rdtsc(); #endif /** diff --git a/source/lib/sysdep/os/win/acpi.h b/source/lib/sysdep/os/win/acpi.h index 67d1b160db..682f317841 100644 --- a/source/lib/sysdep/os/win/acpi.h +++ b/source/lib/sysdep/os/win/acpi.h @@ -59,7 +59,7 @@ struct AcpiGenericAddress std::uint8_t registerBitWidth; std::uint8_t registerBitOffset; std::uint8_t accessSize; - u64 address; + std::uint64_t address; }; struct FADT // signature is FACP! diff --git a/source/lib/sysdep/os/win/tests/test_ia32.h b/source/lib/sysdep/os/win/tests/test_ia32.h index 0f6af21a87..47a87e1ee0 100644 --- a/source/lib/sysdep/os/win/tests/test_ia32.h +++ b/source/lib/sysdep/os/win/tests/test_ia32.h @@ -34,9 +34,9 @@ public: void test_rdtsc() { // must increase monotonously - const u64 c1 = x86_x64::rdtsc(); - const u64 c2 = x86_x64::rdtsc(); - const u64 c3 = x86_x64::rdtsc(); + const std::uint64_t c1 = x86_x64::rdtsc(); + const std::uint64_t c2 = x86_x64::rdtsc(); + const std::uint64_t c3 = x86_x64::rdtsc(); TS_ASSERT(c1 < c2 && c2 < c3); } diff --git a/source/lib/sysdep/os/win/wdbg_sym.cpp b/source/lib/sysdep/os/win/wdbg_sym.cpp index a345721696..4eb90f2e46 100644 --- a/source/lib/sysdep/os/win/wdbg_sym.cpp +++ b/source/lib/sysdep/os/win/wdbg_sym.cpp @@ -849,7 +849,7 @@ static Status dump_sym_array(DWORD type_id, const std::uint8_t* p, DumpState& st // if the current value is a printable character, display in that form. // this isn't only done in btChar because characters are sometimes stored // in integers. -static void AppendCharacterIfPrintable(u64 data) +static void AppendCharacterIfPrintable(std::uint64_t data) { if(data < 0x100) { @@ -870,12 +870,12 @@ static Status dump_sym_base_type(DWORD type_id, const std::uint8_t* p, DumpState WARN_RETURN(ERR::SYM_TYPE_INFO_UNAVAILABLE); const size_t size = (size_t)size64; - // single out() call. note: we pass a single u64 for all sizes, + // single out() call. note: we pass a single std::uint64_t for all sizes, // which will only work on little-endian systems. // must be declared before goto to avoid W4 warning. const wchar_t* fmt = L""; - u64 data = movzx_le64(p, size); + std::uint64_t data = movzx_le64(p, size); // if value is 0xCC..CC (uninitialized mem), we display as hex. // the output would otherwise be garbage; this makes it obvious. // note: be very careful to correctly handle size=0 (e.g. void*). diff --git a/source/lib/sysdep/os/win/wnuma.cpp b/source/lib/sysdep/os/win/wnuma.cpp index c635de61b0..1289be1f1b 100644 --- a/source/lib/sysdep/os/win/wnuma.cpp +++ b/source/lib/sysdep/os/win/wnuma.cpp @@ -181,11 +181,11 @@ struct AffinityMemory AffinityHeader header; std::uint32_t proximityDomainNumber; std::uint16_t reserved1; - u64 baseAddress; - u64 length; + std::uint64_t baseAddress; + std::uint64_t length; std::uint32_t reserved2; std::uint32_t flags; - u64 reserved3; + std::uint64_t reserved3; }; // AffinityX2APIC omitted, since the APIC ID is sufficient for our purposes @@ -363,7 +363,7 @@ size_t numa_AvailableMemory(size_t node) struct SLIT { AcpiTable header; - u64 numSystemLocalities; + std::uint64_t numSystemLocalities; std::uint8_t entries[1]; // numSystemLocalities*numSystemLocalities entries }; diff --git a/source/lib/sysdep/os/win/wvm.cpp b/source/lib/sysdep/os/win/wvm.cpp index 88432d9d98..02bd69524a 100644 --- a/source/lib/sysdep/os/win/wvm.cpp +++ b/source/lib/sysdep/os/win/wvm.cpp @@ -231,7 +231,7 @@ CACHE_ALIGNED(struct AddressRangeDescriptor) // POD base = AllocateLargeOrSmallPages(0, m_TotalSize, MEM_RESERVE); if(!base) { - debug_printf("AllocateLargeOrSmallPages of %lld failed\n", (u64)m_TotalSize); + debug_printf("AllocateLargeOrSmallPages of %lld failed\n", static_cast(m_TotalSize)); DEBUG_DISPLAY_ERROR(ErrorString()); return ERR::NO_MEM; // NOWARN (error string is more helpful) } diff --git a/source/lib/sysdep/os_cpu.cpp b/source/lib/sysdep/os_cpu.cpp index e1eb7215bb..e84e8c65ee 100644 --- a/source/lib/sysdep/os_cpu.cpp +++ b/source/lib/sysdep/os_cpu.cpp @@ -31,7 +31,6 @@ #include "lib/alignment.h" #include "lib/code_annotation.h" #include "lib/sysdep/os.h" -#include "lib/types.h" #if OS_WIN # include "lib/sysdep/os/win/wcpu.h" diff --git a/source/lib/sysdep/tests/test_sysdep.h b/source/lib/sysdep/tests/test_sysdep.h index a58edad64f..89e68fe1c9 100644 --- a/source/lib/sysdep/tests/test_sysdep.h +++ b/source/lib/sysdep/tests/test_sysdep.h @@ -31,7 +31,6 @@ #include "lib/sysdep/filesystem.h" #include "lib/sysdep/os.h" #include "lib/sysdep/sysdep.h" -#include "lib/types.h" #include #include @@ -45,7 +44,7 @@ class TestSysdep : public CxxTest::TestSuite public: void test_random() { - u64 a = 0, b = 0; + std::uint64_t a = 0, b = 0; TS_ASSERT_OK(sys_generate_random_bytes(reinterpret_cast(&a), sizeof(a))); TS_ASSERT_OK(sys_generate_random_bytes(reinterpret_cast(&b), sizeof(b))); TS_ASSERT_DIFFERS(a, b); diff --git a/source/lib/tests/test_bits.h b/source/lib/tests/test_bits.h index 28d2febc5b..dfc2d32eae 100644 --- a/source/lib/tests/test_bits.h +++ b/source/lib/tests/test_bits.h @@ -23,7 +23,6 @@ #include "lib/self_test.h" #include "lib/bits.h" -#include "lib/types.h" //#define EQUALS(actual, expected) ENSURE((actual) == (expected)) #define EQUALS TS_ASSERT_EQUALS @@ -36,9 +35,9 @@ public: EQUALS(Bit(0), 1u); EQUALS(Bit(8), 0x100u); EQUALS(Bit(31), static_cast(0x80000000ul)); - EQUALS(Bit(1), u64(2)); - EQUALS(Bit(32), u64(0x100000000ull)); - EQUALS(Bit(63), u64(0x8000000000000000ull)); + EQUALS(Bit(1), static_cast(2)); + EQUALS(Bit(32), static_cast(0x100000000ull)); + EQUALS(Bit(63), static_cast(0x8000000000000000ull)); } void test_IsBitSet() @@ -48,10 +47,10 @@ public: EQUALS(IsBitSet(2u, 1), true); EQUALS(IsBitSet(0xFFFFFFFFul, 0), true); EQUALS(IsBitSet(0xFFFFFFFFul, 31), true); - EQUALS(IsBitSet(0xFFFFFFFFFFFFFFFFull, 0), true); - EQUALS(IsBitSet(0xFFFFFFFFFFFFFFFFull, 31), true); - EQUALS(IsBitSet(0xFFFFFFFFFFFFFFFFull, 32), true); - EQUALS(IsBitSet(0xFFFFFFFFFFFFFFFFull, 63), true); + EQUALS(IsBitSet(0xFFFFFFFFFFFFFFFFull, 0), true); + EQUALS(IsBitSet(0xFFFFFFFFFFFFFFFFull, 31), true); + EQUALS(IsBitSet(0xFFFFFFFFFFFFFFFFull, 32), true); + EQUALS(IsBitSet(0xFFFFFFFFFFFFFFFFull, 63), true); } void test_bit_mask() @@ -62,10 +61,10 @@ public: EQUALS(bit_mask(0), 0u); EQUALS(bit_mask(2), 0x3u); EQUALS(bit_mask(32), 0xFFFFFFFFul); - EQUALS(bit_mask(0), 0u); - EQUALS(bit_mask(2), 0x3u); - EQUALS(bit_mask(32), 0xFFFFFFFFull); - EQUALS(bit_mask(64), 0xFFFFFFFFFFFFFFFFull); + EQUALS(bit_mask(0), 0u); + EQUALS(bit_mask(2), 0x3u); + EQUALS(bit_mask(32), 0xFFFFFFFFull); + EQUALS(bit_mask(64), 0xFFFFFFFFFFFFFFFFull); } void test_bits() @@ -78,11 +77,11 @@ public: EQUALS(bits(0xAA55, 14, 15), 0x2); EQUALS(bits(0ul, 0, 31), 0ul); EQUALS(bits(0xFFFFFFFFul, 0, 31), 0xFFFFFFFFul); - EQUALS(bits(0ull, 0, 63), 0ull); - EQUALS(bits(0xFFFFFFFFull, 0, 31), 0xFFFFFFFFull); - EQUALS(bits(0x0000FFFFFFFF0000ull, 16, 47), 0xFFFFFFFFull); - EQUALS(bits(0xFFFFFFFFFFFFFFFFull, 0, 63), 0xFFFFFFFFFFFFFFFFull); - EQUALS(bits(0xA5A5A5A5A5A5A5A5ull, 32, 63), 0xA5A5A5A5ull); + EQUALS(bits(0ull, 0, 63), 0ull); + EQUALS(bits(0xFFFFFFFFull, 0, 31), 0xFFFFFFFFull); + EQUALS(bits(0x0000FFFFFFFF0000ull, 16, 47), 0xFFFFFFFFull); + EQUALS(bits(0xFFFFFFFFFFFFFFFFull, 0, 63), 0xFFFFFFFFFFFFFFFFull); + EQUALS(bits(0xA5A5A5A5A5A5A5A5ull, 32, 63), 0xA5A5A5A5ull); } void test_round_up() diff --git a/source/lib/tests/test_fnv_hash.h b/source/lib/tests/test_fnv_hash.h index 4dfbfc1388..640c38ad36 100644 --- a/source/lib/tests/test_fnv_hash.h +++ b/source/lib/tests/test_fnv_hash.h @@ -23,7 +23,6 @@ #include "lib/self_test.h" #include "lib/fnv_hash.h" -#include "lib/types.h" class TestFnvHash : public CxxTest::TestSuite { @@ -36,7 +35,7 @@ public: TS_ASSERT_EQUALS(fnv_hash("abcdef", 6), h1); // same result if hashing buffer TS_ASSERT_EQUALS(fnv_hash64(""), 0xCBF29CE484222325ull); // verify initial value - const u64 h2 = fnv_hash64("abcdef"); + const std::uint64_t h2 = fnv_hash64("abcdef"); TS_ASSERT_EQUALS(h2, 0xD80BDA3FBE244A0Aull); // verify value for simple string TS_ASSERT_EQUALS(fnv_hash64("abcdef", 6), h2); // same result if hashing buffer } diff --git a/source/lib/tex/tex_dds.cpp b/source/lib/tex/tex_dds.cpp index 9bc47cd3cd..fafd1876c0 100644 --- a/source/lib/tex/tex_dds.cpp +++ b/source/lib/tex/tex_dds.cpp @@ -40,7 +40,6 @@ #include "lib/status.h" #include "lib/tex/tex.h" #include "lib/tex/tex_internal.h" -#include "lib/types.h" #include #include @@ -224,7 +223,7 @@ private: std::uint8_t dxt5_a_tbl[8]; // alpha block; interpretation depends on dxt. - u64 a_bits; + std::uint64_t a_bits; // table of 2-bit color selectors std::uint32_t c_selectors; diff --git a/source/lib/types.h b/source/lib/types.h index cabfd8cb15..fa53333cf4 100644 --- a/source/lib/types.h +++ b/source/lib/types.h @@ -29,8 +29,6 @@ #include -typedef uint64_t u64; - typedef unsigned int uint; #endif // #ifndef INCLUDED_TYPES diff --git a/source/maths/Fixed.cpp b/source/maths/Fixed.cpp index 8f19729c48..bda0933878 100644 --- a/source/maths/Fixed.cpp +++ b/source/maths/Fixed.cpp @@ -74,7 +74,7 @@ CFixed_15_16 CFixed_15_16::FromString(const CStr8& s) } } // too many digits or invalid character or end of string - add the fractional part and stop - r += CFixed_15_16(((u64)frac << 16) / div); + r += CFixed_15_16((static_cast(frac) << 16) / div); break; } else @@ -120,18 +120,18 @@ CStr8 CFixed_15_16::ToString() const div *= 10; // Low estimate of d such that ((frac+d)<<16)/div == fraction - std::uint32_t digit = (((u64)fraction*div) >> 16) - frac; + std::uint32_t digit = ((static_cast(fraction) * div) >> 16) - frac; frac += digit; // If this gives the exact target, then add the digit and stop - if (((u64)frac << 16) / div == fraction) + if ((static_cast(frac) << 16) / div == fraction) { builder.Append(digit); break; } // If the next higher digit gives the exact target, then add that digit and stop - if (digit <= 8 && (((u64)frac+1) << 16) / div == fraction) + if (digit <= 8 && ((static_cast(frac) + 1) << 16) / div == fraction) { builder.Append(digit+1); break; diff --git a/source/maths/Fixed.h b/source/maths/Fixed.h index de031cdd59..3fd2cb3a43 100644 --- a/source/maths/Fixed.h +++ b/source/maths/Fixed.h @@ -20,7 +20,6 @@ #include "lib/debug.h" #include "lib/sysdep/compiler.h" -#include "lib/types.h" #include "maths/Sqrt.h" #include @@ -41,12 +40,13 @@ class CStrW; #define MUL_I64_I32_I32(a, b)\ (__emul((a), (b))) #define SQUARE_U64_FIXED(a)\ - static_cast(__emul((a).GetInternalValue(), (a).GetInternalValue())) + static_cast(__emul((a).GetInternalValue(), (a).GetInternalValue())) #else #define MUL_I64_I32_I32(a, b)\ static_cast(a) * static_cast(b) #define SQUARE_U64_FIXED(a)\ - static_cast(static_cast((a).GetInternalValue()) * static_cast((a).GetInternalValue())) + static_cast(static_cast((a).GetInternalValue()) * \ + static_cast((a).GetInternalValue())) #endif //define overflow macros @@ -359,7 +359,7 @@ public: { if (value <= 0) return CFixed(0); - std::uint32_t s = isqrt64((u64)value << fract_bits); + std::uint32_t s = isqrt64(static_cast(value) << fract_bits); return CFixed(s); } diff --git a/source/maths/FixedVector2D.h b/source/maths/FixedVector2D.h index 2c5bda9fba..7aaec8bc55 100644 --- a/source/maths/FixedVector2D.h +++ b/source/maths/FixedVector2D.h @@ -18,7 +18,6 @@ #ifndef INCLUDED_FIXED_VECTOR2D #define INCLUDED_FIXED_VECTOR2D -#include "lib/types.h" #include "maths/Fixed.h" #include "maths/Sqrt.h" @@ -102,9 +101,9 @@ public: fixed Length() const { // Do intermediate calculations with 64-bit ints to avoid overflows - u64 xx = SQUARE_U64_FIXED(X); - u64 yy = SQUARE_U64_FIXED(Y); - u64 d2 = xx + yy; + std::uint64_t xx = SQUARE_U64_FIXED(X); + std::uint64_t yy = SQUARE_U64_FIXED(Y); + std::uint64_t d2 = xx + yy; CheckUnsignedAdditionOverflow(d2, xx, L"Overflow in CFixedVector2D::Length() part 1") std::uint32_t d = isqrt64(d2); @@ -122,8 +121,8 @@ public: */ int CompareLength(fixed cmp) const { - u64 d2 = SQUARE_U64_FIXED(X) + SQUARE_U64_FIXED(Y); // d2 <= 2^63 (no overflow) - u64 cmpSquared = SQUARE_U64_FIXED(cmp); + std::uint64_t d2 = SQUARE_U64_FIXED(X) + SQUARE_U64_FIXED(Y); // d2 <= 2^63 (no overflow) + std::uint64_t cmpSquared = SQUARE_U64_FIXED(cmp); if (d2 < cmpSquared) return -1; @@ -138,9 +137,9 @@ public: * Same as above, but avoids squaring the compared value. * The argument must be the result of an SQUARE_U64_FIXED operation. */ - int CompareLengthSquared(u64 cmpSquared) const + int CompareLengthSquared(std::uint64_t cmpSquared) const { - u64 d2 = SQUARE_U64_FIXED(X) + SQUARE_U64_FIXED(Y); // d2 <= 2^63 (no overflow) + std::uint64_t d2 = SQUARE_U64_FIXED(X) + SQUARE_U64_FIXED(Y); // d2 <= 2^63 (no overflow) if (d2 < cmpSquared) return -1; @@ -158,8 +157,8 @@ public: */ int CompareLength(const CFixedVector2D& other) const { - u64 d2 = SQUARE_U64_FIXED(X) + SQUARE_U64_FIXED(Y); - u64 od2 = SQUARE_U64_FIXED(other.X) + SQUARE_U64_FIXED(other.Y); + std::uint64_t d2 = SQUARE_U64_FIXED(X) + SQUARE_U64_FIXED(Y); + std::uint64_t od2 = SQUARE_U64_FIXED(other.X) + SQUARE_U64_FIXED(other.Y); if (d2 < od2) return -1; diff --git a/source/maths/FixedVector3D.h b/source/maths/FixedVector3D.h index 9a86b2b7f0..94f4ddef98 100644 --- a/source/maths/FixedVector3D.h +++ b/source/maths/FixedVector3D.h @@ -18,7 +18,6 @@ #ifndef INCLUDED_FIXED_VECTOR3D #define INCLUDED_FIXED_VECTOR3D -#include "lib/types.h" #include "maths/Fixed.h" #include "maths/Sqrt.h" @@ -83,13 +82,13 @@ public: fixed Length() const { // Do intermediate calculations with 64-bit ints to avoid overflows - u64 xx = SQUARE_U64_FIXED(X); - u64 yy = SQUARE_U64_FIXED(Y); - u64 zz = SQUARE_U64_FIXED(Z); - u64 t = xx + yy; + std::uint64_t xx = SQUARE_U64_FIXED(X); + std::uint64_t yy = SQUARE_U64_FIXED(Y); + std::uint64_t zz = SQUARE_U64_FIXED(Z); + std::uint64_t t = xx + yy; CheckUnsignedAdditionOverflow(t, xx, L"Overflow in CFixedVector3D::Length() part 1") - u64 d2 = t + zz; + std::uint64_t d2 = t + zz; CheckUnsignedAdditionOverflow(d2, t, L"Overflow in CFixedVector3D::Length() part 2") std::uint32_t d = isqrt64(d2); diff --git a/source/maths/MD5.cpp b/source/maths/MD5.cpp index 5e8537313b..4855ca62a1 100644 --- a/source/maths/MD5.cpp +++ b/source/maths/MD5.cpp @@ -75,7 +75,7 @@ void MD5::UpdateRest(const std::uint8_t* data, size_t len) void MD5::Final(std::uint8_t* digest) { // Compute the message length in bits (before padding) - u64 len = m_InputLen * 8; + std::uint64_t len = m_InputLen * 8; // Pad with 1-bit const std::uint8_t pad = 0x80; diff --git a/source/maths/MD5.h b/source/maths/MD5.h index 8da13d9eb1..2cc9a99302 100644 --- a/source/maths/MD5.h +++ b/source/maths/MD5.h @@ -19,7 +19,6 @@ #define INCLUDED_MD5 #include "lib/code_annotation.h" -#include "lib/types.h" #include @@ -69,7 +68,7 @@ private: std::uint32_t m_Digest[4]; // internal state std::uint8_t m_Buf[64]; // buffered input bytes size_t m_BufLen; // bytes in m_Buf that are valid - u64 m_InputLen; // bytes + std::uint64_t m_InputLen; // bytes }; #endif // INCLUDED_MD5 diff --git a/source/maths/Sqrt.cpp b/source/maths/Sqrt.cpp index 2493fd8cca..587cc82c7b 100644 --- a/source/maths/Sqrt.cpp +++ b/source/maths/Sqrt.cpp @@ -20,11 +20,11 @@ #include "Sqrt.h" // Based on http://freaknet.org/martin/tape/gos/misc/personal/msc/sqrt/sqrt.html -std::uint32_t isqrt64(u64 n) +std::uint32_t isqrt64(std::uint64_t n) { - u64 op = n; - u64 res = 0; - u64 one = (u64)1 << 62; // highest power of four <= than the argument + std::uint64_t op = n; + std::uint64_t res = 0; + std::uint64_t one = static_cast(1) << 62; // highest power of four <= than the argument while (one > op) one >>= 2; diff --git a/source/maths/Sqrt.h b/source/maths/Sqrt.h index 14efc4a59c..bb71573ec4 100644 --- a/source/maths/Sqrt.h +++ b/source/maths/Sqrt.h @@ -18,12 +18,10 @@ #ifndef INCLUDED_MATH_SQRT #define INCLUDED_MATH_SQRT -#include "lib/types.h" - /** * 64-bit integer square root. - * Returns r such that r^2 <= n < (r+1)^2, for the complete u64 range. + * Returns r such that r^2 <= n < (r+1)^2, for the complete std::uint64_t range. */ -std::uint32_t isqrt64(u64 n); +std::uint32_t isqrt64(std::uint64_t n); #endif // INCLUDED_MATH_SQRT diff --git a/source/maths/tests/test_Sqrt.h b/source/maths/tests/test_Sqrt.h index f3d7ea670c..fdfd67501f 100644 --- a/source/maths/tests/test_Sqrt.h +++ b/source/maths/tests/test_Sqrt.h @@ -17,7 +17,6 @@ #include "lib/self_test.h" -#include "lib/types.h" #include "maths/Sqrt.h" #include @@ -29,12 +28,12 @@ class TestSqrt : public CxxTest::TestSuite public: void t(std::uint32_t n) { - TS_ASSERT_EQUALS(isqrt64((u64)n*(u64)n), n); + TS_ASSERT_EQUALS(isqrt64(static_cast(n) * static_cast(n)), n); } - void s(u64 n, u64 exp) + void s(std::uint64_t n, std::uint64_t exp) { - TS_ASSERT_EQUALS((u64)isqrt64(n), exp); + TS_ASSERT_EQUALS(static_cast(isqrt64(n)), exp); } void test_sqrt() @@ -68,21 +67,21 @@ public: s(999999, 999); s(1000000, 1000); s(1000001, 1000); - s((u64)-1, 4294967295u); + s(static_cast(-1), 4294967295u); } void test_random() { - // Test with some random u64s, to make sure the output agrees with floor(sqrt(double)) + // Test with some random std::uint64_ts, to make sure the output agrees with floor(sqrt(double)) // (TODO: This might be making non-portable assumptions about sqrt(double)) std::mt19937 rng; - std::uniform_int_distribution ints(0, (u64)-1); + std::uniform_int_distribution ints(0, static_cast(-1)); for (size_t i = 0; i < 1024; ++i) { - u64 n = ints(rng); - s(n, static_cast(sqrt(static_cast(n)))); + std::uint64_t n = ints(rng); + s(n, static_cast(sqrt(static_cast(n)))); } } }; diff --git a/source/ps/CacheLoader.cpp b/source/ps/CacheLoader.cpp index c27fd80f61..b507868f03 100644 --- a/source/ps/CacheLoader.cpp +++ b/source/ps/CacheLoader.cpp @@ -129,8 +129,8 @@ VfsPath CCacheLoader::LooseCachePath(const VfsPath& sourcePath, const MD5& initi return VfsPath(); } - u64 mtime = (u64)fileInfo.MTime() & ~1; // skip lowest bit, since zip and FAT don't preserve it - u64 size = (u64)fileInfo.Size(); + std::uint64_t mtime = static_cast(fileInfo.MTime()) & ~1; // skip lowest bit, since zip and FAT don't preserve it + std::uint64_t size = static_cast(fileInfo.Size()); // Construct a hash of the file data and settings. diff --git a/source/ps/ModIo.cpp b/source/ps/ModIo.cpp index 49f1ccfb3a..701d66784c 100644 --- a/source/ps/ModIo.cpp +++ b/source/ps/ModIo.cpp @@ -559,10 +559,12 @@ bool ModIo::VerifyDownloadedFile(std::string& err) // Verify filesize, as a first basic download check. { std::error_code ec{}; - const u64 fileSize{static_cast(std::filesystem::file_size(std::filesystem::path(m_DownloadFilePath.string()), ec))}; + const std::uint64_t fileSize{static_cast(std::filesystem::file_size( + std::filesystem::path(m_DownloadFilePath.string()), ec))}; if (ec) LOGERROR("Failed to get filesize for '%s', reason: %s", m_DownloadFilePath.string8().c_str(), ec.message()); - const u64 expectedFileSize{std::stoull(m_ModData[m_DownloadModID].properties.at("filesize"))}; + const std::uint64_t expectedFileSize{std::stoull( + m_ModData[m_DownloadModID].properties.at("filesize"))}; if (ec || fileSize != expectedFileSize) { diff --git a/source/ps/VisualReplay.cpp b/source/ps/VisualReplay.cpp index d6a2cdbbfb..e3a0a71554 100644 --- a/source/ps/VisualReplay.cpp +++ b/source/ps/VisualReplay.cpp @@ -26,7 +26,6 @@ #include "lib/posix/posix_types.h" #include "lib/status.h" #include "lib/sysdep/filesystem.h" -#include "lib/types.h" #include "network/NetClient.h" #include "network/NetServer.h" #include "ps/CLogger.h" @@ -138,7 +137,7 @@ JS::HandleObject VisualReplay::ReloadReplayCache(const Script::Interface& script Script::Request rq(scriptInterface); // Maps the filename onto the index, mtime and size - using replayCacheMap = std::map>; + using replayCacheMap = std::map>; replayCacheMap fileList; @@ -196,8 +195,11 @@ JS::HandleObject VisualReplay::ReloadReplayCache(const Script::Interface& script continue; CFileInfo fileInfo; GetFileInfo(replayFile, &fileInfo); - if ((u64)fileInfo.MTime() == std::get<1>(it->second) && (off_t)fileInfo.Size() == std::get<2>(it->second)) + if (static_cast(fileInfo.MTime()) == std::get<1>(it->second) && + (off_t)fileInfo.Size() == std::get<2>(it->second)) + { isNew = false; + } } else isNew = false; diff --git a/source/scriptinterface/tests/test_ScriptInterface.h b/source/scriptinterface/tests/test_ScriptInterface.h index a4d55de4d9..de6fbf4d5a 100644 --- a/source/scriptinterface/tests/test_ScriptInterface.h +++ b/source/scriptinterface/tests/test_ScriptInterface.h @@ -18,7 +18,6 @@ #include "lib/self_test.h" #include "lib/path.h" -#include "lib/types.h" #include "ps/CLogger.h" #include "scriptinterface/FunctionWrapper.h" #include "scriptinterface/JSON.h" @@ -247,11 +246,11 @@ public: boost::rand48 rng; script.ReplaceNondeterministicRNG(rng); - rng.seed((u64)0); + rng.seed(static_cast(0)); TS_ASSERT(script.Eval("Math.random()", d1)); TS_ASSERT(script.Eval("Math.random()", d2)); TS_ASSERT_DIFFERS(d1, d2); - rng.seed((u64)0); + rng.seed(static_cast(0)); TS_ASSERT(script.Eval("Math.random()", d2)); TS_ASSERT_EQUALS(d1, d2); } diff --git a/source/simulation2/components/CCmpRangeManager.cpp b/source/simulation2/components/CCmpRangeManager.cpp index 00b508d75c..f43de80b00 100644 --- a/source/simulation2/components/CCmpRangeManager.cpp +++ b/source/simulation2/components/CCmpRangeManager.cpp @@ -24,7 +24,6 @@ #include "graphics/Overlay.h" #include "lib/debug.h" #include "lib/posix/posix_types.h" -#include "lib/types.h" #include "maths/Fixed.h" #include "maths/FixedVector2D.h" #include "maths/FixedVector3D.h" @@ -210,8 +209,8 @@ struct Query */ static bool InParabolicRange(CFixedVector3D v, fixed range) { - u64 xx = SQUARE_U64_FIXED(v.X); // xx <= 2^62 - u64 zz = SQUARE_U64_FIXED(v.Z); + std::uint64_t xx = SQUARE_U64_FIXED(v.X); // xx <= 2^62 + std::uint64_t zz = SQUARE_U64_FIXED(v.Z); std::int64_t d2 = (xx + zz) >> 1; // d2 <= 2^62 (no overflow) std::int32_t y = v.Y.GetInternalValue(); @@ -1547,7 +1546,7 @@ public: return r; // angle = 0 goes in the positive Z direction - u64 precisionSquared = SQUARE_U64_FIXED(PARABOLIC_RANGE_TOLERANCE); + std::uint64_t precisionSquared = SQUARE_U64_FIXED(PARABOLIC_RANGE_TOLERANCE); CmpPtr cmpWaterManager(GetSystemEntity()); entity_pos_t waterLevel = cmpWaterManager ? cmpWaterManager->GetWaterLevel(pos.X, pos.Z) : entity_pos_t::Zero();