From 3df6cb704f680d2fcff369cbdf2fad609e8559eb Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 30 Jan 2022 15:15:38 -0800 Subject: [PATCH] Global: Fix some type conversion warnings. Hidden by some warning disables. --- Common/Arm64Emitter.cpp | 6 +++--- Common/File/FileDescriptor.cpp | 4 ++-- Common/Math/curves.cpp | 2 +- Common/Render/DrawBuffer.cpp | 2 +- Core/Core.cpp | 4 ++-- Core/FileLoaders/DiskCachingFileLoader.cpp | 4 ++-- Core/HW/Display.cpp | 16 ++++++++-------- Core/HW/SasAudio.h | 2 +- Core/MIPS/JitCommon/JitBlockCache.cpp | 8 ++++---- Core/MIPS/MIPSIntVFPU.cpp | 2 +- Core/MIPS/MIPSVFPUUtils.cpp | 2 +- Core/MIPS/MIPSVFPUUtils.h | 2 +- Core/MIPS/x86/Asm.cpp | 8 +++++--- Core/MemFault.cpp | 4 ++-- Core/Util/DisArm64.cpp | 6 +++--- android/jni/TestRunner.cpp | 2 +- headless/Headless.cpp | 4 ++-- unittest/TestX64Emitter.cpp | 2 +- 18 files changed, 41 insertions(+), 39 deletions(-) diff --git a/Common/Arm64Emitter.cpp b/Common/Arm64Emitter.cpp index ec6e0ef61c..ce047cd41d 100644 --- a/Common/Arm64Emitter.cpp +++ b/Common/Arm64Emitter.cpp @@ -53,11 +53,11 @@ bool IsPowerOfTwo(uint64_t x) { bool IsImmArithmetic(uint64_t input, u32 *val, bool *shift) { if (input < 4096) { - if (val) *val = input; + if (val) *val = (uint32_t)input; if (shift) *shift = false; return true; } else if ((input & 0xFFF000) == input) { - if (val) *val = input >> 12; + if (val) *val = (uint32_t)(input >> 12); if (shift) *shift = true; return true; } @@ -1963,7 +1963,7 @@ void ARM64XEmitter::MOVI2R(ARM64Reg Rd, u64 imm, bool optimize) // TODO: Make some more systemic use of MOVN, but this will take care of most cases. // Small negative integer. Use MOVN if (!Is64Bit(Rd) && (imm | 0xFFFF0000) == imm) { - MOVN(Rd, ~imm, SHIFT_0); + MOVN(Rd, (u32)(~imm), SHIFT_0); return; } diff --git a/Common/File/FileDescriptor.cpp b/Common/File/FileDescriptor.cpp index 139e394c41..480bdf31b8 100644 --- a/Common/File/FileDescriptor.cpp +++ b/Common/File/FileDescriptor.cpp @@ -83,8 +83,8 @@ size_t Write(int fd, const std::string &str) { bool WaitUntilReady(int fd, double timeout, bool for_write) { struct timeval tv; - tv.tv_sec = floor(timeout); - tv.tv_usec = (timeout - floor(timeout)) * 1000000.0; + tv.tv_sec = (long)floor(timeout); + tv.tv_usec = (long)((timeout - floor(timeout)) * 1000000.0); fd_set fds; FD_ZERO(&fds); diff --git a/Common/Math/curves.cpp b/Common/Math/curves.cpp index 2488ba5c30..099327c6c1 100644 --- a/Common/Math/curves.cpp +++ b/Common/Math/curves.cpp @@ -37,7 +37,7 @@ float linearOut(int t, int fadeOutLength) { float ease(float val) { if (val > 1.0f) return 1.0f; if (val < 0.0f) return 0.0f; - return ((-cosf(val * PI)) + 1.0f) * 0.5; + return (float)(((-cosf(val * PI)) + 1.0f) * 0.5); } float ease(int t, int fadeLength) diff --git a/Common/Render/DrawBuffer.cpp b/Common/Render/DrawBuffer.cpp index 92ee2d057d..1881fcddb6 100644 --- a/Common/Render/DrawBuffer.cpp +++ b/Common/Render/DrawBuffer.cpp @@ -148,7 +148,7 @@ void DrawBuffer::RectOutline(float x, float y, float w, float h, uint32_t color, void DrawBuffer::MultiVGradient(float x, float y, float w, float h, GradientStop *stops, int numStops) { for (int i = 0; i < numStops - 1; i++) { float t0 = stops[i].t, t1 = stops[i+1].t; - uint32_t c0 = stops[i].t, c1 = stops[i+1].t; + uint32_t c0 = stops[i].color, c1 = stops[i+1].color; RectVGradient(x, y + h * t0, w, h * (t1 - t0), c0, c1); } } diff --git a/Core/Core.cpp b/Core/Core.cpp index 56e113b75c..5fb5357352 100644 --- a/Core/Core.cpp +++ b/Core/Core.cpp @@ -188,8 +188,8 @@ bool UpdateScreenScale(int width, int height) { pixel_in_dps_x = 1.0f / g_dpi_scale_x; pixel_in_dps_y = 1.0f / g_dpi_scale_y; - int new_dp_xres = width * g_dpi_scale_x; - int new_dp_yres = height * g_dpi_scale_y; + int new_dp_xres = (int)(width * g_dpi_scale_x); + int new_dp_yres = (int)(height * g_dpi_scale_y); bool dp_changed = new_dp_xres != dp_xres || new_dp_yres != dp_yres; bool px_changed = pixel_xres != width || pixel_yres != height; diff --git a/Core/FileLoaders/DiskCachingFileLoader.cpp b/Core/FileLoaders/DiskCachingFileLoader.cpp index 73ba1ca868..ac3fdbd694 100644 --- a/Core/FileLoaders/DiskCachingFileLoader.cpp +++ b/Core/FileLoaders/DiskCachingFileLoader.cpp @@ -780,12 +780,12 @@ u32 DiskCachingFileLoaderCache::DetermineMaxBlocks() { } // This might be smaller than what's free, but if they try to launch a second game, // they'll be happier when it can be cached too. - return freeBlocksWithFlex; + return (u32)freeBlocksWithFlex; } // Might be lower than LOWER_BOUND, but that's okay. That means not enough space. // We abandon the idea of flex since there's not enough space free anyway. - return freeBlocks; + return (u32)freeBlocks; } u32 DiskCachingFileLoaderCache::CountCachedFiles() { diff --git a/Core/HW/Display.cpp b/Core/HW/Display.cpp index 1335593cd4..cf28654074 100644 --- a/Core/HW/Display.cpp +++ b/Core/HW/Display.cpp @@ -75,10 +75,10 @@ static void CalculateFPS() { if (now >= lastFpsTime + 1.0) { double frames = (numVBlanks - lastFpsFrame); - actualFps = (actualFlips - lastActualFlips); + actualFps = (float)(actualFlips - lastActualFlips); fps = frames / (now - lastFpsTime); - flips = 60.0 * (double)(gpuStats.numFlips - lastNumFlips) / frames; + flips = (float)(60.0 * (double)(gpuStats.numFlips - lastNumFlips) / frames); lastFpsFrame = numVBlanks; lastNumFlips = gpuStats.numFlips; @@ -105,17 +105,17 @@ static void CalculateFPS() { // TODO: Also average actualFps void __DisplayGetFPS(float *out_vps, float *out_fps, float *out_actual_fps) { - *out_vps = fps; + *out_vps = (float)fps; *out_fps = flips; *out_actual_fps = actualFps; } void __DisplayGetVPS(float *out_vps) { - *out_vps = fps; + *out_vps = (float)fps; } void __DisplayGetAveragedFPS(float *out_vps, float *out_fps) { - float avg = 0.0; + double avg = 0.0; if (fpsHistoryValid > 0) { for (int i = 0; i < fpsHistoryValid; ++i) { avg += fpsHistory[i]; @@ -123,7 +123,7 @@ void __DisplayGetAveragedFPS(float *out_vps, float *out_fps) { avg /= (double)fpsHistoryValid; } - *out_vps = *out_fps = avg; + *out_vps = *out_fps = (float)avg; } int __DisplayGetFlipCount() { @@ -147,7 +147,7 @@ uint64_t DisplayFrameStartTicks() { } uint32_t __DisplayGetCurrentHcount() { - const int ticksIntoFrame = CoreTiming::GetTicks() - frameStartTicks; + const int ticksIntoFrame = (int)(CoreTiming::GetTicks() - frameStartTicks); const int ticksPerVblank = CoreTiming::GetClockFrequencyHz() / 60 / hCountPerVblank; // Can't seem to produce a 0 on real hardware, offsetting by 1 makes things look right. return 1 + (ticksIntoFrame / ticksPerVblank); @@ -279,7 +279,7 @@ int DisplayCalculateFrameSkip() { int frameSkipNum; if (g_Config.iFrameSkipType == 1) { // Calculate the frames to skip dynamically using the set percentage of the current fps - frameSkipNum = ceil(flips * (static_cast(g_Config.iFrameSkip) / 100.00)); + frameSkipNum = (int)ceil(flips * (static_cast(g_Config.iFrameSkip) / 100.00)); } else { // Use the set number of frames to skip frameSkipNum = g_Config.iFrameSkip; diff --git a/Core/HW/SasAudio.h b/Core/HW/SasAudio.h index de883afa36..9a2deca577 100644 --- a/Core/HW/SasAudio.h +++ b/Core/HW/SasAudio.h @@ -161,7 +161,7 @@ public: inline void Step(); int GetHeight() const { - return height_ > (s64)PSP_SAS_ENVELOPE_HEIGHT_MAX ? PSP_SAS_ENVELOPE_HEIGHT_MAX : height_; + return (int)(height_ > (s64)PSP_SAS_ENVELOPE_HEIGHT_MAX ? PSP_SAS_ENVELOPE_HEIGHT_MAX : height_); } bool NeedsKeyOn() const { return state_ == STATE_KEYON; diff --git a/Core/MIPS/JitCommon/JitBlockCache.cpp b/Core/MIPS/JitCommon/JitBlockCache.cpp index 7a0e3179f2..87e75c397c 100644 --- a/Core/MIPS/JitCommon/JitBlockCache.cpp +++ b/Core/MIPS/JitCommon/JitBlockCache.cpp @@ -656,12 +656,12 @@ void JitBlockCache::ComputeStats(BlockCacheStats &bcStats) const { bcStats.maxBloatBlock = b->originalAddress; } totalBloat += bloat; - bcStats.bloatMap[bloat] = b->originalAddress; + bcStats.bloatMap[(float)bloat] = b->originalAddress; } bcStats.numBlocks = num_blocks_; - bcStats.minBloat = minBloat; - bcStats.maxBloat = maxBloat; - bcStats.avgBloat = totalBloat / (double)num_blocks_; + bcStats.minBloat = (float)minBloat; + bcStats.maxBloat = (float)maxBloat; + bcStats.avgBloat = (float)(totalBloat / (double)num_blocks_); } JitBlockDebugInfo JitBlockCache::GetBlockDebugInfo(int blockNum) const { diff --git a/Core/MIPS/MIPSIntVFPU.cpp b/Core/MIPS/MIPSIntVFPU.cpp index 1266efbc68..8f761b858d 100644 --- a/Core/MIPS/MIPSIntVFPU.cpp +++ b/Core/MIPS/MIPSIntVFPU.cpp @@ -634,7 +634,7 @@ namespace MIPSInt case 20: d[i] = powf(2.0f, s[i]); break; //vexp2 case 21: d[i] = logf(s[i])/log(2.0f); break; //vlog2 case 22: d[i] = USE_VPFU_SQRT ? vfpu_sqrt(s[i]) : fabsf(sqrtf(s[i])); break; //vsqrt - case 23: d[i] = asinf(s[i]) / M_PI_2; break; //vasin + case 23: d[i] = (float)(asinf(s[i]) / M_PI_2); break; //vasin case 24: d[i] = -1.0f / s[i]; break; // vnrcp case 26: { d[i] = -vfpu_sin(s[i]); } break; // vnsin case 28: d[i] = 1.0f / powf(2.0, s[i]); break; // vrexp2 diff --git a/Core/MIPS/MIPSVFPUUtils.cpp b/Core/MIPS/MIPSVFPUUtils.cpp index ab058bd935..0f1d6688ab 100644 --- a/Core/MIPS/MIPSVFPUUtils.cpp +++ b/Core/MIPS/MIPSVFPUUtils.cpp @@ -832,7 +832,7 @@ static inline uint32_t mant_mul(uint32_t a, uint32_t b) { if (m & 0x007FFFFF) { m += 0x01437000; } - return m >> 23; + return (uint32_t)(m >> 23); } float vfpu_rsqrt(float a) { diff --git a/Core/MIPS/MIPSVFPUUtils.h b/Core/MIPS/MIPSVFPUUtils.h index 8200e8c87d..df1a1b85b0 100644 --- a/Core/MIPS/MIPSVFPUUtils.h +++ b/Core/MIPS/MIPSVFPUUtils.h @@ -55,7 +55,7 @@ extern float vfpu_cos(float); extern void vfpu_sincos(float, float&, float&); inline float vfpu_asin(float angle) { - return asinf(angle) / M_PI_2; + return (float)(asinf(angle) / M_PI_2); } inline float vfpu_clamp(float v, float min, float max) { diff --git a/Core/MIPS/x86/Asm.cpp b/Core/MIPS/x86/Asm.cpp index 03ce2ab7f1..fef6f0487c 100644 --- a/Core/MIPS/x86/Asm.cpp +++ b/Core/MIPS/x86/Asm.cpp @@ -181,10 +181,12 @@ void Jit::GenerateFixedCode(JitOptions &jo) { #if PPSSPP_ARCH(X86) ADD(32, R(EAX), ImmPtr(GetBasePtr())); #elif PPSSPP_ARCH(AMD64) - if (jo.reserveR15ForAsm) + if (jo.reserveR15ForAsm) { ADD(64, R(RAX), R(JITBASEREG)); - else - ADD(64, R(EAX), Imm32(jitbase)); + } else { + // See above, reserveR15ForAsm is used when above 0x7FFFFFFF. + ADD(64, R(EAX), Imm32((u32)jitbase)); + } #endif JMPptr(R(EAX)); SetJumpTarget(notfound); diff --git a/Core/MemFault.cpp b/Core/MemFault.cpp index e7c58c5705..a55dda88f1 100644 --- a/Core/MemFault.cpp +++ b/Core/MemFault.cpp @@ -118,7 +118,7 @@ bool HandleFault(uintptr_t hostAddress, void *ctx) { // OK, a guest executable did a bad access. Take care of it. - uint32_t guestAddress = hostAddress - baseAddress; + uint32_t guestAddress = (uint32_t)(hostAddress - baseAddress); // TODO: Share the struct between the various analyzers, that will allow us to share most of // the implementations here. @@ -173,7 +173,7 @@ bool HandleFault(uintptr_t hostAddress, void *ctx) { // TODO: Do the other archs and platforms. #if PPSSPP_ARCH(AMD64) && PPSSPP_PLATFORM(WINDOWS) // We know which register the address is in, look in Asm.cpp. - targetAddr = context->Rax; + targetAddr = (uint32_t)context->Rax; #endif Core_ExecException(targetAddr, currentMIPS->pc, ExecExceptionType::JUMP); // Redirect execution to a crash handler that will switch to CoreState::CORE_RUNTIME_ERROR immediately. diff --git a/Core/Util/DisArm64.cpp b/Core/Util/DisArm64.cpp index b03fc0d111..eac1edaed5 100644 --- a/Core/Util/DisArm64.cpp +++ b/Core/Util/DisArm64.cpp @@ -120,14 +120,14 @@ void DecodeBitMasks(int immN, int imms, int immr, uint64_t *tmask, uint64_t *wma // if len < 1 then ReservedValue(); // assert M >= (1 << len); // Determine S, R and S - R parameters - int levels = Ones(len); + int levels = (int)Ones(len); uint32_t S = imms & levels; uint32_t R = immr & levels; int diff = S - R; // 6-bit subtract with borrow int esize = 1 << len; int d = diff & Ones(len - 1); - uint32_t welem = Ones(S + 1); - uint32_t telem = Ones(d + 1); + uint32_t welem = (uint32_t)Ones(S + 1); + uint32_t telem = (uint32_t)Ones(d + 1); if (wmask) { uint64_t rotated = ROR(welem, R, esize); *wmask = Replicate(rotated, esize); diff --git a/android/jni/TestRunner.cpp b/android/jni/TestRunner.cpp index 6e9c3b792b..d032a9db75 100644 --- a/android/jni/TestRunner.cpp +++ b/android/jni/TestRunner.cpp @@ -129,7 +129,7 @@ bool RunTests() { // Run the emu until the test exits INFO_LOG(SYSTEM, "Test: Entering runloop."); while (true) { - int blockTicks = usToCycles(1000000 / 10); + int blockTicks = (int)usToCycles(1000000 / 10); while (coreState == CORE_RUNNING) { PSP_RunLoopFor(blockTicks); } diff --git a/headless/Headless.cpp b/headless/Headless.cpp index 22beaa129a..c33609db3d 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -202,7 +202,7 @@ bool RunAutoTest(HeadlessHost *headlessHost, CoreParameter &coreParameter, bool coreState = coreParameter.startBreak ? CORE_STEPPING : CORE_RUNNING; while (coreState == CORE_RUNNING || coreState == CORE_STEPPING) { - int blockTicks = usToCycles(1000000 / 10); + int blockTicks = (int)usToCycles(1000000 / 10); PSP_RunLoopFor(blockTicks); // If we were rendering, this might be a nice time to do something about it. @@ -319,7 +319,7 @@ int main(int argc, const char* argv[]) } else if (!strncmp(argv[i], "--screenshot=", strlen("--screenshot=")) && strlen(argv[i]) > strlen("--screenshot=")) screenshotFilename = argv[i] + strlen("--screenshot="); else if (!strncmp(argv[i], "--timeout=", strlen("--timeout=")) && strlen(argv[i]) > strlen("--timeout=")) - timeout = strtod(argv[i] + strlen("--timeout="), NULL); + timeout = (float)strtod(argv[i] + strlen("--timeout="), NULL); else if (!strncmp(argv[i], "--debugger=", strlen("--debugger=")) && strlen(argv[i]) > strlen("--debugger=")) debuggerPort = (int)strtoul(argv[i] + strlen("--debugger="), NULL, 10); else if (!strcmp(argv[i], "--teamcity")) diff --git a/unittest/TestX64Emitter.cpp b/unittest/TestX64Emitter.cpp index 5ca64f2c1b..c92b415d12 100644 --- a/unittest/TestX64Emitter.cpp +++ b/unittest/TestX64Emitter.cpp @@ -15,7 +15,7 @@ static const u8 *prevStart = NULL; bool CheckLast(Gen::XEmitter &emit, const char *comp) { - auto vec = DisassembleX86(prevStart, emit.GetCodePointer() - prevStart); + auto vec = DisassembleX86(prevStart, (int)(emit.GetCodePointer() - prevStart)); EXPECT_EQ_STR(vec[0], std::string(comp)); return true; }