Misc: Simplify platform/compiler macros

This commit is contained in:
Stenzek 2023-12-22 20:41:59 +10:00 committed by Connor McLaughlin
parent dc859ca0a6
commit b844bb1268
14 changed files with 92 additions and 124 deletions

View File

@ -17,9 +17,9 @@
// make sure __POSIX__ is defined for all systems where we assume POSIX compliance
#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
#ifndef __POSIX__
#define __POSIX__ 1
#endif
#ifndef __POSIX__
#define __POSIX__ 1
#endif
#endif
#include "Pcsx2Types.h"
@ -35,21 +35,16 @@
// --------------------------------------------------------------------------------------
// Dev / Debug conditionals - Consts for using if() statements instead of uglier #ifdef.
// --------------------------------------------------------------------------------------
// Note: Using if() optimizes nicely in Devel and Release builds, but will generate extra
// code overhead in debug builds (since debug neither inlines, nor optimizes out const-
// level conditionals). Normally not a concern, but if you stick if( IsDevbuild ) in
// some tight loops it will likely make debug builds unusably slow.
//
#ifdef PCSX2_DEVBUILD
static constexpr bool IsDevBuild = true;
static constexpr bool IsDevBuild = true;
#else
static constexpr bool IsDevBuild = false;
static constexpr bool IsDevBuild = false;
#endif
#ifdef PCSX2_DEBUG
static constexpr bool IsDebugBuild = true;
static constexpr bool IsDebugBuild = true;
#else
static constexpr bool IsDebugBuild = false;
static constexpr bool IsDebugBuild = false;
#endif
// Defines the memory page size for the target platform at compilation. All supported platforms
@ -63,38 +58,40 @@ static constexpr unsigned int __pagemask = __pagesize - 1;
// --------------------------------------------------------------------------------------
#ifdef _MSC_VER
#define __noinline __declspec(noinline)
#define __noreturn __declspec(noreturn)
#define __noinline __declspec(noinline)
#define __noreturn __declspec(noreturn)
#define RESTRICT __restrict
#define ASSUME(x) __assume(x)
#else
// --------------------------------------------------------------------------------------
// GCC / Intel Compilers Section
// GCC / Clang Compilers Section
// --------------------------------------------------------------------------------------
#define __assume(cond) do { if (!(cond)) __builtin_unreachable(); } while(0)
// SysV ABI passes vector parameters through registers unconditionally.
#ifndef _WIN32
#define __vectorcall
#endif
// SysV ABI passes vector parameters through registers unconditionally.
#ifndef _WIN32
#define __vectorcall
#endif
// Inlining note: GCC needs ((unused)) attributes defined on inlined functions to suppress
// warnings when a static inlined function isn't used in the scope of a single file (which
// happens *by design* like all the friggen time >_<)
// Inlining note: GCC needs ((unused)) attributes defined on inlined functions to suppress
// warnings when a static inlined function isn't used in the scope of a single file (which
// happens *by design* like all the friggen time >_<)
#define __forceinline __attribute__((always_inline, unused))
#define __noinline __attribute__((noinline))
#define __noreturn __attribute__((noreturn))
#define RESTRICT __restrict__
#define ASSUME(x) \
do \
{ \
if (!(x)) \
__builtin_unreachable(); \
} while (0)
#define _inline __inline__ __attribute__((unused))
#ifdef NDEBUG
#define __forceinline __attribute__((always_inline, unused))
#else
#define __forceinline __attribute__((unused))
#endif
#ifndef __noinline
#define __noinline __attribute__((noinline))
#endif
#ifndef __noreturn
#define __noreturn __attribute__((noreturn))
#endif
#endif
// --------------------------------------------------------------------------------------
@ -110,50 +107,18 @@ static constexpr unsigned int __pagemask = __pagesize - 1;
//
#define __fi __forceinline
#ifdef PCSX2_DEVBUILD
#define __ri
#define __ri
#else
#define __ri __fi
#endif
#ifndef RESTRICT
#if defined(_MSC_VER)
#define RESTRICT __restrict
#elif defined(__GNUC__)
#define RESTRICT __restrict__
#else
#define RESTRICT
#endif
#endif
// __assume, potentially enables optimization.
#ifdef _MSC_VER
#define ASSUME(x) __assume(x)
#else
#define ASSUME(x) \
do \
{ \
if (!(x)) \
__builtin_unreachable(); \
} while (0)
#define __ri __fi
#endif
//////////////////////////////////////////////////////////////////////////////////////////
// Safe deallocation macros -- checks pointer validity (non-null) when needed, and sets
// pointer to null after deallocation.
#define safe_delete(ptr) \
((void)(delete (ptr)), (ptr) = NULL)
#define safe_delete_array(ptr) \
((void)(delete[](ptr)), (ptr) = NULL)
// No checks for NULL.
#define safe_free(ptr) \
((void)(free(ptr), !!0), (ptr) = NULL)
//((void) (( ( (ptr) != NULL ) && (free( ptr ), !!0) ), (ptr) = NULL))
#define safe_fclose(ptr) \
((void)((((ptr) != NULL) && (fclose(ptr), !!0)), (ptr) = NULL))
#define safe_delete(ptr) (delete (ptr), (ptr) = nullptr)
#define safe_delete_array(ptr) (delete[] (ptr), (ptr) = nullptr)
#define safe_free(ptr) (std::free(ptr), (ptr) = nullptr)
// --------------------------------------------------------------------------------------
// ImplementEnumOperators (macro)
@ -257,6 +222,6 @@ static constexpr s64 _4gb = _1gb * 4;
// Disable some spammy warnings which wx appeared to disable.
// We probably should fix these at some point.
#ifdef _MSC_VER
#pragma warning(disable: 4244) // warning C4244: 'initializing': conversion from 'uptr' to 'uint', possible loss of data
#pragma warning(disable: 4267) // warning C4267: 'initializing': conversion from 'size_t' to 'uint', possible loss of data
#pragma warning(disable : 4244) // warning C4244: 'initializing': conversion from 'uptr' to 'uint', possible loss of data
#pragma warning(disable : 4267) // warning C4267: 'initializing': conversion from 'size_t' to 'uint', possible loss of data
#endif

