From 7de717d47ccf69b5bbf241cac12fb0f473b49773 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 2 Apr 2023 11:19:23 +0200 Subject: [PATCH] /W4: Use 'constexpr' to evaluate branch at compile time Fixes many compiler warnings. --- r5dev/common/pseudodefs.h | 2 +- r5dev/tier0/threadtools.h | 2 +- r5dev/tier1/strtools.cpp | 2 +- r5dev/tier1/utlbuffer.h | 6 +++--- r5dev/tier2/meshutils.cpp | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/r5dev/common/pseudodefs.h b/r5dev/common/pseudodefs.h index 5c6dd914..e87b162d 100644 --- a/r5dev/common/pseudodefs.h +++ b/r5dev/common/pseudodefs.h @@ -241,7 +241,7 @@ template T __ROL__(T value, int count) { count %= nbits; T high = value >> (nbits - count); - if ( T(-1) < 0 ) // signed value + if constexpr ( T(-1) < 0 ) // signed value high &= ~((T(-1) << count)); value <<= count; value |= high; diff --git a/r5dev/tier0/threadtools.h b/r5dev/tier0/threadtools.h index 248cfd90..d210c404 100644 --- a/r5dev/tier0/threadtools.h +++ b/r5dev/tier0/threadtools.h @@ -136,7 +136,7 @@ public: bool AssignIf(T conditionValue, T newValue) { - if (sizeof(T) == sizeof(int32)) + if constexpr(sizeof(T) == sizeof(int32)) return ThreadInterlockedAssignIf((LONG*)&m_value, (int32)newValue, (int32)conditionValue); else return ThreadInterlockedAssignIf64((int64*)&m_value, (int64)newValue, (int64)conditionValue); diff --git a/r5dev/tier1/strtools.cpp b/r5dev/tier1/strtools.cpp index a9866565..db01113f 100644 --- a/r5dev/tier1/strtools.cpp +++ b/r5dev/tier1/strtools.cpp @@ -592,7 +592,7 @@ bool V_IsAbsolutePath(const char* pStr) bool bIsAbsolute = (pStr[0] && pStr[1] == ':') || pStr[0] == '/' || pStr[0] == '\\'; #endif - if (IsX360() && !bIsAbsolute) + if constexpr (IsX360() && !bIsAbsolute) { bIsAbsolute = (V_stristr(pStr, ":") != NULL); } diff --git a/r5dev/tier1/utlbuffer.h b/r5dev/tier1/utlbuffer.h index 917b7b3e..8b098707 100644 --- a/r5dev/tier1/utlbuffer.h +++ b/r5dev/tier1/utlbuffer.h @@ -214,7 +214,7 @@ public: FORCEINLINE void ActivateByteSwappingIfBigEndian(void) { - if ((IsX360() || IsPS3())) + if constexpr ((IsX360() || IsPS3())) ActivateByteSwapping(true); } @@ -714,7 +714,7 @@ inline void CUtlBuffer::GetTypeBin< float >(float& dest) if (CheckGet(sizeof(float))) { uintptr_t pData = (uintptr_t)PeekGet(); - if ((IsX360() || IsPS3()) && (pData & 0x03)) + if constexpr ((IsX360() || IsPS3()) && (pData & 0x03)) { // handle unaligned read ((unsigned char*)&dest)[0] = ((unsigned char*)pData)[0]; @@ -745,7 +745,7 @@ inline void CUtlBuffer::GetTypeBin< double >(double& dest) if (CheckGet(sizeof(double))) { uintptr_t pData = (uintptr_t)PeekGet(); - if ((IsX360() || IsPS3()) && (pData & 0x07)) + if constexpr ((IsX360() || IsPS3()) && (pData & 0x07)) { // handle unaligned read ((unsigned char*)&dest)[0] = ((unsigned char*)pData)[0]; diff --git a/r5dev/tier2/meshutils.cpp b/r5dev/tier2/meshutils.cpp index ae5b0ea8..bc01ecfb 100644 --- a/r5dev/tier2/meshutils.cpp +++ b/r5dev/tier2/meshutils.cpp @@ -44,7 +44,7 @@ void GenerateQuadIndexBuffer(unsigned short* pIndices, int nIndexCount, int nFir for (i = 0; i < numQuads; ++i) { // Have to deal with endian-ness - if (IsX360() || IsPS3()) + if constexpr (IsX360() || IsPS3()) { // this avoids compiler write reodering and prevents the write-combined out-of-order penalty // _WriteBarrier won't compile here, and volatile is ignored