/usr/include/graphene-1.0/graphene-simd4f.h is in libgraphene-1.0-dev 1.8.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | /* graphene-simd4f.h: SIMD wrappers and operations
*
* Copyright 2014 Emmanuele Bassi
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SH1_0 THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef __GRAPHENE_SIMD4F_H__
#define __GRAPHENE_SIMD4F_H__
#if !defined(GRAPHENE_H_INSIDE) && !defined(GRAPHENE_COMPILATION)
#error "Only graphene.h can be included directly."
#endif
/* needed for memcpy() */
#include <string.h>
#include <math.h>
#include "graphene-config.h"
#include "graphene-macros.h"
#include "graphene-version-macros.h"
GRAPHENE_BEGIN_DECLS
/* Platform specific operations */
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_init (float x,
float y,
float z,
float w);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_init_zero (void);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_init_4f (const float *v);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_init_3f (const float *v);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_init_2f (const float *v);
GRAPHENE_AVAILABLE_IN_1_0
void graphene_simd4f_dup_4f (const graphene_simd4f_t s,
float *v);
GRAPHENE_AVAILABLE_IN_1_0
void graphene_simd4f_dup_3f (const graphene_simd4f_t s,
float *v);
GRAPHENE_AVAILABLE_IN_1_0
void graphene_simd4f_dup_2f (const graphene_simd4f_t s,
float *v);
GRAPHENE_AVAILABLE_IN_1_2
float graphene_simd4f_get (const graphene_simd4f_t s,
unsigned int i);
GRAPHENE_AVAILABLE_IN_1_0
float graphene_simd4f_get_x (const graphene_simd4f_t s);
GRAPHENE_AVAILABLE_IN_1_0
float graphene_simd4f_get_y (const graphene_simd4f_t s);
GRAPHENE_AVAILABLE_IN_1_0
float graphene_simd4f_get_z (const graphene_simd4f_t s);
GRAPHENE_AVAILABLE_IN_1_0
float graphene_simd4f_get_w (const graphene_simd4f_t s);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_splat (float v);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_splat_x (const graphene_simd4f_t s);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_splat_y (const graphene_simd4f_t s);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_splat_z (const graphene_simd4f_t s);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_splat_w (const graphene_simd4f_t s);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_add (const graphene_simd4f_t a,
const graphene_simd4f_t b);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_sub (const graphene_simd4f_t a,
const graphene_simd4f_t b);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_mul (const graphene_simd4f_t a,
const graphene_simd4f_t b);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_div (const graphene_simd4f_t a,
const graphene_simd4f_t b);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_sqrt (const graphene_simd4f_t s);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_reciprocal (const graphene_simd4f_t s);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_rsqrt (const graphene_simd4f_t s);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_cross3 (const graphene_simd4f_t a,
const graphene_simd4f_t b);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_dot3 (const graphene_simd4f_t a,
const graphene_simd4f_t b);
GRAPHENE_AVAILABLE_IN_1_4
float graphene_simd4f_dot3_scalar (const graphene_simd4f_t a,
const graphene_simd4f_t b);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_min (const graphene_simd4f_t a,
const graphene_simd4f_t b);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_max (const graphene_simd4f_t a,
const graphene_simd4f_t b);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_shuffle_wxyz (const graphene_simd4f_t s);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_shuffle_zwxy (const graphene_simd4f_t s);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_shuffle_yzwx (const graphene_simd4f_t s);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_zero_w (const graphene_simd4f_t s);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_zero_zw (const graphene_simd4f_t s);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_merge_high (const graphene_simd4f_t a,
const graphene_simd4f_t b);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_merge_low (const graphene_simd4f_t a,
const graphene_simd4f_t b);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_merge_w (const graphene_simd4f_t s,
float v);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_flip_sign_0101 (const graphene_simd4f_t s);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_flip_sign_1010 (const graphene_simd4f_t s);
GRAPHENE_AVAILABLE_IN_1_0
bool graphene_simd4f_cmp_eq (const graphene_simd4f_t a,
const graphene_simd4f_t b);
GRAPHENE_AVAILABLE_IN_1_0
bool graphene_simd4f_cmp_neq (const graphene_simd4f_t a,
const graphene_simd4f_t b);
GRAPHENE_AVAILABLE_IN_1_2
bool graphene_simd4f_cmp_lt (const graphene_simd4f_t a,
const graphene_simd4f_t b);
GRAPHENE_AVAILABLE_IN_1_2
bool graphene_simd4f_cmp_le (const graphene_simd4f_t a,
const graphene_simd4f_t b);
GRAPHENE_AVAILABLE_IN_1_2
bool graphene_simd4f_cmp_ge (const graphene_simd4f_t a,
const graphene_simd4f_t b);
GRAPHENE_AVAILABLE_IN_1_2
bool graphene_simd4f_cmp_gt (const graphene_simd4f_t a,
const graphene_simd4f_t b);
GRAPHENE_AVAILABLE_IN_1_0
graphene_simd4f_t graphene_simd4f_neg (const graphene_simd4f_t s);
#if !defined(__GI_SCANNER__) && defined(GRAPHENE_USE_SSE)
/* SSE2 implementation of SIMD 4f */
/* Union type used to do single lane reading without memcpy */
typedef union {
graphene_simd4f_t s;
float f[4];
} graphene_simd4f_union_t;
/* On GCC, we use __extension__ macros to avoid a static inline */
# if defined(__GNUC__)
/* Use GCC statement __extension__ to inline all these functions */
# define graphene_simd4f_init(x,y,z,w) \
(__extension__ ({ \
(graphene_simd4f_t) { (x), (y), (z), (w) }; \
}))
# define graphene_simd4f_init_zero() \
(__extension__ ({ \
(graphene_simd4f_t) _mm_setzero_ps(); \
}))
# define graphene_simd4f_init_4f(v) \
(__extension__ ({ \
(graphene_simd4f_t) _mm_loadu_ps (v); \
}))
# define graphene_simd4f_init_3f(v) \
(__extension__ ({ \
(graphene_simd4f_t) { (v)[0], (v)[1], (v)[2], 0.f }; \
}))
# define graphene_simd4f_init_2f(v) \
(__extension__ ({ \
(graphene_simd4f_t) { (v)[0], (v)[1], 0.f, 0.f }; \
}))
# define graphene_simd4f_dup_4f(s,v) \
(__extension__ ({ \
_mm_storeu_ps ((v), (s)); \
}))
# define graphene_simd4f_dup_3f(s,v) \
(__extension__ ({ \
memcpy ((v), &(s), sizeof (float) * 3); \
}))
# define graphene_simd4f_dup_2f(s,v) \
(__extension__ ({ \
memcpy ((v), &(s), sizeof (float) * 2); \
}))
# define graphene_simd4f_get(s,i) \
(__extension__ ({ \
graphene_simd4f_union_t __u = { (s) }; \
(float) __u.f[(i)]; \
}))
# define graphene_simd4f_get_x(s) graphene_simd4f_get (s, 0)
# define graphene_simd4f_get_y(s) graphene_simd4f_get (s, 1)
# define graphene_simd4f_get_z(s) graphene_simd4f_get (s, 2)
# define graphene_simd4f_get_w(s) graphene_simd4f_get (s, 3)
# define graphene_simd4f_splat(v) \
(__extension__ ({ \
(graphene_simd4f_t) _mm_set1_ps ((v)); \
}))
# define graphene_simd4f_splat_x(v) \
(__extension__ ({ \
(graphene_simd4f_t) _mm_shuffle_ps ((v), (v), _MM_SHUFFLE (0, 0, 0, 0)); \
}))
# define graphene_simd4f_splat_y(v) \
(__extension__ ({ \
(graphene_simd4f_t) _mm_shuffle_ps ((v), (v), _MM_SHUFFLE (1, 1, 1, 1)); \
}))
# define graphene_simd4f_splat_z(v) \
(__extension__ ({ \
(graphene_simd4f_t) _mm_shuffle_ps ((v), (v), _MM_SHUFFLE (2, 2, 2, 2)); \
}))
# define graphene_simd4f_splat_w(v) \
(__extension__ ({ \
(graphene_simd4f_t) _mm_shuffle_ps ((v), (v), _MM_SHUFFLE (3, 3, 3, 3)); \
}))
# define graphene_simd4f_add(a,b) \
(__extension__ ({ \
(graphene_simd4f_t) _mm_add_ps ((a), (b)); \
}))
# define graphene_simd4f_sub(a,b) \
(__extension__ ({ \
(graphene_simd4f_t) _mm_sub_ps ((a), (b)); \
}))
# define graphene_simd4f_mul(a,b) \
(__extension__ ({ \
(graphene_simd4f_t) _mm_mul_ps ((a), (b)); \
}))
# define graphene_simd4f_div(a,b) \
(__extension__ ({ \
(graphene_simd4f_t) _mm_div_ps ((a), (b)); \
}))
# define graphene_simd4f_sqrt(v) \
(__extension__ ({ \
(graphene_simd4f_t) _mm_sqrt_ps ((v)); \
}))
# define graphene_simd4f_reciprocal(v) \
(__extension__ ({ \
const graphene_simd4f_t __two = graphene_simd4f_init (2.0f, 2.0f, 2.0f, 2.0f); \
graphene_simd4f_t __s = _mm_rcp_ps ((v)); \
graphene_simd4f_mul (__s, graphene_simd4f_sub (__two, graphene_simd4f_mul ((v), __s))); \
}))
# define graphene_simd4f_rsqrt(v) \
(__extension__ ({ \
const graphene_simd4f_t __half = graphene_simd4f_init (0.5f, 0.5f, 0.5f, 0.5f); \
const graphene_simd4f_t __three = graphene_simd4f_init (3.0f, 3.0f, 3.0f, 3.0f); \
graphene_simd4f_t __s = _mm_rsqrt_ps ((v)); \
graphene_simd4f_mul (graphene_simd4f_mul (__s, __half), \
graphene_simd4f_sub (__three, \
graphene_simd4f_mul (__s, graphene_simd4f_mul ((v), __s)))); \
}))
# define graphene_simd4f_cross3(a,b) \
(__extension__ ({ \
const graphene_simd4f_t __a_yzx = _mm_shuffle_ps ((a), (a), _MM_SHUFFLE (3, 0, 2, 1)); \
const graphene_simd4f_t __a_zxy = _mm_shuffle_ps ((a), (a), _MM_SHUFFLE (3, 1, 0, 2)); \
const graphene_simd4f_t __b_yzx = _mm_shuffle_ps ((b), (b), _MM_SHUFFLE (3, 0, 2, 1)); \
const graphene_simd4f_t __b_zxy = _mm_shuffle_ps ((b), (b), _MM_SHUFFLE (3, 1, 0, 2)); \
(graphene_simd4f_t) _mm_sub_ps (_mm_mul_ps (__a_yzx, __b_zxy), _mm_mul_ps (__a_zxy, __b_yzx)); \
}))
# if defined(GRAPHENE_USE_SSE4_1)
# define graphene_simd4f_dot3(a,b) \
(__extension__ ({ \
(graphene_simd4f_t) _mm_dp_ps ((a), (b), 0x7f); \
}))
# else
# define graphene_simd4f_dot3(a,b) \
(__extension__ ({ \
GRAPHENE_ALIGN16 const unsigned int __mask_bits[] = { 0xffffffff, 0xffffffff, 0xffffffff, 0 }; \
const graphene_simd4f_t __mask = _mm_load_ps ((const float *) __mask_bits); \
const graphene_simd4f_t __m = _mm_mul_ps ((a), (b)); \
const graphene_simd4f_t __s0 = _mm_and_ps (__m, __mask); \
const graphene_simd4f_t __s1 = _mm_add_ps (__s0, _mm_movehl_ps (__s0, __s0)); \
const graphene_simd4f_t __s2 = _mm_add_ss (__s1, _mm_shuffle_ps (__s1, __s1, 1)); \
(graphene_simd4f_t) _mm_shuffle_ps (__s2, __s2, 0); \
}))
# endif
# define graphene_simd4f_dot3_scalar(a,b) \
(__extension__ ({ \
float __res; \
_mm_store_ss (&__res, graphene_simd4f_dot3 (a, b)); \
__res; \
}))
# define graphene_simd4f_min(a,b) \
(__extension__ ({ \
(graphene_simd4f_t) _mm_min_ps ((a), (b)); \
}))
# define graphene_simd4f_max(a,b) \
(__extension__ ({ \
(graphene_simd4f_t) _mm_max_ps ((a), (b)); \
}))
# define graphene_simd4f_shuffle_wxyz(v) \
(__extension__ ({ \
(graphene_simd4f_t) _mm_shuffle_ps ((v), (v), _MM_SHUFFLE (2, 1, 0, 3)); \
}))
# define graphene_simd4f_shuffle_zwxy(v) \
(__extension__ ({ \
(graphene_simd4f_t) _mm_shuffle_ps ((v), (v), _MM_SHUFFLE (1, 0, 3, 2)); \
}))
# define graphene_simd4f_shuffle_yzwx(v) \
(__extension__ ({ \
(graphene_simd4f_t) _mm_shuffle_ps ((v), (v), _MM_SHUFFLE (0, 3, 2, 1)); \
}))
# define graphene_simd4f_zero_w(v) \
(__extension__ ({ \
graphene_simd4f_t __s = _mm_unpackhi_ps ((v), _mm_setzero_ps ()); \
(graphene_simd4f_t) _mm_movelh_ps ((v), __s); \
}))
# define graphene_simd4f_zero_zw(v) \
(__extension__ ({ \
(graphene_simd4f_t) _mm_movelh_ps ((v), _mm_setzero_ps ()); \
}))
# define graphene_simd4f_merge_w(s,v) \
(__extension__ ({ \
graphene_simd4f_t __s = _mm_unpackhi_ps ((s), _mm_set1_ps ((v))); \
(graphene_simd4f_t) _mm_movelh_ps ((s), __s); \
}))
# define graphene_simd4f_merge_high(a,b) \
(__extension__ ({ \
(graphene_simd4f_t) _mm_movehl_ps ((b), (a)); \
}))
# define graphene_simd4f_merge_low(a,b) \
(__extension__ ({ \
(graphene_simd4f_t) _mm_movelh_ps ((a), (b)); \
}))
typedef GRAPHENE_ALIGN16 union {
unsigned int ui[4];
float f[4];
} graphene_simd4f_uif_t;
# define graphene_simd4f_flip_sign_0101(v) \
(__extension__ ({ \
const graphene_simd4f_uif_t __pnpn = { { \
0x00000000, \
0x80000000, \
0x00000000, \
0x80000000 \
} }; \
(graphene_simd4f_t) _mm_xor_ps ((v), _mm_load_ps (__pnpn.f)); \
}))
# define graphene_simd4f_flip_sign_1010(v) \
(__extension__ ({ \
const graphene_simd4f_uif_t __npnp = { { \
0x80000000, \
0x00000000, \
0x80000000, \
0x00000000, \
} }; \
(graphene_simd4f_t) _mm_xor_ps ((v), _mm_load_ps (__npnp.f)); \
}))
# define graphene_simd4f_cmp_eq(a,b) \
(__extension__ ({ \
__m128i __res = (__m128i) _mm_cmpneq_ps ((a), (b)); \
(bool) (_mm_movemask_epi8 (__res) == 0); \
}))
# define graphene_simd4f_cmp_neq(a,b) \
(__extension__ ({ \
__m128i __res = (__m128i) _mm_cmpneq_ps ((a), (b)); \
(bool) (_mm_movemask_epi8 (__res) != 0); \
}))
# define graphene_simd4f_cmp_lt(a,b) \
(__extension__ ({ \
__m128i __res = (__m128i) _mm_cmplt_ps ((a), (b)); \
(bool) (_mm_movemask_epi8 (__res) == 0xffff); \
}))
# define graphene_simd4f_cmp_le(a,b) \
(__extension__ ({ \
__m128i __res = (__m128i) _mm_cmple_ps ((a), (b)); \
(bool) (_mm_movemask_epi8 (__res) == 0xffff); \
}))
# define graphene_simd4f_cmp_ge(a,b) \
(__extension__ ({ \
__m128i __res = (__m128i) _mm_cmpge_ps ((a), (b)); \
(bool) (_mm_movemask_epi8 (__res) == 0xffff); \
}))
# define graphene_simd4f_cmp_gt(a,b) \
(__extension__ ({ \
__m128i __res = (__m128i) _mm_cmpgt_ps ((a), (b)); \
(bool) (_mm_movemask_epi8 (__res) == 0xffff); \
}))
# define graphene_simd4f_neg(s) \
(__extension__ ({ \
const graphene_simd4f_uif_t __mask = { { \
0x80000000, \
0x80000000, \
0x80000000, \
0x80000000, \
} }; \
(graphene_simd4f_t) _mm_xor_ps ((s), _mm_load_ps (__mask.f)); \
}))
/* On MSVC, we use static inlines */
# elif defined (_MSC_VER)
/* Use static inline to inline all these functions */
#define graphene_simd4f_init(x,y,z,w) _simd4f_init(x,y,z,w)
static inline graphene_simd4f_t
_simd4f_init (float x, float y, float z, float w)
{
graphene_simd4f_t __s = { x, y, z, w };
return __s;
}
#define graphene_simd4f_init_zero() \
_mm_setzero_ps()
#define graphene_simd4f_init_4f(v) \
_mm_loadu_ps(v)
#define graphene_simd4f_init_3f(v) \
graphene_simd4f_init (v[0], v[1], v[2], 0.f)
#define graphene_simd4f_init_2f(v) \
graphene_simd4f_init (v[0], v[1], 0.f, 0.f)
#define graphene_simd4f_dup_4f(s,v) \
_mm_storeu_ps (v, s)
#define graphene_simd4f_dup_3f(s,v) \
memcpy (v, &s, sizeof (float) * 3)
#define graphene_simd4f_dup_2f(s,v) \
memcpy (v, &s, sizeof (float) * 2)
#define graphene_simd4f_get(s,i) _simd4f_get_xyzw(s, i)
#define graphene_simd4f_get_x(s) _simd4f_get_xyzw(s, 0)
#define graphene_simd4f_get_y(s) _simd4f_get_xyzw(s, 1)
#define graphene_simd4f_get_z(s) _simd4f_get_xyzw(s, 2)
#define graphene_simd4f_get_w(s) _simd4f_get_xyzw(s, 3)
static inline float
_simd4f_get_xyzw (graphene_simd4f_t s, int mode)
{
/* mode: get_x=0
get_y=1
get_z=2
get_w=3 */
graphene_simd4f_union_t u;
u.s = s;
return u.f[mode];
}
#define graphene_simd4f_splat(v) \
_mm_set1_ps (v)
#define graphene_simd4f_splat_x(v) \
_mm_shuffle_ps (v, v, _MM_SHUFFLE (0, 0, 0, 0))
#define graphene_simd4f_splat_y(v) \
_mm_shuffle_ps (v, v, _MM_SHUFFLE (1, 1, 1, 1))
#define graphene_simd4f_splat_z(v) \
_mm_shuffle_ps (v, v, _MM_SHUFFLE (2, 2, 2, 2))
#define graphene_simd4f_splat_w(v) \
_mm_shuffle_ps (v, v, _MM_SHUFFLE (3, 3, 3, 3))
#define graphene_simd4f_add(a,b) \
_mm_add_ps (a, b)
#define graphene_simd4f_sub(a,b) \
_mm_sub_ps (a, b)
#define graphene_simd4f_mul(a,b) \
_mm_mul_ps (a, b)
#define graphene_simd4f_div(a,b) \
_mm_div_ps (a, b)
#define graphene_simd4f_sqrt(v) \
_mm_sqrt_ps (v)
#define graphene_simd4f_reciprocal(v) _simd4f_reciprocal(v)
static inline graphene_simd4f_t
_simd4f_reciprocal(const graphene_simd4f_t v)
{
const graphene_simd4f_t __two = graphene_simd4f_init (2.0f, 2.0f, 2.0f, 2.0f);
graphene_simd4f_t __s = _mm_rcp_ps (v);
return graphene_simd4f_mul (__s,
graphene_simd4f_sub (__two,
graphene_simd4f_mul (v, __s)));
}
#define graphene_simd4f_rsqrt(v) _simd4f_rsqrt(v)
static inline graphene_simd4f_t
_simd4f_rsqrt(const graphene_simd4f_t v)
{
const graphene_simd4f_t __half = graphene_simd4f_init (0.5f, 0.5f, 0.5f, 0.5f);
const graphene_simd4f_t __three = graphene_simd4f_init (3.0f, 3.0f, 3.0f, 3.0f);
graphene_simd4f_t __s = _mm_rsqrt_ps (v);
return graphene_simd4f_mul (graphene_simd4f_mul (__s, __half),
graphene_simd4f_sub (__three,
graphene_simd4f_mul (__s, graphene_simd4f_mul (v, __s))));
}
#define graphene_simd4f_cross3(a,b) \
_simd4f_cross3(a,b)
static inline graphene_simd4f_t
_simd4f_cross3 (const graphene_simd4f_t a,
const graphene_simd4f_t b)
{
const graphene_simd4f_t __a_yzx = _mm_shuffle_ps (a, a, _MM_SHUFFLE (3, 0, 2, 1));
const graphene_simd4f_t __a_zxy = _mm_shuffle_ps (a, a, _MM_SHUFFLE (3, 1, 0, 2));
const graphene_simd4f_t __b_yzx = _mm_shuffle_ps (b, b, _MM_SHUFFLE (3, 0, 2, 1));
const graphene_simd4f_t __b_zxy = _mm_shuffle_ps (b, b, _MM_SHUFFLE (3, 1, 0, 2));
return _mm_sub_ps (_mm_mul_ps (__a_yzx, __b_zxy), _mm_mul_ps (__a_zxy, __b_yzx));
}
#define graphene_simd4f_dot3(a,b) \
_simd4f_dot3(a,b)
static inline graphene_simd4f_t
_simd4f_dot3 (const graphene_simd4f_t a,
const graphene_simd4f_t b)
{
#if defined(GRAPHENE_USE_SSE4_1)
return _mm_dp_ps (a, b, 0x7f);
#else
GRAPHENE_ALIGN16 const unsigned int __mask_bits[] = { 0xffffffff, 0xffffffff, 0xffffffff, 0 };
const graphene_simd4f_t __mask = _mm_load_ps ((const float *) __mask_bits);
const graphene_simd4f_t __m = _mm_mul_ps ((a), (b));
const graphene_simd4f_t __s0 = _mm_and_ps (__m, __mask);
const graphene_simd4f_t __s1 = _mm_add_ps (__s0, _mm_movehl_ps (__s0, __s0));
const graphene_simd4f_t __s2 = _mm_add_ss (__s1, _mm_shuffle_ps (__s1, __s1, 1));
return _mm_shuffle_ps (__s2, __s2, 0);
#endif
}
#define graphene_simd4f_dot3_scalar(a,b) \
_simd4f_dot3_scalar(a,b)
static inline float
_simd4f_dot3_scalar (const graphene_simd4f_t a,
const graphene_simd4f_t b)
{
float __res;
_mm_store_ss (&__res, graphene_simd4f_dot3 (a, b));
return __res;
}
#define graphene_simd4f_min(a,b) \
_mm_min_ps (a, b)
#define graphene_simd4f_max(a,b) \
_mm_max_ps (a, b)
#define graphene_simd4f_shuffle_wxyz(v) \
_mm_shuffle_ps (v, v, _MM_SHUFFLE (2, 1, 0, 3))
#define graphene_simd4f_shuffle_zwxy(v) \
_mm_shuffle_ps (v, v, _MM_SHUFFLE (1, 0, 3, 2))
#define graphene_simd4f_shuffle_yzwx(v) \
_mm_shuffle_ps (v, v, _MM_SHUFFLE (0, 3, 2, 1))
#define graphene_simd4f_zero_w(v) \
_mm_movelh_ps (v, _mm_unpackhi_ps (v, _mm_setzero_ps ()))
#define graphene_simd4f_zero_zw(v) \
_mm_movelh_ps (v, _mm_setzero_ps ())
#define graphene_simd4f_merge_w(s,v) \
_mm_movelh_ps (s, _mm_unpackhi_ps (s, _mm_set1_ps (v)))
#define graphene_simd4f_merge_high(a,b) \
_mm_movehl_ps (b, a)
#define graphene_simd4f_merge_low(a,b) \
_mm_movelh_ps (a, b)
typedef GRAPHENE_ALIGN16 union {
unsigned int ui[4];
float f[4];
} graphene_simd4f_uif_t;
#define graphene_simd4f_flip_sign_0101(v) _simd4f_flip_sign_0101(v)
static inline graphene_simd4f_t
_simd4f_flip_sign_0101 (const graphene_simd4f_t v)
{
const graphene_simd4f_uif_t __pnpn = { {
0x00000000,
0x80000000,
0x00000000,
0x80000000
} };
return _mm_xor_ps (v, _mm_load_ps (__pnpn.f));
}
#define graphene_simd4f_flip_sign_1010(v) _simd4f_flip_sign_1010(v)
static inline graphene_simd4f_t
_simd4f_flip_sign_1010(const graphene_simd4f_t v)
{
const graphene_simd4f_uif_t __npnp = { {
0x80000000,
0x00000000,
0x80000000,
0x00000000,
} };
return _mm_xor_ps (v, _mm_load_ps (__npnp.f));
}
#define graphene_simd4f_cmp_eq(a,b) _simd4f_cmp_eq(a,b)
static inline bool
_simd4f_cmp_eq (const graphene_simd4f_t a,
const graphene_simd4f_t b)
{
__m128i __res = _mm_castps_si128 (_mm_cmpneq_ps (a, b));
return (_mm_movemask_epi8 (__res) == 0);
}
#define graphene_simd4f_cmp_neq(a,b) _simd4f_cmp_neq(a,b)
static inline bool
_simd4f_cmp_neq (const graphene_simd4f_t a,
const graphene_simd4f_t b)
{
__m128i __res = _mm_castps_si128 (_mm_cmpneq_ps (a, b));
return (_mm_movemask_epi8 (__res) != 0);
}
#define graphene_simd4f_cmp_lt(a,b) _simd4f_cmp_lt(a,b)
static inline bool
_simd4f_cmp_lt (const graphene_simd4f_t a,
const graphene_simd4f_t b)
{
__m128i __res = _mm_castps_si128 (_mm_cmplt_ps (a, b));
return (_mm_movemask_epi8 (__res) == 0xffff);
}
#define graphene_simd4f_cmp_le(a,b) _simd4f_cmp_le(a,b)
static inline bool
_simd4f_cmp_le (const graphene_simd4f_t a,
const graphene_simd4f_t b)
{
__m128i __res = _mm_castps_si128 (_mm_cmple_ps (a, b));
return (_mm_movemask_epi8 (__res) == 0xffff);
}
#define graphene_simd4f_cmp_ge(a,b) _simd4f_cmp_ge(a,b)
static inline bool
_simd4f_cmp_ge (const graphene_simd4f_t a,
const graphene_simd4f_t b)
{
__m128i __res = _mm_castps_si128 (_mm_cmpge_ps (a, b));
return (_mm_movemask_epi8 (__res) == 0xffff);
}
#define graphene_simd4f_cmp_gt(a,b) _simd4f_cmp_gt(a,b)
static inline bool
_simd4f_cmp_gt (const graphene_simd4f_t a,
const graphene_simd4f_t b)
{
__m128i __res = _mm_castps_si128 (_mm_cmpgt_ps (a, b));
return (_mm_movemask_epi8 (__res) == 0xffff);
}
#define graphene_simd4f_neg(s) _simd4f_neg(s)
static inline graphene_simd4f_t
_simd4f_neg (const graphene_simd4f_t s)
{
const graphene_simd4f_uif_t __mask = { {
0x80000000,
0x80000000,
0x80000000,
0x80000000,
} };
return _mm_xor_ps (s, _mm_load_ps (__mask.f));
}
#else
# error "Need GCC-compatible or Visual Studio compiler for SSE extensions."
/* Use static inline to inline all these functions */
# endif /* __GNUC__ */
#elif !defined(__GI_SCANNER__) && defined(GRAPHENE_USE_GCC)
/* GCC vector intrinsic implementation of SIMD 4f */
typedef int graphene_simd4i_t __attribute__((vector_size (16)));
# define graphene_simd4f_init(x,y,z,w) \
(__extension__ ({ \
(graphene_simd4f_t) { (x), (y), (z), (w) }; \
}))
# define graphene_simd4f_init_zero() \
(__extension__ ({ \
(graphene_simd4f_t) { 0.f, 0.f, 0.f, 0.f }; \
}))
# define graphene_simd4f_init_4f(v) \
(__extension__ ({ \
(graphene_simd4f_t) { (v)[0], (v)[1], (v)[2], (v)[3] }; \
}))
# define graphene_simd4f_init_3f(v) \
(__extension__ ({ \
(graphene_simd4f_t) { (v)[0], (v)[1], (v)[2], 0.f }; \
}))
# define graphene_simd4f_init_2f(v) \
(__extension__ ({ \
(graphene_simd4f_t) { (v)[0], (v)[1], 0.f, 0.f }; \
}))
# define graphene_simd4f_dup_4f(s,v) \
(__extension__ ({ \
memcpy ((v), &(s), sizeof (float) * 4); \
}))
# define graphene_simd4f_dup_3f(s,v) \
(__extension__ ({ \
memcpy ((v), &(s), sizeof (float) * 3); \
}))
# define graphene_simd4f_dup_2f(s,v) \
(__extension__ ({ \
memcpy ((v), &(s), sizeof (float) * 2); \
}))
# define graphene_simd4f_get(s,i) (__extension__ ({ (float) (s)[(i)]; }))
# define graphene_simd4f_get_x(s) graphene_simd4f_get ((s), 0)
# define graphene_simd4f_get_y(s) graphene_simd4f_get ((s), 1)
# define graphene_simd4f_get_z(s) graphene_simd4f_get ((s), 2)
# define graphene_simd4f_get_w(s) graphene_simd4f_get ((s), 3)
# define graphene_simd4f_splat(v) \
(__extension__ ({ \
(graphene_simd4f_t) { (v), (v), (v), (v) }; \
}))
# define graphene_simd4f_splat_x(v) \
(__extension__ ({ \
float __val = graphene_simd4f_get_x ((v)); \
(graphene_simd4f_t) { __val, __val, __val, __val }; \
}))
# define graphene_simd4f_splat_y(v) \
(__extension__ ({ \
float __val = graphene_simd4f_get_y ((v)); \
(graphene_simd4f_t) { __val, __val, __val, __val }; \
}))
# define graphene_simd4f_splat_z(v) \
(__extension__ ({ \
float __val = graphene_simd4f_get_z ((v)); \
(graphene_simd4f_t) { __val, __val, __val, __val }; \
}))
# define graphene_simd4f_splat_w(v) \
(__extension__ ({ \
float __val = graphene_simd4f_get_w ((v)); \
(graphene_simd4f_t) { __val, __val, __val, __val }; \
}))
# define graphene_simd4f_reciprocal(v) \
(__extension__ ({ \
(graphene_simd4f_t) { \
(v)[0] != 0.f ? 1.f / (v)[0] : 0.f, \
(v)[1] != 0.f ? 1.f / (v)[1] : 0.f, \
(v)[2] != 0.f ? 1.f / (v)[2] : 0.f, \
(v)[3] != 0.f ? 1.f / (v)[3] : 0.f, \
}; \
}))
# define graphene_simd4f_sqrt(v) \
(__extension__ ({ \
(graphene_simd4f_t) { \
sqrtf ((v)[0]), \
sqrtf ((v)[1]), \
sqrtf ((v)[2]), \
sqrtf ((v)[3]), \
}; \
}))
# define graphene_simd4f_rsqrt(v) \
(__extension__ ({ \
(graphene_simd4f_t) { \
(v)[0] != 0.f ? 1.f / sqrtf ((v)[0]) : 0.f, \
(v)[1] != 0.f ? 1.f / sqrtf ((v)[1]) : 0.f, \
(v)[2] != 0.f ? 1.f / sqrtf ((v)[2]) : 0.f, \
(v)[3] != 0.f ? 1.f / sqrtf ((v)[3]) : 0.f, \
}; \
}))
# define graphene_simd4f_add(a,b) (__extension__ ({ (graphene_simd4f_t) ((a) + (b)); }))
# define graphene_simd4f_sub(a,b) (__extension__ ({ (graphene_simd4f_t) ((a) - (b)); }))
# define graphene_simd4f_mul(a,b) (__extension__ ({ (graphene_simd4f_t) ((a) * (b)); }))
# define graphene_simd4f_div(a,b) (__extension__ ({ (graphene_simd4f_t) ((a) / (b)); }))
# define graphene_simd4f_cross3(a,b) \
(__extension__ ({ \
const graphene_simd4f_t __a = (a); \
const graphene_simd4f_t __b = (b); \
graphene_simd4f_init (__a[1] * __b[2] - __a[2] * __b[1], \
__a[2] * __b[0] - __a[0] * __b[2], \
__a[0] * __b[1] - __a[1] * __b[0], \
0.f); \
}))
# define graphene_simd4f_dot3(a,b) \
(__extension__ ({ \
const graphene_simd4f_t __a = (a); \
const graphene_simd4f_t __b = (b); \
const float __res = __a[0] * __b[0] + __a[1] * __b[1] + __a[2] * __b[2]; \
graphene_simd4f_init (__res, __res, __res, __res); \
}))
# define graphene_simd4f_dot3_scalar(a,b) \
(__extension__ ({ \
graphene_simd4f_get_x (graphene_simd4f_dot3 (a, b)); \
}))
# define graphene_simd4f_min(a,b) \
(__extension__ ({ \
const graphene_simd4f_t __a = (a); \
const graphene_simd4f_t __b = (b); \
graphene_simd4f_init (__a[0] < __b[0] ? __a[0] : __b[0], \
__a[1] < __b[1] ? __a[1] : __b[1], \
__a[2] < __b[2] ? __a[2] : __b[2], \
__a[3] < __b[3] ? __a[3] : __b[3]); \
}))
# define graphene_simd4f_max(a,b) \
(__extension__ ({ \
const graphene_simd4f_t __a = (a); \
const graphene_simd4f_t __b = (b); \
graphene_simd4f_init (__a[0] > __b[0] ? __a[0] : __b[0], \
__a[1] > __b[1] ? __a[1] : __b[1], \
__a[2] > __b[2] ? __a[2] : __b[2], \
__a[3] > __b[3] ? __a[3] : __b[3]); \
}))
# define graphene_simd4f_shuffle_wxyz(v) \
(__extension__ ({ \
const graphene_simd4i_t __mask = { 3, 0, 1, 2 }; \
(graphene_simd4f_t) __builtin_shuffle ((v), __mask); \
}))
# define graphene_simd4f_shuffle_zwxy(v) \
(__extension__ ({ \
const graphene_simd4i_t __mask = { 2, 3, 0, 1 }; \
(graphene_simd4f_t) __builtin_shuffle ((v), __mask); \
}))
# define graphene_simd4f_shuffle_yzwx(v) \
(__extension__ ({ \
const graphene_simd4i_t __mask = { 1, 2, 3, 0 }; \
(graphene_simd4f_t) __builtin_shuffle ((v), __mask); \
}))
# define graphene_simd4f_zero_w(v) \
(__extension__ ({ \
const graphene_simd4i_t __mask = { 0, 1, 2, 4 }; \
(graphene_simd4f_t) __builtin_shuffle ((v), graphene_simd4f_init_zero (), __mask); \
}))
# define graphene_simd4f_zero_zw(v) \
(__extension__ ({ \
const graphene_simd4i_t __mask = { 0, 1, 4, 4 }; \
(graphene_simd4f_t) __builtin_shuffle ((v), graphene_simd4f_init_zero (), __mask); \
}))
# define graphene_simd4f_merge_w(s,v) \
(__extension__ ({ \
const graphene_simd4i_t __mask = { 0, 1, 2, 4 }; \
(graphene_simd4f_t) __builtin_shuffle ((s), graphene_simd4f_splat ((v)), __mask); \
}))
# define graphene_simd4f_merge_high(a,b) \
(__extension__ ({ \
const graphene_simd4i_t __mask = { 2, 3, 6, 7 }; \
(graphene_simd4f_t) __builtin_shuffle ((a), (b), __mask); \
}))
# define graphene_simd4f_merge_low(a,b) \
(__extension__ ({ \
const graphene_simd4i_t __mask = { 0, 1, 4, 5 }; \
(graphene_simd4f_t) __builtin_shuffle ((a), (b), __mask); \
}))
# define graphene_simd4f_flip_sign_0101(v) \
(__extension__ ({ \
const graphene_simd4f_t __v = (v); \
graphene_simd4f_init (__v[0], -__v[1], __v[2], -__v[3]); \
}))
# define graphene_simd4f_flip_sign_1010(v) \
(__extension__ ({ \
const graphene_simd4f_t __v = (v); \
graphene_simd4f_init (-__v[0], __v[1], -__v[2], __v[3]); \
}))
# define graphene_simd4f_cmp_eq(a,b) \
(__extension__ ({ \
const graphene_simd4i_t __res = (a) == (b); \
(bool) (__res[0] != 0 && \
__res[1] != 0 && \
__res[2] != 0 && \
__res[3] != 0); \
}))
# define graphene_simd4f_cmp_neq(a,b) (!graphene_simd4f_cmp_eq (a,b))
# define graphene_simd4f_cmp_lt(a,b) \
(__extension__ ({ \
const graphene_simd4i_t __res = (a) < (b); \
(bool) (__res[0] != 0 && \
__res[1] != 0 && \
__res[2] != 0 && \
__res[3] != 0); \
}))
# define graphene_simd4f_cmp_le(a,b) \
(__extension__ ({ \
const graphene_simd4i_t __res = (a) <= (b); \
(bool) (__res[0] != 0 && \
__res[1] != 0 && \
__res[2] != 0 && \
__res[3] != 0); \
}))
# define graphene_simd4f_cmp_ge(a,b) \
(__extension__ ({ \
const graphene_simd4i_t __res = (a) >= (b); \
(bool) (__res[0] != 0 && \
__res[1] != 0 && \
__res[2] != 0 && \
__res[3] != 0); \
}))
# define graphene_simd4f_cmp_gt(a,b) \
(__extension__ ({ \
const graphene_simd4i_t __res = (a) > (b); \
(bool) (__res[0] != 0 && \
__res[1] != 0 && \
__res[2] != 0 && \
__res[3] != 0); \
}))
# define graphene_simd4f_neg(s) \
(__extension__ ({ \
const graphene_simd4f_t __s = (s); \
const graphene_simd4f_t __minus_one = graphene_simd4f_splat (-1.f); \
graphene_simd4f_mul (__s, __minus_one); \
}))
#elif !defined(__GI_SCANNER__) && defined(GRAPHENE_USE_ARM_NEON)
/* ARM Neon implementation of SIMD4f */
# warning "The ARM Neon implementation of graphene_simd4f_t is experimental."
/* Union type used for single lane reading without memcpy */
typedef union {
graphene_simd4f_t s;
float f[4];
} graphene_simd4f_union_t;
/* NEON has optimised 2-lanes vectors we can use */
typedef float32x2_t graphene_simd2f_t;
# define graphene_simd4f_init(x,y,z,w) \
(__extension__ ({ \
const float32_t __v[4] = { (x), (y), (z), (w) }; \
(graphene_simd4f_t) vld1q_f32 (__v); \
}))
# define graphene_simd4f_init_zero() \
(__extension__ ({ \
(graphene_simd4f_t) vdupq_n_f32 (0.f); \
}))
# define graphene_simd4f_init_4f(v) \
(__extension__ ({ \
const float32_t *__v32 = (const float32_t *) (v); \
(graphene_simd4f_t) vld1q_f32 (__v32); \
}))
# define graphene_simd4f_init_3f(v) \
(__extension__ ({ \
graphene_simd4f_init (v[0], v[1], v[2], 0.f); \
}))
# define graphene_simd4f_init_2f(v) \
(__extension__ ({ \
const float32_t *__v32 = (const float32_t *) (v); \
const graphene_simd2f_t __low = vld1_f32 (__v32); \
const float32_t __zero = 0; \
const graphene_simd2f_t __high = vld1_dup_f32 (&__zero); \
(graphene_simd4f_t) vcombine_f32 (__low, __high); \
}))
# define graphene_simd4f_dup_4f(s,v) \
(__extension__ ({ \
vst1q_f32 ((float32_t *) (v), (s)); \
}))
# define graphene_simd4f_dup_3f(s,v) \
(__extension__ ({ \
float *__v = (v); \
vst1q_lane_f32 (__v++, (s), 0); \
vst1q_lane_f32 (__v++, (s), 1); \
vst1q_lane_f32 (__v, (s), 2); \
}))
# define graphene_simd4f_dup_2f(s,v) \
(__extension__ ({ \
const graphene_simd2f_t __low = vget_low_f32 ((s)); \
vst1_f32 ((float32_t *) (v), __low); \
}))
# define graphene_simd4f_get(s,i) \
(__extension__ ({ \
(float) vgetq_lane_f32 ((s), (i)); \
}))
# define graphene_simd4f_get_x(s) graphene_simd4f_get (s, 0)
# define graphene_simd4f_get_y(s) graphene_simd4f_get (s, 1)
# define graphene_simd4f_get_z(s) graphene_simd4f_get (s, 2)
# define graphene_simd4f_get_w(s) graphene_simd4f_get (s, 3)
# define graphene_simd4f_splat(v) \
(__extension__ ({ \
(graphene_simd4f_t) vdupq_n_f32 ((v)); \
}))
# define graphene_simd4f_splat_x(s) \
(__extension__ ({ \
graphene_simd4f_splat (graphene_simd4f_get_x ((s))); \
}))
# define graphene_simd4f_splat_y(s) \
(__extension__ ({ \
graphene_simd4f_splat (graphene_simd4f_get_y ((s))); \
}))
# define graphene_simd4f_splat_z(s) \
(__extension__ ({ \
graphene_simd4f_splat (graphene_simd4f_get_z ((s))); \
}))
# define graphene_simd4f_splat_w(s) \
(__extension__ ({ \
graphene_simd4f_splat (graphene_simd4f_get_w ((s))); \
}))
# define graphene_simd4f_reciprocal(s) \
(__extension__ ({ \
graphene_simd4f_t __est = vrecpeq_f32 ((s)); \
__est = vmulq_f32 (vrecpsq_f32 (__est, (s)), __est); \
(graphene_simd4f_t) vmulq_f32 (vrecpsq_f32 (__est, (s)), __est); \
}))
# define graphene_simd4f_add(a,b) \
(__extension__ ({ \
(graphene_simd4f_t) vaddq_f32 ((a), (b)); \
}))
# define graphene_simd4f_sub(a,b) \
(__extension__ ({ \
(graphene_simd4f_t) vsubq_f32 ((a), (b)); \
}))
# define graphene_simd4f_mul(a,b) \
(__extension__ ({ \
(graphene_simd4f_t) vmulq_f32 ((a), (b)); \
}))
# define graphene_simd4f_div(a,b) \
(__extension__ ({ \
graphene_simd4f_t __rec = graphene_simd4f_reciprocal ((b)); \
(graphene_simd4f_t) vmulq_f32 ((a), __rec); \
}))
# define _simd4f_rsqrt_iter(v,estimate) \
(__extension__ ({ \
const graphene_simd4f_t __est1 = vmulq_f32 ((estimate), (v)); \
(graphene_simd4f_t) vmulq_f32 ((estimate), vrsqrtsq_f32 (__est1, (estimate))); \
}))
# define graphene_simd4f_rsqrt(s) \
(__extension__ ({ \
graphene_simd4f_t __estimate = vrsqrteq_f32 ((s)); \
__estimate = _simd4f_rsqrt_iter ((s), __estimate); \
__estimate = _simd4f_rsqrt_iter ((s), __estimate); \
_simd4f_rsqrt_iter ((s), __estimate); \
}))
# define graphene_simd4f_sqrt(s) \
(__extension__ ({ \
graphene_simd4f_t __rsq = graphene_simd4f_rsqrt ((s)); \
graphene_simd4f_t __rrsq = graphene_simd4f_reciprocal (__rsq); \
uint32x4_t __tmp = vreinterpretq_u32_f32 ((s)); \
(graphene_simd4f_t) vreinterpretq_f32_u32 (vandq_u32 (vtstq_u32 (__tmp, __tmp), vreinterpretq_u32_f32 (__rrsq))); \
}))
# define graphene_simd4f_cross3(a,b) \
(__extension__ ({ \
const uint32_t __mask_bits[] = { 0xffffffff, 0xffffffff, 0xffffffff, 0 }; \
const int32x4_t __mask = vld1q_s32 ((const int32_t *) __mask_bits); \
const graphene_simd4f_t __a = (a), __b = (b); \
const graphene_simd2f_t __a_low = vget_low_f32 (__a); \
const graphene_simd2f_t __b_low = vget_low_f32 (__b); \
const graphene_simd4f_t __a_yzx = vcombine_f32 (vext_f32 (__a_low, vget_high_f32 (__a), 1), __a_low); \
const graphene_simd4f_t __b_yzx = vcombine_f32 (vext_f32 (__b_low, vget_high_f32 (__b), 1), __b_low); \
graphene_simd4f_t __s3 = graphene_simd4f_sub (graphene_simd4f_mul (__b_yzx, __a), \
graphene_simd4f_mul (__a_yzx, __b)); \
graphene_simd2f_t __s3_low = vget_low_f32 (__s3); \
__s3 = vcombine_f32 (vext_f32 (__s3_low, vget_high_f32 (__s3), 1), __s3_low); \
(graphene_simd4f_t) vandq_s32 ((int32x4_t) __s3, __mask); \
}))
# define graphene_simd4f_dot3(a,b) \
(__extension__ ({ \
graphene_simd4f_splat (graphene_simd4f_dot3_scalar (a, b)); \
}))
# define graphene_simd4f_dot3_scalar(a,b) \
(__extension__ ({ \
const graphene_simd4f_t __m = graphene_simd4f_mul (a, b); \
const graphene_simd2f_t __s1 = vpadd_f32 (vget_low_f32 (__m), vget_low_f32 (__m)); \
(float) vget_lane_f32 (vadd_f32 (__s1, vget_high_f32 (__m)), 0); \
}))
# define graphene_simd4f_min(a,b) \
(__extension__ ({ \
(graphene_simd4f_t) vminq_f32 ((a), (b)); \
}))
# define graphene_simd4f_max(a,b) \
(__extension__ ({ \
(graphene_simd4f_t) vmaxq_f32 (a, b); \
}))
# define graphene_simd4f_shuffle_wxyz(v) \
(__extension__ ({ \
graphene_simd4f_union_t __u = { (v) }; \
graphene_simd4f_init (__u.f[3], __u.f[0], __u.f[1], __u.f[2]); \
}))
# define graphene_simd4f_shuffle_zwxy(v) \
(__extension__ ({ \
graphene_simd4f_union_t __u = { (v) }; \
graphene_simd4f_init (__u.f[2], __u.f[3], __u.f[0], __u.f[1]); \
}))
# define graphene_simd4f_shuffle_yzwx(v) \
(__extension__ ({ \
graphene_simd4f_union_t __u = { (v) }; \
graphene_simd4f_init (__u.f[1], __u.f[2], __u.f[3], __u.f[0]); \
}))
# define graphene_simd4f_zero_w(v) \
(__extension__ ({ \
graphene_simd4f_union_t __u = { (v) }; \
graphene_simd4f_init (__u.f[0], __u.f[1], __u.f[2], 0.f); \
}))
# define graphene_simd4f_zero_zw(v) \
(__extension__ ({ \
graphene_simd4f_union_t __u = { (v) }; \
graphene_simd4f_init (__u.f[0], __u.f[1], 0.f, 0.f); \
}))
# define graphene_simd4f_merge_w(s,v) \
(__extension__ ({ \
graphene_simd4f_union_t __u = { (s) }; \
graphene_simd4f_init (__u.f[0], __u.f[1], __u.f[2], (v)); \
}))
# define graphene_simd4f_merge_high(a,b) \
(__extension__ ({ \
graphene_simd4f_union_t __u_a = { (a) }; \
graphene_simd4f_union_t __u_b = { (b) }; \
graphene_simd4f_init (__u_a.f[2], __u_a.f[3], __u_b.f[2], __u_b.f[3]); \
}))
# define graphene_simd4f_merge_low(a,b) \
(__extension__ ({ \
graphene_simd4f_union_t __u_a = { (a) }; \
graphene_simd4f_union_t __u_b = { (b) }; \
graphene_simd4f_init (__u_a.f[0], __u_a.f[1], __u_b.f[0], __u_b.f[1]); \
}))
# define graphene_simd4f_flip_sign_0101(s) \
(__extension__ ({ \
const unsigned int __upnpn[4] = { \
0x00000000, \
0x80000000, \
0x00000000, \
0x80000000 \
}; \
const uint32x4_t __pnpn = vld1q_u32 (__upnpn); \
(graphene_simd4f_t) vreinterpretq_f32_u32 (veorq_u32 (vreinterpretq_u32_f32 ((s)), __pnpn)); \
}))
# define graphene_simd4f_flip_sign_1010(s) \
(__extension__ ({ \
const unsigned int __unpnp[4] = { \
0x80000000, \
0x00000000, \
0x80000000, \
0x00000000 \
}; \
const uint32x4_t __npnp = vld1q_u32 (__unpnp); \
(graphene_simd4f_t) vreinterpretq_f32_u32 (veorq_u32 (vreinterpretq_u32_f32 ((s)), __npnp)); \
}))
# define _graphene_movemask(a) \
(__extension__ ({ \
const int8_t __attribute__ ((aligned (16))) __xr[8] = { -7,-6,-5,-4,-3,-2,-1,0 }; \
const uint8x8_t __mask_and = vdup_n_u8 (0x80); \
const int8x8_t __mask_shift = vld1_s8 (__xr); \
uint8x8_t __lo = vget_low_u8 ((a)); \
uint8x8_t __hi = vget_high_u8 ((a)); \
__lo = vand_u8 (__lo, __mask_and); \
__lo = vshl_u8 (__lo, __mask_shift); \
__hi = vand_u8 (__hi, __mask_and); \
__hi = vshl_u8 (__hi, __mask_shift); \
__lo = vpadd_u8 (__lo, __lo); \
__lo = vpadd_u8 (__lo, __lo); \
__lo = vpadd_u8 (__lo, __lo); \
__hi = vpadd_u8 (__hi, __hi); \
__hi = vpadd_u8 (__hi, __hi); \
__hi = vpadd_u8 (__hi, __hi); \
(bool) ((__hi[0] << 8) | (__lo[0] & 0xff)); \
}))
# define graphene_simd4f_cmp_eq(a,b) \
(__extension__ ({ \
const graphene_simd4f_union_t __u_a = { (a) }; \
const graphene_simd4f_union_t __u_b = { (b) }; \
(bool) (__u_a.f[0] == __u_b.f[0] && \
__u_a.f[1] == __u_b.f[1] && \
__u_a.f[2] == __u_b.f[2] && \
__u_a.f[3] == __u_b.f[3]); \
}))
# define graphene_simd4f_cmp_neq(a,b) \
(__extension__ ({ \
const graphene_simd4f_union_t __u_a = { (a) }; \
const graphene_simd4f_union_t __u_b = { (b) }; \
(bool) (__u_a.f[0] != __u_b.f[0] && \
__u_a.f[1] != __u_b.f[1] && \
__u_a.f[2] != __u_b.f[2] && \
__u_a.f[3] != __u_b.f[3]); \
}))
# define graphene_simd4f_cmp_lt(a,b) \
(__extension__ ({ \
const uint8x16_t __mask = vreinterpretq_u8_u32 (vcltq_f32 ((a), (b))); \
(bool) (_graphene_movemask (__mask) != 0); \
}))
# define graphene_simd4f_cmp_le(a,b) \
(__extension__ ({ \
const uint8x16_t __mask = vreinterpretq_u8_u32 (vcleq_f32 ((a), (b))); \
(bool) (_graphene_movemask (__mask) != 0); \
}))
# define graphene_simd4f_cmp_ge(a,b) \
(__extension__ ({ \
const uint8x16_t __mask = vreinterpretq_u8_u32 (vcgeq_f32 ((a), (b))); \
(bool) (_graphene_movemask (__mask) != 0); \
}))
# define graphene_simd4f_cmp_gt(a,b) \
(__extension__ ({ \
const uint8x16_t __mask = vreinterpretq_u8_u32 (vcgeq_f32 ((a), (b))); \
(bool) (_graphene_movemask (__mask) != 0); \
}))
# define graphene_simd4f_neg(s) \
(__extension__ ({ \
const unsigned int __umask[4] = { \
0x80000000, \
0x80000000, \
0x80000000, \
0x80000000 \
}; \
const uint32x4_t __mask = vld1q_u32 (__umask); \
(graphene_simd4f_t) vreinterpretq_f32_u32 (veorq_u32 (vreinterpretq_u32_f32 ((s)), __mask)); \
}))
#elif defined(__GI_SCANNER__) || defined(GRAPHENE_USE_SCALAR)
/* Fallback implementation using scalar types */
#define graphene_simd4f_init(x,y,z,w) \
(graphene_simd4f_init ((x), (y), (z), (w)))
#define graphene_simd4f_init_zero() \
(graphene_simd4f_init_zero ())
#define graphene_simd4f_init_4f(v) \
(graphene_simd4f_init_4f ((const float *) (v)))
#define graphene_simd4f_init_3f(v) \
(graphene_simd4f_init_3f ((const float *) (v)))
#define graphene_simd4f_init_2f(v) \
(graphene_simd4f_init_2f ((const float *) (v)))
#define graphene_simd4f_dup_4f(s,v) \
(graphene_simd4f_dup_4f ((s), (float *) (v)))
#define graphene_simd4f_dup_3f(s,v) \
(graphene_simd4f_dup_3f ((s), (float *) (v)))
#define graphene_simd4f_dup_2f(s,v) \
(graphene_simd4f_dup_2f ((s), (float *) (v)))
#define graphene_simd4f_get(s,i) \
(graphene_simd4f_get ((s), (i)))
#define graphene_simd4f_get_x(s) \
(graphene_simd4f_get_x ((s)))
#define graphene_simd4f_get_y(s) \
(graphene_simd4f_get_y ((s)))
#define graphene_simd4f_get_z(s) \
(graphene_simd4f_get_z ((s)))
#define graphene_simd4f_get_w(s) \
(graphene_simd4f_get_w ((s)))
#define graphene_simd4f_splat(v) \
(graphene_simd4f_splat ((v)))
#define graphene_simd4f_splat_x(s) \
(graphene_simd4f_splat_x ((s)))
#define graphene_simd4f_splat_y(s) \
(graphene_simd4f_splat_y ((s)))
#define graphene_simd4f_splat_z(s) \
(graphene_simd4f_splat_z ((s)))
#define graphene_simd4f_splat_w(s) \
(graphene_simd4f_splat_w ((s)))
#define graphene_simd4f_add(a,b) \
(graphene_simd4f_add ((a), (b)))
#define graphene_simd4f_sub(a,b) \
(graphene_simd4f_sub ((a), (b)))
#define graphene_simd4f_mul(a,b) \
(graphene_simd4f_mul ((a), (b)))
#define graphene_simd4f_div(a,b) \
(graphene_simd4f_div ((a), (b)))
#define graphene_simd4f_sqrt(s) \
(graphene_simd4f_sqrt ((s)))
#define graphene_simd4f_rsqrt(s) \
(graphene_simd4f_rsqrt ((s)))
#define graphene_simd4f_reciprocal(s) \
(graphene_simd4f_reciprocal ((s)))
#define graphene_simd4f_cross3(a,b) \
(graphene_simd4f_cross3 ((a), (b)))
#define graphene_simd4f_dot3(a,b) \
(graphene_simd4f_dot3 ((a), (b)))
#define graphene_simd4f_dot3_scalar(a,b) \
(graphene_simd4f_dot3_scalar ((a), (b)))
#define graphene_simd4f_min(a,b) \
(graphene_simd4f_min ((a), (b)))
#define graphene_simd4f_max(a,b) \
(graphene_simd4f_max ((a), (b)))
#define graphene_simd4f_shuffle_wxyz(s) \
(graphene_simd4f_shuffle_wxyz ((s)))
#define graphene_simd4f_shuffle_zwxy(s) \
(graphene_simd4f_shuffle_zwxy ((s)))
#define graphene_simd4f_shuffle_yzwx(s) \
(graphene_simd4f_shuffle_yzwx ((s)))
#define graphene_simd4f_flip_sign_0101(s) \
(graphene_simd4f_flip_sign_0101 ((s)))
#define graphene_simd4f_flip_sign_1010(s) \
(graphene_simd4f_flip_sign_1010 ((s)))
#define graphene_simd4f_zero_w(v) \
(graphene_simd4f_zero_w ((v)))
#define graphene_simd4f_zero_zw(v) \
(graphene_simd4f_zero_zw ((v)))
#define graphene_simd4f_merge_w(s,v) \
(graphene_simd4f_merge_w ((s), (v)))
#define graphene_simd4f_merge_high(a,b) \
(graphene_simd4f_merge_high ((a), (b)))
#define graphene_simd4f_merge_low(a,b) \
(graphene_simd4f_merge_low ((a), (b)))
#define graphene_simd4f_cmp_eq(a,b) \
(graphene_simd4f_cmp_eq ((a), (b)))
#define graphene_simd4f_cmp_neq(a,b) \
(graphene_simd4f_cmp_neq ((a), (b)))
#define graphene_simd4f_cmp_lt(a,b) \
(graphene_simd4f_cmp_lt ((a), (b)))
#define graphene_simd4f_cmp_le(a,b) \
(graphene_simd4f_cmp_le ((a), (b)))
#define graphene_simd4f_cmp_ge(a,b) \
(graphene_simd4f_cmp_ge ((a), (b)))
#define graphene_simd4f_cmp_gt(a,b) \
(graphene_simd4f_cmp_gt ((a), (b)))
#define graphene_simd4f_neg(s) \
(graphene_simd4f_neg ((s)))
#else
# error "Unsupported simd4f implementation."
#endif
/* Generic operations, inlined */
/**
* graphene_simd4f_madd:
* @m1: a #graphene_simd4f_t
* @m2: a #graphene_simd4f_t
* @a: a #graphene_simd4f_t
*
* Adds @a to the product of @m1 and @m2.
*
* Returns: the result vector
*
* Since: 1.0
*/
static inline graphene_simd4f_t
graphene_simd4f_madd (const graphene_simd4f_t m1,
const graphene_simd4f_t m2,
const graphene_simd4f_t a)
{
return graphene_simd4f_add (graphene_simd4f_mul (m1, m2), a);
}
/**
* graphene_simd4f_sum:
* @v: a #graphene_simd4f_t
*
* Sums all components of the given vector.
*
* Returns: a vector with all components set to be the
* sum of the passed #graphene_simd4f_t
*
* Since: 1.0
*/
static inline graphene_simd4f_t
graphene_simd4f_sum (const graphene_simd4f_t v)
{
const graphene_simd4f_t x = graphene_simd4f_splat_x (v);
const graphene_simd4f_t y = graphene_simd4f_splat_y (v);
const graphene_simd4f_t z = graphene_simd4f_splat_z (v);
const graphene_simd4f_t w = graphene_simd4f_splat_w (v);
return graphene_simd4f_add (graphene_simd4f_add (x, y),
graphene_simd4f_add (z, w));
}
/**
* graphene_simd4f_sum_scalar:
* @v: a #graphene_simd4f_t
*
* Sums all the components of the given vector.
*
* Returns: a scalar value with the sum of the components
* of the given #graphene_simd4f_t
*
* Since: 1.0
*/
static inline float
graphene_simd4f_sum_scalar (const graphene_simd4f_t v)
{
return graphene_simd4f_get_x (graphene_simd4f_sum (v));
}
/**
* graphene_simd4f_dot4:
* @a: a #graphene_simd4f_t
* @b: a #graphene_simd4f_t
*
* Computes the dot product of all the components of the two
* given #graphene_simd4f_t.
*
* Returns: a vector whose components are all set to be the
* dot product of the components of the two operands
*
* Since: 1.0
*/
static inline graphene_simd4f_t
graphene_simd4f_dot4 (const graphene_simd4f_t a,
const graphene_simd4f_t b)
{
return graphene_simd4f_sum (graphene_simd4f_mul (a, b));
}
/**
* graphene_simd4f_dot2:
* @a: a #graphene_simd4f_t
* @b: a #graphene_simd4f_t
*
* Computes the dot product of the first two components of the
* two given #graphene_simd4f_t.
*
* Returns: a vector whose components are all set to the
* dot product of the components of the two operands
*
* Since: 1.0
*/
static inline graphene_simd4f_t
graphene_simd4f_dot2 (const graphene_simd4f_t a,
const graphene_simd4f_t b)
{
const graphene_simd4f_t m = graphene_simd4f_mul (a, b);
const graphene_simd4f_t x = graphene_simd4f_splat_x (m);
const graphene_simd4f_t y = graphene_simd4f_splat_y (m);
return graphene_simd4f_add (x, y);
}
/**
* graphene_simd4f_length4:
* @v: a #graphene_simd4f_t
*
* Computes the length of the given #graphene_simd4f_t vector,
* using all four of its components.
*
* Returns: the length vector
*
* Since: 1.0
*/
static inline graphene_simd4f_t
graphene_simd4f_length4 (const graphene_simd4f_t v)
{
return graphene_simd4f_sqrt (graphene_simd4f_dot4 (v, v));
}
/**
* graphene_simd4f_length3:
* @v: a #graphene_simd4f_t
*
* Computes the length of the given #graphene_simd4f_t vector,
* using the first three of its components.
*
* Returns: the length vector
*
* Since: 1.0
*/
static inline graphene_simd4f_t
graphene_simd4f_length3 (const graphene_simd4f_t v)
{
return graphene_simd4f_sqrt (graphene_simd4f_dot3 (v, v));
}
/**
* graphene_simd4f_length2:
* @v: a #graphene_simd4f_t
*
* Computes the length of the given #graphene_simd4f_t vector,
* using the first two of its components.
*
* Returns: the length vector
*
* Since: 1.0
*/
static inline graphene_simd4f_t
graphene_simd4f_length2 (const graphene_simd4f_t v)
{
return graphene_simd4f_sqrt (graphene_simd4f_dot2 (v, v));
}
/**
* graphene_simd4f_normalize4:
* @v: a #graphene_simd4f_t
*
* Computes the normalization of the given #graphene_simd4f_t vector,
* using all of its components.
*
* Returns: the normalized vector
*
* Since: 1.0
*/
static inline graphene_simd4f_t
graphene_simd4f_normalize4 (const graphene_simd4f_t v)
{
graphene_simd4f_t invlen = graphene_simd4f_rsqrt (graphene_simd4f_dot4 (v, v));
return graphene_simd4f_mul (v, invlen);
}
/**
* graphene_simd4f_normalize3:
* @v: a #graphene_simd4f_t
*
* Computes the normalization of the given #graphene_simd4f_t vector,
* using the first three of its components.
*
* Returns: the normalized vector
*
* Since: 1.0
*/
static inline graphene_simd4f_t
graphene_simd4f_normalize3 (const graphene_simd4f_t v)
{
graphene_simd4f_t invlen = graphene_simd4f_rsqrt (graphene_simd4f_dot3 (v, v));
return graphene_simd4f_mul (v, invlen);
}
/**
* graphene_simd4f_normalize2:
* @v: a #graphene_simd4f_t
*
* Computes the normalization of the given #graphene_simd4f_t vector,
* using the first two of its components.
*
* Returns: the normalized vector
*
* Since: 1.0
*/
static inline graphene_simd4f_t
graphene_simd4f_normalize2 (const graphene_simd4f_t v)
{
graphene_simd4f_t invlen = graphene_simd4f_rsqrt (graphene_simd4f_dot2 (v, v));
return graphene_simd4f_mul (v, invlen);
}
/**
* graphene_simd4f_is_zero4:
* @v: a #graphene_simd4f_t
*
* Checks whether the given #graphene_simd4f_t has all its components
* set to 0.
*
* Returns: `true` if all the vector components are zero
*
* Since: 1.0
*/
static inline bool
graphene_simd4f_is_zero4 (const graphene_simd4f_t v)
{
graphene_simd4f_t zero = graphene_simd4f_init_zero ();
return graphene_simd4f_cmp_eq (v, zero);
}
/**
* graphene_simd4f_is_zero3:
* @v: a #graphene_simd4f_t
*
* Checks whether the given #graphene_simd4f_t has the first three of
* its components set to 0.
*
* Returns: `true` if the vector's components are zero
*
* Since: 1.0
*/
static inline bool
graphene_simd4f_is_zero3 (const graphene_simd4f_t v)
{
return graphene_simd4f_get_x (v) == 0.f &&
graphene_simd4f_get_y (v) == 0.f &&
graphene_simd4f_get_z (v) == 0.f;
}
/**
* graphene_simd4f_is_zero2:
* @v: a #graphene_simd4f_t
*
* Checks whether the given #graphene_simd4f_t has the first two of
* its components set to 0.
*
* Returns: `true` if the vector's components are zero
*
* Since: 1.0
*/
static inline bool
graphene_simd4f_is_zero2 (const graphene_simd4f_t v)
{
return graphene_simd4f_get_x (v) == 0.f &&
graphene_simd4f_get_y (v) == 0.f;
}
/**
* graphene_simd4f_interpolate:
* @a: a #graphene_simd4f_t
* @b: a #graphene_simd4f_t
* @f: the interpolation factor
*
* Linearly interpolates all components of the two given
* #graphene_simd4f_t vectors using the given factor @f.
*
* Returns: the intrerpolated vector
*
* Since: 1.0
*/
static inline graphene_simd4f_t
graphene_simd4f_interpolate (const graphene_simd4f_t a,
const graphene_simd4f_t b,
float f)
{
const graphene_simd4f_t one_minus_f = graphene_simd4f_sub (graphene_simd4f_splat (1.f),
graphene_simd4f_splat (f));
return graphene_simd4f_add (graphene_simd4f_mul (one_minus_f, a),
graphene_simd4f_mul (graphene_simd4f_splat (f), b));
}
/**
* graphene_simd4f_clamp:
* @v: a #graphene_simd4f_t
* @min: the lower boundary
* @max: the upper boundary
*
* Ensures that all components of the vector @v are within
* the components of the @lower and @upper boundaries.
*
* Returns: the clamped vector
*
* Since: 1.2
*/
static inline graphene_simd4f_t
graphene_simd4f_clamp (const graphene_simd4f_t v,
const graphene_simd4f_t min,
const graphene_simd4f_t max)
{
const graphene_simd4f_t tmp = graphene_simd4f_max (min, v);
return graphene_simd4f_min (tmp, max);
}
/**
* graphene_simd4f_clamp_scalar:
* @v: a #graphene_simd4f_t
* @min: the lower boundary
* @max: the upper boundary
*
* Ensures that all components of the vector @v are within
* the @lower and @upper boundary scalar values.
*
* Returns: the clamped vector
*
* Since: 1.2
*/
static inline graphene_simd4f_t
graphene_simd4f_clamp_scalar (const graphene_simd4f_t v,
float min,
float max)
{
return graphene_simd4f_clamp (v,
graphene_simd4f_splat (min),
graphene_simd4f_splat (max));
}
/**
* graphene_simd4f_min_val:
* @v: a #graphene_simd4f_t
*
* Computes the minimum value of all the channels in the given vector.
*
* Returns: a vector whose components are all set to the
* minimum value in the original vector
*
* Since: 1.4
*/
static inline graphene_simd4f_t
graphene_simd4f_min_val (const graphene_simd4f_t v)
{
graphene_simd4f_t s = v;
s = graphene_simd4f_min (s, graphene_simd4f_shuffle_wxyz (s));
s = graphene_simd4f_min (s, graphene_simd4f_shuffle_zwxy (s));
return s;
}
/**
* graphene_simd4f_max_val:
* @v: a #graphene_simd4f_t
*
* Computes the maximum value of all the channels in the given vector.
*
* Returns: a vector whose components are all set to the
* maximum value in the original vector
*
* Since: 1.4
*/
static inline graphene_simd4f_t
graphene_simd4f_max_val (const graphene_simd4f_t v)
{
graphene_simd4f_t s = v;
s = graphene_simd4f_max (s, graphene_simd4f_shuffle_wxyz (s));
s = graphene_simd4f_max (s, graphene_simd4f_shuffle_zwxy (s));
return s;
}
GRAPHENE_END_DECLS
#endif /* __GRAPHENE_SIMD4F_H__ */
|