2009-09-12 10:09:59 +00:00
|
|
|
/* PCSX2 - PS2 Emulator for PCs
|
2010-05-03 14:08:02 +00:00
|
|
|
* Copyright (C) 2002-2010 PCSX2 Dev Team
|
2009-10-04 09:00:07 +00:00
|
|
|
*
|
2009-09-12 10:09:59 +00:00
|
|
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
2009-03-13 07:27:52 +00:00
|
|
|
*
|
2009-09-12 10:09:59 +00:00
|
|
|
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
2009-07-29 14:00:00 +00:00
|
|
|
*
|
2009-09-12 10:09:59 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
2009-03-13 07:27:52 +00:00
|
|
|
*/
|
2009-07-29 14:00:00 +00:00
|
|
|
|
2009-03-13 07:27:52 +00:00
|
|
|
#ifndef __PCSX2DEFS_H__
|
|
|
|
#define __PCSX2DEFS_H__
|
|
|
|
|
2009-12-25 18:58:25 +00:00
|
|
|
// Indicate that this is the wx port to the plugins.
|
|
|
|
#define WX_PCSX2
|
|
|
|
|
2014-08-03 18:11:22 +00:00
|
|
|
#ifdef __CYGWIN__
|
|
|
|
#define __linux__
|
2009-03-13 07:27:52 +00:00
|
|
|
#endif
|
|
|
|
|
2015-11-17 17:35:02 +00:00
|
|
|
// make sure __POSIX__ is defined for all systems where we assume POSIX
|
|
|
|
// compliance
|
|
|
|
#if defined(__linux__) || defined(__APPLE__) || defined(__unix__) || defined(__CYGWIN__) || defined(__LINUX__)
|
2016-11-12 15:28:37 +00:00
|
|
|
#if !defined(__POSIX__)
|
|
|
|
#define __POSIX__ 1
|
|
|
|
#endif
|
2015-11-17 17:35:02 +00:00
|
|
|
#endif
|
|
|
|
|
2009-07-29 14:00:00 +00:00
|
|
|
#include "Pcsx2Types.h"
|
|
|
|
|
2016-07-16 14:40:29 +00:00
|
|
|
#include "x86emitter/x86_intrin.h"
|
2009-06-18 08:20:19 +00:00
|
|
|
|
2009-03-13 07:27:52 +00:00
|
|
|
// Renamed ARRAYSIZE to ArraySize -- looks nice and gets rid of Windows.h conflicts (air)
|
2009-05-04 14:12:21 +00:00
|
|
|
// Notes: I'd have used ARRAY_SIZE instead but ran into cross-platform lib conflicts with
|
|
|
|
// that as well. >_<
|
2009-03-13 07:27:52 +00:00
|
|
|
#ifndef ArraySize
|
2016-11-12 15:28:37 +00:00
|
|
|
#define ArraySize(x) (sizeof(x) / sizeof((x)[0]))
|
2009-07-29 14:00:00 +00:00
|
|
|
#endif
|
|
|
|
|
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
|
|
|
// --------------------------------------------------------------------------------------
|
2009-07-29 14:00:00 +00:00
|
|
|
// 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 __cplusplus
|
2016-11-12 15:28:37 +00:00
|
|
|
#ifdef PCSX2_DEVBUILD
|
|
|
|
static const bool IsDevBuild = true;
|
|
|
|
#else
|
|
|
|
static const bool IsDevBuild = false;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef PCSX2_DEBUG
|
|
|
|
static const bool IsDebugBuild = true;
|
|
|
|
#else
|
|
|
|
static const bool IsDebugBuild = false;
|
|
|
|
#endif
|
2009-07-29 14:00:00 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
#ifdef PCSX2_DEVBUILD
|
|
|
|
static const u8 IsDevBuild = 1;
|
|
|
|
#else
|
|
|
|
static const u8 IsDevBuild = 0;
|
|
|
|
#endif
|
2009-07-29 14:00:00 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
#ifdef PCSX2_DEBUG
|
|
|
|
static const u8 IsDebugBuild = 1;
|
|
|
|
#else
|
|
|
|
static const u8 IsDebugBuild = 0;
|
|
|
|
#endif
|
2009-07-29 14:00:00 +00:00
|
|
|
#endif
|
|
|
|
|
2009-12-14 12:18:55 +00:00
|
|
|
#ifdef PCSX2_DEBUG
|
2016-11-12 15:28:37 +00:00
|
|
|
#define pxDebugCode(code) code
|
2009-12-14 12:18:55 +00:00
|
|
|
#else
|
2016-11-12 15:28:37 +00:00
|
|
|
#define pxDebugCode(code)
|
2009-12-14 12:18:55 +00:00
|
|
|
#endif
|
|
|
|
|
2010-07-02 15:32:03 +00:00
|
|
|
#ifdef PCSX2_DEVBUILD
|
2016-11-12 15:28:37 +00:00
|
|
|
#define pxDevelCode(code) code
|
2010-07-02 15:32:03 +00:00
|
|
|
#else
|
2016-11-12 15:28:37 +00:00
|
|
|
#define pxDevelCode(code)
|
2010-07-02 15:32:03 +00:00
|
|
|
#endif
|
|
|
|
|
2015-10-06 23:49:13 +00:00
|
|
|
#if defined(PCSX2_DEBUG) || defined(PCSX2_DEVBUILD)
|
2016-11-12 15:28:37 +00:00
|
|
|
#define pxReleaseCode(code)
|
|
|
|
#define pxNonReleaseCode(code) code
|
2010-07-02 15:32:03 +00:00
|
|
|
#else
|
2016-11-12 15:28:37 +00:00
|
|
|
#define pxReleaseCode(code) code
|
|
|
|
#define pxNonReleaseCode(code)
|
2010-07-02 15:32:03 +00:00
|
|
|
#endif
|
2009-12-14 12:18:55 +00:00
|
|
|
|
2010-08-09 04:10:38 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
2009-10-05 02:15:49 +00:00
|
|
|
// __aligned / __aligned16 / __pagealigned
|
2010-08-09 04:10:38 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
2009-07-29 14:00:00 +00:00
|
|
|
// GCC Warning! The GCC linker (LD) typically fails to assure alignment of class members.
|
|
|
|
// If you want alignment to be assured, the variable must either be a member of a struct
|
|
|
|
// or a static global.
|
|
|
|
//
|
2009-10-05 02:15:49 +00:00
|
|
|
// __pagealigned is equivalent to __aligned(0x1000), and is used to align a dynarec code
|
|
|
|
// buffer to a page boundary (allows the use of execution-enabled mprotect).
|
|
|
|
//
|
2009-07-29 14:00:00 +00:00
|
|
|
// General Performance Warning: Any function that specifies alignment on a local (stack)
|
|
|
|
// variable will have to align the stack frame on enter, and restore it on exit (adds
|
|
|
|
// overhead). Furthermore, compilers cannot inline functions that have aligned local
|
|
|
|
// vars. So use local var alignment with much caution.
|
|
|
|
//
|
2009-11-02 07:00:59 +00:00
|
|
|
|
|
|
|
// Defines the memory page size for the target platform at compilation. All supported platforms
|
|
|
|
// (which means Intel only right now) have a 4k granularity.
|
2016-11-12 15:28:37 +00:00
|
|
|
#define PCSX2_PAGESIZE 0x1000
|
|
|
|
static const int __pagesize = PCSX2_PAGESIZE;
|
2009-11-02 07:00:59 +00:00
|
|
|
|
2010-08-09 04:10:38 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
2009-11-07 14:13:07 +00:00
|
|
|
// Structure Packing (__packed)
|
2010-08-09 04:10:38 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
2009-11-07 14:13:07 +00:00
|
|
|
// Current Method:
|
|
|
|
// Use a combination of embedded compiler-specific #pragma mess in conjunction with a
|
|
|
|
// __packed macro. The former appeases the MSVC gods, the latter appeases the GCC gods.
|
|
|
|
// The end result looks something like this:
|
|
|
|
//
|
|
|
|
// #ifdef _MSC_VER
|
|
|
|
// # pragma pack(1)
|
|
|
|
// #endif
|
|
|
|
//
|
|
|
|
// struct SomeKindaFail {
|
|
|
|
// u8 neat;
|
|
|
|
// u32 unaligned32;
|
|
|
|
// } __packed;
|
|
|
|
//
|
|
|
|
// MSVC 2008 and better support __pragma, however there's no way to support that in
|
|
|
|
// a way that's backwards compatible to VS 2005, without still including the old-style
|
|
|
|
// #pragma mess. So there's really not much point (yet) in using it. I've included macros
|
|
|
|
// that utilize __pragma (commented out below) which can be deployed at a time when we
|
|
|
|
// are ok with the idea of completely breaking backwards compat with VC2005/prior.
|
|
|
|
//
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
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
|
|
|
|
|
2009-11-07 14:13:07 +00:00
|
|
|
// Using these breaks compat with VC2005; so we're not using it yet.
|
|
|
|
//# define __pack_begin __pragma(pack(1))
|
|
|
|
//# define __pack_end __pragma(pack())
|
|
|
|
|
|
|
|
// This is the 2005/earlier compatible packing define, which must be used in conjunction
|
|
|
|
// with #ifdef _MSC_VER/#pragma pack() directives (ugly).
|
2016-11-12 15:28:37 +00:00
|
|
|
#define __packed
|
2009-11-07 14:13:07 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
#define __aligned(alig) __declspec(align(alig))
|
|
|
|
#define __aligned16 __declspec(align(16))
|
|
|
|
#define __aligned32 __declspec(align(32))
|
|
|
|
#define __pagealigned __declspec(align(PCSX2_PAGESIZE))
|
2009-10-05 02:15:49 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
// Deprecated; use __align instead.
|
|
|
|
#define PCSX2_ALIGNED(alig, x) __declspec(align(alig)) x
|
|
|
|
#define PCSX2_ALIGNED_EXTERN(alig, x) extern __declspec(align(alig)) x
|
|
|
|
#define PCSX2_ALIGNED16(x) __declspec(align(16)) x
|
|
|
|
#define PCSX2_ALIGNED16_EXTERN(x) extern __declspec(align(16)) x
|
2009-03-13 07:27:52 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
#define __noinline __declspec(noinline)
|
2009-05-27 13:10:43 +00:00
|
|
|
|
2009-07-29 14:00:00 +00:00
|
|
|
// Don't know if there are Visual C++ equivalents of these.
|
2016-11-12 15:28:37 +00:00
|
|
|
#define likely(x) (!!(x))
|
|
|
|
#define unlikely(x) (!!(x))
|
2009-05-27 13:10:43 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
#define CALLBACK __stdcall
|
2009-03-13 07:27:52 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2009-11-07 14:13:07 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// GCC / Intel Compilers Section
|
|
|
|
// --------------------------------------------------------------------------------------
|
2009-05-19 13:25:09 +00:00
|
|
|
|
2016-05-01 09:27:11 +00:00
|
|
|
#ifndef __packed
|
2016-11-12 15:28:37 +00:00
|
|
|
#define __packed __attribute__((packed))
|
2016-05-01 09:27:11 +00:00
|
|
|
#endif
|
|
|
|
#ifndef __aligned
|
2016-11-12 15:28:37 +00:00
|
|
|
#define __aligned(alig) __attribute__((aligned(alig)))
|
2016-05-01 09:27:11 +00:00
|
|
|
#endif
|
2016-11-12 15:28:37 +00:00
|
|
|
#define __aligned16 __attribute__((aligned(16)))
|
|
|
|
#define __aligned32 __attribute__((aligned(32)))
|
|
|
|
#define __pagealigned __attribute__((aligned(PCSX2_PAGESIZE)))
|
|
|
|
// Deprecated; use __align instead.
|
|
|
|
#define PCSX2_ALIGNED(alig, x) x __attribute((aligned(alig)))
|
|
|
|
#define PCSX2_ALIGNED16(x) x __attribute((aligned(16)))
|
|
|
|
#define PCSX2_ALIGNED_EXTERN(alig, x) extern x __attribute((aligned(alig)))
|
|
|
|
#define PCSX2_ALIGNED16_EXTERN(x) extern x __attribute((aligned(16)))
|
|
|
|
|
|
|
|
#define __assume(cond) ((void)0) // GCC has no equivalent for __assume
|
|
|
|
#define CALLBACK __attribute__((stdcall))
|
2009-03-13 07:27:52 +00:00
|
|
|
|
2009-09-22 17:28:48 +00:00
|
|
|
// 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 >_<)
|
|
|
|
|
2016-05-01 09:27:11 +00:00
|
|
|
#ifndef __fastcall
|
2016-11-12 15:28:37 +00:00
|
|
|
#define __fastcall __attribute__((fastcall))
|
|
|
|
#endif
|
|
|
|
#define _inline __inline__ __attribute__((unused))
|
|
|
|
#ifdef NDEBUG
|
|
|
|
#define __forceinline __attribute__((always_inline, unused))
|
|
|
|
#else
|
|
|
|
#define __forceinline __attribute__((unused))
|
|
|
|
#endif
|
2016-05-01 09:27:11 +00:00
|
|
|
#ifndef __noinline
|
2016-11-12 15:28:37 +00:00
|
|
|
#define __noinline __attribute__((noinline))
|
2016-05-01 09:27:11 +00:00
|
|
|
#endif
|
2016-11-12 15:28:37 +00:00
|
|
|
#define likely(x) __builtin_expect(!!(x), 1)
|
|
|
|
#define unlikely(x) __builtin_expect(!!(x), 0)
|
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.
|
|
|
|
//
|
|
|
|
#ifdef PCSX2_DEVBUILD
|
2016-11-12 15:28:37 +00:00
|
|
|
#define __releaseinline
|
2010-08-09 04:10:38 +00:00
|
|
|
#else
|
2016-11-12 15:28:37 +00:00
|
|
|
#define __releaseinline __forceinline
|
2009-05-19 13:25:09 +00:00
|
|
|
#endif
|
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
#define __ri __releaseinline
|
|
|
|
#define __fi __forceinline
|
|
|
|
#define __fc __fastcall
|
2009-11-07 15:46:09 +00:00
|
|
|
|
2009-07-29 14:00:00 +00:00
|
|
|
#endif
|
2019-06-17 00:33:17 +00:00
|
|
|
|
|
|
|
#if defined(__x86_64__) || defined(_M_AMD64)
|
|
|
|
#define __M_X86_64
|
|
|
|
#endif
|