mirror of
https://github.com/WinampDesktop/winamp.git
synced 2025-06-17 20:55:45 -04:00
Common: Add GSVector
Mostly based on PCSX2.
This commit is contained in:
@ -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>
|
||||
|
Reference in New Issue
Block a user