Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #120 from Sonicadvance1/Arch-clean
Make our architecture defines less stupid.
  • Loading branch information
Parlane committed Mar 4, 2014
2 parents d1ccd96 + 4f02132 commit 09212d4
Show file tree
Hide file tree
Showing 60 changed files with 368 additions and 349 deletions.
54 changes: 41 additions & 13 deletions CMakeLists.txt
Expand Up @@ -115,25 +115,53 @@ if(DOLPHIN_IS_STABLE)
else()
set(DOLPHIN_VERSION_PATCH ${DOLPHIN_WC_REVISION})
endif()

# Architecture detection and arch specific settings
message(${CMAKE_SYSTEM_PROCESSOR})
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm")
set(_M_GENERIC 1)

# Detect 64bit or 32bit
# CMake doesn't provide a simple way to determine 32bit or 64bit
# If we ever support a architecture that is 64bit with 32bit pointers then this'll break
# Of course the chances of that are slim(x32?) so who cares
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_ARCH_64 1)
add_definitions(-D_ARCH_64=1)
else()
set(_ARCH_32 1)
add_definitions(-D_ARCH_32=1)
endif()

if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^x86")
add_definitions(-msse2)
set(_M_X86 1)
add_definitions(-D_M_X86=1)
if(_ARCH_64)
set(_M_X86_64 1)
add_definitions(-D_M_X86_64=1)
else()
set(_M_X86_32 1)
add_definitions(-D_M_X86_32=1)
endif()
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm")
# This option only applies to 32bit ARM
set(_M_ARM 1)
set(_M_ARM_32 1)
add_definitions(-D_M_ARM=1 -D_M_ARM_32=1)
set(_M_GENERIC 1)
add_definitions(-D_M_GENERIC=1)
if(${ANDROID_NDK_ABI_NAME} MATCHES "armeabi-v7a")
add_definitions(-marm -march=armv7-a)
endif()
endif()

if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "mips")
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
# This option only applies to 64bit ARM
set(_M_ARM 1)
set(_M_ARM_64 1)
add_definitions(-D_M_ARM=1 -D_M_ARM_64=1)
set(_M_GENERIC 1)
endif()

# Set these next two lines to test generic
#set(_M_GENERIC 1)
#add_definitions(-D_M_GENERIC=1)
# Various compile flags
if(NOT _M_GENERIC)
add_definitions(-msse2)
add_definitions(-D_M_GENERIC=1)
else()
set(_M_GENERIC 1)
add_definitions(-D_M_GENERIC=1)
endif()

include(CheckCXXCompilerFlag)
Expand Down
15 changes: 7 additions & 8 deletions Source/Core/Common/CMakeLists.txt
Expand Up @@ -27,15 +27,14 @@ set(SRCS BreakPoints.cpp
Crypto/bn.cpp
Crypto/ec.cpp)

if(_M_ARM) #ARM
set(SRCS ${SRCS}
ArmCPUDetect.cpp
ArmEmitter.cpp)
if(_M_ARM_32) #ARMv7
set(SRCS ${SRCS}
ArmCPUDetect.cpp
ArmEmitter.cpp)
else()
if(NOT _M_GENERIC) #X86
set(SRCS ${SRCS}
x64FPURoundMode.cpp
)
if(_M_X86) #X86
set(SRCS ${SRCS}
x64FPURoundMode.cpp)
endif()
set(SRCS ${SRCS} x64CPUDetect.cpp)
endif()
Expand Down
30 changes: 15 additions & 15 deletions Source/Core/Common/Common.h
Expand Up @@ -101,25 +101,25 @@ class NonCopyable

#endif

// Architecture detection for Windows
// Architecture detection is done in cmake on all other platforms
// Windows is built on only x86/x86_64
#if _WIN32 || _WIN64
#define _M_X86 1
#if _WIN64
#define _ARCH_64 1
#define _M_X86_64 1
#else
#define _ARCH_32 1
#define _M_X86_32 1
#endif
#endif

// Windows compatibility
#define _M_64BIT defined(_LP64) || defined(_WIN64)
#ifndef _WIN32
#include <limits.h>
#define MAX_PATH PATH_MAX
#ifdef __x86_64__
#define _M_X64 1
#endif
#ifdef __i386__
#define _M_IX86 1
#endif
#ifdef __arm__
#define _M_ARM 1
#define _M_GENERIC 1
#endif
#ifdef __mips__
#define _M_MIPS 1
#define _M_GENERIC 1
#endif

