1
0
mirror of https://github.com/microsoft/DirectXMath synced 2024-11-21 20:00:12 +00:00

XMVectorRound fix for NO INTRINICS to match round to nearest (even)

This commit is contained in:
Chuck Walbourn 2016-10-27 00:02:18 -07:00
parent 25558020ce
commit d98156cdb7
4 changed files with 5 additions and 34 deletions

View File

@ -200,7 +200,7 @@ inline XMVECTOR CalculateEigenVector( _In_ float m11, _In_ float m12, _In_ float
fTmp[1] = ( float )( m13 * m12 - m23 * ( m11 - e ) );
fTmp[2] = ( float )( ( m11 - e ) * ( m22 - e ) - m12 * m12 );
XMVECTOR vTmp = XMLoadFloat3( (XMFLOAT3*)fTmp );
XMVECTOR vTmp = XMLoadFloat3( reinterpret_cast<const XMFLOAT3*>(fTmp) );
if( XMVector3Equal( vTmp, XMVectorZero() ) ) // planar or linear
{

View File

@ -126,15 +126,6 @@
#include <sal.h>
#include <assert.h>
#ifndef _XM_NO_ROUNDF_
#ifdef _MSC_VER
#include <yvals.h>
#if defined(_CPPLIB_VER) && ( _CPPLIB_VER < 610 )
#define _XM_NO_ROUNDF_
#endif
#endif
#endif
#pragma warning(push)
#pragma warning(disable : 4005 4668)
// C4005/4668: Old header issue

View File

@ -14,8 +14,8 @@
#pragma once
#if defined(_XM_NO_INTRINSICS_)
#define XMISNAN(x) ((*(uint32_t*)&(x) & 0x7F800000) == 0x7F800000 && (*(uint32_t*)&(x) & 0x7FFFFF) != 0)
#define XMISINF(x) ((*(uint32_t*)&(x) & 0x7FFFFFFF) == 0x7F800000)
#define XMISNAN(x) ((*(const uint32_t*)&(x) & 0x7F800000) == 0x7F800000 && (*(const uint32_t*)&(x) & 0x7FFFFF) != 0)
#define XMISINF(x) ((*(const uint32_t*)&(x) & 0x7FFFFFFF) == 0x7F800000)
#endif
#if defined(_XM_SSE_INTRINSICS_)
@ -2309,10 +2309,9 @@ inline XMVECTOR XM_CALLCONV XMVectorMax
//------------------------------------------------------------------------------
#ifdef _XM_NO_ROUNDF_
namespace Internal
{
// Round to nearest (even) a.k.a. banker's rounding
inline float round_to_nearest( float x )
{
float i = floorf(x);
@ -2323,7 +2322,7 @@ namespace Internal
return i + 1.f;
float int_part;
modff( i / 2.f, &int_part );
(void)modff( i / 2.f, &int_part );
if ( (2.f*int_part) == i )
{
return i;
@ -2333,8 +2332,6 @@ namespace Internal
}
};
#endif
#if !defined(_XM_NO_INTRINSICS_)
#pragma float_control(push)
#pragma float_control(precise, on)
@ -2347,21 +2344,12 @@ inline XMVECTOR XM_CALLCONV XMVectorRound
{
#if defined(_XM_NO_INTRINSICS_)
#ifdef _XM_NO_ROUNDF_
XMVECTOR Result;
Result.vector4_f32[0] = Internal::round_to_nearest( V.vector4_f32[0] );
Result.vector4_f32[1] = Internal::round_to_nearest( V.vector4_f32[1] );
Result.vector4_f32[2] = Internal::round_to_nearest( V.vector4_f32[2] );
Result.vector4_f32[3] = Internal::round_to_nearest( V.vector4_f32[3] );
return Result;
#else
XMVECTOR Result;
Result.vector4_f32[0] = roundf( V.vector4_f32[0] );
Result.vector4_f32[1] = roundf( V.vector4_f32[1] );
Result.vector4_f32[2] = roundf( V.vector4_f32[2] );
Result.vector4_f32[3] = roundf( V.vector4_f32[3] );
return Result;
#endif
#elif defined(_XM_ARM_NEON_INTRINSICS_)
uint32x4_t sign = vandq_u32( V, g_XMNegativeZero );

View File

@ -2479,15 +2479,9 @@ inline void XM_CALLCONV PackedVector::XMStoreFloat3SE
fi.i = 0x83000000 - (exp << 23);
float ScaleR = fi.f;
#ifdef _XM_NO_ROUNDF_
pDestination->xm = static_cast<uint32_t>( Internal::round_to_nearest(x * ScaleR) );
pDestination->ym = static_cast<uint32_t>( Internal::round_to_nearest(y * ScaleR) );
pDestination->zm = static_cast<uint32_t>( Internal::round_to_nearest(z * ScaleR) );
#else
pDestination->xm = static_cast<uint32_t>( lroundf(x * ScaleR) );
pDestination->ym = static_cast<uint32_t>( lroundf(y * ScaleR) );
pDestination->zm = static_cast<uint32_t>( lroundf(z * ScaleR) );
#endif
}
//------------------------------------------------------------------------------
@ -4364,5 +4358,3 @@ inline PackedVector::XMU555::XMU555
XMVECTOR V = XMLoadFloat3(reinterpret_cast<const XMFLOAT3*>(pArray));
XMStoreU555(this, XMVectorSetW(V, ((_w) ? 1.0f : 0.0f) ));
}