Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arm64 Support #1

Draft
wants to merge 4 commits into
base: BAR105
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion AI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ set(CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_PROFILE}")

remove_definitions(-DSTREFLOP_SSE)
# remove_definitions(-DSTREFLOP_SSE)
remove_definitions(-DSTREFLOP_NEON)
add_definitions(${PIC_FLAG} -D_REENTRANT -D_GNU_SOURCE=1)

if (MINGW)
Expand Down
2 changes: 1 addition & 1 deletion AI/Interfaces/C/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ macro (configure_native_skirmish_ai mySourceDirRel_var additionalSources_var

# Create a list of all the AIs own source files
get_native_sources_recursive(mySources "${mySourceDir}" "${myDir}")

enable_language(ASM)
# Compile the library
add_library(${myTarget} MODULE ${mySources} ${additionalSources} ${myVersionDepFile})
set_target_properties(${myTarget} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/data)
Expand Down
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,8 @@ option(ENABLE_STREFLOP "build Spring with streflop support (REQUIRED FOR MULTIPL

if (ENABLE_STREFLOP)
## note: is removed in ./AI/CMakeLists.txt since it would break AI compilation
add_definitions(-DSTREFLOP_SSE)
# add_definitions(-DSTREFLOP_SSE)
add_definitions(-DSTREFLOP_NEON)
else ()
add_definitions(-DNOT_USING_STREFLOP)
endif ()
Expand Down Expand Up @@ -462,10 +463,11 @@ if (CMAKE_COMPILER_IS_GNUCXX)
set(FALLBACK_MARCH "i686")
endif (MARCH_BITS EQUAL 64)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=${FALLBACK_MARCH} -mtune=generic ${FALLBACK_SSE_FLAGS}")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=${FALLBACK_MARCH} -mtune=generic ${FALLBACK_SSE_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8-a+simd -ffp-contract=off")
endif (NOT MARCH_FLAG STREQUAL "generic")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SSE_FLAGS} -mfpmath=sse") #SSE_FLAGS are now user input only
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SSE_FLAGS} -mfpmath=sse") #SSE_FLAGS are now user input only
elseif (MSVC)
set(MSVC_CXX_FLAGS "/arch:SSE2") #default, but still set explicitly
# silence warnings
Expand Down
36 changes: 36 additions & 0 deletions pr.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
diff --git a/src/Version.cpp b/src/Version.cpp
index 300fa83..2ba270d 100644
--- a/src/Version.cpp
+++ b/src/Version.cpp
@@ -32,6 +32,8 @@ const char* platformToString(Platform platform)
return "linux64";
case Platform::Windows_x64:
return "windows64";
+ case Platform::Linux_arm64:
+ return "linuxArm64";
default:
// unreachable
std::abort();
diff --git a/src/Version.h b/src/Version.h
index 4c114df..c13d844 100644
--- a/src/Version.h
+++ b/src/Version.h
@@ -8,12 +8,17 @@ const char* getAgent();
enum class Platform {
Windows_x64,
Linux_x64,
+ Linux_arm64
};

#if defined(_WIN64)
constexpr Platform PRD_CURRENT_PLATFORM = Platform::Windows_x64;
-#elif defined(__linux__) && defined(__x86_64__)
+#elif defined(__linux__)
+#if defined(__x86_64__)
constexpr Platform PRD_CURRENT_PLATFORM = Platform::Linux_x64;
+#else
+constexpr Platform PRD_CURRENT_PLATFORM = Platform::Linux_arm64;
+#endif
#endif

const char* platformToString(Platform Platform);
29 changes: 15 additions & 14 deletions rts/Sim/Path/QTPFS/NodeLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@

#include <limits>

#if defined(_MSC_VER)
#include <intrin.h>
// visual c
inline int __bsfd (int mask)
{
unsigned long index;
_BitScanForward(&index, mask);
return index;
}
#elif defined(__GNUC__)
#include <x86intrin.h>
#else
#error no bsfd intrinsic currently set
#endif
// #if defined(_MSC_VER)
// #include <intrin.h>
// // visual c
// inline int __bsfd (int mask)
// {
// unsigned long index;
// _BitScanForward(&index, mask);
// return index;
// }
// #elif defined(__GNUC__)
// #include <x86intrin.h>
// #else
// #error no bsfd intrinsic currently set
// #endif
#include "System/sse2neon.h"