View File

@ -319,7 +319,7 @@ public:
case 1: WriteColumn32<1, alignment, mask>(dst, src, srcpitch); break;
case 2: WriteColumn32<2, alignment, mask>(dst, src, srcpitch); break;
case 3: WriteColumn32<3, alignment, mask>(dst, src, srcpitch); break;
default: __assume(0);
default: ASSUME(0);
}
}
@ -332,7 +332,7 @@ public:
case 1: WriteColumn16<1, alignment>(dst, src, srcpitch); break;
case 2: WriteColumn16<2, alignment>(dst, src, srcpitch); break;
case 3: WriteColumn16<3, alignment>(dst, src, srcpitch); break;
default: __assume(0);
default: ASSUME(0);
}
}
@ -345,7 +345,7 @@ public:
case 1: WriteColumn8<1, alignment>(dst, src, srcpitch); break;
case 2: WriteColumn8<2, alignment>(dst, src, srcpitch); break;
case 3: WriteColumn8<3, alignment>(dst, src, srcpitch); break;
default: __assume(0);
default: ASSUME(0);
}
}
@ -358,7 +358,7 @@ public:
case 1: WriteColumn4<1, alignment>(dst, src, srcpitch); break;
case 2: WriteColumn4<2, alignment>(dst, src, srcpitch); break;
case 3: WriteColumn4<3, alignment>(dst, src, srcpitch); break;
default: __assume(0);
default: ASSUME(0);
}
}
@ -640,7 +640,7 @@ public:
case 1: ReadColumn32<1>(src, dst, dstpitch); break;
case 2: ReadColumn32<2>(src, dst, dstpitch); break;
case 3: ReadColumn32<3>(src, dst, dstpitch); break;
default: __assume(0);
default: ASSUME(0);
}
}
@ -652,7 +652,7 @@ public:
case 1: ReadColumn16<1>(src, dst, dstpitch); break;
case 2: ReadColumn16<2>(src, dst, dstpitch); break;
case 3: ReadColumn16<3>(src, dst, dstpitch); break;
default: __assume(0);
default: ASSUME(0);
}
}
@ -664,7 +664,7 @@ public:
case 1: ReadColumn8<1>(src, dst, dstpitch); break;
case 2: ReadColumn8<2>(src, dst, dstpitch); break;
case 3: ReadColumn8<3>(src, dst, dstpitch); break;
default: __assume(0);
default: ASSUME(0);
}
}
@ -676,7 +676,7 @@ public:
case 1: ReadColumn4<1>(src, dst, dstpitch); break;
case 2: ReadColumn4<2>(src, dst, dstpitch); break;
case 3: ReadColumn4<3>(src, dst, dstpitch); break;
default: __assume(0);
default: ASSUME(0);
}
}

