1717#error DirectX Math requires C++
1818#endif
1919
20- #define DIRECTX_MATH_VERSION 302
20+ #define DIRECTX_MATH_VERSION 303
2121
2222#if !defined(_XM_BIGENDIAN_) && !defined(_XM_LITTLEENDIAN_)
2323#if defined(_M_AMD64) || defined(_M_IX86) || defined(_M_ARM)
2929#endif
3030#endif // !_XM_BIGENDIAN_ && !_XM_LITTLEENDIAN_
3131
32+
33+
3234#if !defined(_XM_ARM_NEON_INTRINSICS_) && !defined(_XM_SSE_INTRINSICS_) && !defined(_XM_VMX128_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_)
3335#if defined(_M_IX86) || defined(_M_AMD64)
3436#define _XM_SSE_INTRINSICS_
6264#endif
6365#endif
6466
65- #ifdef _WIN32_WCE
66- inline float powf (float _X, float _Y) { return ((float )pow ((double )_X, (double )_Y)); }
67- inline float logf (float _X) { return ((float )log ((double )_X)); }
68- inline float tanf (float _X) { return ((float )tan ((double )_X)); }
69- inline float atanf (float _X) { return ((float )atan ((double )_X)); }
70- inline float sinhf (float _X) { return ((float )sinh ((double )_X)); }
71- inline float coshf (float _X) { return ((float )cosh ((double )_X)); }
72- inline float tanhf (float _X) { return ((float )tanh ((double )_X)); }
73- #endif
67+
7468
7569#include < sal.h>
7670#include < assert.h>
@@ -261,8 +255,8 @@ __declspec(align(16)) struct XMVECTORF32
261255 inline operator XMVECTOR () const { return v; }
262256 inline operator const float *() const { return f; }
263257#if !defined(_XM_NO_INTRINSICS_) && defined(_XM_SSE_INTRINSICS_)
264- inline operator __m128i () const { return reinterpret_cast < const __m128i *>(&v)[ 0 ] ; }
265- inline operator __m128d () const { return reinterpret_cast < const __m128d *>(&v)[ 0 ] ; }
258+ inline operator __m128i () const { return _mm_castps_si128 (v) ; }
259+ inline operator __m128d () const { return _mm_castps_pd (v) ; }
266260#endif
267261};
268262
@@ -276,8 +270,8 @@ __declspec(align(16)) struct XMVECTORI32
276270
277271 inline operator XMVECTOR () const { return v; }
278272#if !defined(_XM_NO_INTRINSICS_) && defined(_XM_SSE_INTRINSICS_)
279- inline operator __m128i () const { return reinterpret_cast < const __m128i *>(&v)[ 0 ] ; }
280- inline operator __m128d () const { return reinterpret_cast < const __m128d *>(&v)[ 0 ] ; }
273+ inline operator __m128i () const { return _mm_castps_si128 (v) ; }
274+ inline operator __m128d () const { return _mm_castps_pd (v) ; }
281275#endif
282276};
283277
@@ -291,8 +285,8 @@ __declspec(align(16)) struct XMVECTORU8
291285
292286 inline operator XMVECTOR () const { return v; }
293287#if !defined(_XM_NO_INTRINSICS_) && defined(_XM_SSE_INTRINSICS_)
294- inline operator __m128i () const { return reinterpret_cast < const __m128i *>(&v)[ 0 ] ; }
295- inline operator __m128d () const { return reinterpret_cast < const __m128d *>(&v)[ 0 ] ; }
288+ inline operator __m128i () const { return _mm_castps_si128 (v) ; }
289+ inline operator __m128d () const { return _mm_castps_pd (v) ; }
296290#endif
297291};
298292
@@ -306,8 +300,8 @@ __declspec(align(16)) struct XMVECTORU32
306300
307301 inline operator XMVECTOR () const { return v; }
308302#if !defined(_XM_NO_INTRINSICS_) && defined(_XM_SSE_INTRINSICS_)
309- inline operator __m128i () const { return reinterpret_cast < const __m128i *>(&v)[ 0 ] ; }
310- inline operator __m128d () const { return reinterpret_cast < const __m128d *>(&v)[ 0 ] ; }
303+ inline operator __m128i () const { return _mm_castps_si128 (v) ; }
304+ inline operator __m128d () const { return _mm_castps_pd (v) ; }
311305#endif
312306};
313307
@@ -350,6 +344,7 @@ struct XMMATRIX
350344__declspec (align(16 )) struct XMMATRIX
351345#endif
352346{
347+ #ifdef _XM_NO_INTRINSICS_
353348 union
354349 {
355350 XMVECTOR r[4 ];
@@ -362,6 +357,9 @@ __declspec(align(16)) struct XMMATRIX
362357 };
363358 float m[4 ][4 ];
364359 };
360+ #else
361+ XMVECTOR r[4 ];
362+ #endif
365363
366364 XMMATRIX () {}
367365 XMMATRIX (FXMVECTOR R0, FXMVECTOR R1, FXMVECTOR R2, GXMVECTOR R3) { r[0 ] = R0; r[1 ] = R1; r[2 ] = R2; r[3 ] = R3; }
@@ -371,8 +369,10 @@ __declspec(align(16)) struct XMMATRIX
371369 float m30, float m31, float m32, float m33);
372370 explicit XMMATRIX (_In_reads_(16 ) const float *pArray);
373371
372+ #ifdef _XM_NO_INTRINSICS_
374373 float operator () (size_t Row, size_t Column) const { return m[Row][Column]; }
375374 float & operator () (size_t Row, size_t Column) { return m[Row][Column]; }
375+ #endif
376376
377377 XMMATRIX& operator = (const XMMATRIX& M) { r[0 ] = M.r [0 ]; r[1 ] = M.r [1 ]; r[2 ] = M.r [2 ]; r[3 ] = M.r [3 ]; return *this ; }
378378
@@ -403,7 +403,7 @@ struct XMFLOAT2
403403
404404 XMFLOAT2 () {}
405405 XMFLOAT2 (float _x, float _y) : x(_x), y(_y) {}
406- XMFLOAT2 (_In_reads_(2 ) const float *pArray) : x(pArray[0 ]), y(pArray[1 ]) {}
406+ explicit XMFLOAT2 (_In_reads_(2 ) const float *pArray) : x(pArray[0 ]), y(pArray[1 ]) {}
407407
408408 XMFLOAT2& operator = (const XMFLOAT2& Float2) { x = Float2.x ; y = Float2.y ; return *this ; }
409409};
@@ -413,7 +413,7 @@ __declspec(align(16)) struct XMFLOAT2A : public XMFLOAT2
413413{
414414 XMFLOAT2A () : XMFLOAT2 () {}
415415 XMFLOAT2A (float _x, float _y) : XMFLOAT2 (_x, _y) {}
416- XMFLOAT2A (_In_reads_ (2 ) const float *pArray) : XMFLOAT2 (pArray) {}
416+ explicit XMFLOAT2A (_In_reads_ (2 ) const float *pArray) : XMFLOAT2 (pArray) {}
417417
418418 XMFLOAT2A& operator = (const XMFLOAT2A& Float2) { x = Float2.x ; y = Float2.y ; return *this ; }
419419};
@@ -455,7 +455,7 @@ struct XMFLOAT3
455455
456456 XMFLOAT3 () {}
457457 XMFLOAT3 (float _x, float _y, float _z) : x(_x), y(_y), z(_z) {}
458- XMFLOAT3 (_In_reads_(3 ) const float *pArray) : x(pArray[0 ]), y(pArray[1 ]), z(pArray[2 ]) {}
458+ explicit XMFLOAT3 (_In_reads_(3 ) const float *pArray) : x(pArray[0 ]), y(pArray[1 ]), z(pArray[2 ]) {}
459459
460460 XMFLOAT3& operator = (const XMFLOAT3& Float3) { x = Float3.x ; y = Float3.y ; z = Float3.z ; return *this ; }
461461};
@@ -465,7 +465,7 @@ __declspec(align(16)) struct XMFLOAT3A : public XMFLOAT3
465465{
466466 XMFLOAT3A () : XMFLOAT3 () {}
467467 XMFLOAT3A (float _x, float _y, float _z) : XMFLOAT3 (_x, _y, _z) {}
468- XMFLOAT3A (_In_reads_ (3 ) const float *pArray) : XMFLOAT3 (pArray) {}
468+ explicit XMFLOAT3A (_In_reads_ (3 ) const float *pArray) : XMFLOAT3 (pArray) {}
469469
470470 XMFLOAT3A& operator = (const XMFLOAT3A& Float3) { x = Float3.x ; y = Float3.y ; z = Float3.z ; return *this ; }
471471};
@@ -482,7 +482,7 @@ struct XMINT3
482482 XMINT3 (int32_t _x, int32_t _y, int32_t _z) : x(_x), y(_y), z(_z) {}
483483 explicit XMINT3 (_In_reads_(3 ) const int32_t *pArray) : x(pArray[0 ]), y(pArray[1 ]), z(pArray[2 ]) {}
484484
485- XMINT3& operator = (const XMINT3& Int3 ) { x = Int3 .x ; y = Int3 .y ; z = Int3 .z ; return *this ; }
485+ XMINT3& operator = (const XMINT3& i3 ) { x = i3 .x ; y = i3 .y ; z = i3 .z ; return *this ; }
486486};
487487
488488// 3D Vector; 32 bit unsigned integer components
@@ -496,7 +496,7 @@ struct XMUINT3
496496 XMUINT3 (uint32_t _x, uint32_t _y, uint32_t _z) : x(_x), y(_y), z(_z) {}
497497 explicit XMUINT3 (_In_reads_(3 ) const uint32_t *pArray) : x(pArray[0 ]), y(pArray[1 ]), z(pArray[2 ]) {}
498498
499- XMUINT3& operator = (const XMUINT3& UInt3 ) { x = UInt3 .x ; y = UInt3 .y ; z = UInt3 .z ; return *this ; }
499+ XMUINT3& operator = (const XMUINT3& u3 ) { x = u3 .x ; y = u3 .y ; z = u3 .z ; return *this ; }
500500};
501501
502502// ------------------------------------------------------------------------------
@@ -510,7 +510,7 @@ struct XMFLOAT4
510510
511511 XMFLOAT4 () {}
512512 XMFLOAT4 (float _x, float _y, float _z, float _w) : x(_x), y(_y), z(_z), w(_w) {}
513- XMFLOAT4 (_In_reads_(4 ) const float *pArray) : x(pArray[0 ]), y(pArray[1 ]), z(pArray[2 ]), w(pArray[3 ]) {}
513+ explicit XMFLOAT4 (_In_reads_(4 ) const float *pArray) : x(pArray[0 ]), y(pArray[1 ]), z(pArray[2 ]), w(pArray[3 ]) {}
514514
515515 XMFLOAT4& operator = (const XMFLOAT4& Float4) { x = Float4.x ; y = Float4.y ; z = Float4.z ; w = Float4.w ; return *this ; }
516516};
@@ -520,7 +520,7 @@ __declspec(align(16)) struct XMFLOAT4A : public XMFLOAT4
520520{
521521 XMFLOAT4A () : XMFLOAT4 () {}
522522 XMFLOAT4A (float _x, float _y, float _z, float _w) : XMFLOAT4 (_x, _y, _z, _w) {}
523- XMFLOAT4A (_In_reads_ (4 ) const float *pArray) : XMFLOAT4 (pArray) {}
523+ explicit XMFLOAT4A (_In_reads_ (4 ) const float *pArray) : XMFLOAT4 (pArray) {}
524524
525525 XMFLOAT4A& operator = (const XMFLOAT4A& Float4) { x = Float4.x ; y = Float4.y ; z = Float4.z ; w = Float4.w ; return *this ; }
526526};
@@ -1368,6 +1368,8 @@ template<class T> inline T XMMax(T a, T b) { return (a > b) ? a : b; }
13681368
13691369#if defined(_XM_SSE_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_)
13701370
1371+ #define XM_PERMUTE_PS ( v, c ) _mm_shuffle_ps( v, v, c )
1372+
13711373// PermuteHelper internal template (SSE only)
13721374namespace Internal
13731375{
@@ -1384,8 +1386,8 @@ namespace Internal
13841386 WhichW ? 0xFFFFFFFF : 0 ,
13851387 };
13861388
1387- XMVECTOR shuffled1 = _mm_shuffle_ps (v1, v1, Shuffle);
1388- XMVECTOR shuffled2 = _mm_shuffle_ps (v2, v2, Shuffle);
1389+ XMVECTOR shuffled1 = XM_PERMUTE_PS ( v1, Shuffle);
1390+ XMVECTOR shuffled2 = XM_PERMUTE_PS ( v2, Shuffle);
13891391
13901392 XMVECTOR masked1 = _mm_andnot_ps (selectMask, shuffled1);
13911393 XMVECTOR masked2 = _mm_and_ps (selectMask, shuffled2);
@@ -1397,13 +1399,13 @@ namespace Internal
13971399 // Fast path for permutes that only read from the first vector.
13981400 template <uint32_t Shuffle> struct PermuteHelper <Shuffle, false , false , false , false >
13991401 {
1400- static XMVECTOR Permute (FXMVECTOR v1, FXMVECTOR v2) { (v2); return _mm_shuffle_ps (v1, v1, Shuffle); }
1402+ static XMVECTOR Permute (FXMVECTOR v1, FXMVECTOR v2) { (v2); return XM_PERMUTE_PS ( v1, Shuffle); }
14011403 };
14021404
14031405 // Fast path for permutes that only read from the second vector.
14041406 template <uint32_t Shuffle> struct PermuteHelper <Shuffle, true , true , true , true >
14051407 {
1406- static XMVECTOR Permute (FXMVECTOR v1, FXMVECTOR v2){ (v1); return _mm_shuffle_ps (v2, v2, Shuffle); }
1408+ static XMVECTOR Permute (FXMVECTOR v1, FXMVECTOR v2){ (v1); return XM_PERMUTE_PS ( v2, Shuffle); }
14071409 };
14081410
14091411 // Fast path for permutes that read XY from the first vector, ZW from the second.
@@ -1488,7 +1490,7 @@ template<> inline XMVECTOR XMVectorPermute<1,2,3,4>(FXMVECTOR V1, FXMVECTOR V2)
14881490template <> inline XMVECTOR XMVectorPermute<2 ,3 ,4 ,5 >(FXMVECTOR V1, FXMVECTOR V2) { return vextq_f32 (V1, V2, 2 ); }
14891491template <> inline XMVECTOR XMVectorPermute<3 ,4 ,5 ,6 >(FXMVECTOR V1, FXMVECTOR V2) { return vextq_f32 (V1, V2, 3 ); }
14901492
1491- #endif _XM_ARM_NEON_INTRINSICS_ && !_XM_NO_INTRINSICS_
1493+ #endif // _XM_ARM_NEON_INTRINSICS_ && !_XM_NO_INTRINSICS_
14921494
14931495// ------------------------------------------------------------------------------
14941496
@@ -1502,7 +1504,7 @@ template<uint32_t SwizzleX, uint32_t SwizzleY, uint32_t SwizzleZ, uint32_t Swizz
15021504 static_assert (SwizzleW <= 3 , " SwizzleW template parameter out of range" );
15031505
15041506#if defined(_XM_SSE_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_)
1505- return _mm_shuffle_ps ( V, V, _MM_SHUFFLE ( SwizzleW, SwizzleZ, SwizzleY, SwizzleX ) );
1507+ return XM_PERMUTE_PS ( V, _MM_SHUFFLE ( SwizzleW, SwizzleZ, SwizzleY, SwizzleX ) );
15061508#elif defined(_XM_VMX128_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_)
15071509 return __vpermwi (V, ((SwizzleX & 3 ) << 6 ) | ((SwizzleY & 3 ) << 4 ) | ((SwizzleZ & 3 ) << 2 ) | (SwizzleW & 3 ) );
15081510#else
@@ -1515,6 +1517,7 @@ template<uint32_t SwizzleX, uint32_t SwizzleY, uint32_t SwizzleZ, uint32_t Swizz
15151517// Specialized swizzles
15161518template <> inline XMVECTOR XMVectorSwizzle<0 ,1 ,2 ,3 >(FXMVECTOR V) { return V; }
15171519
1520+
15181521#if defined(_XM_ARM_NEON_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_)
15191522
15201523template <> inline XMVECTOR XMVectorSwizzle<0 ,0 ,0 ,0 >(FXMVECTOR V) { return vdupq_lane_f32 ( vget_low_f32 (V), 0 ); }
@@ -1548,7 +1551,7 @@ template<> inline XMVECTOR XMVectorSwizzle<1,2,3,0>(FXMVECTOR V) { return vextq_
15481551template <> inline XMVECTOR XMVectorSwizzle<2 ,3 ,0 ,1 >(FXMVECTOR V) { return vextq_f32 (V, V, 2 ); }
15491552template <> inline XMVECTOR XMVectorSwizzle<3 ,0 ,1 ,2 >(FXMVECTOR V) { return vextq_f32 (V, V, 3 ); }
15501553
1551- #endif _XM_ARM_NEON_INTRINSICS_ && !_XM_NO_INTRINSICS_
1554+ #endif // _XM_ARM_NEON_INTRINSICS_ && !_XM_NO_INTRINSICS_
15521555
15531556// ------------------------------------------------------------------------------
15541557
@@ -1760,7 +1763,7 @@ inline XMVECTOR XMVectorSetBinaryConstant(uint32_t C0, uint32_t C1, uint32_t C2,
17601763 vTemp = _mm_cmpeq_epi32 (vTemp,g_vMask1);
17611764 // 0xFFFFFFFF -> 1.0f, 0x00000000 -> 0.0f
17621765 vTemp = _mm_and_si128 (vTemp,g_XMOne);
1763- return reinterpret_cast < const __m128 *>(& vTemp)[ 0 ] ;
1766+ return _mm_castsi128_ps ( vTemp);
17641767#endif
17651768}
17661769
@@ -1799,7 +1802,7 @@ inline XMVECTOR XMVectorSplatConstant(int32_t IntConstant, uint32_t DivExponent)
17991802 // Splat the scalar value (It's really a float)
18001803 vScale = _mm_set1_epi32 (uScale);
18011804 // Multiply by the reciprocal (Perform a right shift by DivExponent)
1802- vResult = _mm_mul_ps (vResult,reinterpret_cast < const __m128 *>(& vScale)[ 0 ] );
1805+ vResult = _mm_mul_ps (vResult,_mm_castsi128_ps ( vScale));
18031806 return vResult;
18041807#endif
18051808}
@@ -1824,13 +1827,14 @@ inline XMVECTOR XMVectorSplatConstantInt(int32_t IntConstant)
18241827}
18251828
18261829// Implemented for VMX128 intrinsics as #defines aboves
1827- #endif _XM_NO_INTRINSICS_ || _XM_SSE_INTRINSICS_ || _XM_ARM_NEON_INTRINSICS_
1830+ #endif // _XM_NO_INTRINSICS_ || _XM_SSE_INTRINSICS_ || _XM_ARM_NEON_INTRINSICS_
18281831
18291832#include " DirectXMathConvert.inl"
18301833#include " DirectXMathVector.inl"
18311834#include " DirectXMathMatrix.inl"
18321835#include " DirectXMathMisc.inl"
18331836
1837+
18341838#pragma prefast(pop)
18351839#pragma warning(pop)
18361840
0 commit comments