#define __forceinline inline __attribute__((always_inline))
#define GC_ALIGNED16(x) __attribute__((aligned(16))) x
#define GC_ALIGNED32(x) __attribute__((aligned(32))) x
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Common/CommonFuncs.h
Expand Up @@ -148,7 +148,7 @@ inline u64 _rotr64(u64 x, unsigned int shift){
#define fstat64 _fstat64
#define fileno _fileno

#if _M_IX86
#if _M_X86_32
#define Crash() {__asm int 3}
#else
extern "C" {
Expand Down Expand Up @@ -188,7 +188,7 @@ inline u32 swap24(const u8* _data) {return (_data[0] << 16) | (_data[1] << 8) |
inline u16 swap16(u16 _data) {return _byteswap_ushort(_data);}
inline u32 swap32(u32 _data) {return _byteswap_ulong (_data);}
inline u64 swap64(u64 _data) {return _byteswap_uint64(_data);}
#elif _M_ARM
#elif _M_ARM_32
inline u16 swap16 (u16 _data) { u32 data = _data; __asm__ ("rev16 %0, %1\n" : "=l" (data) : "l" (data)); return (u16)data;}
inline u32 swap32 (u32 _data) {__asm__ ("rev %0, %1\n" : "=l" (_data) : "l" (_data)); return _data;}
inline u64 swap64(u64 _data) {return ((u64)swap32(_data) << 32) | swap32(_data >> 32);}
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Common/ExtendedTrace.cpp
Expand Up @@ -152,7 +152,7 @@ static BOOL GetFunctionInfoFromAddresses( ULONG fnAddress, ULONG stackAddress, L
_tcscpy( lpszSymbol, _T("?") );

// Get symbol info for IP
#ifndef _M_X64
#if _M_X86_32
DWORD dwDisp = 0;
if ( SymGetSymFromAddr( GetCurrentProcess(), (ULONG)fnAddress, &dwDisp, pSym ) )
#else
Expand Down Expand Up @@ -313,7 +313,7 @@ void StackTrace( HANDLE hThread, const char* lpszMessage, FILE *file )
}

::ZeroMemory( &callStack, sizeof(callStack) );
#ifndef _M_X64
#if _M_X86_32
callStack.AddrPC.Offset = context.Eip;
callStack.AddrStack.Offset = context.Esp;
callStack.AddrFrame.Offset = context.Ebp;
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Common/Hash.cpp
Expand Up @@ -99,7 +99,7 @@ u32 HashEctor(const u8* ptr, int length)
}


#ifdef _M_X64
#if _ARCH_64

//-----------------------------------------------------------------------------
// Block read - if your platform needs to do endian-swapping or can only
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Common/MathUtil.h
Expand Up @@ -155,7 +155,7 @@ inline int Log2(u64 val)
#if defined(__GNUC__)
return 63 - __builtin_clzll(val);

#elif defined(_MSC_VER) && defined(_M_X64)
#elif defined(_MSC_VER) && _ARCH_64
unsigned long result = -1;
_BitScanReverse64(&result, val);
return result;
Expand Down
6 changes: 3 additions & 3 deletions Source/Core/Common/MemArena.cpp
Expand Up @@ -129,7 +129,7 @@ void MemArena::ReleaseView(void* view, size_t size)

u8* MemArena::Find4GBBase()
{
#ifdef _M_X64
#if _ARCH_64
#ifdef _WIN32
// 64 bit
u8* base = (u8*)VirtualAlloc(0, 0xE1000000, MEM_RESERVE, PAGE_READWRITE);
Expand Down Expand Up @@ -206,7 +206,7 @@ static bool Memory_TryBase(u8 *base, const MemoryView *views, int num_views, u32
if (!*views[i].out_ptr_low)
goto bail;
}
#ifdef _M_X64
#if _ARCH_64
*views[i].out_ptr = (u8*)arena->CreateView(
position, views[i].size, base + views[i].virtual_address);
#else
Expand Down Expand Up @@ -247,7 +247,7 @@ u8 *MemoryMap_Setup(const MemoryView *views, int num_views, u32 flags, MemArena
arena->GrabLowMemSpace(total_mem);

// Now, create views in high memory where there's plenty of space.
#ifdef _M_X64
#if _ARCH_64
u8 *base = MemArena::Find4GBBase();
// This really shouldn't fail - in 64-bit, there will always be enough
// address space.
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Common/MemoryUtil.cpp
Expand Up @@ -75,7 +75,7 @@ void* AllocateExecutableMemory(size_t size, bool low)
}
#endif

#if defined(_M_X64)
#if _ARCH_64
if ((u64)ptr >= 0x80000000 && low == true)
PanicAlert("Executable memory ended up above 2GB!");
#endif
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Common/StdConditionVariable.h
Expand Up @@ -40,7 +40,7 @@
#define USE_RVALUE_REFERENCES
#endif

#if defined(_WIN32) && defined(_M_X64)
#if defined(_WIN32) && _M_X86_64
#define USE_CONDITION_VARIABLES
#elif defined(_WIN32)
#define USE_EVENTS
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Common/StdMutex.h
Expand Up @@ -44,7 +44,7 @@
#define USE_RVALUE_REFERENCES
#endif

#if defined(_WIN32) && defined(_M_X64)
#if defined(_WIN32) && _M_X86_64
#define USE_SRWLOCKS
#endif

Expand Down
14 changes: 8 additions & 6 deletions Source/Core/Common/Version.cpp
Expand Up @@ -24,14 +24,16 @@ const char *scm_rev_str = "Dolphin "
BUILD_TYPE_STR SCM_DESC_STR;
#endif

#ifdef _M_X64
#if _M_X86_64
#define NP_ARCH "x64"
#else
#ifdef _M_ARM
#define NP_ARCH "ARM"
#else
#elif _M_ARM_32
#define NP_ARCH "ARM32"
#elif _M_ARM_64
#define NP_ARCH "ARM64"
#elif _M_X86_32
#define NP_ARCH "x86"
#endif
#else
#define NP_ARCH "Unk"
#endif

#ifdef _WIN32
Expand Down
16 changes: 8 additions & 8 deletions Source/Core/Common/x64ABI.cpp
Expand Up @@ -20,7 +20,7 @@ unsigned int XEmitter::ABI_GetAlignedFrameSize(unsigned int frameSize, bool noPr
// for Win64) into this rather than having a separate prolog.
// On Windows 32-bit, the required alignment is only 4 bytes, so we just
// ensure that the frame size isn't misaligned.
#ifdef _M_X64
#if _M_X86_64
// expect frameSize == 0
frameSize = noProlog ? 0x28 : 0;
#elif defined(_WIN32)
Expand All @@ -38,7 +38,7 @@ void XEmitter::ABI_AlignStack(unsigned int frameSize, bool noProlog) {
unsigned int fillSize =
ABI_GetAlignedFrameSize(frameSize, noProlog) - frameSize;
if (fillSize != 0) {
#ifdef _M_X64
#if _M_X86_64
SUB(64, R(RSP), Imm8(fillSize));
#else
SUB(32, R(ESP), Imm8(fillSize));
Expand All @@ -49,7 +49,7 @@ void XEmitter::ABI_AlignStack(unsigned int frameSize, bool noProlog) {
void XEmitter::ABI_RestoreStack(unsigned int frameSize, bool noProlog) {
unsigned int alignedSize = ABI_GetAlignedFrameSize(frameSize, noProlog);
if (alignedSize != 0) {
#ifdef _M_X64
#if _M_X86_64
ADD(64, R(RSP), Imm8(alignedSize));
#else
ADD(32, R(ESP), Imm8(alignedSize));
Expand All @@ -60,13 +60,13 @@ void XEmitter::ABI_RestoreStack(unsigned int frameSize, bool noProlog) {
void XEmitter::ABI_PushRegistersAndAdjustStack(u32 mask, bool noProlog)
{
int regSize =
#ifdef _M_X64
#if _M_X86_64
8;
#else
4;
#endif
int shadow = 0;
#if defined(_WIN32) && defined(_M_X64)
#if defined(_WIN32) && _M_X86_64
shadow = 0x20;
#endif
int count = 0;
Expand Down Expand Up @@ -101,13 +101,13 @@ void XEmitter::ABI_PushRegistersAndAdjustStack(u32 mask, bool noProlog)
void XEmitter::ABI_PopRegistersAndAdjustStack(u32 mask, bool noProlog)
{
int regSize =
#ifdef _M_X64
#if _M_X86_64
8;
#else
4;
#endif
int size = 0;
#if defined(_WIN32) && defined(_M_X64)
#if defined(_WIN32) && _M_X86_64
size += 0x20;
#endif
for (int x = 0; x < 16; x++)
Expand Down Expand Up @@ -137,7 +137,7 @@ void XEmitter::ABI_PopRegistersAndAdjustStack(u32 mask, bool noProlog)
}
}

#ifdef _M_IX86 // All32
#if _M_X86_32 // All32

// Shared code between Win32 and Unix32
void XEmitter::ABI_CallFunction(void *func) {
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Common/x64ABI.h
Expand Up @@ -31,7 +31,7 @@
// Callee-save: RBX RBP R12 R13 R14 R15
// Parameters: RDI RSI RDX RCX R8 R9

#ifdef _M_IX86 // 32 bit calling convention, shared by all
#if _M_X86_32 // 32 bit calling convention, shared by all

// 32-bit don't pass parameters in regs, but these are convenient to have anyway when we have to
// choose regs to put stuff in.
Expand Down
10 changes: 5 additions & 5 deletions Source/Core/Common/x64CPUDetect.cpp
Expand Up @@ -98,16 +98,16 @@ CPUInfo::CPUInfo() {
void CPUInfo::Detect()
{
memset(this, 0, sizeof(*this));
#ifdef _M_IX86
#if _M_X86_32
Mode64bit = false;
#elif defined (_M_X64)
#elif _M_X86_64
Mode64bit = true;
OS64bit = true;
#endif
num_cores = 1;

#ifdef _WIN32
#ifdef _M_IX86
#if _M_X86_32
BOOL f64 = false;
IsWow64Process(GetCurrentProcess(), &f64);
OS64bit = (f64 == TRUE) ? true : false;
Expand Down Expand Up @@ -170,9 +170,9 @@ void CPUInfo::Detect()
GC_ALIGNED16(u8 fx_state[512]);
memset(fx_state, 0, sizeof(fx_state));
#ifdef _WIN32
#ifdef _M_IX86
#if _M_X86_32
_fxsave(fx_state);
#elif defined (_M_X64)
#elif _M_X86_64
_fxsave64(fx_state);
#endif
#else
Expand Down

0 comments on commit 09212d4

Please sign in to comment.