View File

@ -202,7 +202,7 @@ bool GSClut::CanLoadCLUT(const GIFRegTEX0& TEX0, const bool update_CBP)
m_CBP[1] = TEX0.CBP;
break;
default:
__assume(0);
ASSUME(0);
}
return true;

View File

@ -235,7 +235,7 @@ void GSLocalMemoryFunctions::WriteImageColumn(GSLocalMemory& mem, int l, int r,
case PSMZ16: GSBlock::WriteColumn16<alignment>(y, mem.BlockPtr16Z(x, y, bp, bw), &src[x * 2], srcpitch); break;
case PSMZ16S: GSBlock::WriteColumn16<alignment>(y, mem.BlockPtr16SZ(x, y, bp, bw), &src[x * 2], srcpitch); break;
// TODO
default: __assume(0);
default: ASSUME(0);
}
}
}
@ -262,7 +262,7 @@ void GSLocalMemoryFunctions::WriteImageBlock(GSLocalMemory& mem, int l, int r, i
case PSMZ16: GSBlock::WriteBlock16<alignment>(mem.BlockPtr16Z(x, y, bp, bw), &src[x * 2], srcpitch); break;
case PSMZ16S: GSBlock::WriteBlock16<alignment>(mem.BlockPtr16SZ(x, y, bp, bw), &src[x * 2], srcpitch); break;
// TODO
default: __assume(0);
default: ASSUME(0);
}
}
}
@ -289,7 +289,7 @@ void GSLocalMemoryFunctions::WriteImageLeftRight(GSLocalMemory& mem, int l, int
case PSMZ16: mem.WritePixel16Z(x, y, *(u16*)&src[x * 2], bp, bw); break;
case PSMZ16S: mem.WritePixel16SZ(x, y, *(u16*)&src[x * 2], bp, bw); break;
// TODO
default: __assume(0);
default: ASSUME(0);
}
}
}
@ -328,7 +328,7 @@ void GSLocalMemoryFunctions::WriteImageTopBottom(GSLocalMemory& mem, int l, int
case PSMZ16: dst = mem.BlockPtr16Z(x, y, bp, bw); break;
case PSMZ16S: dst = mem.BlockPtr16SZ(x, y, bp, bw); break;
// TODO
default: __assume(0);
default: ASSUME(0);
}
switch (psm)
@ -361,7 +361,7 @@ void GSLocalMemoryFunctions::WriteImageTopBottom(GSLocalMemory& mem, int l, int
break;
// TODO
default:
__assume(0);
ASSUME(0);
}
}
@ -421,7 +421,7 @@ void GSLocalMemoryFunctions::WriteImageTopBottom(GSLocalMemory& mem, int l, int
case PSMZ16: dst = mem.BlockPtr16Z(x, y, bp, bw); break;
case PSMZ16S: dst = mem.BlockPtr16SZ(x, y, bp, bw); break;
// TODO
default: __assume(0);
default: ASSUME(0);
}
switch (psm)
@ -454,7 +454,7 @@ void GSLocalMemoryFunctions::WriteImageTopBottom(GSLocalMemory& mem, int l, int
break;
// TODO
default:
__assume(0);
ASSUME(0);
}
}
}

View File

@ -1219,7 +1219,7 @@ struct alignas(32) GIFPath
case 16:
break;
default:
__assume(0);
ASSUME(0);
}
}
}

View File

