Merge pull request #487 from JeffProgrammer/mac_m1

Add support for Apple Silicon
This commit is contained in:
Brian Roberts 2021-05-11 15:17:28 -05:00 committed by GitHub
commit 6fe51cd9c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 50 additions and 10 deletions

View file

@ -135,6 +135,8 @@ void tc_spinloop()
// Pause would do nothing on the Xbox. Threads are not scheduled. // Pause would do nothing on the Xbox. Threads are not scheduled.
#elif defined( _WIN64 ) #elif defined( _WIN64 )
YieldProcessor( ); YieldProcessor( );
#elif (defined( __arm64__ ) && defined( __APPLE__ )) || defined( __arch64__ )
pthread_yield_np();
#else #else
__asm { pause }; __asm { pause };
#endif #endif

View file

@ -447,7 +447,7 @@ bool CodeBlock::read(StringTableEntry fileName, Stream &st)
{ {
U32 ip; U32 ip;
st.read(&ip); st.read(&ip);
#ifdef TORQUE_CPU_X64 #if defined(TORQUE_CPU_X64) || defined(TORQUE_CPU_ARM64)
*(U64*)(code + ip) = (U64)ste; *(U64*)(code + ip) = (U64)ste;
#else #else
code[ip] = *((U32 *)&ste); code[ip] = *((U32 *)&ste);

View file

@ -65,7 +65,7 @@ namespace Compiler
void evalSTEtoCode(StringTableEntry ste, U32 ip, U32 *ptr) void evalSTEtoCode(StringTableEntry ste, U32 ip, U32 *ptr)
{ {
#ifdef TORQUE_CPU_X64 #if defined(TORQUE_CPU_X64) || defined(TORQUE_CPU_ARM64)
*(U64*)(ptr) = (U64)ste; *(U64*)(ptr) = (U64)ste;
#else #else
*ptr = (U32)ste; *ptr = (U32)ste;

View file

@ -254,7 +254,7 @@ namespace Compiler
inline StringTableEntry CodeToSTE(U32 *code, U32 ip) inline StringTableEntry CodeToSTE(U32 *code, U32 ip)
{ {
#ifdef TORQUE_CPU_X64 #if defined(TORQUE_CPU_X64) || defined(TORQUE_CPU_ARM64)
return (StringTableEntry)(*((U64*)(code + ip))); return (StringTableEntry)(*((U64*)(code + ip)));
#else #else
return (StringTableEntry)(*(code + ip)); return (StringTableEntry)(*(code + ip));

View file

@ -70,7 +70,7 @@
#include "core/util/md5.h" #include "core/util/md5.h"
#include "console/enginePrimitives.h" #include "console/enginePrimitives.h"
#if defined (TORQUE_OS_MAC) && defined(TORQUE_CPU_X64) #if defined (TORQUE_OS_MAC) && (defined(TORQUE_CPU_X64) || defined(TORQUE_CPU_ARM64))
typedef unsigned int unsigned32; typedef unsigned int unsigned32;
#else #else
typedef unsigned long unsigned32; typedef unsigned long unsigned32;

View file

@ -120,6 +120,11 @@ typedef unsigned long U64;
# define TORQUE_CPU_X64 # define TORQUE_CPU_X64
# define TORQUE_LITTLE_ENDIAN # define TORQUE_LITTLE_ENDIAN
#elif (defined( __arm64__ ) && defined( __APPLE__ )) || defined( __arch64__ )
# define TORQUE_CPU_STRING "Arm 64"
# define TORQUE_CPU_ARM64
# define TORQUE_LITTLE_ENDIAN
#else #else
# error "GCC: Unsupported Target CPU" # error "GCC: Unsupported Target CPU"
#endif #endif

View file

@ -128,7 +128,7 @@ static const F32 F32_MAX = F32(3.402823466e+38F); ///< Constant
#endif #endif
/// Integral type matching the host's memory address width. /// Integral type matching the host's memory address width.
#ifdef TORQUE_CPU_X64 #if defined(TORQUE_CPU_X64) || defined(TORQUE_CPU_ARM64)
typedef U64 MEM_ADDRESS; typedef U64 MEM_ADDRESS;
#else #else
typedef U32 MEM_ADDRESS; typedef U32 MEM_ADDRESS;

View file

@ -34,21 +34,29 @@ static MRandomLCG sgPlatRandom;
U32 Platform::getMathControlState() U32 Platform::getMathControlState()
{ {
#ifdef TORQUE_CPU_X86
U16 cw; U16 cw;
asm("fstcw %0" : "=m" (cw) :); asm("fstcw %0" : "=m" (cw) :);
return cw; return cw;
#else
return 0;
#endif
} }
void Platform::setMathControlState(U32 state) void Platform::setMathControlState(U32 state)
{ {
#ifdef TORQUE_CPU_X86
U16 cw = state; U16 cw = state;
asm("fldcw %0" : : "m" (cw)); asm("fldcw %0" : : "m" (cw));
#endif
} }
void Platform::setMathControlStateKnown() void Platform::setMathControlStateKnown()
{ {
#ifdef TORQUE_CPU_X86
U16 cw = 0x27F; U16 cw = 0x27F;
asm("fldcw %0" : : "m" (cw)); asm("fldcw %0" : : "m" (cw));
#endif
} }
//-------------------------------------- //--------------------------------------

View file

@ -24,6 +24,11 @@ project(lpng)
# addDef(PNG_NO_ASSEMBLER_CODE) # addDef(PNG_NO_ASSEMBLER_CODE)
# Issues with Neon at the moment (Arm support)
# https://sourceforge.net/p/libpng/bugs/281/
set(PNG_ARM_NEON off CACHE STRING "")
add_definitions(-DPNG_ARM_NEON_OPT=0)
addInclude(${libDir}/zlib) addInclude(${libDir}/zlib)
finishLibrary("${libDir}/${PROJECT_NAME}") finishLibrary("${libDir}/${PROJECT_NAME}")

View file

@ -692,8 +692,8 @@ if(WIN32)
endif() endif()
if (APPLE) if (APPLE)
addFramework("Cocoa") addFramework("Cocoa")
addFramework("OpenGL") addFramework("OpenGL")
#These are needed by sdl2 static lib #These are needed by sdl2 static lib
addFramework("CoreAudio") addFramework("CoreAudio")
addFramework("AudioUnit") addFramework("AudioUnit")
@ -704,9 +704,29 @@ if (APPLE)
addFramework("Carbon") addFramework("Carbon")
addFramework("AudioToolbox") addFramework("AudioToolbox")
addLib("iconv") addLib("iconv")
#set a few arch defaults endif()
set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "OSX Architecture" FORCE)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "OSX Deployment target" FORCE) #detect Architecture
if (APPLE AND NOT IOS)
option(TORQUE_MACOS_UNIVERSAL_BINARY OFF)
# Detect architecture if not using universal
if (TORQUE_MACOS_UNIVERSAL_BINARY)
set(ARCHITECTURE_STRING_APPLE "x86_64;arm64")
set(DEPLOYMENT_TARGET_APPLE "10.13")
else()
check_c_compiler_flag("-arch arm64" armSupportedApple)
if(armSupportedApple)
set(ARCHITECTURE_STRING_APPLE "arm64")
set(DEPLOYMENT_TARGET_APPLE "11.0")
else()
set(ARCHITECTURE_STRING_APPLE "x86_64")
set(DEPLOYMENT_TARGET_APPLE "10.9")
endif()
endif()
set(CMAKE_OSX_ARCHITECTURES ${ARCHITECTURE_STRING_APPLE} CACHE STRING "OSX Architecture" FORCE)
set(CMAKE_OSX_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET_APPLE} CACHE STRING "OSX Deployment target" FORCE)
endif() endif()
if(UNIX AND NOT APPLE) if(UNIX AND NOT APPLE)