winamp/src/common/gsvector.h
Stenzek 0ae6ddcf7f
Common: Add GSVector
Mostly based on PCSX2.
2024-07-03 00:24:12 +10:00

66 lines
1.4 KiB
C++

// 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