@ -364,7 +364,7 @@ GSVideoMode GSState::GetVideoMode()
return GSVideoMode::Unknown;
}
__assume(0); // unreachable
ASSUME(0); // unreachable
}
float GSState::GetTvRefreshRate()
@ -388,7 +388,7 @@ float GSState::GetTvRefreshRate()
return 0;
}
__assume(0); // unreachable
ASSUME(0); // unreachable
}
const char* GSState::GetFlushReasonString(GSFlushReason reason)
@ -1658,7 +1658,7 @@ void GSState::FlushPrim()
case GS_INVALID:
break;
default:
__assume(0);
ASSUME(0);
}
pxAssert((int)unused < GSUtil::GetVertexCount(PRIM->PRIM));
@ -2427,7 +2427,7 @@ void GSState::Transfer(const u8* mem, u32 size)
break;
default:
__assume(0);
ASSUME(0);
}
path.nloop = 0;
@ -2494,7 +2494,7 @@ void GSState::Transfer(const u8* mem, u32 size)
break;
}
default:
__assume(0);
ASSUME(0);
}
}
@ -3477,7 +3477,7 @@ __forceinline void GSState::VertexKick(u32 skip)
GrowVertexBuffer(); // in case too many vertices were skipped
break;
default:
__assume(0);
ASSUME(0);
}
return;
@ -3576,7 +3576,7 @@ __forceinline void GSState::VertexKick(u32 skip)
m_vertex.tail = head;
return;
default:
__assume(0);
ASSUME(0);
}
// Update rectangle for the current draw. We can use the re-integer coordinates from min/max here.
@ -3678,7 +3678,7 @@ GSState::TextureMinMaxResult GSState::GetTextureMinMax(GIFRegTEX0 TEX0, GIFRegCL
vr.z = (maxu | minu) + 1;
break;
default:
__assume(0);
ASSUME(0);
}
switch (wmt)
@ -3696,7 +3696,7 @@ GSState::TextureMinMaxResult GSState::GetTextureMinMax(GIFRegTEX0 TEX0, GIFRegCL
vr.w = (maxv | minv) + 1;
break;
default:
__assume(0);
ASSUME(0);
}
// Software renderer fixes TEX0 so that TW/TH contain MAXU/MAXV.
@ -3925,7 +3925,7 @@ void GSState::CalcAlphaMinMax(const int tex_alpha_min, const int tex_alpha_max)
m_mem.m_clut.GetAlphaMinMax32(a.y, a.w);
break;
default:
__assume(0);
ASSUME(0);
}
switch (context->TEX0.TFX)
@ -3955,7 +3955,7 @@ void GSState::CalcAlphaMinMax(const int tex_alpha_min, const int tex_alpha_max)
a.z = a.w;
break;
default:
__assume(0);
ASSUME(0);
}
}
min = a.x;
@ -3995,7 +3995,7 @@ bool GSState::TryAlphaTest(u32& fm, u32& zm)
return true;
break;
default:
__assume(0);
ASSUME(0);
}
bool pass = true;
@ -4069,7 +4069,7 @@ bool GSState::TryAlphaTest(u32& fm, u32& zm)
return false;
break;
default:
__assume(0);
ASSUME(0);
}
}
@ -4091,7 +4091,7 @@ bool GSState::TryAlphaTest(u32& fm, u32& zm)
zm = 0xffffffff;
break;
default:
__assume(0);
ASSUME(0);
}
}

View File

@ -553,7 +553,7 @@ public:
case 1: return yyyy(v).zxzw(*this);
case 2: return yyzz(v).zxzw(*this);
case 3: return yyww(v).zxzw(*this);
default: __assume(0);
default: ASSUME(0);
}
break;
case 1:
@ -563,7 +563,7 @@ public:
case 1: return xxyy(v).xzzw(*this);
case 2: return xxzz(v).xzzw(*this);
case 3: return xxww(v).xzzw(*this);
default: __assume(0);
default: ASSUME(0);
}
break;
case 2:
@ -573,7 +573,7 @@ public:
case 1: return xyzx(wwyy(v));
case 2: return xyzx(wwzz(v));
case 3: return xyzx(wwww(v));
default: __assume(0);
default: ASSUME(0);
}
break;
case 3:
@ -583,11 +583,11 @@ public:
case 1: return xyxz(zzyy(v));
case 2: return xyxz(zzzz(v));
case 3: return xyxz(zzww(v));
default: __assume(0);
default: ASSUME(0);
}
break;
default:
__assume(0);
ASSUME(0);
}
#endif