#include "NodeLayer.h"
#include "PathManager.h"
Expand Down
3 changes: 2 additions & 1 deletion rts/System/FastMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#define FASTMATH_H

#ifndef DEDICATED_NOSSE
#include <xmmintrin.h>
// #include <xmmintrin.h>
#include "System/sse2neon.h"
#endif
#include <cinttypes>

Expand Down
5 changes: 3 additions & 2 deletions rts/System/Matrix44f.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
#include <algorithm>
#include <cstring>

#include <xmmintrin.h>
#include <emmintrin.h>
// #include <xmmintrin.h>
// #include <emmintrin.h>
#include "System/sse2neon.h"

CR_BIND(CMatrix44f, )

Expand Down
30 changes: 15 additions & 15 deletions rts/System/Platform/Linux/CrashHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,20 +709,20 @@ namespace CrashHandler

unw_cursor_t cursor;

#if (defined(__arm__) || defined(__APPLE__))
// #if (defined(__arm__) || defined(__APPLE__))
// ucontext_t and unw_context_t are not aliases here
unw_context_t thisctx;
unw_getcontext(&thisctx);
#else
// Effective ucontext_t. If uc not supplied, use unw_getcontext
// locally. This is appropriate inside signal handlers.
ucontext_t thisctx;

if (uc == nullptr) {
unw_getcontext(&thisctx);
uc = &thisctx;
}
#endif
// #else
// // Effective ucontext_t. If uc not supplied, use unw_getcontext
// // locally. This is appropriate inside signal handlers.
// ucontext_t thisctx;
//
// if (uc == nullptr) {
// unw_getcontext(&thisctx);
// uc = &thisctx;
// }
// #endif


char procbuffer[1024];
Expand All @@ -742,11 +742,11 @@ namespace CrashHandler
}
*/

#if (defined(__arm__) || defined(__APPLE__))
// #if (defined(__arm__) || defined(__APPLE__))
const int err = unw_init_local(&cursor, &thisctx);
#else
const int err = unw_init_local(&cursor, uc);
#endif
// #else
// const int err = unw_init_local(&cursor, uc);
// #endif

if (err != 0) {
LOG_L(L_ERROR, "unw_init_local returned %d", err);
Expand Down
2 changes: 1 addition & 1 deletion rts/System/ScopedFPUSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ScopedDisableFpuExceptions {
streflop::fesetenv(&fenv);
}
private:
streflop::fpenv_t fenv;
streflop::fenv_t fenv;
};

#else
Expand Down
7 changes: 6 additions & 1 deletion rts/System/Sync/FPUCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void good_fpu_init() { LOG_L(L_WARNING, "[%s] streflop is disabled", __func__);

#ifdef STREFLOP_SSE
#elif STREFLOP_X87
#elif STREFLOP_NEON
#else
#error "streflop FP-math mode must be either SSE or X87"
#endif
Expand Down Expand Up @@ -92,7 +93,7 @@ void good_fpu_control_registers(const char* text)
constexpr int x87_c = 0x0032; // signan

#ifdef STREFLOP_H
streflop::fpenv_t fenv;
streflop::fenv_t fenv;
streflop::fegetenv(&fenv);

#if defined(STREFLOP_SSE)
Expand Down Expand Up @@ -139,6 +140,8 @@ void good_fpu_init()
LOG("[%s][STREFLOP_SSE]", __func__);
#elif (defined(STREFLOP_X87))
LOG("[%s][STREFLOP_X87]", __func__);
#elif (defined(STREFLOP_NEON))
LOG("[%s][STREFLOP_NEON]", __func__);
#else
#error
#endif
Expand All @@ -157,6 +160,8 @@ void good_fpu_init()
LOG_L(L_WARNING, "\tStreflop floating-point math is set to X87 mode");
LOG_L(L_WARNING, "\tThis may cause desyncs during multi-player games");
LOG_L(L_WARNING, "\tYour CPU is %s SSE-capable; consider %s", (sseFlag == 0)? "not": "", (sseFlag == 1)? "recompiling": "upgrading");
#elif (defined(STREFLOP_NEON))
LOG_L(L_WARNING, "\tStreflop NEON mode, glhf");
#else
#error
#endif
Expand Down
3 changes: 2 additions & 1 deletion rts/System/Threading/SpringThreading.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#include <atomic>
#include <thread>
#include <condition_variable>
#include <immintrin.h>
// #include <immintrin.h>
#include "System/sse2neon.h"


#if defined(_WIN32)
Expand Down
Loading