2024-07-30 11:42:36 +00:00
|
|
|
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team
|
|
|
|
// SPDX-License-Identifier: GPL-3.0+
|
2009-07-29 14:00:00 +00:00
|
|
|
|
2021-09-01 20:31:46 +00:00
|
|
|
#pragma once
|
2009-03-13 07:27:52 +00:00
|
|
|
|
2009-07-29 14:00:00 +00:00
|
|
|
#include "Pcsx2Types.h"
|
2024-03-21 06:43:50 +00:00
|
|
|
|
|
|
|
#include <bit>
|
2022-10-12 13:57:53 +00:00
|
|
|
#include <cstddef>
|
2009-07-29 14:00:00 +00:00
|
|
|
|
2010-08-09 04:10:38 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
2009-07-29 14:00:00 +00:00
|
|
|
// Dev / Debug conditionals - Consts for using if() statements instead of uglier #ifdef.
|
2010-08-09 04:10:38 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
2016-11-12 15:28:37 +00:00
|
|
|
#ifdef PCSX2_DEVBUILD
|
2023-12-22 10:41:59 +00:00
|
|
|
static constexpr bool IsDevBuild = true;
|
2016-11-12 15:28:37 +00:00
|
|
|
#else
|
2023-12-22 10:41:59 +00:00
|
|
|
static constexpr bool IsDevBuild = false;
|
2016-11-12 15:28:37 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef PCSX2_DEBUG
|
2023-12-22 10:41:59 +00:00
|
|
|
static constexpr bool IsDebugBuild = true;
|
2016-11-12 15:28:37 +00:00
|
|
|
#else
|
2023-12-22 10:41:59 +00:00
|
|
|
static constexpr bool IsDebugBuild = false;
|
2010-07-02 15:32:03 +00:00
|
|
|
#endif
|
2009-12-14 12:18:55 +00:00
|
|
|
|
2024-03-21 06:43:50 +00:00
|
|
|
// Defines the memory page size for the target platform at compilation.
|
|
|
|
#if defined(OVERRIDE_HOST_PAGE_SIZE)
|
|
|
|
static constexpr unsigned int __pagesize = OVERRIDE_HOST_PAGE_SIZE;
|
|
|
|
static constexpr unsigned int __pagemask = __pagesize - 1;
|
|
|
|
static constexpr unsigned int __pageshift = std::bit_width(__pagemask);
|
|
|
|
#elif defined(_M_ARM64)
|
|
|
|
// Apple Silicon uses 16KB pages and 128 byte cache lines.
|
|
|
|
static constexpr unsigned int __pagesize = 0x4000;
|
|
|
|
static constexpr unsigned int __pageshift = 14;
|
|
|
|
static constexpr unsigned int __pagemask = __pagesize - 1;
|
|
|
|
#else
|
|
|
|
// X86 uses a 4KB granularity and 64 byte cache lines.
|
|
|
|
static constexpr unsigned int __pagesize = 0x1000;
|
|
|
|
static constexpr unsigned int __pageshift = 12;
|
|
|
|
static constexpr unsigned int __pagemask = __pagesize - 1;
|
|
|
|
#endif
|
|
|
|
#if defined(OVERRIDE_HOST_CACHE_LINE_SIZE)
|
|
|
|
static constexpr unsigned int __cachelinesize = OVERRIDE_HOST_CACHE_LINE_SIZE;
|
|
|
|
#elif defined(_M_ARM64)
|
|
|
|
static constexpr unsigned int __cachelinesize = 128;
|
|
|
|
#else
|
|
|
|
static constexpr unsigned int __cachelinesize = 64;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// We use 4KB alignment for globals for both Apple and x86 platforms, since computing the
|
|
|
|
// address on ARM64 is a single instruction (adrp).
|
|
|
|
static constexpr unsigned int __pagealignsize = 0x1000;
|
2009-11-02 07:00:59 +00:00
|
|
|
|
2009-11-07 14:13:07 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
2010-04-25 00:31:27 +00:00
|
|
|
// Microsoft Visual Studio
|
2009-11-07 14:13:07 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
2009-03-13 07:27:52 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
|
2023-12-22 11:57:49 +00:00
|
|
|
#define __forceinline_odr __forceinline
|
2023-12-22 10:41:59 +00:00
|
|
|
#define __noinline __declspec(noinline)
|
|
|
|
#define __noreturn __declspec(noreturn)
|
|
|
|
|
|
|
|
#define RESTRICT __restrict
|
|
|
|
#define ASSUME(x) __assume(x)
|
2009-05-27 13:10:43 +00:00
|
|
|
|
2009-03-13 07:27:52 +00:00
|
|
|
#else
|
|
|
|
|
2009-11-07 14:13:07 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
2023-12-22 10:41:59 +00:00
|
|
|
// GCC / Clang Compilers Section
|
2009-11-07 14:13:07 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
2009-05-19 13:25:09 +00:00
|
|
|
|
2023-12-22 10:41:59 +00:00
|
|
|
// 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 >_<)
|
2022-05-12 12:34:42 +00:00
|
|
|
|
2023-12-22 11:57:49 +00:00
|
|
|
// __forceinline_odr is for member functions that are defined in headers. MSVC can't specify
|
|
|
|
// inline and __forceinline at the same time, but it required to not get ODR errors in GCC.
|
|
|
|
|
2023-12-22 10:41:59 +00:00
|
|
|
#define __forceinline __attribute__((always_inline, unused))
|
2023-12-22 11:57:49 +00:00
|
|
|
#define __forceinline_odr __forceinline inline
|
2023-12-22 10:41:59 +00:00
|
|
|
#define __noinline __attribute__((noinline))
|
|
|
|
#define __noreturn __attribute__((noreturn))
|
2021-08-29 20:49:55 +00:00
|
|
|
|
2023-12-22 10:41:59 +00:00
|
|
|
#define RESTRICT __restrict__
|
|
|
|
|
|
|
|
#define ASSUME(x) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
if (!(x)) \
|
|
|
|
__builtin_unreachable(); \
|
|
|
|
} while (0)
|
2021-08-29 20:49:55 +00:00
|
|
|
|
2009-03-13 07:27:52 +00:00
|
|
|
#endif
|
|
|
|
|
2010-08-09 04:10:38 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// __releaseinline / __ri -- a forceinline macro that is enabled for RELEASE/PUBLIC builds ONLY.
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// This is useful because forceinline can make certain types of debugging problematic since
|
|
|
|
// functions that look like they should be called won't breakpoint since their code is
|
|
|
|
// inlined, and it can make stack traces confusing or near useless.
|
|
|
|
//
|
|
|
|
// Use __releaseinline for things which are generally large functions where trace debugging
|
|
|
|
// from Devel builds is likely useful; but which should be inlined in an optimized Release
|
|
|
|
// environment.
|
|
|
|
//
|
2023-12-22 09:41:44 +00:00
|
|
|
#define __fi __forceinline
|
2010-08-09 04:10:38 +00:00
|
|
|
#ifdef PCSX2_DEVBUILD
|
2023-12-22 10:41:59 +00:00
|
|
|
#define __ri
|
2010-08-09 04:10:38 +00:00
|
|
|
#else
|
2023-12-22 10:41:59 +00:00
|
|
|
#define __ri __fi
|
2023-12-22 10:30:31 +00:00
|
|
|
#endif
|
|
|
|
|
2022-05-18 13:27:23 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Safe deallocation macros -- checks pointer validity (non-null) when needed, and sets
|
|
|
|
// pointer to null after deallocation.
|
|
|
|
|
2023-12-22 10:41:59 +00:00
|
|
|
#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)
|
2022-05-18 13:27:23 +00:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// DeclareNoncopyableObject
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// This macro provides an easy and clean method for ensuring objects are not copyable.
|
|
|
|
// Simply add the macro to the head or tail of your class declaration, and attempts to
|
2022-12-25 12:31:46 +00:00
|
|
|
// copy the class will give you a moderately obtuse compiler error.
|
2022-05-18 13:27:23 +00:00
|
|
|
//
|
|
|
|
#ifndef DeclareNoncopyableObject
|
|
|
|
#define DeclareNoncopyableObject(classname) \
|
|
|
|
public: \
|
|
|
|
classname(const classname&) = delete; \
|
|
|
|
classname& operator=(const classname&) = delete
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// Handy Human-readable constants for common immediate values (_16kb -> _4gb)
|
|
|
|
|
|
|
|
static constexpr sptr _1kb = 1024 * 1;
|
|
|
|
static constexpr sptr _4kb = _1kb * 4;
|
|
|
|
static constexpr sptr _16kb = _1kb * 16;
|
|
|
|
static constexpr sptr _32kb = _1kb * 32;
|
|
|
|
static constexpr sptr _64kb = _1kb * 64;
|
|
|
|
static constexpr sptr _128kb = _1kb * 128;
|
|
|
|
static constexpr sptr _256kb = _1kb * 256;
|
|
|
|
|
|
|
|
static constexpr s64 _1mb = 1024 * 1024;
|
|
|
|
static constexpr s64 _8mb = _1mb * 8;
|
|
|
|
static constexpr s64 _16mb = _1mb * 16;
|
|
|
|
static constexpr s64 _32mb = _1mb * 32;
|
|
|
|
static constexpr s64 _64mb = _1mb * 64;
|
|
|
|
static constexpr s64 _256mb = _1mb * 256;
|
|
|
|
static constexpr s64 _1gb = _1mb * 1024;
|
|
|
|
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
|
2023-12-22 10:41:59 +00:00
|
|
|
#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
|
2022-05-18 13:27:23 +00:00
|
|
|
#endif
|