View File

@ -512,7 +512,7 @@ public:
case 1: return yyyy(v).zxzw(*this);
case 2: return yyzz(v).zxzw(*this);
case 3: return yyww(v).zxzw(*this);
default: __assume(0);
default: ASSUME(0);
}
break;
case 1:
@ -522,7 +522,7 @@ public:
case 1: return xxyy(v).xzzw(*this);
case 2: return xxzz(v).xzzw(*this);
case 3: return xxww(v).xzzw(*this);
default: __assume(0);
default: ASSUME(0);
}
break;
case 2:
@ -532,7 +532,7 @@ public:
case 1: return xyzx(wwyy(v));
case 2: return xyzx(wwzz(v));
case 3: return xyzx(wwww(v));
default: __assume(0);
default: ASSUME(0);
}
break;
case 3:
@ -542,11 +542,11 @@ public:
case 1: return xyxz(zzyy(v));
case 2: return xyxz(zzzz(v));
case 3: return xyxz(zzww(v));
default: __assume(0);
default: ASSUME(0);
}
break;
default:
__assume(0);
ASSUME(0);
}
return *this;

View File

@ -3107,7 +3107,7 @@ void GSRendererHW::SetupIA(float target_scale, float sx, float sy)
break;
default:
__assume(0);
ASSUME(0);
}
m_conf.verts = m_vertex.buff;
@ -5376,7 +5376,7 @@ __ri void GSRendererHW::DrawPrims(GSTextureCache::Target* rt, GSTextureCache::Ta
case AFAIL_FB_ONLY: z = false; break; // rgba
case AFAIL_ZB_ONLY: r = g = b = a = false; break; // z
case AFAIL_RGB_ONLY: z = a = false; break; // rgb
default: __assume(0);
default: ASSUME(0);
}
// Depth test should be disabled when depth writes are masked and similarly, Alpha test must be disabled

View File

@ -365,7 +365,7 @@ bool GSRendererHWFunctions::SwPrimRender(GSRendererHW& hw, bool invalidate_tc, b
gd.t.mask.U32[0] = 0xffffffff;
break;
default:
__assume(0);
ASSUME(0);
}
switch (context->CLAMP.WMT)
@ -393,7 +393,7 @@ bool GSRendererHWFunctions::SwPrimRender(GSRendererHW& hw, bool invalidate_tc, b
gd.t.mask.U32[2] = 0xffffffff;
break;
default:
__assume(0);
ASSUME(0);
}
gd.t.min = gd.t.min.xxxxlh();

View File

@ -395,7 +395,7 @@ __ri static bool TestAlpha(T& test, T& fm, T& zm, const T& ga, const GSScanlineG
break;
default:
__assume(0);
ASSUME(0);
}
switch (sel.afail)
@ -420,7 +420,7 @@ __ri static bool TestAlpha(T& test, T& fm, T& zm, const T& ga, const GSScanlineG
break;
default:
__assume(0);
ASSUME(0);
}
return true;

View File

@ -246,7 +246,7 @@ void GSRasterizer::Draw(GSRasterizerData& data)
break;
default:
__assume(0);
ASSUME(0);
}
#if _M_SSE >= 0x501

View File

@ -1241,7 +1241,7 @@ bool GSRendererSW::GetScanlineGlobalData(SharedData* data)
gd.t.mask.U32[0] = 0xffffffff;
break;
default:
__assume(0);
ASSUME(0);
}
switch (context->CLAMP.WMT)
@ -1270,7 +1270,7 @@ bool GSRendererSW::GetScanlineGlobalData(SharedData* data)
gd.t.mask.U32[2] = 0xffffffff;
break;
default:
__assume(0);
ASSUME(0);
}
gd.t.min = gd.t.min.xxxxlh();

View File

@ -23,6 +23,9 @@
#ifdef PCSX2_DEVBUILD
#define safe_fclose(ptr) \
((void)((((ptr) != nullptr) && (std::fclose(ptr), !!0)), (ptr) = nullptr))
static FILE* DMA4LogFile = nullptr;
static FILE* DMA7LogFile = nullptr;
static FILE* ADMA4LogFile = nullptr;