mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-22 13:55:38 +00:00
Common: Add GSVector
Mostly based on PCSX2.
This commit is contained in:
parent
baab966b4e
commit
0ae6ddcf7f
|
@ -57,6 +57,8 @@ function(detect_architecture)
|
|||
if("x86_64" IN_LIST CMAKE_OSX_ARCHITECTURES)
|
||||
message(STATUS "Building x86_64 MacOS binaries.")
|
||||
set(CPU_ARCH_X64 TRUE PARENT_SCOPE)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Xarch_x86_64 -msse4.1" PARENT_SCOPE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xarch_864_64 -msse4.1" PARENT_SCOPE)
|
||||
endif()
|
||||
if("arm64" IN_LIST CMAKE_OSX_ARCHITECTURES)
|
||||
message(STATUS "Building ARM64 MacOS binaries.")
|
||||
|
@ -67,6 +69,8 @@ function(detect_architecture)
|
|||
CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
message(STATUS "Building x86_64 binaries.")
|
||||
set(CPU_ARCH_X64 TRUE PARENT_SCOPE)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.1" PARENT_SCOPE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1" PARENT_SCOPE)
|
||||
elseif(("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64") AND
|
||||
CMAKE_SIZEOF_VOID_P EQUAL 8) # Might have an A64 kernel, e.g. Raspbian.
|
||||
message(STATUS "Building ARM64 binaries.")
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
<PreprocessorDefinitions>_HAS_EXCEPTIONS=0;_CRT_INTERNAL_NONSTDC_NAMES;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DepsIncludeDir)</AdditionalIncludeDirectories>
|
||||
<AdditionalOptions Condition="!$(Configuration.Contains(Clang))">/Zc:__cplusplus /Zo /utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
<AdditionalOptions Condition="$(Configuration.Contains(Clang)) And '$(Platform)'=='x64'"> -msse4.1 %(AdditionalOptions)</AdditionalOptions>
|
||||
<!-- Force ThinLTO for Release builds, MSVC doesn't seem to do it otherwise. -->
|
||||
<AdditionalOptions Condition="$(Configuration.Contains(Clang)) And $(Configuration.Contains(ReleaseLTCG))"> -flto=thin %(AdditionalOptions)</AdditionalOptions>
|
||||
<ExceptionHandling>false</ExceptionHandling>
|
||||
|
|
|
@ -21,6 +21,11 @@ add_library(common
|
|||
fifo_queue.h
|
||||
file_system.cpp
|
||||
file_system.h
|
||||
gsvector.h
|
||||
gsvector_formatter.h
|
||||
gsvector_neon.h
|
||||
gsvector_nosimd.h
|
||||
gsvector_sse.h
|
||||
intrin.h
|
||||
hash_combine.h
|
||||
heap_array.h
|
||||
|
|
|
@ -16,6 +16,11 @@
|
|||
<ClInclude Include="fastjmp.h" />
|
||||
<ClInclude Include="fifo_queue.h" />
|
||||
<ClInclude Include="file_system.h" />
|
||||
<ClInclude Include="gsvector.h" />
|
||||
<ClInclude Include="gsvector_formatter.h" />
|
||||
<ClInclude Include="gsvector_neon.h" />
|
||||
<ClInclude Include="gsvector_nosimd.h" />
|
||||
<ClInclude Include="gsvector_sse.h" />
|
||||
<ClInclude Include="hash_combine.h" />
|
||||
<ClInclude Include="heap_array.h" />
|
||||
<ClInclude Include="intrin.h" />
|
||||
|
@ -70,6 +75,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Natvis Include="bitfield.natvis" />
|
||||
<Natvis Include="gsvector.natvis" />
|
||||
<Natvis Include="thirdparty\llvm.natvis" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
@ -46,6 +46,11 @@
|
|||
</ClInclude>
|
||||
<ClInclude Include="dynamic_library.h" />
|
||||
<ClInclude Include="binary_span_reader_writer.h" />
|
||||
<ClInclude Include="gsvector_sse.h" />
|
||||
<ClInclude Include="gsvector_neon.h" />
|
||||
<ClInclude Include="gsvector.h" />
|
||||
<ClInclude Include="gsvector_formatter.h" />
|
||||
<ClInclude Include="gsvector_nosimd.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="small_string.cpp" />
|
||||
|
@ -80,6 +85,7 @@
|
|||
<Natvis Include="thirdparty\llvm.natvis">
|
||||
<Filter>thirdparty</Filter>
|
||||
</Natvis>
|
||||
<Natvis Include="gsvector.natvis" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="thirdparty">
|
||||
|
|
65
src/common/gsvector.h
Normal file
65
src/common/gsvector.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/intrin.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
enum Align_Mode
|
||||
{
|
||||
Align_Outside,
|
||||
Align_Inside,
|
||||
Align_NegInf,
|
||||
Align_PosInf
|
||||
};
|
||||
|
||||
enum Round_Mode
|
||||
{
|
||||
Round_NearestInt = 8,
|
||||
Round_NegInf = 9,
|
||||
Round_PosInf = 10,
|
||||
Round_Truncate = 11
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class GSVector2T
|
||||
{
|
||||
public:
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
T x, y;
|
||||
};
|
||||
struct
|
||||
{
|
||||
T r, g;
|
||||
};
|
||||
struct
|
||||
{
|
||||
T v[2];
|
||||
};
|
||||
};
|
||||
|
||||
GSVector2T() = default;
|
||||
|
||||
ALWAYS_INLINE constexpr GSVector2T(T x) : x(x), y(x) {}
|
||||
ALWAYS_INLINE constexpr GSVector2T(T x, T y) : x(x), y(y) {}
|
||||
ALWAYS_INLINE constexpr bool operator==(const GSVector2T& v) const { return std::memcmp(this, &v, sizeof(*this)) == 0; }
|
||||
ALWAYS_INLINE constexpr bool operator!=(const GSVector2T& v) const { return std::memcmp(this, &v, sizeof(*this)) != 0; }
|
||||
ALWAYS_INLINE constexpr GSVector2T operator*(const GSVector2T& v) const { return {x * v.x, y * v.y}; }
|
||||
ALWAYS_INLINE constexpr GSVector2T operator/(const GSVector2T& v) const { return {x / v.x, y / v.y}; }
|
||||
};
|
||||
|
||||
using GSVector2 = GSVector2T<float>;
|
||||
using GSVector2i = GSVector2T<s32>;
|
||||
|
||||
#if defined(CPU_ARCH_SSE)
|
||||
#include "common/gsvector_sse.h"
|
||||
#elif defined(CPU_ARCH_NEON)
|
||||
#include "common/gsvector_neon.h"
|
||||
#else
|
||||
#include "common/gsvector_nosimd.h"
|
||||
#endif
|
10
src/common/gsvector.natvis
Normal file
10
src/common/gsvector.natvis
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
|
||||
<Type Name="GSVector2T<*>">
|
||||
<DisplayString>{{ {x}, {y} }}</DisplayString>
|
||||
</Type>
|
||||
|
||||
<Type Name="GSVector4i">
|
||||
<DisplayString>{{ {I32[0]}, {I32[1]}, {I32[2]}, {I32[3]} }}</DisplayString>
|
||||
</Type>
|
||||
</AutoVisualizer>
|
21
src/common/gsvector_formatter.h
Normal file
21
src/common/gsvector_formatter.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
// SPDX-FileCopyrightText: 2024 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gsvector.h"
|
||||
#include "small_string.h"
|
||||
|
||||
#include "fmt/format.h"
|
||||
|
||||
template<>
|
||||
struct fmt::formatter<GSVector4i> : formatter<std::string_view>
|
||||
{
|
||||
auto format(const GSVector4i& rc, format_context& ctx) const
|
||||
{
|
||||
const TinyString str =
|
||||
TinyString::from_format("{},{} => {},{} ({}x{})", rc.left, rc.top, rc.right, rc.bottom, rc.width(), rc.height());
|
||||
|
||||
return fmt::formatter<std::string_view>::format(str.view(), ctx);
|
||||
}
|
||||
};
|
1712
src/common/gsvector_neon.h
Normal file
1712
src/common/gsvector_neon.h
Normal file
File diff suppressed because it is too large
Load diff
1612
src/common/gsvector_nosimd.h
Normal file
1612
src/common/gsvector_nosimd.h
Normal file
File diff suppressed because it is too large
Load diff
1322
src/common/gsvector_sse.h
Normal file
1322
src/common/gsvector_sse.h
Normal file
File diff suppressed because it is too large
Load diff
|
@ -13,7 +13,21 @@
|
|||
#if defined(CPU_ARCH_X86) || defined(CPU_ARCH_X64)
|
||||
#define CPU_ARCH_SSE 1
|
||||
#include <emmintrin.h>
|
||||
#elif defined(CPU_ARCH_ARM64)
|
||||
#include <tmmintrin.h>
|
||||
#include <smmintrin.h>
|
||||
#include <immintrin.h>
|
||||
|
||||
#if defined(__AVX2__)
|
||||
#define CPU_ARCH_AVX 1
|
||||
#define CPU_ARCH_AVX2 1
|
||||
#define CPU_ARCH_SSE41 1
|
||||
#elif defined(__AVX__)
|
||||
#define CPU_ARCH_AVX 1
|
||||
#define CPU_ARCH_SSE41 1
|
||||
#elif defined(__SSE4_1__) || defined(_MSC_VER)
|
||||
#define CPU_ARCH_SSE41 1
|
||||
#endif
|
||||
#elif defined(CPU_ARCH_ARM32) || defined(CPU_ARCH_ARM64)
|
||||
#define CPU_ARCH_NEON 1
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
#include <arm64_neon.h>
|
||||
|
|
Loading…
Reference in a new issue