Код: Выделить всё
#define MPHY_INLINE __inline__ __attribute__((always_inline))
#define MPHY_USE_SSE
MPHY_NAMESPACE_BEGIN
class [[nodiscard]] alignas(MPHY_VECTOR_ALIGNMENT) UVector4
{
public:
#if defined(MPHY_USE_SSE)
using Type = __m128i;
#elif defined(MPHY_USE_NEON)
using Type = uint32x4_t;
#else
using Type = struct { uint32 _Data[4]; };
#endif
UVector4() = default;
UVector4(const UVector4& inRHS) = default;
UVector4& operator=(const UVector4& inRHS) = default;
MPHY_INLINE UVector4(Type inRHS)
: _Value(inRHS)
{}
MPHY_INLINE UVector4(uint32 inX, uint32 inY, uint32 inZ, uint32 inW);
MPHY_INLINE bool operator==(UVec4Arg inV2) const;
MPHY_INLINE bool operator!=(UVec4Arg inV2) const
{
return !(*this == inV2);
}
template
MPHY_INLINE UVector4 Swizzle() const;
static MPHY_INLINE UVector4 sEquals(UVec4Arg inVal1, UVec4Arg inVal2);
MPHY_INLINE bool TestAllTrue() const;
MPHY_INLINE int GetTrues() const;
UVector4 UVector4::sXor(UVec4Arg inV1, UVec4Arg inV2);
UVector4 UVector4::sReplicate(uint32 inV);
// Component wise Logical Xor
static MPHY_INLINE UVector4 sXor(UVec4Arg inV1, UVec4Arg inV2);
union
{
Type _Value;
uint32 _U32[4];
};
};
static_assert(std::is_trivial(), "It is supposed to a trivial type.");
#include "UVector4.inl"
UVector4::UVector4(uint32 inX, uint32 inY, uint32 inZ, uint32 inW)
{
#if defined(MPHY_USE_SSE)
_Value = _mm_set_epi32(int(inW), int(inZ), int(inY), int(inX));
#elif defined(MPHY_USE_NEON)
uint32x2_t xy = vcreate_u32(static_cast(inX) | (static_cast(inY) 31) | (_U32[3] >> 31);
#endif
}
bool UVector4::TestAllTrue() const
{
return GetTrues() == 0b1111;
}
UVector4 UVector4::sReplicate(uint32 inV)
{
#if defined(MPHY_USE_SSE)
return _mm_set1_epi32(int(inV));
#elif defined(MPHY_USE_NEON)
return vdupq_n_u32(inV);
#else
return UVector(inV, inV, inV, inV);
#endif
}
UVector4 UVector4::sAnd(UVec4Arg inV1, UVec4Arg inV2)
{
#if defined(MPHY_USE_SSE)
return _mm_and_si128(inV1._Value, inV2._Value);
#elif defined(MPHY_USE_NEON)
return vandq_u32(inV1._Value, inV2._Value);
#else
return UVector4(
inV1._U32[0] & inV2._U32[0],
inV1._U32[1] & inV2._U32[1],
inV1._U32[2] & inV2._U32[2],
inV1._U32[3] & inV2._U32[3]);
#endif
}
< /code>
Пример использования, где отображается ошибка: < /p>
class [[nodiscard]] alignas(MPHY_VECTOR_ALIGNMENT) Vector4
{
public:
#if defined(MPHY_USE_SSE)
using Type = __m128;
#elif defined(MPHY_USE_NEON)
using Type = float32x4_t;
#else
using Type = struct {float _Data[4];};
#endif
MPHY_INLINE UVector4 ReinterpretToInt() const;
union
{
Type _Value;
float _F32[4];
};
};
UVector4 Vector4::ReinterpretToInt() const
{
#if defined(MPHY_USE_SSE)
return UVector4(_mm_castps_si128(_Value));
#elif defined(MPHY_USE_NEON)
return vreinterpretq_u32_f32(_Value);
#else
return *reinterpret_cast(this);
#endif
}
// Usage Code.
UVector4 asin_sign = UVector4::sAnd(ReinterpretToInt(),UVector4::sReplicate(0x80000000U));
< /code>
Класс был действительно длинным, но я добавил только несколько методов, которых должно быть достаточно. Я собираю программу с использованием GCC-11.4.0 на поп-ОС 22.04. У меня нет идей о том, что не так с кодом в этом файле.
Подробнее здесь: https://stackoverflow.com/questions/796 ... -as-far-as