From c65b1c81397ac4c3ee214e4406f1cb5be8636e98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20H=C3=B6hne?= <77296181+THoehne@users.noreply.github.com> Date: Tue, 21 Jan 2025 23:57:42 +0100 Subject: [PATCH] Update SIMD and Platform Linux. --- .vscode/settings.json | 22 +++++++++++++++++++ .../Source/Runtime/Core/public/HAL/Platform.h | 3 +-- .../Runtime/Core/public/HAL/PlatformTypes.h | 19 ++-------------- .../Runtime/Core/public/Math/Boilerplate.h | 14 ++++++++++-- .../Runtime/Core/public/Math/MathTypes.h | 1 - .../public/Math/SIMD/PhanesVectorMathSSE.hpp | 12 +++++----- MathTestFPU/CMakeLists.txt | 4 ++++ 7 files changed, 47 insertions(+), 28 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 MathTestFPU/CMakeLists.txt diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..2935f1f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,22 @@ +{ + "C_Cpp.formatting": "clangFormat", + "C_Cpp.loggingLevel": "Error", + "C_Cpp.default.cppStandard": "c++20", + "C_Cpp.default.includePath": [ + "${workspaceFolder}/Engine/Source/Runtime", + "${workspaceFolder}/Engine/Source/ThirdParty" + ], + + "C_Cpp.default.browse.path": [ + "${workspaceFolder}/Engine/Source/Runtime", + "${workspaceFolder}/Engine/Source/ThirdParty" + ], + "C_Cpp.default.browse.databaseFilename": "${workspaceFolder}/.vscode/browse.vc.db", + "files.associations": { + "cstdint": "cpp" + }, + "C_Cpp.default.defines": [ + "P_LINUX_BUILD", + "__SSE__", + ], +} \ No newline at end of file diff --git a/Engine/Source/Runtime/Core/public/HAL/Platform.h b/Engine/Source/Runtime/Core/public/HAL/Platform.h index fed865b..f3656d0 100644 --- a/Engine/Source/Runtime/Core/public/HAL/Platform.h +++ b/Engine/Source/Runtime/Core/public/HAL/Platform.h @@ -14,9 +14,9 @@ // User defines build platform #ifdef P_WIN_BUILD # define P_PLATFORM P_PLATFORM_WIN +# error Windows system is not yet supported. #elif P_LINUX_BUILD # define P_PLATFORM P_PLATFORM_LIN -# error Linux / Unix system is not yet supported. #elif P_MAC_BUILD # define P_PLATFORM P_PLATFORM_MAC # error Mac target system is not yet supported. @@ -133,7 +133,6 @@ // Clang #elif (defined(__clang__)) -# error PhanesEngine only supports MSVC -> Visual Studio # if defined(__apple_build_version__) # # if (__clang_major__ < 6) diff --git a/Engine/Source/Runtime/Core/public/HAL/PlatformTypes.h b/Engine/Source/Runtime/Core/public/HAL/PlatformTypes.h index 7d4e9d3..2b062a7 100644 --- a/Engine/Source/Runtime/Core/public/HAL/PlatformTypes.h +++ b/Engine/Source/Runtime/Core/public/HAL/PlatformTypes.h @@ -1,30 +1,15 @@ #pragma once +#include "PhanesEnginePCH.h" + // ============================================= // // Turn os specific types into global types. // // ============================================= // -// TODO: include int128 - namespace Phanes::Core::Types { -#ifdef P_WIN_BUILD - - // MSCV++ specific types - - typedef FLOAT128 float128; - -//#elif P_UNIX_BUILD -// -// // GCC specific types -// -// typedef __float128 float128; - -#endif - - // Specific types size // // 8-Bit integer diff --git a/Engine/Source/Runtime/Core/public/Math/Boilerplate.h b/Engine/Source/Runtime/Core/public/Math/Boilerplate.h index bed7074..1184937 100644 --- a/Engine/Source/Runtime/Core/public/Math/Boilerplate.h +++ b/Engine/Source/Runtime/Core/public/Math/Boilerplate.h @@ -28,9 +28,19 @@ #define FORCEINLINE __forceinline -#elif defined(P_UNIX_BUILD) +#elif defined(P_LINUX_BUILD) + + #ifdef P_DEBUG - #error Only Windows is supported at the moment. + #define P_DEBUGBREAK __builtin_trap(); + + #else + + #define P_DEBUGBREAK + + #endif // P_DEBUG + + #define FORCEINLINE inline __attribute__((always_inline)) #elif defined(P_ARM_BUILD) diff --git a/Engine/Source/Runtime/Core/public/Math/MathTypes.h b/Engine/Source/Runtime/Core/public/Math/MathTypes.h index 4d99a07..d56898b 100644 --- a/Engine/Source/Runtime/Core/public/Math/MathTypes.h +++ b/Engine/Source/Runtime/Core/public/Math/MathTypes.h @@ -4,7 +4,6 @@ # include "PhanesEnginePCH.h" #else # define NOMINMAX -# include # include #endif diff --git a/Engine/Source/Runtime/Core/public/Math/SIMD/PhanesVectorMathSSE.hpp b/Engine/Source/Runtime/Core/public/Math/SIMD/PhanesVectorMathSSE.hpp index 26ff481..92208cf 100644 --- a/Engine/Source/Runtime/Core/public/Math/SIMD/PhanesVectorMathSSE.hpp +++ b/Engine/Source/Runtime/Core/public/Math/SIMD/PhanesVectorMathSSE.hpp @@ -113,7 +113,7 @@ namespace Phanes::Core::Math::SIMD /// void vec3_fix(Phanes::Core::Types::Vec4f32Reg v1) { - v1.m128_f32[3] = 0.0f; + v1 = _mm_and_ps(v1, _mm_castsi128_ps(_mm_set_epi32(0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000))); } } @@ -265,7 +265,7 @@ namespace Phanes::Core::Math::Detail static FORCEINLINE float map(const Phanes::Core::Math::TVector4& v1) { __m128 tmp = _mm_mul_ps(v1.data, v1.data); - return sqrt(tmp.m128_f32[0] + tmp.m128_f32[1] + tmp.m128_f32[2] + tmp.m128_f32[3]); + return _mm_cvtss_f32(_mm_sqrt_ps(SIMD::vec4_hadd(tmp))); } }; @@ -515,7 +515,7 @@ namespace Phanes::Core::Math::Detail static FORCEINLINE double map(const Phanes::Core::Math::TVector2& v1) { __m128d tmp = _mm_mul_pd(v1.data, v1.data); - return sqrt(tmp.m128d_f64[0] + tmp.m128d_f64[1]); + return _mm_cvtsd_f64(_mm_sqrt_pd(_mm_hadd_pd(tmp, tmp))); } }; @@ -526,7 +526,7 @@ namespace Phanes::Core::Math::Detail static FORCEINLINE double map(const Phanes::Core::Math::TVector2& v1) { __m128d tmp = _mm_mul_pd(v1.data, v1.data); - return tmp.m128d_f64[0] + tmp.m128d_f64[1]; + return _mm_cvtsd_f64(_mm_hadd_pd(tmp, tmp)); } }; @@ -657,7 +657,7 @@ namespace Phanes::Core::Math::Detail static FORCEINLINE void map(Phanes::Core::Math::TIntVector4& v1, const int* comp) { - v1.comp = _mm_loadu_epi32(comp); + v1.comp = _mm_set_epi32(comp[3], comp[2], comp[1], comp[0]); } static FORCEINLINE void map(Phanes::Core::Math::TIntVector4& r, const Phanes::Core::Math::TIntVector2& v1, const Phanes::Core::Math::TIntVector2& v2) @@ -875,7 +875,7 @@ namespace Phanes::Core::Math::Detail static FORCEINLINE void map(Phanes::Core::Math::TIntVector2& v1, const Phanes::Core::Types::int64* comp) { - v1.comp = _mm_loadu_epi64(comp); + v1.comp = _mm_set_epi64x(comp[1], comp[0]); } }; diff --git a/MathTestFPU/CMakeLists.txt b/MathTestFPU/CMakeLists.txt new file mode 100644 index 0000000..8e006d2 --- /dev/null +++ b/MathTestFPU/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(2.8) + +project(MathTestFPU) +