aboutsummaryrefslogtreecommitdiff
path: root/PxShared/src/foundation/include/PsVecMathAoSScalarInline.h
blob: 41f707a7c20c0f702ccd9735adb86dc1f9e5a0e5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//  * Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
//  * Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in the
//    documentation and/or other materials provided with the distribution.
//  * Neither the name of NVIDIA CORPORATION nor the names of its
//    contributors may be used to endorse or promote products derived
//    from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.

#ifndef PSFOUNDATION_PSVECMATHAOSSCALARINLINE_H
#define PSFOUNDATION_PSVECMATHAOSSCALARINLINE_H

#if COMPILE_VECTOR_INTRINSICS
#error Scalar version should not be included when using vector intrinsics.
#endif

namespace physx
{
namespace shdfnd
{
namespace aos
{

#define BOOL_TO_U32(b) (PxU32)(- PxI32(b))
#define TRUE_TO_U32 (PxU32)(-1)
#define FALSE_TO_U32 (PxU32)(0)

#define BOOL_TO_U16(b) (PxU16)(- PxI32(b))

#define PX_VECMATH_ASSERT_ENABLED 0

#if PX_VECMATH_ASSERT_ENABLED
#define VECMATHAOS_ASSERT(x) { PX_ASSERT(x); }
#else
#define VECMATHAOS_ASSERT(x)
#endif

/////////////////////////////////////////////////////////////////////
////INTERNAL USE ONLY AND TESTS
/////////////////////////////////////////////////////////////////////

namespace internalScalarSimd
{
PX_FORCE_INLINE PxF32 FStore(const FloatV a)
{
	return a.x;
}

PX_FORCE_INLINE bool hasZeroElementInFloatV(const FloatV a)
{
	return (0 == a.x);
}

PX_FORCE_INLINE bool hasZeroElementInVec3V(const Vec3V a)
{
	return (0 == a.x || 0 == a.y || 0 == a.z);
}

PX_FORCE_INLINE bool hasZeroElementInVec4V(const Vec4V a)
{
	return (0 == a.x || 0 == a.y || 0 == a.z || 0 == a.w);
}
}

namespace _VecMathTests
{
// PT: this function returns an invalid Vec3V (W!=0.0f) just for unit-testing 'isValidVec3V'
PX_FORCE_INLINE Vec3V getInvalidVec3V()
{
	Vec3V tmp;
	tmp.x = tmp.y = tmp.z = 0.0f;
	tmp.pad = 1.0f;
	return tmp;
}

PX_FORCE_INLINE bool allElementsEqualFloatV(const FloatV a, const FloatV b)
{
	return (a.x == b.x);
}

PX_FORCE_INLINE bool allElementsEqualVec3V(const Vec3V a, const Vec3V b)
{
	return (a.x == b.x && a.y == b.y && a.z == b.z);
}

PX_FORCE_INLINE bool allElementsEqualVec4V(const Vec4V a, const Vec4V b)
{
	return (a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w);
}

PX_FORCE_INLINE bool allElementsEqualBoolV(const BoolV a, const BoolV b)
{
	return (a.ux == b.ux && a.uy == b.uy && a.uz == b.uz && a.uw == b.uw);
}

PX_FORCE_INLINE bool allElementsEqualVecU32V(const VecU32V a, const VecU32V b)
{
	return (a.u32[0] == b.u32[0] && a.u32[1] == b.u32[1] && a.u32[2] == b.u32[2] && a.u32[3] == b.u32[3]);
}

PX_FORCE_INLINE bool allElementsEqualVecI32V(const VecI32V a, const VecI32V b)
{
	return (a.i32[0] == b.i32[0] && a.i32[1] == b.i32[1] && a.i32[2] == b.i32[2] && a.i32[3] == b.i32[3]);
}

#define VECMATH_AOS_EPSILON (1e-3f)

PX_FORCE_INLINE bool allElementsNearEqualFloatV(const FloatV a, const FloatV b)
{
	const PxF32 cx = a.x - b.x;
	return (cx > -VECMATH_AOS_EPSILON && cx < VECMATH_AOS_EPSILON);
}

PX_FORCE_INLINE bool allElementsNearEqualVec3V(const Vec3V a, const Vec3V b)
{
	const PxF32 cx = a.x - b.x;
	const PxF32 cy = a.y - b.y;
	const PxF32 cz = a.z - b.z;
	return (cx > -VECMATH_AOS_EPSILON && cx < VECMATH_AOS_EPSILON && cy > -VECMATH_AOS_EPSILON &&
	        cy < VECMATH_AOS_EPSILON && cz > -VECMATH_AOS_EPSILON && cz < VECMATH_AOS_EPSILON);
}

PX_FORCE_INLINE bool allElementsNearEqualVec4V(const Vec4V a, const Vec4V b)
{
	const PxF32 cx = a.x - b.x;
	const PxF32 cy = a.y - b.y;
	const PxF32 cz = a.z - b.z;
	const PxF32 cw = a.w - b.w;
	return (cx > -VECMATH_AOS_EPSILON && cx < VECMATH_AOS_EPSILON && cy > -VECMATH_AOS_EPSILON &&
	        cy < VECMATH_AOS_EPSILON && cz > -VECMATH_AOS_EPSILON && cz < VECMATH_AOS_EPSILON &&
	        cw > -VECMATH_AOS_EPSILON && cw < VECMATH_AOS_EPSILON);
}
}

///////////////////////////////////////////////////////

PX_FORCE_INLINE bool isValidVec3V(const Vec3V a)
{
	return a.pad == 0.f;
}

PX_FORCE_INLINE bool isFiniteFloatV(const FloatV a)
{
	return PxIsFinite(a.x);
}

PX_FORCE_INLINE bool isFiniteVec3V(const Vec3V a)
{
	return PxIsFinite(a.x) && PxIsFinite(a.y) && PxIsFinite(a.z);
}

PX_FORCE_INLINE bool isFiniteVec4V(const Vec4V a)
{
	return PxIsFinite(a.x) && PxIsFinite(a.y) && PxIsFinite(a.z) && PxIsFinite(a.w);
}

/////////////////////////////////////////////////////////////////////
////VECTORISED FUNCTION IMPLEMENTATIONS
/////////////////////////////////////////////////////////////////////

PX_FORCE_INLINE FloatV FLoad(const PxF32 f)
{
	return FloatV(f);
}

PX_FORCE_INLINE Vec3V V3Load(const PxF32 f)
{
	return Vec3V(f, f, f);
}

PX_FORCE_INLINE Vec4V V4Load(const PxF32 f)
{
	return Vec4V(f, f, f, f);
}

PX_FORCE_INLINE BoolV BLoad(const bool f)
{
#if PX_ARM
	// SD: Android ARM builds fail if this is done with a cast.
	// Might also fail because of something else but the select
	// operator here seems to fix everything that failed in release builds.
	return f ? BTTTT() : BFFFF();
#else
	return BoolV(BOOL_TO_U32(f), BOOL_TO_U32(f), BOOL_TO_U32(f), BOOL_TO_U32(f));
#endif
}

PX_FORCE_INLINE Vec3V V3LoadA(const PxVec3& f)
{
	return Vec3V(f.x, f.y, f.z);
}

PX_FORCE_INLINE Vec3V V3LoadU(const PxVec3& f)
{
	return Vec3V(f.x, f.y, f.z);
}

PX_FORCE_INLINE Vec3V V3LoadUnsafeA(const PxVec3& f)
{
	return Vec3V(f.x, f.y, f.z);
}

PX_FORCE_INLINE Vec3V V3LoadA(const PxF32* const f)
{
	return Vec3V(f[0], f[1], f[2]);
}

PX_FORCE_INLINE Vec3V V3LoadU(const PxF32* const f)
{
	return Vec3V(f[0], f[1], f[2]);
}

PX_FORCE_INLINE Vec3V Vec3V_From_Vec4V(Vec4V f)
{
	return Vec3V(f.x, f.y, f.z);
}

PX_FORCE_INLINE Vec3V Vec3V_From_Vec4V_WUndefined(const Vec4V v)
{
	return Vec3V(v.x, v.y, v.z);
}

PX_FORCE_INLINE Vec4V Vec4V_From_Vec3V(Vec3V f)
{
	return Vec4V(f.x, f.y, f.z, 0.0f);
}

PX_FORCE_INLINE Vec4V Vec4V_From_FloatV(FloatV f)
{
	return Vec4V(f.x, f.x, f.x, f.x);
}

PX_FORCE_INLINE Vec3V Vec3V_From_FloatV(FloatV f)
{
	return Vec3V(f.x, f.x, f.x);
}

PX_FORCE_INLINE Vec3V Vec3V_From_FloatV_WUndefined(FloatV f)
{
	return Vec3V(f.x, f.x, f.x);
}

PX_FORCE_INLINE Vec4V V4LoadA(const PxF32* const f)
{
	return Vec4V(f[0], f[1], f[2], f[3]);
}

PX_FORCE_INLINE void V4StoreA(const Vec4V a, PxF32* f)
{
	*reinterpret_cast<Vec4V*>(f) = a;
}

PX_FORCE_INLINE void V4StoreU(const Vec4V a, PxF32* f)
{
	*reinterpret_cast<PxVec4*>(f) = *reinterpret_cast<const PxVec4*>(&a.x);
}

PX_FORCE_INLINE void BStoreA(const BoolV a, PxU32* f)
{
	*reinterpret_cast<BoolV*>(f) = a;
}

PX_FORCE_INLINE void U4StoreA(const VecU32V uv, PxU32* u)
{
	*reinterpret_cast<VecU32V*>(u) = uv;
}

PX_FORCE_INLINE void I4StoreA(const VecI32V iv, PxI32* i)
{
	*reinterpret_cast<VecI32V*>(i) = iv;
}

PX_FORCE_INLINE Vec4V V4LoadU(const PxF32* const f)
{
	return Vec4V(f[0], f[1], f[2], f[3]);
}

PX_FORCE_INLINE Vec4V Vec4V_From_PxVec3_WUndefined(const PxVec3& f)
{
	return Vec4V(f[0], f[1], f[2], 0.0f);
}

PX_FORCE_INLINE BoolV BLoad(const bool* const f)
{
	return BoolV(BOOL_TO_U32(f[0]), BOOL_TO_U32(f[1]), BOOL_TO_U32(f[2]), BOOL_TO_U32(f[3]));
}

PX_FORCE_INLINE void FStore(const FloatV a, PxF32* PX_RESTRICT f)
{
	*f = a.x;
}

PX_FORCE_INLINE void V3StoreA(const Vec3V a, PxVec3& f)
{
	f = PxVec3(a.x, a.y, a.z);
}

PX_FORCE_INLINE void V3StoreU(const Vec3V a, PxVec3& f)
{
	f = PxVec3(a.x, a.y, a.z);
}

PX_FORCE_INLINE void Store_From_BoolV(const BoolV b, PxU32* b2)
{
	*b2 = b.ux;
}

//////////////////////////
// FLOATV
//////////////////////////

PX_FORCE_INLINE FloatV FZero()
{
	return FLoad(0.0f);
}

PX_FORCE_INLINE FloatV FOne()
{
	return FLoad(1.0f);
}

PX_FORCE_INLINE FloatV FHalf()
{
	return FLoad(0.5f);
}

PX_FORCE_INLINE FloatV FEps()
{
	return FLoad(PX_EPS_REAL);
}

PX_FORCE_INLINE FloatV FEps6()
{
	return FLoad(1e-6f);
}

PX_FORCE_INLINE FloatV FMax()
{
	return FLoad(PX_MAX_REAL);
}

PX_FORCE_INLINE FloatV FNegMax()
{
	return FLoad(-PX_MAX_REAL);
}

PX_FORCE_INLINE FloatV FNeg(const FloatV f)
{
	return FloatV(-f.x);
}

PX_FORCE_INLINE FloatV FAdd(const FloatV a, const FloatV b)
{
	return FloatV(a.x + b.x);
}

PX_FORCE_INLINE FloatV FSub(const FloatV a, const FloatV b)
{
	return FloatV(a.x - b.x);
}

PX_FORCE_INLINE FloatV FMul(const FloatV a, const FloatV b)
{
	return FloatV(a.x * b.x);
}

PX_FORCE_INLINE FloatV FDiv(const FloatV a, const FloatV b)
{
	VECMATHAOS_ASSERT(b.x != 0.0f);
	return FloatV(a.x / b.x);
}

PX_FORCE_INLINE FloatV FDivFast(const FloatV a, const FloatV b)
{
	VECMATHAOS_ASSERT(b.x != 0.0f);
	return FloatV(a.x / b.x);
}

PX_FORCE_INLINE FloatV FRecip(const FloatV a)
{
	VECMATHAOS_ASSERT(a.x != 0.0f);
	return 1.0f / a.x;
}

PX_FORCE_INLINE FloatV FRecipFast(const FloatV a)
{
	VECMATHAOS_ASSERT(a.x != 0.0f);
	return 1.0f / a.x;
}

PX_FORCE_INLINE FloatV FRsqrt(const FloatV a)
{
	VECMATHAOS_ASSERT(a.x != 0.0f);
	return PxRecipSqrt(a.x);
}

PX_FORCE_INLINE FloatV FSqrt(const FloatV a)
{
	return PxSqrt(a.x);
}

PX_FORCE_INLINE FloatV FRsqrtFast(const FloatV a)
{
	VECMATHAOS_ASSERT(a.x != 0.0f);
	return PxRecipSqrt(a.x);
}

PX_FORCE_INLINE FloatV FScaleAdd(const FloatV a, const FloatV b, const FloatV c)
{
	return FAdd(FMul(a, b), c);
}

PX_FORCE_INLINE FloatV FNegScaleSub(const FloatV a, const FloatV b, const FloatV c)
{
	return FSub(c, FMul(a, b));
}

PX_FORCE_INLINE FloatV FAbs(const FloatV a)
{
	return FloatV(PxAbs(a.x));
}

PX_FORCE_INLINE FloatV FSel(const BoolV c, const FloatV a, const FloatV b)
{
	return FloatV(c.ux ? a.x : b.x);
}

PX_FORCE_INLINE BoolV FIsGrtr(const FloatV a, const FloatV b)
{
	return BLoad(a.x > b.x);
}

PX_FORCE_INLINE BoolV FIsGrtrOrEq(const FloatV a, const FloatV b)
{
	return BLoad(a.x >= b.x);
}

PX_FORCE_INLINE BoolV FIsEq(const FloatV a, const FloatV b)
{
	return BLoad(a.x == b.x);
}

PX_FORCE_INLINE FloatV FMax(const FloatV a, const FloatV b)
{
	return (a.x > b.x ? FloatV(a.x) : FloatV(b.x));
}

PX_FORCE_INLINE FloatV FMin(const FloatV a, const FloatV b)
{
	return (a.x > b.x ? FloatV(b.x) : FloatV(a.x));
}

PX_FORCE_INLINE FloatV FClamp(const FloatV a, const FloatV minV, const FloatV maxV)
{
	return FMax(FMin(a, maxV), minV);
}

PX_FORCE_INLINE PxU32 FAllGrtr(const FloatV a, const FloatV b)
{
	return BOOL_TO_U32(a.x > b.x);
}

PX_FORCE_INLINE PxU32 FAllGrtrOrEq(const FloatV a, const FloatV b)
{
	return BOOL_TO_U32(a.x >= b.x);
}
PX_FORCE_INLINE PxU32 FAllEq(const FloatV a, const FloatV b)
{
	return BOOL_TO_U32(a.x == b.x);
}

PX_FORCE_INLINE FloatV FRound(const FloatV a)
{
	return floorf(a.x + 0.5f);
}

PX_FORCE_INLINE FloatV FSin(const FloatV a)
{
	return sinf(a.x);
}

PX_FORCE_INLINE FloatV FCos(const FloatV a)
{
	return cosf(a.x);
}

PX_FORCE_INLINE PxU32 FOutOfBounds(const FloatV a, const FloatV min, const FloatV max)
{
	return BOOL_TO_U32(a.x > max.x || a.x < min.x);
}

PX_FORCE_INLINE PxU32 FInBounds(const FloatV a, const FloatV min, const FloatV max)
{
	return BOOL_TO_U32(a.x >= min.x && a.x <= max.x);
}

PX_FORCE_INLINE PxU32 FOutOfBounds(const FloatV a, const FloatV bounds)
{
	return FOutOfBounds(a, FNeg(bounds), bounds);
}

PX_FORCE_INLINE PxU32 FInBounds(const FloatV a, const FloatV bounds)
{
	return FInBounds(a, FNeg(bounds), bounds);
}

/////////////////////
// VEC3V
/////////////////////

PX_FORCE_INLINE Vec3V V3Splat(const FloatV f)
{
	return Vec3V(f.x, f.x, f.x);
}

PX_FORCE_INLINE Vec3V V3Merge(const FloatVArg x, const FloatVArg y, const FloatVArg z)
{
	return Vec3V(x.x, y.x, z.x);
}

PX_FORCE_INLINE Vec3V V3UnitX()
{
	return Vec3V(1.0f, 0.0f, 0.0f);
}

PX_FORCE_INLINE Vec3V V3UnitY()
{
	return Vec3V(0.0f, 1.0f, 0.0f);
}

PX_FORCE_INLINE Vec3V V3UnitZ()
{
	return Vec3V(0.0f, 0.0f, 1.0f);
}

PX_FORCE_INLINE FloatV V3GetX(const Vec3V f)
{
	return FloatV(f.x);
}

PX_FORCE_INLINE FloatV V3GetY(const Vec3V f)
{
	return FloatV(f.y);
}

PX_FORCE_INLINE FloatV V3GetZ(const Vec3V f)
{
	return FloatV(f.z);
}

PX_FORCE_INLINE Vec3V V3SetX(const Vec3V v, const FloatV f)
{
	return Vec3V(f.x, v.y, v.z);
}

PX_FORCE_INLINE Vec3V V3SetY(const Vec3V v, const FloatV f)
{
	return Vec3V(v.x, f.x, v.z);
}

PX_FORCE_INLINE Vec3V V3SetZ(const Vec3V v, const FloatV f)
{
	return Vec3V(v.x, v.y, f.x);
}

PX_FORCE_INLINE Vec3V V3ColX(const Vec3V a, const Vec3V b, const Vec3V c)
{
	return Vec3V(a.x, b.x, c.x);
}

PX_FORCE_INLINE Vec3V V3ColY(const Vec3V a, const Vec3V b, const Vec3V c)
{
	return Vec3V(a.y, b.y, c.y);
}

PX_FORCE_INLINE Vec3V V3ColZ(const Vec3V a, const Vec3V b, const Vec3V c)
{
	return Vec3V(a.z, b.z, c.z);
}

PX_FORCE_INLINE Vec3V V3Zero()
{
	return V3Load(0.0f);
}

PX_FORCE_INLINE Vec3V V3One()
{
	return V3Load(1.0f);
}

PX_FORCE_INLINE Vec3V V3Eps()
{
	return V3Load(PX_EPS_REAL);
}

PX_FORCE_INLINE Vec3V V3Neg(const Vec3V c)
{
	return Vec3V(-c.x, -c.y, -c.z);
}

PX_FORCE_INLINE Vec3V V3Add(const Vec3V a, const Vec3V b)
{
	return Vec3V(a.x + b.x, a.y + b.y, a.z + b.z);
}

PX_FORCE_INLINE Vec3V V3Sub(const Vec3V a, const Vec3V b)
{
	return Vec3V(a.x - b.x, a.y - b.y, a.z - b.z);
}

PX_FORCE_INLINE Vec3V V3Scale(const Vec3V a, const FloatV b)
{
	return Vec3V(a.x * b.x, a.y * b.x, a.z * b.x);
}

PX_FORCE_INLINE Vec3V V3Mul(const Vec3V a, const Vec3V b)
{
	return Vec3V(a.x * b.x, a.y * b.y, a.z * b.z);
}

PX_FORCE_INLINE Vec3V V3ScaleInv(const Vec3V a, const FloatV b)
{
	const PxF32 bInv = 1.0f / b.x;
	return Vec3V(a.x * bInv, a.y * bInv, a.z * bInv);
}

PX_FORCE_INLINE Vec3V V3Div(const Vec3V a, const Vec3V b)
{
	return Vec3V(a.x / b.x, a.y / b.y, a.z / b.z);
}

PX_FORCE_INLINE Vec3V V3ScaleInvFast(const Vec3V a, const FloatV b)
{
	const PxF32 bInv = 1.0f / b.x;
	return Vec3V(a.x * bInv, a.y * bInv, a.z * bInv);
}

PX_FORCE_INLINE Vec3V V3DivFast(const Vec3V a, const Vec3V b)
{
	return Vec3V(a.x / b.x, a.y / b.y, a.z / b.z);
}

PX_FORCE_INLINE Vec3V V3Recip(const Vec3V a)
{
	return Vec3V(1.0f / a.x, 1.0f / a.y, 1.0f / a.z);
}

PX_FORCE_INLINE Vec3V V3RecipFast(const Vec3V a)
{
	return Vec3V(1.0f / a.x, 1.0f / a.y, 1.0f / a.z);
}

PX_FORCE_INLINE Vec3V V3Rsqrt(const Vec3V a)
{
	return Vec3V(PxRecipSqrt(a.x), PxRecipSqrt(a.y), PxRecipSqrt(a.z));
}

PX_FORCE_INLINE Vec3V V3RsqrtFast(const Vec3V a)
{
	return Vec3V(PxRecipSqrt(a.x), PxRecipSqrt(a.y), PxRecipSqrt(a.z));
}

PX_FORCE_INLINE Vec3V V3ScaleAdd(const Vec3V a, const FloatV b, const Vec3V c)
{
	return V3Add(V3Scale(a, b), c);
}

PX_FORCE_INLINE Vec3V V3NegScaleSub(const Vec3V a, const FloatV b, const Vec3V c)
{
	return V3Sub(c, V3Scale(a, b));
}

PX_FORCE_INLINE Vec3V V3MulAdd(const Vec3V a, const Vec3V b, const Vec3V c)
{
	return V3Add(V3Mul(a, b), c);
}

PX_FORCE_INLINE Vec3V V3NegMulSub(const Vec3V a, const Vec3V b, const Vec3V c)
{
	return V3Sub(c, V3Mul(a, b));
}

PX_FORCE_INLINE FloatV V3Dot(const Vec3V a, const Vec3V b)
{
	return FloatV(a.x * b.x + a.y * b.y + a.z * b.z);
}

PX_FORCE_INLINE VecCrossV V3PrepareCross(const Vec3VArg normal)
{
	return normal;
}

PX_FORCE_INLINE Vec3V V3Cross(const Vec3V a, const Vec3V b)
{
	return Vec3V(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
}

PX_FORCE_INLINE FloatV V3Length(const Vec3V a)
{
	return FloatV(PxSqrt(a.x * a.x + a.y * a.y + a.z * a.z));
}

PX_FORCE_INLINE FloatV V3LengthSq(const Vec3V a)
{
	return FloatV(a.x * a.x + a.y * a.y + a.z * a.z);
}

PX_FORCE_INLINE Vec3V V3Normalize(const Vec3V a)
{
	VECMATHAOS_ASSERT(a.x != 0 || a.y != 0 || a.z != 0);
	const PxF32 lengthInv = 1.0f / PxSqrt(a.x * a.x + a.y * a.y + a.z * a.z);
	return Vec3V(a.x * lengthInv, a.y * lengthInv, a.z * lengthInv);
}

PX_FORCE_INLINE Vec3V V3NormalizeSafe(const Vec3V a, const Vec3V unsafeReturnValue)
{
	const PxF32 length = PxSqrt(a.x * a.x + a.y * a.y + a.z * a.z);
	if(PX_EPS_REAL >= length)
	{
		return unsafeReturnValue;
	}
	else
	{
		const PxF32 lengthInv = 1.0f / length;
		return Vec3V(a.x * lengthInv, a.y * lengthInv, a.z * lengthInv);
	}
}

PX_FORCE_INLINE Vec3V V3NormalizeFast(const Vec3V a)
{
	VECMATHAOS_ASSERT(a.x != 0 || a.y != 0 || a.z != 0);
	const PxF32 lengthInv = 1.0f / PxSqrt(a.x * a.x + a.y * a.y + a.z * a.z);
	return Vec3V(a.x * lengthInv, a.y * lengthInv, a.z * lengthInv);
}

PX_FORCE_INLINE Vec3V V3Sel(const BoolV c, const Vec3V a, const Vec3V b)
{
	return Vec3V(c.ux ? a.x : b.x, c.uy ? a.y : b.y, c.uz ? a.z : b.z);
}

PX_FORCE_INLINE BoolV V3IsGrtr(const Vec3V a, const Vec3V b)
{
	return BoolV(BOOL_TO_U32(a.x > b.x), BOOL_TO_U32(a.y > b.y), BOOL_TO_U32(a.z > b.z), FALSE_TO_U32);
}

PX_FORCE_INLINE BoolV V3IsGrtrOrEq(const Vec3V a, const Vec3V b)
{
	return BoolV(BOOL_TO_U32(a.x >= b.x), BOOL_TO_U32(a.y >= b.y), BOOL_TO_U32(a.z >= b.z), TRUE_TO_U32);
}

PX_FORCE_INLINE BoolV V3IsEq(const Vec3V a, const Vec3V b)
{
	return BoolV(BOOL_TO_U32(a.x == b.x), BOOL_TO_U32(a.y == b.y), BOOL_TO_U32(a.z == b.z), TRUE_TO_U32);
}

PX_FORCE_INLINE Vec3V V3Max(const Vec3V a, const Vec3V b)
{
	return Vec3V(a.x > b.x ? a.x : b.x, a.y > b.y ? a.y : b.y, a.z > b.z ? a.z : b.z);
}

PX_FORCE_INLINE Vec3V V3Min(const Vec3V a, const Vec3V b)
{
	return Vec3V(a.x < b.x ? a.x : b.x, a.y < b.y ? a.y : b.y, a.z < b.z ? a.z : b.z);
}

PX_FORCE_INLINE FloatV V3ExtractMax(const Vec3V a)
{
	const PxF32 t0 = (a.x >= a.y) ? a.x : a.y;
	return t0 >= a.z ? t0 : a.z;
}

PX_FORCE_INLINE FloatV V3ExtractMin(const Vec3V a)
{
	const PxF32 t0 = (a.x <= a.y) ? a.x : a.y;
	return t0 <= a.z ? t0 : a.z;
}

// return (a >= 0.0f) ? 1.0f : -1.0f;
PX_FORCE_INLINE Vec3V V3Sign(const Vec3V a)
{
	return Vec3V((a.x >= 0.f ? 1.f : -1.f), (a.y >= 0.f ? 1.f : -1.f), (a.z >= 0.f ? 1.f : -1.f));
}

PX_FORCE_INLINE Vec3V V3Clamp(const Vec3V a, const Vec3V minV, const Vec3V maxV)
{
	return V3Max(V3Min(a, maxV), minV);
}

PX_FORCE_INLINE Vec3V V3Abs(const Vec3V a)
{
	return V3Max(a, V3Neg(a));
}

PX_FORCE_INLINE PxU32 V3AllGrtr(const Vec3V a, const Vec3V b)
{
	return BOOL_TO_U32((a.x > b.x) & (a.y > b.y) & (a.z > b.z));
}

PX_FORCE_INLINE PxU32 V3AllGrtrOrEq(const Vec3V a, const Vec3V b)
{
	return BOOL_TO_U32((a.x >= b.x) & (a.y >= b.y) & (a.z >= b.z));
}

PX_FORCE_INLINE PxU32 V3AllEq(const Vec3V a, const Vec3V b)
{
	return BOOL_TO_U32((a.x == b.x) & (a.y == b.y) & (a.z == b.z));
}

PX_FORCE_INLINE Vec3V V3Round(const Vec3V a)
{
	return Vec3V(floorf(a.x + 0.5f), floorf(a.y + 0.5f), floorf(a.z + 0.5f));
}

PX_FORCE_INLINE Vec3V V3Sin(const Vec3V a)
{
	return Vec3V(sinf(a.x), sinf(a.y), sinf(a.z));
}

PX_FORCE_INLINE Vec3V V3Cos(const Vec3V a)
{
	return Vec3V(cosf(a.x), cosf(a.y), cosf(a.z));
}

PX_FORCE_INLINE Vec3V V3PermYZZ(const Vec3V a)
{
	return Vec3V(a.y, a.z, a.z);
}

PX_FORCE_INLINE Vec3V V3PermXYX(const Vec3V a)
{
	return Vec3V(a.x, a.y, a.x);
}

PX_FORCE_INLINE Vec3V V3PermYZX(const Vec3V a)
{
	return Vec3V(a.y, a.z, a.x);
}

PX_FORCE_INLINE Vec3V V3PermZXY(const Vec3V a)
{
	return Vec3V(a.z, a.x, a.y);
}

PX_FORCE_INLINE Vec3V V3PermZZY(const Vec3V a)
{
	return Vec3V(a.z, a.z, a.y);
}

PX_FORCE_INLINE Vec3V V3PermYXX(const Vec3V a)
{
	return Vec3V(a.y, a.x, a.x);
}

PX_FORCE_INLINE Vec3V V3Perm_Zero_1Z_0Y(const Vec3V v0, const Vec3V v1)
{
	return Vec3V(0.0f, v1.z, v0.y);
}

PX_FORCE_INLINE Vec3V V3Perm_0Z_Zero_1X(const Vec3V v0, const Vec3V v1)
{
	return Vec3V(v0.z, 0.0f, v1.x);
}

PX_FORCE_INLINE Vec3V V3Perm_1Y_0X_Zero(const Vec3V v0, const Vec3V v1)
{
	return Vec3V(v1.y, v0.x, 0.0f);
}

PX_FORCE_INLINE FloatV V3SumElems(const Vec3V a)
{
	return FloatV(a.x + a.y + a.z);
}

PX_FORCE_INLINE PxU32 V3OutOfBounds(const Vec3V a, const Vec3V min, const Vec3V max)
{
	return BOOL_TO_U32(a.x > max.x || a.y > max.y || a.z > max.z || a.x < min.x || a.y < min.y || a.z < min.z);
}

PX_FORCE_INLINE PxU32 V3InBounds(const Vec3V a, const Vec3V min, const Vec3V max)
{
	return BOOL_TO_U32(a.x <= max.x && a.y <= max.y && a.z <= max.z && a.x >= min.x && a.y >= min.y && a.z >= min.z);
}

PX_FORCE_INLINE PxU32 V3OutOfBounds(const Vec3V a, const Vec3V bounds)
{
	return V3OutOfBounds(a, V3Neg(bounds), bounds);
}

PX_FORCE_INLINE PxU32 V3InBounds(const Vec3V a, const Vec3V bounds)
{
	return V3InBounds(a, V3Neg(bounds), bounds);
}

PX_FORCE_INLINE void V3Transpose(Vec3V& col0, Vec3V& col1, Vec3V& col2)
{
	const PxF32 t01 = col0.y, t02 = col0.z, t12 = col1.z;
	col0.y = col1.x;
	col0.z = col2.x;
	col1.z = col2.y;
	col1.x = t01;
	col2.x = t02;
	col2.y = t12;
}

/////////////////////////
// VEC4V
/////////////////////////

PX_FORCE_INLINE Vec4V V4Splat(const FloatV f)
{
	return Vec4V(f.x, f.x, f.x, f.x);
}

PX_FORCE_INLINE Vec4V V4Merge(const FloatV* const floatVArray)
{
	return Vec4V(floatVArray[0].x, floatVArray[1].x, floatVArray[2].x, floatVArray[3].x);
}

PX_FORCE_INLINE Vec4V V4Merge(const FloatVArg x, const FloatVArg y, const FloatVArg z, const FloatVArg w)
{
	return Vec4V(x.x, y.x, z.x, w.x);
}

PX_FORCE_INLINE Vec4V V4MergeW(const Vec4VArg x, const Vec4VArg y, const Vec4VArg z, const Vec4VArg w)
{
	return Vec4V(x.w, y.w, z.w, w.w);
}

PX_FORCE_INLINE Vec4V V4MergeZ(const Vec4VArg x, const Vec4VArg y, const Vec4VArg z, const Vec4VArg w)
{
	return Vec4V(x.z, y.z, z.z, w.z);
}

PX_FORCE_INLINE Vec4V V4MergeY(const Vec4VArg x, const Vec4VArg y, const Vec4VArg z, const Vec4VArg w)
{
	return Vec4V(x.y, y.y, z.y, w.y);
}

PX_FORCE_INLINE Vec4V V4MergeX(const Vec4VArg x, const Vec4VArg y, const Vec4VArg z, const Vec4VArg w)
{
	return Vec4V(x.x, y.x, z.x, w.x);
}

PX_FORCE_INLINE Vec4V V4UnpackXY(const Vec4VArg a, const Vec4VArg b)
{
	return Vec4V(a.x, b.x, a.y, b.y);
}

PX_FORCE_INLINE Vec4V V4UnpackZW(const Vec4VArg a, const Vec4VArg b)
{
	return Vec4V(a.z, b.z, a.w, b.w);
}

PX_FORCE_INLINE Vec4V V4UnitX()
{
	return Vec4V(1.0f, 0.0f, 0.0f, 0.0f);
}

PX_FORCE_INLINE Vec4V V4UnitY()
{
	return Vec4V(0.0f, 1.0f, 0.0f, 0.0f);
}

PX_FORCE_INLINE Vec4V V4UnitZ()
{
	return Vec4V(0.0f, 0.0f, 1.0f, 0.0f);
}

PX_FORCE_INLINE Vec4V V4UnitW()
{
	return Vec4V(0.0f, 0.0f, 0.0f, 1.0f);
}

PX_FORCE_INLINE FloatV V4GetX(const Vec4V f)
{
	return FloatV(f.x);
}

PX_FORCE_INLINE FloatV V4GetY(const Vec4V f)
{
	return FloatV(f.y);
}

PX_FORCE_INLINE FloatV V4GetZ(const Vec4V f)
{
	return FloatV(f.z);
}

PX_FORCE_INLINE FloatV V4GetW(const Vec4V f)
{
	return FloatV(f.w);
}

PX_FORCE_INLINE Vec4V V4SetX(const Vec4V v, const FloatV f)
{
	return Vec4V(f.x, v.y, v.z, v.w);
}

PX_FORCE_INLINE Vec4V V4SetY(const Vec4V v, const FloatV f)
{
	return Vec4V(v.x, f.x, v.z, v.w);
}

PX_FORCE_INLINE Vec4V V4SetZ(const Vec4V v, const FloatV f)
{
	return Vec4V(v.x, v.y, f.x, v.w);
}

PX_FORCE_INLINE Vec4V V4SetW(const Vec4V v, const FloatV f)
{
	return Vec4V(v.x, v.y, v.z, f.x);
}

PX_FORCE_INLINE Vec4V V4SetW(const Vec3V v, const FloatV f)
{
	return Vec4V(v.x, v.y, v.z, f.x);
}

PX_FORCE_INLINE Vec4V V4ClearW(const Vec4V v)
{
	return Vec4V(v.x, v.y, v.z, 0.0f);
}

PX_FORCE_INLINE Vec4V V4PermYXWZ(const Vec4V v)
{
	return Vec4V(v.y, v.x, v.w, v.z);
}

PX_FORCE_INLINE Vec4V V4PermXZXZ(const Vec4V v)
{
	return Vec4V(v.x, v.z, v.x, v.z);
}

PX_FORCE_INLINE Vec4V V4PermYWYW(const Vec4V v)
{
	return Vec4V(v.y, v.w, v.y, v.w);
}

PX_FORCE_INLINE Vec4V V4PermYZXW(const Vec4V v)
{
	return Vec4V(v.y, v.z, v.x, v.w);
}

PX_FORCE_INLINE Vec4V V4PermZWXY(const Vec4V v)
{
	return Vec4V(v.z, v.w, v.x, v.y);
}

template <PxU8 _x, PxU8 _y, PxU8 _z, PxU8 _w>
PX_FORCE_INLINE Vec4V V4Perm(const Vec4V v)
{
	const PxF32 f[4] = { v.x, v.y, v.z, v.w };
	return Vec4V(f[_x], f[_y], f[_z], f[_w]);
}

PX_FORCE_INLINE Vec4V V4Zero()
{
	return V4Load(0.0f);
}

PX_FORCE_INLINE Vec4V V4One()
{
	return V4Load(1.0f);
}

PX_FORCE_INLINE Vec4V V4Eps()
{
	return V4Load(PX_EPS_REAL);
}

PX_FORCE_INLINE Vec4V V4Neg(const Vec4V c)
{
	return Vec4V(-c.x, -c.y, -c.z, -c.w);
}

PX_FORCE_INLINE Vec4V V4Add(const Vec4V a, const Vec4V b)
{
	return Vec4V(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
}

PX_FORCE_INLINE Vec4V V4Sub(const Vec4V a, const Vec4V b)
{
	return Vec4V(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
}

PX_FORCE_INLINE Vec4V V4Scale(const Vec4V a, const FloatV b)
{
	return Vec4V(a.x * b.x, a.y * b.x, a.z * b.x, a.w * b.x);
}

PX_FORCE_INLINE Vec4V V4Mul(const Vec4V a, const Vec4V b)
{
	return Vec4V(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
}

PX_FORCE_INLINE Vec4V V4ScaleInv(const Vec4V a, const FloatV b)
{
	const PxF32 bInv = 1.0f / b.x;
	return Vec4V(a.x * bInv, a.y * bInv, a.z * bInv, a.w * bInv);
}

PX_FORCE_INLINE Vec4V V4Div(const Vec4V a, const Vec4V b)
{
	VECMATHAOS_ASSERT(b.x != 0 && b.y != 0 && b.z != 0 && b.w != 0);
	return Vec4V(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w);
}

PX_FORCE_INLINE Vec4V V4ScaleInvFast(const Vec4V a, const FloatV b)
{
	const PxF32 bInv = 1.0f / b.x;
	return Vec4V(a.x * bInv, a.y * bInv, a.z * bInv, a.w * bInv);
}

PX_FORCE_INLINE Vec4V V4DivFast(const Vec4V a, const Vec4V b)
{
	return Vec4V(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w);
}

PX_FORCE_INLINE Vec4V V4Recip(const Vec4V a)
{
	return Vec4V(1.0f / a.x, 1.0f / a.y, 1.0f / a.z, 1.0f / a.w);
}

PX_FORCE_INLINE Vec4V V4RecipFast(const Vec4V a)
{
	return Vec4V(1.0f / a.x, 1.0f / a.y, 1.0f / a.z, 1.0f / a.w);
}

PX_FORCE_INLINE Vec4V V4Rsqrt(const Vec4V a)
{
	return Vec4V(PxRecipSqrt(a.x), PxRecipSqrt(a.y), PxRecipSqrt(a.z), PxRecipSqrt(a.w));
}

PX_FORCE_INLINE Vec4V V4RsqrtFast(const Vec4V a)
{
	return Vec4V(PxRecipSqrt(a.x), PxRecipSqrt(a.y), PxRecipSqrt(a.z), PxRecipSqrt(a.w));
}

PX_FORCE_INLINE Vec4V V4Sqrt(const Vec4V a)
{
	return Vec4V(PxSqrt(a.x), PxSqrt(a.y), PxSqrt(a.z), PxSqrt(a.w));
}

PX_FORCE_INLINE Vec4V V4ScaleAdd(const Vec4V a, const FloatV b, const Vec4V c)
{
	return V4Add(V4Scale(a, b), c);
}

PX_FORCE_INLINE Vec4V V4NegScaleSub(const Vec4V a, const FloatV b, const Vec4V c)
{
	return V4Sub(c, V4Scale(a, b));
}

PX_FORCE_INLINE Vec4V V4MulAdd(const Vec4V a, const Vec4V b, const Vec4V c)
{
	return V4Add(V4Mul(a, b), c);
}

PX_FORCE_INLINE Vec4V V4NegMulSub(const Vec4V a, const Vec4V b, const Vec4V c)
{
	return V4Sub(c, V4Mul(a, b));
}

PX_FORCE_INLINE FloatV V4SumElements(const Vec4V a)
{
	return FloatV(a.x + a.y + a.z + a.w);
}

PX_FORCE_INLINE FloatV V4Dot(const Vec4V a, const Vec4V b)
{
	return FloatV(a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w);
}

PX_FORCE_INLINE FloatV V4Dot3(const Vec4V a, const Vec4V b)
{
	return FloatV(a.x * b.x + a.y * b.y + a.z * b.z);
}

PX_FORCE_INLINE Vec4V V4Cross(const Vec4V a, const Vec4V b)
{
	return Vec4V(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x, 0.0f);
}

PX_FORCE_INLINE FloatV V4Length(const Vec4V a)
{
	return FloatV(PxSqrt(a.x * a.x + a.y * a.y + a.z * a.z + a.w * a.w));
}

PX_FORCE_INLINE FloatV V4LengthSq(const Vec4V a)
{
	return V4Dot(a, a);
}

PX_FORCE_INLINE Vec4V V4Normalize(const Vec4V a)
{
	VECMATHAOS_ASSERT(0 != a.x || 0 != a.y || 0 != a.z || 0 != a.w);
	const FloatV length = FloatV(V4Length(a));
	return V4ScaleInv(a, length);
}

PX_FORCE_INLINE Vec4V V4NormalizeSafe(const Vec4V a, const Vec4V unsafeReturnValue)
{
	const FloatV length = FloatV(V4Length(a));
	if(PX_EPS_REAL >= length.x)
	{
		return unsafeReturnValue;
	}
	else
	{
		return V4ScaleInv(a, length);
	}
}
PX_FORCE_INLINE Vec4V V4NormalizeFast(const Vec4V a)
{
	VECMATHAOS_ASSERT(0 != a.x || 0 != a.y || 0 != a.z || 0 != a.w);
	const FloatV length = FloatV(V4Length(a));
	return V4ScaleInv(a, length);
}

PX_FORCE_INLINE Vec4V V4Sel(const BoolV c, const Vec4V a, const Vec4V b)
{
	return Vec4V(c.ux ? a.x : b.x, c.uy ? a.y : b.y, c.uz ? a.z : b.z, c.uw ? a.w : b.w);
}

PX_FORCE_INLINE BoolV V4IsGrtr(const Vec4V a, const Vec4V b)
{
	return BoolV(BOOL_TO_U32(a.x > b.x), BOOL_TO_U32(a.y > b.y), BOOL_TO_U32(a.z > b.z), BOOL_TO_U32(a.w > b.w));
}

PX_FORCE_INLINE BoolV V4IsGrtrOrEq(const Vec4V a, const Vec4V b)
{
	return BoolV(BOOL_TO_U32(a.x >= b.x), BOOL_TO_U32(a.y >= b.y), BOOL_TO_U32(a.z >= b.z), BOOL_TO_U32(a.w >= b.w));
}

PX_FORCE_INLINE BoolV V4IsEq(const Vec4V a, const Vec4V b)
{
	return BoolV(BOOL_TO_U32(a.x == b.x), BOOL_TO_U32(a.y == b.y), BOOL_TO_U32(a.z == b.z), BOOL_TO_U32(a.w == b.w));
}

PX_FORCE_INLINE Vec4V V4Max(const Vec4V a, const Vec4V b)
{
	return Vec4V(a.x > b.x ? a.x : b.x, a.y > b.y ? a.y : b.y, a.z > b.z ? a.z : b.z, a.w > b.w ? a.w : b.w);
}

PX_FORCE_INLINE Vec4V V4Min(const Vec4V a, const Vec4V b)
{
	return Vec4V(a.x < b.x ? a.x : b.x, a.y < b.y ? a.y : b.y, a.z < b.z ? a.z : b.z, a.w < b.w ? a.w : b.w);
}

PX_FORCE_INLINE FloatV V4ExtractMax(const Vec4V a)
{
	const PxF32 t0 = (a.x >= a.y) ? a.x : a.y;
	const PxF32 t1 = (a.z >= a.w) ? a.x : a.w;
	return t0 >= t1 ? t0 : t1;
}

PX_FORCE_INLINE FloatV V4ExtractMin(const Vec4V a)
{
	const PxF32 t0 = (a.x <= a.y) ? a.x : a.y;
	const PxF32 t1 = (a.z <= a.w) ? a.x : a.w;
	return t0 <= t1 ? t0 : t1;
}

PX_FORCE_INLINE Vec4V V4Clamp(const Vec4V a, const Vec4V minV, const Vec4V maxV)
{
	return V4Max(V4Min(a, maxV), minV);
}

PX_FORCE_INLINE Vec4V V4Round(const Vec4V a)
{
	return Vec4V(floorf(a.x + 0.5f), floorf(a.y + 0.5f), floorf(a.z + 0.5f), floorf(a.w + 0.5f));
}

PX_FORCE_INLINE Vec4V V4Sin(const Vec4V a)
{
	return Vec4V(sinf(a.x), sinf(a.y), sinf(a.z), sinf(a.w));
}

PX_FORCE_INLINE Vec4V V4Cos(const Vec4V a)
{
	return Vec4V(cosf(a.x), cosf(a.y), cosf(a.z), cosf(a.w));
}

PX_FORCE_INLINE PxU32 V4AllGrtr(const Vec4V a, const Vec4V b)
{
	return BOOL_TO_U32((a.x > b.x) & (a.y > b.y) & (a.z > b.z) & (a.w > b.w));
}

PX_FORCE_INLINE PxU32 V4AllGrtrOrEq(const Vec4V a, const Vec4V b)
{
	return BOOL_TO_U32((a.x >= b.x) & (a.y >= b.y) & (a.z >= b.z) & (a.w >= b.w));
}

PX_FORCE_INLINE PxU32 V4AllGrtrOrEq3(const Vec4V a, const Vec4V b)
{
	return BOOL_TO_U32((a.x >= b.x) & (a.y >= b.y) & (a.z >= b.z));
}

PX_FORCE_INLINE PxU32 V4AllEq(const Vec4V a, const Vec4V b)
{
	return BOOL_TO_U32((a.x == b.x) & (a.y == b.y) & (a.z == b.z) & (a.w == b.w));
}

PX_FORCE_INLINE PxU32 V4AnyGrtr3(const Vec4V a, const Vec4V b)
{
	return BOOL_TO_U32((a.x > b.x) | (a.y > b.y) | (a.z > b.z));
}

PX_FORCE_INLINE void V4Transpose(Vec4V& col0, Vec4V& col1, Vec4V& col2, Vec4V& col3)
{
	const PxF32 t01 = col0.y, t02 = col0.z, t03 = col0.w;
	const PxF32 t12 = col1.z, t13 = col1.w;
	const PxF32 t23 = col2.w;
	col0.y = col1.x;
	col0.z = col2.x;
	col0.w = col3.x;
	col1.z = col2.y;
	col1.w = col3.y;
	col2.w = col3.z;
	col1.x = t01;
	col2.x = t02;
	col3.x = t03;
	col2.y = t12;
	col3.y = t13;
	col3.z = t23;
}

PX_FORCE_INLINE BoolV BFFFF()
{
	return BoolV(FALSE_TO_U32, FALSE_TO_U32, FALSE_TO_U32, FALSE_TO_U32);
}
PX_FORCE_INLINE BoolV BFFFT()
{
	return BoolV(FALSE_TO_U32, FALSE_TO_U32, FALSE_TO_U32, TRUE_TO_U32);
}
PX_FORCE_INLINE BoolV BFFTF()
{
	return BoolV(FALSE_TO_U32, FALSE_TO_U32, TRUE_TO_U32, FALSE_TO_U32);
}
PX_FORCE_INLINE BoolV BFFTT()
{
	return BoolV(FALSE_TO_U32, FALSE_TO_U32, TRUE_TO_U32, TRUE_TO_U32);
}
PX_FORCE_INLINE BoolV BFTFF()
{
	return BoolV(FALSE_TO_U32, TRUE_TO_U32, FALSE_TO_U32, FALSE_TO_U32);
}
PX_FORCE_INLINE BoolV BFTFT()
{
	return BoolV(FALSE_TO_U32, TRUE_TO_U32, FALSE_TO_U32, TRUE_TO_U32);
}
PX_FORCE_INLINE BoolV BFTTF()
{
	return BoolV(FALSE_TO_U32, TRUE_TO_U32, TRUE_TO_U32, FALSE_TO_U32);
}
PX_FORCE_INLINE BoolV BFTTT()
{
	return BoolV(FALSE_TO_U32, TRUE_TO_U32, TRUE_TO_U32, TRUE_TO_U32);
}
PX_FORCE_INLINE BoolV BTFFF()
{
	return BoolV(TRUE_TO_U32, FALSE_TO_U32, FALSE_TO_U32, FALSE_TO_U32);
}
PX_FORCE_INLINE BoolV BTFFT()
{
	return BoolV(TRUE_TO_U32, FALSE_TO_U32, FALSE_TO_U32, TRUE_TO_U32);
}
PX_FORCE_INLINE BoolV BTFTF()
{
	return BoolV(TRUE_TO_U32, FALSE_TO_U32, TRUE_TO_U32, FALSE_TO_U32);
}
PX_FORCE_INLINE BoolV BTFTT()
{
	return BoolV(TRUE_TO_U32, FALSE_TO_U32, TRUE_TO_U32, TRUE_TO_U32);
}
PX_FORCE_INLINE BoolV BTTFF()
{
	return BoolV(TRUE_TO_U32, TRUE_TO_U32, FALSE_TO_U32, FALSE_TO_U32);
}
PX_FORCE_INLINE BoolV BTTFT()
{
	return BoolV(TRUE_TO_U32, TRUE_TO_U32, FALSE_TO_U32, TRUE_TO_U32);
}
PX_FORCE_INLINE BoolV BTTTF()
{
	return BoolV(TRUE_TO_U32, TRUE_TO_U32, TRUE_TO_U32, FALSE_TO_U32);
}
PX_FORCE_INLINE BoolV BTTTT()
{
	return BoolV(TRUE_TO_U32, TRUE_TO_U32, TRUE_TO_U32, TRUE_TO_U32);
}

PX_FORCE_INLINE BoolV BXMask()
{
	return BTFFF();
}
PX_FORCE_INLINE BoolV BYMask()
{
	return BFTFF();
}
PX_FORCE_INLINE BoolV BZMask()
{
	return BFFTF();
}
PX_FORCE_INLINE BoolV BWMask()
{
	return BFFFT();
}

PX_FORCE_INLINE BoolV BGetX(const BoolV a)
{
	return BoolV(a.ux, a.ux, a.ux, a.ux);
}

PX_FORCE_INLINE BoolV BGetY(const BoolV a)
{
	return BoolV(a.uy, a.uy, a.uy, a.uy);
}

PX_FORCE_INLINE BoolV BGetZ(const BoolV a)
{
	return BoolV(a.uz, a.uz, a.uz, a.uz);
}

PX_FORCE_INLINE BoolV BGetW(const BoolV a)
{
	return BoolV(a.uw, a.uw, a.uw, a.uw);
}

PX_FORCE_INLINE BoolV BSetX(const BoolV v, const BoolV f)
{
	return BoolV(f.ux, v.uy, v.uz, v.uw);
}

PX_FORCE_INLINE BoolV BSetY(const BoolV v, const BoolV f)
{
	return BoolV(v.ux, f.uy, v.uz, v.uw);
}

PX_FORCE_INLINE BoolV BSetZ(const BoolV v, const BoolV f)
{
	return BoolV(v.ux, v.uy, f.uz, v.uw);
}

PX_FORCE_INLINE BoolV BSetW(const BoolV v, const BoolV f)
{
	return BoolV(v.ux, v.uy, v.uz, f.uw);
}

template <int index>
BoolV BSplatElement(BoolV a)
{
	PxU32* b = (PxU32*)&a;
	return BoolV(b[index], b[index], b[index], b[index]);
}

PX_FORCE_INLINE BoolV BAnd(const BoolV a, const BoolV b)
{
	return BoolV(BOOL_TO_U32(a.ux && b.ux), BOOL_TO_U32(a.uy && b.uy), BOOL_TO_U32(a.uz && b.uz), BOOL_TO_U32(a.uw && b.uw));
}

PX_FORCE_INLINE BoolV BAndNot(const BoolV a, const BoolV b)
{
	return BoolV(a.ux & ~b.ux, a.uy & ~b.uy, a.uz & ~b.uz, a.uw & ~b.uw);
}

PX_FORCE_INLINE BoolV BNot(const BoolV a)
{
	return BoolV(~a.ux, ~a.uy, ~a.uz, ~a.uw);
}

PX_FORCE_INLINE BoolV BOr(const BoolV a, const BoolV b)
{
	return BoolV(BOOL_TO_U32(a.ux || b.ux), BOOL_TO_U32(a.uy || b.uy), BOOL_TO_U32(a.uz || b.uz), BOOL_TO_U32(a.uw || b.uw));
}

PX_FORCE_INLINE PxU32 BAllEq(const BoolV a, const BoolV b)
{
	return (a.ux == b.ux && a.uy == b.uy && a.uz == b.uz && a.uw == b.uw ? 1 : 0);
}

PX_FORCE_INLINE PxU32 BAllEqTTTT(const BoolV a)
{
	return BAllEq(a, BTTTT());
}

PX_FORCE_INLINE PxU32 BAllEqFFFF(const BoolV a)
{
	return BAllEq(a, BFFFF());
}

PX_FORCE_INLINE BoolV BAllTrue4(const BoolV a)
{
	return (a.ux & a.uy & a.uz & a.uw) ? BTTTT() : BFFFF();
}

PX_FORCE_INLINE BoolV BAnyTrue4(const BoolV a)
{
	return (a.ux | a.uy | a.uz | a.uw) ? BTTTT() : BFFFF();
}

PX_FORCE_INLINE BoolV BAllTrue3(const BoolV a)
{
	return (a.ux & a.uy & a.uz) ? BTTTT() : BFFFF();
}

PX_FORCE_INLINE BoolV BAnyTrue3(const BoolV a)
{
	return (a.ux | a.uy | a.uz) ? BTTTT() : BFFFF();
}

PX_FORCE_INLINE PxU32 BGetBitMask(const BoolV a)
{
	return (a.ux & 1) | (a.uy & 2) | (a.uz & 4) | (a.uw & 8);
}

//////////////////////////////////
// MAT33V
//////////////////////////////////

PX_FORCE_INLINE Vec3V M33MulV3(const Mat33V& a, const Vec3V b)
{
	return Vec3V(a.col0.x * b.x + a.col1.x * b.y + a.col2.x * b.z, a.col0.y * b.x + a.col1.y * b.y + a.col2.y * b.z,
	             a.col0.z * b.x + a.col1.z * b.y + a.col2.z * b.z);
}

PX_FORCE_INLINE Vec3V M33TrnspsMulV3(const Mat33V& a, const Vec3V b)
{
	return Vec3V(a.col0.x * b.x + a.col0.y * b.y + a.col0.z * b.z, a.col1.x * b.x + a.col1.y * b.y + a.col1.z * b.z,
	             a.col2.x * b.x + a.col2.y * b.y + a.col2.z * b.z);
}

PX_FORCE_INLINE Vec3V M33MulV3AddV3(const Mat33V& A, const Vec3V b, const Vec3V c)
{
	const FloatV x = V3GetX(b);
	const FloatV y = V3GetY(b);
	const FloatV z = V3GetZ(b);
	Vec3V result = V3ScaleAdd(A.col0, x, c);
	result = V3ScaleAdd(A.col1, y, result);
	return V3ScaleAdd(A.col2, z, result);
}

PX_FORCE_INLINE Mat33V M33MulM33(const Mat33V& a, const Mat33V& b)
{
	return Mat33V(M33MulV3(a, b.col0), M33MulV3(a, b.col1), M33MulV3(a, b.col2));
}

PX_FORCE_INLINE Mat33V M33Add(const Mat33V& a, const Mat33V& b)
{
	return Mat33V(V3Add(a.col0, b.col0), V3Add(a.col1, b.col1), V3Add(a.col2, b.col2));
}

PX_FORCE_INLINE Mat33V M33Scale(const Mat33V& a, const FloatV& b)
{
	return Mat33V(V3Scale(a.col0, b), V3Scale(a.col1, b), V3Scale(a.col2, b));
}

PX_FORCE_INLINE Mat33V M33Sub(const Mat33V& a, const Mat33V& b)
{
	return Mat33V(V3Sub(a.col0, b.col0), V3Sub(a.col1, b.col1), V3Sub(a.col2, b.col2));
}

PX_FORCE_INLINE Mat33V M33Neg(const Mat33V& a)
{
	return Mat33V(V3Neg(a.col0), V3Neg(a.col1), V3Neg(a.col2));
}

PX_FORCE_INLINE Mat33V M33Abs(const Mat33V& a)
{
	return Mat33V(V3Abs(a.col0), V3Abs(a.col1), V3Abs(a.col2));
}

PX_FORCE_INLINE Mat33V M33Diagonal(const Vec3VArg d)
{
	const Vec3V x = V3Mul(V3UnitX(), d);
	const Vec3V y = V3Mul(V3UnitY(), d);
	const Vec3V z = V3Mul(V3UnitZ(), d);
	return Mat33V(x, y, z);
}

PX_FORCE_INLINE Mat33V M33Inverse(const Mat33V& a)
{
	const PxF32 det = a.col0.x * (a.col1.y * a.col2.z - a.col1.z * a.col2.y) -
	                  a.col1.x * (a.col0.y * a.col2.z - a.col2.y * a.col0.z) +
	                  a.col2.x * (a.col0.y * a.col1.z - a.col1.y * a.col0.z);

	const PxF32 invDet = 1.0f / det;

	Mat33V ret;
	ret.col0.x = invDet * (a.col1.y * a.col2.z - a.col2.y * a.col1.z);
	ret.col0.y = invDet * (a.col2.y * a.col0.z - a.col0.y * a.col2.z);
	ret.col0.z = invDet * (a.col0.y * a.col1.z - a.col1.y * a.col0.z);

	ret.col1.x = invDet * (a.col2.x * a.col1.z - a.col1.x * a.col2.z);
	ret.col1.y = invDet * (a.col0.x * a.col2.z - a.col2.x * a.col0.z);
	ret.col1.z = invDet * (a.col1.x * a.col0.z - a.col0.x * a.col1.z);

	ret.col2.x = invDet * (a.col1.x * a.col2.y - a.col2.x * a.col1.y);
	ret.col2.y = invDet * (a.col2.x * a.col0.y - a.col0.x * a.col2.y);
	ret.col2.z = invDet * (a.col0.x * a.col1.y - a.col1.x * a.col0.y);

	return ret;
}

PX_FORCE_INLINE Mat33V Mat33V_From_PxMat33(const PxMat33& m)
{
	return Mat33V(V3LoadU(m.column0), V3LoadU(m.column1), V3LoadU(m.column2));
}

PX_FORCE_INLINE void PxMat33_From_Mat33V(const Mat33V& m, PxMat33& out)
{
	PX_ASSERT((size_t(&out) & 15) == 0);
	V3StoreU(m.col0, out.column0);
	V3StoreU(m.col1, out.column1);
	V3StoreU(m.col2, out.column2);
}

PX_FORCE_INLINE Mat33V M33Trnsps(const Mat33V& a)
{
	return Mat33V(Vec3V(a.col0.x, a.col1.x, a.col2.x), Vec3V(a.col0.y, a.col1.y, a.col2.y),
	              Vec3V(a.col0.z, a.col1.z, a.col2.z));
}

PX_FORCE_INLINE Mat33V M33Identity()
{
	return Mat33V(V3UnitX(), V3UnitY(), V3UnitZ());
}

//////////////////////////////////
// MAT34V
//////////////////////////////////

PX_FORCE_INLINE Vec3V M34MulV3(const Mat34V& a, const Vec3V b)
{
	return Vec3V(a.col0.x * b.x + a.col1.x * b.y + a.col2.x * b.z + a.col3.x,
	             a.col0.y * b.x + a.col1.y * b.y + a.col2.y * b.z + a.col3.y,
	             a.col0.z * b.x + a.col1.z * b.y + a.col2.z * b.z + a.col3.z);
}

PX_FORCE_INLINE Vec3V M34Mul33V3(const Mat34V& a, const Vec3V b)
{
	return Vec3V(a.col0.x * b.x + a.col1.x * b.y + a.col2.x * b.z, a.col0.y * b.x + a.col1.y * b.y + a.col2.y * b.z,
	             a.col0.z * b.x + a.col1.z * b.y + a.col2.z * b.z);
}

PX_FORCE_INLINE Vec3V M34TrnspsMul33V3(const Mat34V& a, const Vec3V b)
{
	return Vec3V(a.col0.x * b.x + a.col0.y * b.y + a.col0.z * b.z, a.col1.x * b.x + a.col1.y * b.y + a.col1.z * b.z,
	             a.col2.x * b.x + a.col2.y * b.y + a.col2.z * b.z);
}

PX_FORCE_INLINE Mat34V M34MulM34(const Mat34V& a, const Mat34V& b)
{
	return Mat34V(M34Mul33V3(a, b.col0), M34Mul33V3(a, b.col1), M34Mul33V3(a, b.col2), M34MulV3(a, b.col3));
}

PX_FORCE_INLINE Mat33V M34MulM33(const Mat34V& a, const Mat33V& b)
{
	return Mat33V(M34Mul33V3(a, b.col0), M34Mul33V3(a, b.col1), M34Mul33V3(a, b.col2));
}

PX_FORCE_INLINE Mat33V M34Mul33V3(const Mat34V& a, const Mat33V& b)
{
	return Mat33V(M34Mul33V3(a, b.col0), M34Mul33V3(a, b.col1), M34Mul33V3(a, b.col2));
}

PX_FORCE_INLINE Mat33V M34Mul33MM34(const Mat34V& a, const Mat34V& b)
{
	return Mat33V(M34Mul33V3(a, b.col0), M34Mul33V3(a, b.col1), M34Mul33V3(a, b.col2));
}

PX_FORCE_INLINE Mat34V M34Add(const Mat34V& a, const Mat34V& b)
{
	return Mat34V(V3Add(a.col0, b.col0), V3Add(a.col1, b.col1), V3Add(a.col2, b.col2), V3Add(a.col3, b.col3));
}

PX_FORCE_INLINE Mat33V M34Trnsps33(const Mat34V& a)
{
	return Mat33V(Vec3V(a.col0.x, a.col1.x, a.col2.x), Vec3V(a.col0.y, a.col1.y, a.col2.y),
	              Vec3V(a.col0.z, a.col1.z, a.col2.z));
}

//////////////////////////////////
// MAT44V
//////////////////////////////////

PX_FORCE_INLINE Vec4V M44MulV4(const Mat44V& a, const Vec4V b)
{
	return Vec4V(a.col0.x * b.x + a.col1.x * b.y + a.col2.x * b.z + a.col3.x * b.w,
	             a.col0.y * b.x + a.col1.y * b.y + a.col2.y * b.z + a.col3.y * b.w,
	             a.col0.z * b.x + a.col1.z * b.y + a.col2.z * b.z + a.col3.z * b.w,
	             a.col0.w * b.x + a.col1.w * b.y + a.col2.w * b.z + a.col3.w * b.w);
}

PX_FORCE_INLINE Vec4V M44TrnspsMulV4(const Mat44V& a, const Vec4V b)
{
	return Vec4V(a.col0.x * b.x + a.col0.y * b.y + a.col0.z * b.z + a.col0.w * b.w,
	             a.col1.x * b.x + a.col1.y * b.y + a.col1.z * b.z + a.col1.w * b.w,
	             a.col2.x * b.x + a.col2.y * b.y + a.col2.z * b.z + a.col2.w * b.w,
	             a.col3.x * b.x + a.col3.y * b.y + a.col3.z * b.z + a.col3.w * b.w);
}

PX_FORCE_INLINE Mat44V M44MulM44(const Mat44V& a, const Mat44V& b)
{
	return Mat44V(M44MulV4(a, b.col0), M44MulV4(a, b.col1), M44MulV4(a, b.col2), M44MulV4(a, b.col3));
}

PX_FORCE_INLINE Mat44V M44Add(const Mat44V& a, const Mat44V& b)
{
	return Mat44V(V4Add(a.col0, b.col0), V4Add(a.col1, b.col1), V4Add(a.col2, b.col2), V4Add(a.col3, b.col3));
}

PX_FORCE_INLINE Mat44V M44Inverse(const Mat44V& a)
{
	PxF32 tmp[12];
	PxF32 dst[16];
	PxF32 det;

	const PxF32 src[16] = { a.col0.x, a.col0.y, a.col0.z, a.col0.w, a.col1.x, a.col1.y, a.col1.z, a.col1.w,
		                    a.col2.x, a.col2.y, a.col2.z, a.col2.w, a.col3.x, a.col3.y, a.col3.z, a.col3.w };

	tmp[0] = src[10] * src[15];
	tmp[1] = src[11] * src[14];
	tmp[2] = src[9] * src[15];
	tmp[3] = src[11] * src[13];
	tmp[4] = src[9] * src[14];
	tmp[5] = src[10] * src[13];
	tmp[6] = src[8] * src[15];
	tmp[7] = src[11] * src[12];
	tmp[8] = src[8] * src[14];
	tmp[9] = src[10] * src[12];
	tmp[10] = src[8] * src[13];
	tmp[11] = src[9] * src[12];

	dst[0] = tmp[0] * src[5] + tmp[3] * src[6] + tmp[4] * src[7];
	dst[0] -= tmp[1] * src[5] + tmp[2] * src[6] + tmp[5] * src[7];
	dst[1] = tmp[1] * src[4] + tmp[6] * src[6] + tmp[9] * src[7];
	dst[1] -= tmp[0] * src[4] + tmp[7] * src[6] + tmp[8] * src[7];
	dst[2] = tmp[2] * src[4] + tmp[7] * src[5] + tmp[10] * src[7];
	dst[2] -= tmp[3] * src[4] + tmp[6] * src[5] + tmp[11] * src[7];
	dst[3] = tmp[5] * src[4] + tmp[8] * src[5] + tmp[11] * src[6];
	dst[3] -= tmp[4] * src[4] + tmp[9] * src[5] + tmp[10] * src[6];
	dst[4] = tmp[1] * src[1] + tmp[2] * src[2] + tmp[5] * src[3];
	dst[4] -= tmp[0] * src[1] + tmp[3] * src[2] + tmp[4] * src[3];
	dst[5] = tmp[0] * src[0] + tmp[7] * src[2] + tmp[8] * src[3];
	dst[5] -= tmp[1] * src[0] + tmp[6] * src[2] + tmp[9] * src[3];
	dst[6] = tmp[3] * src[0] + tmp[6] * src[1] + tmp[11] * src[3];
	dst[6] -= tmp[2] * src[0] + tmp[7] * src[1] + tmp[10] * src[3];
	dst[7] = tmp[4] * src[0] + tmp[9] * src[1] + tmp[10] * src[2];
	dst[7] -= tmp[5] * src[0] + tmp[8] * src[1] + tmp[11] * src[2];

	tmp[0] = src[2] * src[7];
	tmp[1] = src[3] * src[6];
	tmp[2] = src[1] * src[7];
	tmp[3] = src[3] * src[5];
	tmp[4] = src[1] * src[6];
	tmp[5] = src[2] * src[5];
	tmp[6] = src[0] * src[7];
	tmp[7] = src[3] * src[4];
	tmp[8] = src[0] * src[6];
	tmp[9] = src[2] * src[4];
	tmp[10] = src[0] * src[5];
	tmp[11] = src[1] * src[4];

	dst[8] = tmp[0] * src[13] + tmp[3] * src[14] + tmp[4] * src[15];
	dst[8] -= tmp[1] * src[13] + tmp[2] * src[14] + tmp[5] * src[15];
	dst[9] = tmp[1] * src[12] + tmp[6] * src[14] + tmp[9] * src[15];
	dst[9] -= tmp[0] * src[12] + tmp[7] * src[14] + tmp[8] * src[15];
	dst[10] = tmp[2] * src[12] + tmp[7] * src[13] + tmp[10] * src[15];
	dst[10] -= tmp[3] * src[12] + tmp[6] * src[13] + tmp[11] * src[15];
	dst[11] = tmp[5] * src[12] + tmp[8] * src[13] + tmp[11] * src[14];
	dst[11] -= tmp[4] * src[12] + tmp[9] * src[13] + tmp[10] * src[14];
	dst[12] = tmp[2] * src[10] + tmp[5] * src[11] + tmp[1] * src[9];
	dst[12] -= tmp[4] * src[11] + tmp[0] * src[9] + tmp[3] * src[10];
	dst[13] = tmp[8] * src[11] + tmp[0] * src[8] + tmp[7] * src[10];
	dst[13] -= tmp[6] * src[10] + tmp[9] * src[11] + tmp[1] * src[8];
	dst[14] = tmp[6] * src[9] + tmp[11] * src[11] + tmp[3] * src[8];
	dst[14] -= tmp[10] * src[11] + tmp[2] * src[8] + tmp[7] * src[9];
	dst[15] = tmp[10] * src[10] + tmp[4] * src[8] + tmp[9] * src[9];
	dst[15] -= tmp[8] * src[9] + tmp[11] * src[10] + tmp[5] * src[8];

	det = src[0] * dst[0] + src[1] * dst[1] + src[2] * dst[2] + src[3] * dst[3];

	det = 1.0f / det;
	for(PxU32 j = 0; j < 16; j++)
	{
		dst[j] *= det;
	}

	return Mat44V(Vec4V(dst[0], dst[4], dst[8], dst[12]), Vec4V(dst[1], dst[5], dst[9], dst[13]),
	              Vec4V(dst[2], dst[6], dst[10], dst[14]), Vec4V(dst[3], dst[7], dst[11], dst[15]));
}

PX_FORCE_INLINE Mat44V M44Trnsps(const Mat44V& a)
{
	return Mat44V(Vec4V(a.col0.x, a.col1.x, a.col2.x, a.col3.x), Vec4V(a.col0.y, a.col1.y, a.col2.y, a.col3.y),
	              Vec4V(a.col0.z, a.col1.z, a.col2.z, a.col3.z), Vec4V(a.col0.w, a.col1.w, a.col2.w, a.col3.w));
}

PX_FORCE_INLINE Vec4V V4LoadXYZW(const PxF32& x, const PxF32& y, const PxF32& z, const PxF32& w)
{
	return Vec4V(x, y, z, w);
}

/*
PX_FORCE_INLINE VecU16V V4U32PK(VecU32V a, VecU32V b)
{
    return VecU16V(
        PxU16(PxClamp<PxU32>((a).u32[0], 0, 0xFFFF)),
        PxU16(PxClamp<PxU32>((a).u32[1], 0, 0xFFFF)),
        PxU16(PxClamp<PxU32>((a).u32[2], 0, 0xFFFF)),
        PxU16(PxClamp<PxU32>((a).u32[3], 0, 0xFFFF)),
        PxU16(PxClamp<PxU32>((b).u32[0], 0, 0xFFFF)),
        PxU16(PxClamp<PxU32>((b).u32[1], 0, 0xFFFF)),
        PxU16(PxClamp<PxU32>((b).u32[2], 0, 0xFFFF)),
        PxU16(PxClamp<PxU32>((b).u32[3], 0, 0xFFFF)));
}
*/

PX_FORCE_INLINE VecU32V V4U32Sel(const BoolV c, const VecU32V a, const VecU32V b)
{
	return VecU32V(c.ux ? a.u32[0] : b.u32[0], c.uy ? a.u32[1] : b.u32[1], c.uz ? a.u32[2] : b.u32[2],
	               c.uw ? a.u32[3] : b.u32[3]);
}

PX_FORCE_INLINE VecU32V V4U32or(VecU32V a, VecU32V b)
{
	return VecU32V((a).u32[0] | (b).u32[0], (a).u32[1] | (b).u32[1], (a).u32[2] | (b).u32[2], (a).u32[3] | (b).u32[3]);
}

PX_FORCE_INLINE VecU32V V4U32xor(VecU32V a, VecU32V b)
{
	return VecU32V((a).u32[0] ^ (b).u32[0], (a).u32[1] ^ (b).u32[1], (a).u32[2] ^ (b).u32[2], (a).u32[3] ^ (b).u32[3]);
}

PX_FORCE_INLINE VecU32V V4U32and(VecU32V a, VecU32V b)
{
	return VecU32V((a).u32[0] & (b).u32[0], (a).u32[1] & (b).u32[1], (a).u32[2] & (b).u32[2], (a).u32[3] & (b).u32[3]);
}

PX_FORCE_INLINE VecU32V V4U32Andc(VecU32V a, VecU32V b)
{
	return VecU32V((a).u32[0] & ~(b).u32[0], (a).u32[1] & ~(b).u32[1], (a).u32[2] & ~(b).u32[2],
	               (a).u32[3] & ~(b).u32[3]);
}

/*
PX_FORCE_INLINE VecU16V V4U16Or(VecU16V a, VecU16V b)
{
    return VecU16V(
        (a).u16[0]|(b).u16[0], (a).u16[1]|(b).u16[1], (a).u16[2]|(b).u16[2], (a).u16[3]|(b).u16[3],
        (a).u16[4]|(b).u16[4], (a).u16[5]|(b).u16[5], (a).u16[6]|(b).u16[6], (a).u16[7]|(b).u16[7]);
}
*/

/*
PX_FORCE_INLINE VecU16V V4U16And(VecU16V a, VecU16V b)
{
    return VecU16V(
        (a).u16[0]&(b).u16[0], (a).u16[1]&(b).u16[1], (a).u16[2]&(b).u16[2], (a).u16[3]&(b).u16[3],
        (a).u16[4]&(b).u16[4], (a).u16[5]&(b).u16[5], (a).u16[6]&(b).u16[6], (a).u16[7]&(b).u16[7]);
}
*/

/*
PX_FORCE_INLINE VecU16V V4U16Andc(VecU16V a, VecU16V b)
{
    return VecU16V(
        (a).u16[0]&~(b).u16[0], (a).u16[1]&~(b).u16[1], (a).u16[2]&~(b).u16[2], (a).u16[3]&~(b).u16[3],
        (a).u16[4]&~(b).u16[4], (a).u16[5]&~(b).u16[5], (a).u16[6]&~(b).u16[6], (a).u16[7]&~(b).u16[7]);
}
*/

/*
template<int a> PX_FORCE_INLINE VecI32V V4ISplat()
{
    return VecI32V(a, a, a, a);
}

template<PxU32 a> PX_FORCE_INLINE VecU32V V4USplat()
{
    return VecU32V(a, a, a, a);
}
*/

/*
PX_FORCE_INLINE void V4U16StoreAligned(VecU16V val, VecU16V* address)
{
    *address = val;
}
*/

PX_FORCE_INLINE void V4U32StoreAligned(VecU32V val, VecU32V* address)
{
	*address = val;
}

PX_FORCE_INLINE Vec4V V4Andc(const Vec4V a, const VecU32V b)
{
	VecU32V r = V4U32Andc(*reinterpret_cast<const VecU32V*>(&a), b);
	return (*reinterpret_cast<const Vec4V*>(&r));
}

PX_FORCE_INLINE VecU32V V4IsGrtrV32u(const Vec4V a, const Vec4V b)
{
	return VecU32V(a.x > b.x ? 0xFFFFffff : 0, a.y > b.y ? 0xFFFFffff : 0, a.z > b.z ? 0xFFFFffff : 0,
	               a.w > b.w ? 0xFFFFffff : 0);
}

PX_FORCE_INLINE VecU16V V4U16LoadAligned(VecU16V* addr)
{
	return *addr;
}

PX_FORCE_INLINE VecU16V V4U16LoadUnaligned(VecU16V* addr)
{
	return *addr;
}

PX_FORCE_INLINE VecU16V V4U16CompareGt(VecU16V a, VecU16V b)
{
	return VecU16V
		(
		BOOL_TO_U16(a.u16[0] > b.u16[0]), BOOL_TO_U16(a.u16[1] > b.u16[1]), BOOL_TO_U16(a.u16[2] > b.u16[2]), BOOL_TO_U16(a.u16[3] > b.u16[3]),
		BOOL_TO_U16(a.u16[4] > b.u16[4]), BOOL_TO_U16(a.u16[5] > b.u16[5]), BOOL_TO_U16(a.u16[6] > b.u16[6]), BOOL_TO_U16(a.u16[7] > b.u16[7])
		);
}

PX_FORCE_INLINE VecU16V V4I16CompareGt(VecU16V a, VecU16V b)
{
	return VecU16V
		(
		BOOL_TO_U16(a.i16[0] > b.i16[0]), BOOL_TO_U16(a.i16[1] > b.i16[1]), BOOL_TO_U16(a.i16[2] > b.i16[2]), BOOL_TO_U16(a.i16[3] > b.i16[3]),
		BOOL_TO_U16(a.i16[4] > b.i16[4]), BOOL_TO_U16(a.i16[5] > b.i16[5]), BOOL_TO_U16(a.i16[6] > b.i16[6]), BOOL_TO_U16(a.i16[7] > b.i16[7])
		);
}

PX_FORCE_INLINE Vec4V Vec4V_From_VecU32V(VecU32V a)
{
	return Vec4V(PxF32((a).u32[0]), PxF32((a).u32[1]), PxF32((a).u32[2]), PxF32((a).u32[3]));
}

PX_FORCE_INLINE Vec4V Vec4V_From_VecI32V(VecI32V a)
{
	return Vec4V(PxF32((a).i32[0]), PxF32((a).i32[1]), PxF32((a).i32[2]), PxF32((a).i32[3]));
}

PX_FORCE_INLINE VecI32V VecI32V_From_Vec4V(Vec4V a)
{
	float* data = (float*)&a;
	return VecI32V(PxI32(data[0]), PxI32(data[1]), PxI32(data[2]), PxI32(data[3]));
}

PX_FORCE_INLINE Vec4V Vec4V_ReinterpretFrom_VecU32V(VecU32V a)
{
	Vec4V b = *reinterpret_cast<Vec4V*>(&a);
	return b;
}

PX_FORCE_INLINE Vec4V Vec4V_ReinterpretFrom_VecI32V(VecI32V a)
{
	Vec4V b = *reinterpret_cast<Vec4V*>(&a);
	return b;
}

PX_FORCE_INLINE VecU32V VecU32V_ReinterpretFrom_Vec4V(Vec4V a)
{
	VecU32V b = *reinterpret_cast<VecU32V*>(&a);
	return b;
}

PX_FORCE_INLINE VecI32V VecI32V_ReinterpretFrom_Vec4V(Vec4V a)
{
	VecI32V b = *reinterpret_cast<VecI32V*>(&a);
	return b;
}

template <int index>
PX_FORCE_INLINE VecU32V V4U32SplatElement(VecU32V a)
{
	return VecU32V((a).u32[index], (a).u32[index], (a).u32[index], (a).u32[index]);
}

template <int index>
PX_FORCE_INLINE VecU32V V4U32SplatElement(BoolV a)
{
	const PxU32 u = (&a.ux)[index];
	return VecU32V(u, u, u, u);
}

template <int index>
PX_FORCE_INLINE Vec4V V4SplatElement(Vec4V a)
{
	float* data = (float*)&a;
	return Vec4V(data[index], data[index], data[index], data[index]);
}

PX_FORCE_INLINE VecU32V U4LoadXYZW(PxU32 x, PxU32 y, PxU32 z, PxU32 w)
{
	return VecU32V(x, y, z, w);
}

PX_FORCE_INLINE Vec4V V4Abs(const Vec4V a)
{
	return V4Max(a, V4Neg(a));
}

PX_FORCE_INLINE BoolV V4IsEqU32(const VecU32V a, const VecU32V b)
{
	return BoolV(BOOL_TO_U32(a.u32[0] == b.u32[0]), BOOL_TO_U32(a.u32[1] == b.u32[1]), BOOL_TO_U32(a.u32[2] == b.u32[2]), BOOL_TO_U32(a.u32[3] == b.u32[3]));
}

PX_FORCE_INLINE VecU32V U4Load(const PxU32 i)
{
	return VecU32V(i, i, i, i);
}

PX_FORCE_INLINE VecU32V U4LoadU(const PxU32* i)
{
	return VecU32V(i[0], i[1], i[2], i[3]);
}

PX_FORCE_INLINE VecU32V U4LoadA(const PxU32* i)
{
	return VecU32V(i[0], i[1], i[2], i[3]);
}

PX_FORCE_INLINE VecI32V I4Load(const PxI32 i)
{
	return VecI32V(i, i, i, i);
}

PX_FORCE_INLINE VecI32V I4LoadU(const PxI32* i)
{
	return VecI32V(i[0], i[1], i[2], i[3]);
}

PX_FORCE_INLINE VecI32V I4LoadA(const PxI32* i)
{
	return VecI32V(i[0], i[1], i[2], i[3]);
}

PX_FORCE_INLINE VecI32V VecI32V_Add(const VecI32VArg a, const VecI32VArg b)
{
	return VecI32V(a.i32[0] + b.i32[0], a.i32[1] + b.i32[1], a.i32[2] + b.i32[2], a.i32[3] + b.i32[3]);
}

PX_FORCE_INLINE VecI32V VecI32V_Sub(const VecI32VArg a, const VecI32VArg b)
{
	return VecI32V(a.i32[0] - b.i32[0], a.i32[1] - b.i32[1], a.i32[2] - b.i32[2], a.i32[3] - b.i32[3]);
}

PX_FORCE_INLINE BoolV VecI32V_IsGrtr(const VecI32VArg a, const VecI32VArg b)
{
	return BoolV(BOOL_TO_U32(a.i32[0] > b.i32[0]), BOOL_TO_U32(a.i32[1] > b.i32[1]), BOOL_TO_U32(a.i32[2] > b.i32[2]), BOOL_TO_U32(a.i32[3] > b.i32[3]));
}

PX_FORCE_INLINE BoolV VecI32V_IsEq(const VecI32VArg a, const VecI32VArg b)
{
	return BoolV(BOOL_TO_U32(a.i32[0] == b.i32[0]), BOOL_TO_U32(a.i32[1] == b.i32[1]), BOOL_TO_U32(a.i32[2] == b.i32[2]), BOOL_TO_U32(a.i32[3] == b.i32[3]));
}

PX_FORCE_INLINE VecI32V V4I32Sel(const BoolV c, const VecI32V a, const VecI32V b)
{
	return VecI32V(c.ux ? a.i32[0] : b.i32[0], c.uy ? a.i32[1] : b.i32[1], c.uz ? a.i32[2] : b.i32[2],
	               c.uw ? a.i32[3] : b.i32[3]);
}

PX_FORCE_INLINE VecI32V VecI32V_Zero()
{
	return VecI32V(0, 0, 0, 0);
}

PX_FORCE_INLINE VecI32V VecI32V_One()
{
	return VecI32V(1, 1, 1, 1);
}

PX_FORCE_INLINE VecI32V VecI32V_Two()
{
	return VecI32V(2, 2, 2, 2);
}

PX_FORCE_INLINE VecI32V VecI32V_MinusOne()
{
	return VecI32V(-1, -1, -1, -1);
}

PX_FORCE_INLINE VecU32V U4Zero()
{
	return VecU32V(0, 0, 0, 0);
}

PX_FORCE_INLINE VecU32V U4One()
{
	return VecU32V(1, 1, 1, 1);
}

PX_FORCE_INLINE VecU32V U4Two()
{
	return VecU32V(2, 2, 2, 2);
}

PX_FORCE_INLINE VecShiftV VecI32V_PrepareShift(const VecI32VArg shift)
{
	return shift;
}

PX_FORCE_INLINE VecI32V VecI32V_LeftShift(const VecI32VArg a, const VecShiftVArg count)
{
	return VecI32V(a.i32[0] << count.i32[0], a.i32[1] << count.i32[1], a.i32[2] << count.i32[2], a.i32[3]
	                                                                                                 << count.i32[3]);
}

PX_FORCE_INLINE VecI32V VecI32V_RightShift(const VecI32VArg a, const VecShiftVArg count)
{
	return VecI32V(a.i32[0] >> count.i32[0], a.i32[1] >> count.i32[1], a.i32[2] >> count.i32[2],
	               a.i32[3] >> count.i32[3]);
}

PX_FORCE_INLINE VecI32V VecI32V_And(const VecI32VArg a, const VecI32VArg b)
{
	return VecI32V(a.i32[0] & b.i32[0], a.i32[1] & b.i32[1], a.i32[2] & b.i32[2], a.i32[3] & b.i32[3]);
}

PX_FORCE_INLINE VecI32V VecI32V_Or(const VecI32VArg a, const VecI32VArg b)
{
	return VecI32V(a.i32[0] | b.i32[0], a.i32[1] | b.i32[1], a.i32[2] | b.i32[2], a.i32[3] | b.i32[3]);
}

PX_FORCE_INLINE VecI32V VecI32V_GetX(const VecI32VArg a)
{
	return VecI32V(a.i32[0], a.i32[0], a.i32[0], a.i32[0]);
}

PX_FORCE_INLINE VecI32V VecI32V_GetY(const VecI32VArg a)
{
	return VecI32V(a.i32[1], a.i32[1], a.i32[1], a.i32[1]);
}

PX_FORCE_INLINE VecI32V VecI32V_GetZ(const VecI32VArg a)
{
	return VecI32V(a.i32[2], a.i32[2], a.i32[2], a.i32[2]);
}

PX_FORCE_INLINE VecI32V VecI32V_GetW(const VecI32VArg a)
{
	return VecI32V(a.i32[3], a.i32[3], a.i32[3], a.i32[3]);
}

PX_FORCE_INLINE VecI32V VecI32V_Sel(const BoolV c, const VecI32VArg a, const VecI32VArg b)
{
	return VecI32V(c.ux ? a.i32[0] : b.i32[0], c.uy ? a.i32[1] : b.i32[1], c.uz ? a.i32[2] : b.i32[2],
	               c.uw ? a.i32[3] : b.i32[3]);
}

PX_FORCE_INLINE VecI32V VecI32V_Merge(const VecI32VArg a, const VecI32VArg b, const VecI32VArg c, const VecI32VArg d)
{
	return VecI32V(a.i32[0], b.i32[0], c.i32[0], d.i32[0]);
}

PX_FORCE_INLINE void PxI32_From_VecI32V(const VecI32VArg a, PxI32* i)
{
	*i = a.i32[0];
}

PX_FORCE_INLINE VecI32V VecI32V_From_BoolV(const BoolVArg b)
{
	return VecI32V(PxI32(b.ux), PxI32(b.uy), PxI32(b.uz), PxI32(b.uw));
}

PX_FORCE_INLINE VecU32V VecU32V_From_BoolV(const BoolVArg b)
{
	return VecU32V(b.ux, b.uy, b.uz, b.uw);
}

PX_FORCE_INLINE void QuatGetMat33V(const QuatVArg q, Vec3V& column0, Vec3V& column1, Vec3V& column2)
{
	const FloatV one = FOne();
	const FloatV x = V4GetX(q);
	const FloatV y = V4GetY(q);
	const FloatV z = V4GetZ(q);
	const FloatV w = V4GetW(q);

	const FloatV x2 = FAdd(x, x);
	const FloatV y2 = FAdd(y, y);
	const FloatV z2 = FAdd(z, z);

	const FloatV xx = FMul(x2, x);
	const FloatV yy = FMul(y2, y);
	const FloatV zz = FMul(z2, z);

	const FloatV xy = FMul(x2, y);
	const FloatV xz = FMul(x2, z);
	const FloatV xw = FMul(x2, w);

	const FloatV yz = FMul(y2, z);
	const FloatV yw = FMul(y2, w);
	const FloatV zw = FMul(z2, w);

	const FloatV v = FSub(one, xx);

	column0 = V3Merge(FSub(FSub(one, yy), zz), FAdd(xy, zw), FSub(xz, yw));
	column1 = V3Merge(FSub(xy, zw), FSub(v, zz), FAdd(yz, xw));
	column2 = V3Merge(FAdd(xz, yw), FSub(yz, xw), FSub(v, yy));
}


// not used

/*
PX_FORCE_INLINE Vec4V V4LoadAligned(Vec4V* addr)
{
    return *addr;
}
*/

/*
PX_FORCE_INLINE Vec4V V4LoadUnaligned(Vec4V* addr)
{
    return *addr;
}
*/

/*
PX_FORCE_INLINE Vec4V V4Ceil(const Vec4V a)
{
    return Vec4V(PxCeil(a.x), PxCeil(a.y), PxCeil(a.z), PxCeil(a.w));
}

PX_FORCE_INLINE Vec4V V4Floor(const Vec4V a)
{
    return Vec4V(PxFloor(a.x), PxFloor(a.y), PxFloor(a.z), PxFloor(a.w));
}
*/

/*
PX_FORCE_INLINE VecU32V V4ConvertToU32VSaturate(const Vec4V a, PxU32 power)
{
    PX_ASSERT(power == 0 && "Non-zero power not supported in convertToU32VSaturate");
    PX_UNUSED(power); // prevent warning in release builds
    PxF32 ffffFFFFasFloat = PxF32(0xFFFF0000);
    return VecU32V(
        PxU32(PxClamp<PxF32>((a).x, 0.0f, ffffFFFFasFloat)),
        PxU32(PxClamp<PxF32>((a).y, 0.0f, ffffFFFFasFloat)),
        PxU32(PxClamp<PxF32>((a).z, 0.0f, ffffFFFFasFloat)),
        PxU32(PxClamp<PxF32>((a).w, 0.0f, ffffFFFFasFloat)));
}
*/

} // namespace aos
} // namespace shdfnd
} // namespace physx

#endif // PSFOUNDATION_PSVECMATHAOSSCALARINLINE_H