1
0
mirror of https://github.com/microsoft/DirectXMath synced 2024-11-22 12:20:06 +00:00
DirectXMath/Extensions/DirectXMathBE.h

96 lines
2.8 KiB
C
Raw Normal View History

2016-08-22 18:43:47 +00:00
//-------------------------------------------------------------------------------------
// DirectXMathBE.h -- Big-endian swap extensions for SIMD C++ Math library
//
2021-02-27 07:17:26 +00:00
// Copyright (c) Microsoft Corporation.
2018-02-24 07:16:27 +00:00
// Licensed under the MIT License.
2016-08-22 18:43:47 +00:00
//
// http://go.microsoft.com/fwlink/?LinkID=615560
//-------------------------------------------------------------------------------------
#pragma once
2019-08-02 21:33:58 +00:00
#if (defined(_M_IX86) || defined(_M_X64) || __i386__ || __x86_64__) && !defined(_M_HYBRID_X86_ARM64)
2016-08-22 18:43:47 +00:00
#include <tmmintrin.h>
#endif
#include <DirectXMath.h>
namespace DirectX
{
inline XMVECTOR XM_CALLCONV XMVectorEndian
(
FXMVECTOR V
)
{
#if defined(_XM_ARM_NEON_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_)
2019-08-02 21:33:58 +00:00
static const XMVECTORU32 idx = { { { 0x00010203u, 0x04050607u, 0x08090A0Bu, 0x0C0D0E0Fu } } };
2016-08-22 18:43:47 +00:00
2019-08-02 21:33:58 +00:00
uint8x8x2_t tbl;
tbl.val[0] = vreinterpret_u8_f32(vget_low_f32(V));
tbl.val[1] = vreinterpret_u8_f32(vget_high_f32(V));
2016-08-22 18:43:47 +00:00
2019-08-02 21:33:58 +00:00
const uint8x8_t rL = vtbl2_u8(tbl, vget_low_u32(idx));
const uint8x8_t rH = vtbl2_u8(tbl, vget_high_u32(idx));
return vcombine_f32(vreinterpret_f32_u8(rL), vreinterpret_f32_u8(rH));
2016-08-22 18:43:47 +00:00
#else
XMVECTORU32 E;
E.v = V;
uint32_t value = E.u[0];
E.u[0] = ( (value << 24) | ((value & 0xFF00) << 8) | ((value & 0xFF0000) >> 8) | (value >> 24) );
value = E.u[1];
E.u[1] = ( (value << 24) | ((value & 0xFF00) << 8) | ((value & 0xFF0000) >> 8) | (value >> 24) );
value = E.u[2];
E.u[2] = ( (value << 24) | ((value & 0xFF00) << 8) | ((value & 0xFF0000) >> 8) | (value >> 24) );
value = E.u[3];
E.u[3] = ( (value << 24) | ((value & 0xFF00) << 8) | ((value & 0xFF0000) >> 8) | (value >> 24) );
return E.v;
#endif
}
2019-08-02 21:33:58 +00:00
#if (defined(_M_IX86) || defined(_M_X64) || __i386__ || __x86_64__) && !defined(_M_HYBRID_X86_ARM64)
2016-08-22 18:43:47 +00:00
namespace SSSE3
{
inline bool XMVerifySSSE3Support()
{
// Should return true on AMD Bulldozer, Intel Core i7/i5/i3, Intel Atom, or later processors
// See http://msdn.microsoft.com/en-us/library/hskdteyh.aspx
2019-08-02 21:33:58 +00:00
int CPUInfo[4] = { -1 };
#if defined(__clang__) || defined(__GNUC__)
2019-08-02 21:33:58 +00:00
__cpuid(0, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]);
#else
__cpuid(CPUInfo, 0);
#endif
2016-08-22 18:43:47 +00:00
if ( CPUInfo[0] < 1 )
return false;
#if defined(__clang__) || defined(__GNUC__)
2019-08-02 21:33:58 +00:00
__cpuid(1, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]);
#else
__cpuid(CPUInfo, 1);
#endif
2016-08-22 18:43:47 +00:00
// Check for SSSE3 instruction set.
return ( (CPUInfo[2] & 0x200) != 0 );
}
inline XMVECTOR XM_CALLCONV XMVectorEndian
(
FXMVECTOR V
)
{
2019-08-02 21:33:58 +00:00
static const XMVECTORU32 idx = { { { 0x00010203u, 0x04050607u, 0x08090A0Bu, 0x0C0D0E0Fu } } };
2016-08-22 18:43:47 +00:00
__m128i Result = _mm_shuffle_epi8( _mm_castps_si128(V), idx );
return _mm_castsi128_ps( Result );
}
2018-02-24 06:41:42 +00:00
} // namespace SSSE3
2019-08-02 21:33:58 +00:00
#endif // X86 || X64
2016-08-22 18:43:47 +00:00
2019-08-02 21:33:58 +00:00
} // namespace DirectX