17
17
#error DirectX Math requires C++
18
18
#endif
19
19
20
- #define DIRECTX_MATH_VERSION 302
20
+ #define DIRECTX_MATH_VERSION 303
21
21
22
22
#if !defined(_XM_BIGENDIAN_) && !defined(_XM_LITTLEENDIAN_)
23
23
#if defined(_M_AMD64) || defined(_M_IX86) || defined(_M_ARM)
29
29
#endif
30
30
#endif // !_XM_BIGENDIAN_ && !_XM_LITTLEENDIAN_
31
31
32
+
33
+
32
34
#if !defined(_XM_ARM_NEON_INTRINSICS_) && !defined(_XM_SSE_INTRINSICS_) && !defined(_XM_VMX128_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_)
33
35
#if defined(_M_IX86) || defined(_M_AMD64)
34
36
#define _XM_SSE_INTRINSICS_
62
64
#endif
63
65
#endif
64
66
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
+
74
68
75
69
#include < sal.h>
76
70
#include < assert.h>
@@ -261,8 +255,8 @@ __declspec(align(16)) struct XMVECTORF32
261
255
inline operator XMVECTOR () const { return v; }
262
256
inline operator const float *() const { return f; }
263
257
#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) ; }
266
260
#endif
267
261
};
268
262
@@ -276,8 +270,8 @@ __declspec(align(16)) struct XMVECTORI32
276
270
277
271
inline operator XMVECTOR () const { return v; }
278
272
#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) ; }
281
275
#endif
282
276
};
283
277
@@ -291,8 +285,8 @@ __declspec(align(16)) struct XMVECTORU8
291
285
292
286
inline operator XMVECTOR () const { return v; }
293
287
#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) ; }
296
290
#endif
297
291
};
298
292
@@ -306,8 +300,8 @@ __declspec(align(16)) struct XMVECTORU32
306
300
307
301
inline operator XMVECTOR () const { return v; }
308
302
#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) ; }
311
305
#endif
312
306
};
313
307
@@ -350,6 +344,7 @@ struct XMMATRIX
350
344
__declspec (align(16 )) struct XMMATRIX
351
345
#endif
352
346
{
347
+ #ifdef _XM_NO_INTRINSICS_
353
348
union
354
349
{
355
350
XMVECTOR r[4 ];
@@ -362,6 +357,9 @@ __declspec(align(16)) struct XMMATRIX
362
357
};
363
358
float m[4 ][4 ];
364
359
};
360
+ #else
361
+ XMVECTOR r[4 ];
362
+ #endif
365
363
366
364
XMMATRIX () {}
367
365
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
371
369
float m30, float m31, float m32, float m33);
372
370
explicit XMMATRIX (_In_reads_(16 ) const float *pArray);
373
371
372
+ #ifdef _XM_NO_INTRINSICS_
374
373
float operator () (size_t Row, size_t Column) const { return m[Row][Column]; }
375
374
float & operator () (size_t Row, size_t Column) { return m[Row][Column]; }
375
+ #endif
376
376
377
377
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 ; }
378
378
@@ -403,7 +403,7 @@ struct XMFLOAT2
403
403
404
404
XMFLOAT2 () {}
405
405
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 ]) {}
407
407
408
408
XMFLOAT2& operator = (const XMFLOAT2& Float2) { x = Float2.x ; y = Float2.y ; return *this ; }
409
409
};
@@ -413,7 +413,7 @@ __declspec(align(16)) struct XMFLOAT2A : public XMFLOAT2
413
413
{
414
414
XMFLOAT2A () : XMFLOAT2 () {}
415
415
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) {}
417
417
418
418
XMFLOAT2A& operator = (const XMFLOAT2A& Float2) { x = Float2.x ; y = Float2.y ; return *this ; }
419
419
};
@@ -455,7 +455,7 @@ struct XMFLOAT3
455
455
456
456
XMFLOAT3 () {}
457
457
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 ]) {}
459
459
460
460
XMFLOAT3& operator = (const XMFLOAT3& Float3) { x = Float3.x ; y = Float3.y ; z = Float3.z ; return *this ; }
461
461
};
@@ -465,7 +465,7 @@ __declspec(align(16)) struct XMFLOAT3A : public XMFLOAT3
465
465
{
466
466
XMFLOAT3A () : XMFLOAT3 () {}
467
467
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) {}
469
469
470
470
XMFLOAT3A& operator = (const XMFLOAT3A& Float3) { x = Float3.x ; y = Float3.y ; z = Float3.z ; return *this ; }
471
471
};
@@ -482,7 +482,7 @@ struct XMINT3
482
482
XMINT3 (int32_t _x, int32_t _y, int32_t _z) : x(_x), y(_y), z(_z) {}
483
483
explicit XMINT3 (_In_reads_(3 ) const int32_t *pArray) : x(pArray[0 ]), y(pArray[1 ]), z(pArray[2 ]) {}
484
484
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 ; }
486
486
};
487
487
488
488
// 3D Vector; 32 bit unsigned integer components
@@ -496,7 +496,7 @@ struct XMUINT3
496
496
XMUINT3 (uint32_t _x, uint32_t _y, uint32_t _z) : x(_x), y(_y), z(_z) {}
497
497
explicit XMUINT3 (_In_reads_(3 ) const uint32_t *pArray) : x(pArray[0 ]), y(pArray[1 ]), z(pArray[2 ]) {}
498
498
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 ; }
500
500
};
501
501
502
502
// ------------------------------------------------------------------------------
@@ -510,7 +510,7 @@ struct XMFLOAT4
510
510
511
511
XMFLOAT4 () {}
512
512
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 ]) {}
514
514
515
515
XMFLOAT4& operator = (const XMFLOAT4& Float4) { x = Float4.x ; y = Float4.y ; z = Float4.z ; w = Float4.w ; return *this ; }
516
516
};
@@ -520,7 +520,7 @@ __declspec(align(16)) struct XMFLOAT4A : public XMFLOAT4
520
520
{
521
521
XMFLOAT4A () : XMFLOAT4 () {}
522
522
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) {}
524
524
525
525
XMFLOAT4A& operator = (const XMFLOAT4A& Float4) { x = Float4.x ; y = Float4.y ; z = Float4.z ; w = Float4.w ; return *this ; }
526
526
};
@@ -1368,6 +1368,8 @@ template<class T> inline T XMMax(T a, T b) { return (a > b) ? a : b; }
1368
1368
1369
1369
#if defined(_XM_SSE_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_)
1370
1370
1371
+ #define XM_PERMUTE_PS ( v, c ) _mm_shuffle_ps( v, v, c )
1372
+
1371
1373
// PermuteHelper internal template (SSE only)
1372
1374
namespace Internal
1373
1375
{
@@ -1384,8 +1386,8 @@ namespace Internal
1384
1386
WhichW ? 0xFFFFFFFF : 0 ,
1385
1387
};
1386
1388
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);
1389
1391
1390
1392
XMVECTOR masked1 = _mm_andnot_ps (selectMask, shuffled1);
1391
1393
XMVECTOR masked2 = _mm_and_ps (selectMask, shuffled2);
@@ -1397,13 +1399,13 @@ namespace Internal
1397
1399
// Fast path for permutes that only read from the first vector.
1398
1400
template <uint32_t Shuffle> struct PermuteHelper <Shuffle, false , false , false , false >
1399
1401
{
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); }
1401
1403
};
1402
1404
1403
1405
// Fast path for permutes that only read from the second vector.
1404
1406
template <uint32_t Shuffle> struct PermuteHelper <Shuffle, true , true , true , true >
1405
1407
{
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); }
1407
1409
};
1408
1410
1409
1411
// 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)
1488
1490
template <> inline XMVECTOR XMVectorPermute<2 ,3 ,4 ,5 >(FXMVECTOR V1, FXMVECTOR V2) { return vextq_f32 (V1, V2, 2 ); }
1489
1491
template <> inline XMVECTOR XMVectorPermute<3 ,4 ,5 ,6 >(FXMVECTOR V1, FXMVECTOR V2) { return vextq_f32 (V1, V2, 3 ); }
1490
1492
1491
- #endif _XM_ARM_NEON_INTRINSICS_ && !_XM_NO_INTRINSICS_
1493
+ #endif // _XM_ARM_NEON_INTRINSICS_ && !_XM_NO_INTRINSICS_
1492
1494
1493
1495
// ------------------------------------------------------------------------------
1494
1496
@@ -1502,7 +1504,7 @@ template<uint32_t SwizzleX, uint32_t SwizzleY, uint32_t SwizzleZ, uint32_t Swizz
1502
1504
static_assert (SwizzleW <= 3 , " SwizzleW template parameter out of range" );
1503
1505
1504
1506
#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 ) );
1506
1508
#elif defined(_XM_VMX128_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_)
1507
1509
return __vpermwi (V, ((SwizzleX & 3 ) << 6 ) | ((SwizzleY & 3 ) << 4 ) | ((SwizzleZ & 3 ) << 2 ) | (SwizzleW & 3 ) );
1508
1510
#else
@@ -1515,6 +1517,7 @@ template<uint32_t SwizzleX, uint32_t SwizzleY, uint32_t SwizzleZ, uint32_t Swizz
1515
1517
// Specialized swizzles
1516
1518
template <> inline XMVECTOR XMVectorSwizzle<0 ,1 ,2 ,3 >(FXMVECTOR V) { return V; }
1517
1519
1520
+
1518
1521
#if defined(_XM_ARM_NEON_INTRINSICS_) && !defined(_XM_NO_INTRINSICS_)
1519
1522
1520
1523
template <> 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_
1548
1551
template <> inline XMVECTOR XMVectorSwizzle<2 ,3 ,0 ,1 >(FXMVECTOR V) { return vextq_f32 (V, V, 2 ); }
1549
1552
template <> inline XMVECTOR XMVectorSwizzle<3 ,0 ,1 ,2 >(FXMVECTOR V) { return vextq_f32 (V, V, 3 ); }
1550
1553
1551
- #endif _XM_ARM_NEON_INTRINSICS_ && !_XM_NO_INTRINSICS_
1554
+ #endif // _XM_ARM_NEON_INTRINSICS_ && !_XM_NO_INTRINSICS_
1552
1555
1553
1556
// ------------------------------------------------------------------------------
1554
1557
@@ -1760,7 +1763,7 @@ inline XMVECTOR XMVectorSetBinaryConstant(uint32_t C0, uint32_t C1, uint32_t C2,
1760
1763
vTemp = _mm_cmpeq_epi32 (vTemp,g_vMask1);
1761
1764
// 0xFFFFFFFF -> 1.0f, 0x00000000 -> 0.0f
1762
1765
vTemp = _mm_and_si128 (vTemp,g_XMOne);
1763
- return reinterpret_cast < const __m128 *>(& vTemp)[ 0 ] ;
1766
+ return _mm_castsi128_ps ( vTemp);
1764
1767
#endif
1765
1768
}
1766
1769
@@ -1799,7 +1802,7 @@ inline XMVECTOR XMVectorSplatConstant(int32_t IntConstant, uint32_t DivExponent)
1799
1802
// Splat the scalar value (It's really a float)
1800
1803
vScale = _mm_set1_epi32 (uScale);
1801
1804
// 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));
1803
1806
return vResult;
1804
1807
#endif
1805
1808
}
@@ -1824,13 +1827,14 @@ inline XMVECTOR XMVectorSplatConstantInt(int32_t IntConstant)
1824
1827
}
1825
1828
1826
1829
// 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_
1828
1831
1829
1832
#include " DirectXMathConvert.inl"
1830
1833
#include " DirectXMathVector.inl"
1831
1834
#include " DirectXMathMatrix.inl"
1832
1835
#include " DirectXMathMisc.inl"
1833
1836
1837
+
1834
1838
#pragma prefast(pop)
1835
1839
#pragma warning(pop)
1836
1840
0 commit comments