1
0
mirror of https://github.com/microsoft/DirectXMath synced 2024-11-22 12:20:06 +00:00
DirectXMath/Extensions/DirectXMathSSE3.h
2018-02-23 23:16:27 -08:00

111 lines
2.3 KiB
C++

//-------------------------------------------------------------------------------------
// DirectXMathSSE3.h -- SSE3 extensions for SIMD C++ Math library
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//
// http://go.microsoft.com/fwlink/?LinkID=615560
//-------------------------------------------------------------------------------------
#ifdef _MSC_VER
#pragma once
#endif
#ifdef _M_ARM
#error SSE3 not supported on ARM platform
#endif
#pragma warning(push)
#pragma warning(disable : 4987)
#include <intrin.h>
#pragma warning(pop)
#include <pmmintrin.h>
#include <DirectXMath.h>
namespace DirectX
{
namespace SSE3
{
inline bool XMVerifySSE3Support()
{
// Should return true on AMD Athlon 64, AMD Phenom, and Intel Pentium 4 or later processors
// See http://msdn.microsoft.com/en-us/library/hskdteyh.aspx
int CPUInfo[4] = {-1};
__cpuid( CPUInfo, 0 );
if ( CPUInfo[0] < 1 )
return false;
__cpuid(CPUInfo, 1 );
// We only check for SSE3 instruction set. SSSE3 instructions are not used.
return ( (CPUInfo[2] & 0x1) != 0 );
}
inline XMVECTOR XM_CALLCONV XMVector2Dot
(
FXMVECTOR V1,
FXMVECTOR V2
)
{
XMVECTOR vTemp = _mm_mul_ps(V1,V2);
vTemp = _mm_hadd_ps(vTemp,vTemp);
return _mm_shuffle_ps(vTemp,vTemp,_MM_SHUFFLE(0,0,0,0));
}
inline XMVECTOR XM_CALLCONV XMVector2LengthSq( FXMVECTOR V )
{
return SSE3::XMVector2Dot(V, V);
}
inline XMVECTOR XM_CALLCONV XMVector3Dot
(
FXMVECTOR V1,
FXMVECTOR V2
)
{
XMVECTOR vTemp = _mm_mul_ps(V1,V2);
vTemp = _mm_and_ps( vTemp, g_XMMask3 );
vTemp = _mm_hadd_ps(vTemp,vTemp);
return _mm_hadd_ps(vTemp,vTemp);
}
inline XMVECTOR XM_CALLCONV XMVector3LengthSq( FXMVECTOR V )
{
return SSE3::XMVector3Dot(V, V);
}
inline XMVECTOR XM_CALLCONV XMVector4Dot
(
FXMVECTOR V1,
FXMVECTOR V2
)
{
XMVECTOR vTemp = _mm_mul_ps(V1,V2);
vTemp = _mm_hadd_ps( vTemp, vTemp );
return _mm_hadd_ps( vTemp, vTemp );
}
inline XMVECTOR XM_CALLCONV XMVector4LengthSq( FXMVECTOR V )
{
return SSE3::XMVector4Dot(V, V);
}
inline XMVECTOR XM_CALLCONV XMVectorSwizzle_0022( FXMVECTOR V )
{
return _mm_moveldup_ps(V);
}
inline XMVECTOR XM_CALLCONV XMVectorSwizzle_1133( FXMVECTOR V )
{
return _mm_movehdup_ps(V);
}
} // namespace SSE3
} // namespace DirectX;