microsoft / DirectXMath

DirectXMath is an all inline SIMD C++ linear algebra library for use in games and graphics apps
https://walbourn.github.io/introducing-directxmath/
MIT License
1.52k stars 234 forks source link

XMStoreByteN4 fails to clamp properly in no-intrinsics mode #111

Closed walbourn closed 4 years ago

walbourn commented 4 years ago
_Use_decl_annotations_
inline void XM_CALLCONV XMStoreByteN4
(
    XMBYTEN4* pDestination,
    FXMVECTOR V
)
{
    assert(pDestination);
#if defined(_XM_NO_INTRINSICS_)

    XMVECTOR N = XMVectorClamp(V, g_XMNegativeOne.v, g_XMOne.v);
    N = XMVectorMultiply(V, g_ByteMax);
    N = XMVectorTruncate(N);

    XMFLOAT4A tmp;
    XMStoreFloat4A(&tmp, N );
    pDestination->x = static_cast<int8_t>(tmp.x);
    pDestination->y = static_cast<int8_t>(tmp.y);
    pDestination->z = static_cast<int8_t>(tmp.z);
    pDestination->w = static_cast<int8_t>(tmp.w);
#elif defined(_XM_ARM_NEON_INTRINSICS_)

should be:

    XMVECTOR N = XMVectorClamp(V, g_XMNegativeOne.v, g_XMOne.v);
    N = XMVectorMultiply(N, g_ByteMax);
    N = XMVectorTruncate(N);
walbourn commented 4 years ago

Fixed in this commit