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
|
/**************************** vectormath_lib.h *****************************
* Author: Agner Fog
* Date created: 2012-05-30
* Last modified: 2016-04-26
* Version: 1.22
* Project: vector classes
* Description:
* Header file defining mathematical functions on floating point vectors
* May use Intel SVML library or AMD LIBM library
*
* Instructions:
* Define VECTORMATH to one of the following values:
* 0: Use ordinary math library (slow)
* 1: Use AMD LIBM library
* 2: Use Intel SVML library with any compiler
* 3: Use Intel SVML library with Intel compiler
*
* For detailed instructions, see VectorClass.pdf
*
* (c) Copyright 2012-2016 GNU General Public License http://www.gnu.org/licenses
\*****************************************************************************/
// check combination of header files
#ifndef VECTORMATH_LIB_H
#define VECTORMATH_LIB_H
#include "vectorf128.h"
#ifndef VECTORMATH
#ifdef __INTEL_COMPILER
#define VECTORMATH 3
#else
#define VECTORMATH 0
#endif // __INTEL_COMPILER
#endif // VECTORMATH
#include <math.h>
#ifdef VCL_NAMESPACE
namespace VCL_NAMESPACE {
#endif
/*****************************************************************************
*
* VECTORMATH = 0. Use ordinary library (scalar)
*
*****************************************************************************/
#if VECTORMATH == 0
#ifndef VECTORMATH_COMMON_H
// exponential and power functions
static inline Vec4f exp (Vec4f const & x) {
float xx[4];
x.store(xx);
return Vec4f(expf(xx[0]), expf(xx[1]), expf(xx[2]), expf(xx[3]));
}
static inline Vec2d exp (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(::exp(xx[0]), ::exp(xx[1]));
}
// There is no certain way to know which functions are available, but at least some (Gnu)
// compilers have defines to specify this
#ifdef HAVE_EXPM1
static inline Vec4f expm1 (Vec4f const & x) {
float xx[4];
x.store(xx);
return Vec4f(expm1(xx[0]), expm1(xx[1]), expm1(xx[2]), expm1(xx[3]));
}
static inline Vec2d expm1 (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(expm1(xx[0]), expm1(xx[1]));
}
#endif
#ifdef HAVE_EXP2
static inline Vec4f exp2 (Vec4f const & x) {
float xx[4];
x.store(xx);
return Vec4f(exp2(xx[0]), exp2(xx[1]), exp2(xx[2]), exp2(xx[3]));
}
static inline Vec2d exp2 (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(exp2(xx[0]), exp2(xx[1]));
}
#else
static inline Vec4f exp2 (Vec4f const & x) {
return exp(x*Vec4f(0.693147180559945309417f /* log(2) */));
}
static inline Vec2d exp2 (Vec2d const & x) {
return exp(x*Vec2d(0.693147180559945309417 /* log(2) */));
}
#endif
static inline Vec4f exp10 (Vec4f const & x) {
return exp(x*Vec4f(2.30258509299404568402f /* log(10) */));
}
static inline Vec2d exp10 (Vec2d const & x) {
return exp(x*Vec2d(2.30258509299404568402 /* log(10) */));
}
static inline Vec4f pow (Vec4f const & a, Vec4f const & b) {
float aa[4], bb[4];
a.store(aa); b.store(bb);
return Vec4f(powf(aa[0],bb[0]), powf(aa[1],bb[1]), powf(aa[2],bb[2]), powf(aa[3],bb[3]));
}
static inline Vec2d pow (Vec2d const & a, Vec2d const & b) {
double aa[4], bb[4];
a.store(aa); b.store(bb);
return Vec2d(::pow(aa[0],bb[0]), ::pow(aa[1],bb[1]));
}
static inline Vec4f log (Vec4f const & x) {
float xx[4];
x.store(xx);
return Vec4f(logf(xx[0]), logf(xx[1]), logf(xx[2]), logf(xx[3]));
}
static inline Vec2d log (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(::log(xx[0]), ::log(xx[1]));
}
#ifdef HAVE_LOG1P
static inline Vec4f log1p (Vec4f const & x) {
float xx[4];
x.store(xx);
return Vec4f(::log1p(xx[0]), ::log1p(xx[1]), ::log1p(xx[2]), ::log1p(xx[3]));
}
static inline Vec2d log1p (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(::log1p(xx[0]), ::log1p(xx[1]));
}
#endif
static inline Vec4f log2 (Vec4f const & x) { // logarithm base 2
return log(x)*Vec4f(1.44269504088896340736f/* log2(e) */);
}
static inline Vec2d log2 (Vec2d const & x) { // logarithm base 2
return log(x)*Vec2d(1.44269504088896340736 /* log2(e) */);
}
static inline Vec4f log10 (Vec4f const & x) { // logarithm base 10
float xx[4];
x.store(xx);
return Vec4f(log10f(xx[0]), log10f(xx[1]), log10f(xx[2]), log10f(xx[3]));
}
static inline Vec2d log10 (Vec2d const & x) { // logarithm base 10
double xx[4];
x.store(xx);
return Vec2d(::log10(xx[0]), ::log10(xx[1]));
}
// trigonometric functions
static inline Vec4f sin(Vec4f const & x) {
float xx[4];
x.store(xx);
return Vec4f(sinf(xx[0]), sinf(xx[1]), sinf(xx[2]), sinf(xx[3]));
}
static inline Vec2d sin (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(::sin(xx[0]), ::sin(xx[1]));
}
static inline Vec4f cos(Vec4f const & x) {
float xx[4];
x.store(xx);
return Vec4f(cosf(xx[0]), cosf(xx[1]), cosf(xx[2]), cosf(xx[3]));
}
static inline Vec2d cos (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(::cos(xx[0]), ::cos(xx[1]));
}
static inline Vec4f sincos (Vec4f * pcos, Vec4f const & x) { // sine and cosine. sin(x) returned, cos(x) in pcos
*pcos = cos(x);
return sin(x);
}
static inline Vec2d sincos (Vec2d * pcos, Vec2d const & x) { // sine and cosine. sin(x) returned, cos(x) in pcos
*pcos = cos(x);
return sin(x);
}
static inline Vec4f tan(Vec4f const & x) {
float xx[4];
x.store(xx);
return Vec4f(tanf(xx[0]), tanf(xx[1]), tanf(xx[2]), tanf(xx[3]));
}
static inline Vec2d tan (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(::tan(xx[0]), ::tan(xx[1]));
}
// inverse trigonometric functions
static inline Vec4f asin(Vec4f const & x) {
float xx[4];
x.store(xx);
return Vec4f(asinf(xx[0]), asinf(xx[1]), asinf(xx[2]), asinf(xx[3]));
}
static inline Vec2d asin (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(::asin(xx[0]), ::asin(xx[1]));
}
static inline Vec4f acos(Vec4f const & x) {
float xx[4];
x.store(xx);
return Vec4f(acosf(xx[0]), acosf(xx[1]), acosf(xx[2]), acosf(xx[3]));
}
static inline Vec2d acos (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(::acos(xx[0]), ::acos(xx[1]));
}
static inline Vec4f atan(Vec4f const & x) {
float xx[4];
x.store(xx);
return Vec4f(atanf(xx[0]), atanf(xx[1]), atanf(xx[2]), atanf(xx[3]));
}
static inline Vec2d atan (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(::atan(xx[0]), ::atan(xx[1]));
}
static inline Vec4f atan2 (Vec4f const & a, Vec4f const & b) { // inverse tangent of a/b
float aa[4], bb[4];
a.store(aa); b.store(bb);
return Vec4f(atan2f(aa[0],bb[0]), atan2f(aa[1],bb[1]), atan2f(aa[2],bb[2]), atan2f(aa[3],bb[3]));
}
static inline Vec2d atan2 (Vec2d const & a, Vec2d const & b) { // inverse tangent of a/b
double aa[4], bb[4];
a.store(aa); b.store(bb);
return Vec2d(::atan2(aa[0],bb[0]), ::atan2(aa[1],bb[1]));
}
#endif // VECTORMATH_COMMON_H
// hyperbolic functions
static inline Vec4f sinh(Vec4f const & x) { // hyperbolic sine
float xx[4];
x.store(xx);
return Vec4f(sinhf(xx[0]), sinhf(xx[1]), sinhf(xx[2]), sinhf(xx[3]));
}
static inline Vec2d sinh (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(::sinh(xx[0]), ::sinh(xx[1]));
}
static inline Vec4f cosh(Vec4f const & x) { // hyperbolic cosine
float xx[4];
x.store(xx);
return Vec4f(coshf(xx[0]), coshf(xx[1]), coshf(xx[2]), coshf(xx[3]));
}
static inline Vec2d cosh (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(::cosh(xx[0]), ::cosh(xx[1]));
}
static inline Vec4f tanh(Vec4f const & x) { // hyperbolic tangent
float xx[4];
x.store(xx);
return Vec4f(tanhf(xx[0]), tanhf(xx[1]), tanhf(xx[2]), tanhf(xx[3]));
}
static inline Vec2d tanh (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(::tanh(xx[0]), ::tanh(xx[1]));
}
// error function
#ifdef HAVE_ERF
static inline Vec4f erf(Vec4f const & x) {
float xx[4];
x.store(xx);
return Vec4f(::erf(xx[0]), ::erf(xx[1]), ::erf(xx[2]), ::erf(xx[3]));
}
static inline Vec2d erf (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(::erf(xx[0]), ::erf(xx[1]));
}
#endif
#ifdef HAVE_ERFC
static inline Vec4f erfc(Vec4f const & x) {
float xx[4];
x.store(xx);
return Vec4f(::erfc(xx[0]), ::erfc(xx[1]), ::erfc(xx[2]), ::erfc(xx[3]));
}
static inline Vec2d erfc (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(::erfc(xx[0]), ::erfc(xx[1]));
}
#endif
// complex exponential function (real part in even numbered elements, imaginary part in odd numbered elements)
static inline Vec4f cexp (Vec4f const & x) { // complex exponential function
float xx[4], ee[2];
x.store(xx);
Vec4f z(cosf(xx[1]),sinf(xx[1]),cosf(xx[3]),sinf(xx[3]));
ee[0] = expf(xx[0]); ee[1] = expf(xx[2]);
return z * Vec4f(ee[0],ee[0],ee[1],ee[1]);
}
static inline Vec2d cexp (Vec2d const & x) { // complex exponential function
double xx[2];
x.store(xx);
Vec2d z(::cos(xx[1]), ::sin(xx[1]));
return z * ::exp(xx[0]);
}
#if defined (VECTORF256_H) // 256 bit vectors defined
#ifndef VECTORMATH_COMMON_H
// exponential and power functions
static inline Vec8f exp (Vec8f const & x) { // exponential function
return Vec8f(exp(x.get_low()), exp(x.get_high()));
}
static inline Vec4d exp (Vec4d const & x) { // exponential function
return Vec4d(exp(x.get_low()), exp(x.get_high()));
}
#ifdef HAVE_EXPM1
static inline Vec8f expm1 (Vec8f const & x) { // exp(x)-1
return Vec8f(expm1(x.get_low()), expm1(x.get_high()));
}
static inline Vec4d expm1 (Vec4d const & x) { // exp(x)-1
return Vec4d(expm1(x.get_low()), expm1(x.get_high()));
}
#endif
static inline Vec8f exp2 (Vec8f const & x) { // pow(2,x)
return Vec8f(exp2(x.get_low()), exp2(x.get_high()));
}
static inline Vec4d exp2 (Vec4d const & x) { // pow(2,x)
return Vec4d(exp2(x.get_low()), exp2(x.get_high()));
}
static inline Vec8f exp10 (Vec8f const & x) { // pow(10,x)
return Vec8f(exp10(x.get_low()), exp10(x.get_high()));
}
static inline Vec4d exp10 (Vec4d const & x) { // pow(10,x)
return Vec4d(exp10(x.get_low()), exp10(x.get_high()));
}
static inline Vec8f pow (Vec8f const & a, Vec8f const & b) { // pow(a,b) = a to the power of b
return Vec8f(pow(a.get_low(),b.get_low()), pow(a.get_high(),b.get_high()));
}
static inline Vec4d pow (Vec4d const & a, Vec4d const & b) { // pow(a,b) = a to the power of b
return Vec4d(pow(a.get_low(),b.get_low()), pow(a.get_high(),b.get_high()));
}
// logarithms
static inline Vec8f log (Vec8f const & x) { // natural logarithm
return Vec8f(log(x.get_low()), log(x.get_high()));
}
static inline Vec4d log (Vec4d const & x) { // natural logarithm
return Vec4d(log(x.get_low()), log(x.get_high()));
}
#ifdef HAVE_LOG1P
static inline Vec8f log1p (Vec8f const & x) { // log(1+x). Avoids loss of precision if 1+x is close to 1
return Vec8f(log1p(x.get_low()), log1p(x.get_high()));
}
static inline Vec4d log1p (Vec4d const & x) { // log(1+x). Avoids loss of precision if 1+x is close to 1
return Vec4d(log1p(x.get_low()), log1p(x.get_high()));
}
#endif
static inline Vec8f log2 (Vec8f const & x) { // logarithm base 2
return Vec8f(log2(x.get_low()), log2(x.get_high()));
}
static inline Vec4d log2 (Vec4d const & x) { // logarithm base 2
return Vec4d(log2(x.get_low()), log2(x.get_high()));
}
static inline Vec8f log10 (Vec8f const & x) { // logarithm base 10
return Vec8f(log10(x.get_low()), log10(x.get_high()));
}
static inline Vec4d log10 (Vec4d const & x) { // logarithm base 10
return Vec4d(log10(x.get_low()), log10(x.get_high()));
}
// trigonometric functions (angles in radians)
static inline Vec8f sin (Vec8f const & x) { // sine
return Vec8f(sin(x.get_low()), sin(x.get_high()));
}
static inline Vec4d sin (Vec4d const & x) { // sine
return Vec4d(sin(x.get_low()), sin(x.get_high()));
}
static inline Vec8f cos (Vec8f const & x) { // cosine
return Vec8f(cos(x.get_low()), cos(x.get_high()));
}
static inline Vec4d cos (Vec4d const & x) { // cosine
return Vec4d(cos(x.get_low()), cos(x.get_high()));
}
static inline Vec8f sincos (Vec8f * pcos, Vec8f const & x) { // sine and cosine. sin(x) returned, cos(x) in pcos
*pcos = Vec8f(cos(x.get_low()), cos(x.get_high()));
return Vec8f(sin(x.get_low()), sin(x.get_high()));
}
static inline Vec4d sincos (Vec4d * pcos, Vec4d const & x) { // sine and cosine. sin(x) returned, cos(x) in pcos
*pcos = Vec4d(cos(x.get_low()), cos(x.get_high()));
return Vec4d(sin(x.get_low()), sin(x.get_high()));
}
static inline Vec8f tan (Vec8f const & x) { // tangent
return Vec8f(tan(x.get_low()), tan(x.get_high()));
}
static inline Vec4d tan (Vec4d const & x) { // tangent
return Vec4d(tan(x.get_low()), tan(x.get_high()));
}
// inverse trigonometric functions
static inline Vec8f asin (Vec8f const & x) { // inverse sine
return Vec8f(asin(x.get_low()), asin(x.get_high()));
}
static inline Vec4d asin (Vec4d const & x) { // inverse sine
return Vec4d(asin(x.get_low()), asin(x.get_high()));
}
static inline Vec8f acos (Vec8f const & x) { // inverse cosine
return Vec8f(acos(x.get_low()), acos(x.get_high()));
}
static inline Vec4d acos (Vec4d const & x) { // inverse cosine
return Vec4d(acos(x.get_low()), acos(x.get_high()));
}
static inline Vec8f atan (Vec8f const & x) { // inverse tangent
return Vec8f(atan(x.get_low()), atan(x.get_high()));
}
static inline Vec4d atan (Vec4d const & x) { // inverse tangent
return Vec4d(atan(x.get_low()), atan(x.get_high()));
}
static inline Vec8f atan2 (Vec8f const & a, Vec8f const & b) { // inverse tangent of a/b
return Vec8f(atan2(a.get_low(),b.get_low()), atan2(a.get_high(),b.get_high()));
}
static inline Vec4d atan2 (Vec4d const & a, Vec4d const & b) { // inverse tangent of a/b
return Vec4d(atan2(a.get_low(),b.get_low()), atan2(a.get_high(),b.get_high()));
}
#endif // VECTORMATH_COMMON_H
// hyperbolic functions and inverse hyperbolic functions
static inline Vec8f sinh (Vec8f const & x) { // hyperbolic sine
return Vec8f(sinh(x.get_low()), sinh(x.get_high()));
}
static inline Vec4d sinh (Vec4d const & x) { // hyperbolic sine
return Vec4d(sinh(x.get_low()), sinh(x.get_high()));
}
static inline Vec8f cosh (Vec8f const & x) { // hyperbolic cosine
return Vec8f(cosh(x.get_low()), cosh(x.get_high()));
}
static inline Vec4d cosh (Vec4d const & x) { // hyperbolic cosine
return Vec4d(cosh(x.get_low()), cosh(x.get_high()));
}
static inline Vec8f tanh (Vec8f const & x) { // hyperbolic tangent
return Vec8f(tanh(x.get_low()), tanh(x.get_high()));
}
static inline Vec4d tanh (Vec4d const & x) { // hyperbolic tangent
return Vec4d(tanh(x.get_low()), tanh(x.get_high()));
}
// error function
#ifdef HAVE_ERF
static inline Vec8f erf (Vec8f const & x) { // error function
return Vec8f(erf(x.get_low()), erf(x.get_high()));
}
static inline Vec4d erf (Vec4d const & x) { // error function
return Vec4d(erf(x.get_low()), erf(x.get_high()));
}
#endif
#ifdef HAVE_ERFC
static inline Vec8f erfc (Vec8f const & x) { // error function complement
return Vec8f(erfc(x.get_low()), erfc(x.get_high()));
}
static inline Vec4d erfc (Vec4d const & x) { // error function complement
return Vec4d(erfc(x.get_low()), erfc(x.get_high()));
}
#endif
// complex exponential function (real part in even numbered elements, imaginary part in odd numbered elements)
static inline Vec8f cexp (Vec8f const & x) { // complex exponential function
return Vec8f(cexp(x.get_low()), cexp(x.get_high()));
}
static inline Vec4d cexp (Vec4d const & x) { // complex exponential function
return Vec4d(cexp(x.get_low()), cexp(x.get_high()));
}
#endif // VECTORF256_H == 1
/*****************************************************************************
*
* VECTORMATH = 1. Use AMD LIBM library
*
*****************************************************************************/
#elif VECTORMATH == 1
//#include <amdlibm.h>
#include "amdlibm.h" // if header file is in current directory
#ifndef VECTORMATH_COMMON_H
// exponential and power functions
static inline Vec4f exp (Vec4f const & x) { // exponential function
return amd_vrs4_expf(x);
}
static inline Vec2d exp (Vec2d const & x) { // exponential function
return amd_vrd2_exp(x);
}
static inline Vec4f expm1 (Vec4f const & x) { // exp(x)-1. Avoids loss of precision if x is close to 1
return amd_vrs4_expm1f(x);
}
static inline Vec2d expm1 (Vec2d const & x) { // exp(x)-1. Avoids loss of precision if x is close to 1
return amd_vrd2_expm1(x);
}
static inline Vec4f exp2 (Vec4f const & x) { // pow(2,x)
return amd_vrs4_exp2f(x);
}
static inline Vec2d exp2 (Vec2d const & x) { // pow(2,x)
return amd_vrd2_exp2(x);
}
static inline Vec4f exp10 (Vec4f const & x) { // pow(10,x)
return amd_vrs4_exp10f(x);
}
static inline Vec2d exp10 (Vec2d const & x) { // pow(10,x)
return amd_vrd2_exp10(x);
}
static inline Vec4f pow (Vec4f const & a, Vec4f const & b) { // pow(a,b) = a to the power of b
return amd_vrs4_powf(a,b);
}
static inline Vec2d pow (Vec2d const & a, Vec2d const & b) { // pow(a,b) = a to the power of b
return amd_vrd2_pow(a,b);
}
static inline Vec4f cbrt (Vec4f const & x) { // pow(x,1/3)
return amd_vrs4_cbrtf(x);
}
static inline Vec2d cbrt (Vec2d const & x) { // pow(x,1/3)
return amd_vrd2_cbrt(x);
}
// logarithms
static inline Vec4f log (Vec4f const & x) { // natural logarithm
return amd_vrs4_logf(x);
}
static inline Vec2d log (Vec2d const & x) { // natural logarithm
return amd_vrd2_log(x);
}
static inline Vec4f log1p (Vec4f const & x) { // log(1+x). Avoids loss of precision if 1+x is close to 1
return amd_vrs4_log1pf(x);
}
static inline Vec2d log1p (Vec2d const & x) { // log(1+x). Avoids loss of precision if 1+x is close to 1
return amd_vrd2_log1p(x);
}
static inline Vec4f log2 (Vec4f const & x) { // logarithm base 2
return amd_vrs4_log2f(x);
}
static inline Vec2d log2 (Vec2d const & x) { // logarithm base 2
return amd_vrd2_log2(x);
}
static inline Vec4f log10 (Vec4f const & x) { // logarithm base 10
return amd_vrs4_log10f(x);
}
static inline Vec2d log10 (Vec2d const & x) { // logarithm base 10
return amd_vrd2_log10(x);
}
// trigonometric functions (angles in radians)
static inline Vec4f sin (Vec4f const & x) { // sine
return amd_vrs4_sinf(x);
}
static inline Vec2d sin (Vec2d const & x) { // sine
return amd_vrd2_sin(x);
}
static inline Vec4f cos (Vec4f const & x) { // cosine
return amd_vrs4_cosf(x);
}
static inline Vec2d cos (Vec2d const & x) { // cosine
return amd_vrd2_cos(x);
}
static inline Vec4f sincos (Vec4f * pcos, Vec4f const & x) { // sine and cosine. sin(x) returned, cos(x) in pcos
__m128 r_sin;
amd_vrs4_sincosf(x, &r_sin, (__m128*)pcos);
return r_sin;
}
static inline Vec2d sincos (Vec2d * pcos, Vec2d const & x) { // sine and cosine. sin(x) returned, cos(x) in pcos
__m128d r_sin;
amd_vrd2_sincos(x, &r_sin, (__m128d*)pcos);
return r_sin;
}
static inline Vec4f tan (Vec4f const & x) { // tangent
return amd_vrs4_tanf(x);
}
static inline Vec2d tan (Vec2d const & x) { // tangent
return amd_vrd2_tan(x);
}
// inverse trigonometric functions not supported
#endif // VECTORMATH_COMMON_H
// hyperbolic functions and inverse hyperbolic functions not supported
// error function not supported
// complex exponential function not supported
#ifdef VECTORF256_H
// Emulate 256 bit vector functions with two 128-bit vectors
#ifndef VECTORMATH_COMMON_H
// exponential and power functions
static inline Vec8f exp (Vec8f const & x) { // exponential function
return Vec8f(exp(x.get_low()), exp(x.get_high()));
}
static inline Vec4d exp (Vec4d const & x) { // exponential function
return Vec4d(exp(x.get_low()), exp(x.get_high()));
}
static inline Vec8f expm1 (Vec8f const & x) { // exp(x)-1. Avoids loss of precision if x is close to 1
return Vec8f(expm1(x.get_low()), expm1(x.get_high()));
}
static inline Vec4d expm1 (Vec4d const & x) { // exp(x)-1. Avoids loss of precision if x is close to 1
return Vec4d(expm1(x.get_low()), expm1(x.get_high()));
}
static inline Vec8f exp2 (Vec8f const & x) { // pow(2,x)
return Vec8f(exp2(x.get_low()), exp2(x.get_high()));
}
static inline Vec4d exp2 (Vec4d const & x) { // pow(2,x)
return Vec4d(exp2(x.get_low()), exp2(x.get_high()));
}
static inline Vec8f exp10 (Vec8f const & x) { // pow(10,x)
return Vec8f(exp10(x.get_low()), exp10(x.get_high()));
}
static inline Vec4d exp10 (Vec4d const & x) { // pow(10,x)
return Vec4d(exp10(x.get_low()), exp10(x.get_high()));
}
static inline Vec8f pow (Vec8f const & a, Vec8f const & b) { // pow(a,b) = a to the power of b
return Vec8f(pow(a.get_low(),b.get_low()), pow(a.get_high(),b.get_high()));
}
static inline Vec4d pow (Vec4d const & a, Vec4d const & b) { // pow(a,b) = a to the power of b
return Vec4d(pow(a.get_low(),b.get_low()), pow(a.get_high(),b.get_high()));
}
static inline Vec8f cbrt (Vec8f const & x) { // pow(x,1/3)
return Vec8f(cbrt(x.get_low()), cbrt(x.get_high()));
}
static inline Vec4d cbrt (Vec4d const & x) { // pow(x,1/3)
return Vec4d(cbrt(x.get_low()), cbrt(x.get_high()));
}
// logarithms
static inline Vec8f log (Vec8f const & x) { // natural logarithm
return Vec8f(log(x.get_low()), log(x.get_high()));
}
static inline Vec4d log (Vec4d const & x) { // natural logarithm
return Vec4d(log(x.get_low()), log(x.get_high()));
}
static inline Vec8f log1p (Vec8f const & x) { // log(1+x). Avoids loss of precision if 1+x is close to 1
return Vec8f(log1p(x.get_low()), log1p(x.get_high()));
}
static inline Vec4d log1p (Vec4d const & x) { // log(1+x). Avoids loss of precision if 1+x is close to 1
return Vec4d(log1p(x.get_low()), log1p(x.get_high()));
}
static inline Vec8f log2 (Vec8f const & x) { // logarithm base 2
return Vec8f(log2(x.get_low()), log2(x.get_high()));
}
static inline Vec4d log2 (Vec4d const & x) { // logarithm base 2
return Vec4d(log2(x.get_low()), log2(x.get_high()));
}
static inline Vec8f log10 (Vec8f const & x) { // logarithm base 10
return Vec8f(log10(x.get_low()), log10(x.get_high()));
}
static inline Vec4d log10 (Vec4d const & x) { // logarithm base 10
return Vec4d(log10(x.get_low()), log10(x.get_high()));
}
// trigonometric functions (angles in radians)
static inline Vec8f sin (Vec8f const & x) { // sine
return Vec8f(sin(x.get_low()), sin(x.get_high()));
}
static inline Vec4d sin (Vec4d const & x) { // sine
return Vec4d(sin(x.get_low()), sin(x.get_high()));
}
static inline Vec8f cos (Vec8f const & x) { // cosine
return Vec8f(cos(x.get_low()), cos(x.get_high()));
}
static inline Vec4d cos (Vec4d const & x) { // cosine
return Vec4d(cos(x.get_low()), cos(x.get_high()));
}
static inline Vec8f sincos (Vec8f * pcos, Vec8f const & x) { // sine and cosine. sin(x) returned, cos(x) in pcos
Vec4f r_sin0, r_sin1, r_cos0, r_cos1;
r_sin0 = sincos(&r_cos0, x.get_low());
r_sin1 = sincos(&r_cos1, x.get_high());
*pcos = Vec8f(r_cos0, r_cos1);
return Vec8f(r_sin0, r_sin1);
}
static inline Vec4d sincos (Vec4d * pcos, Vec4d const & x) { // sine and cosine. sin(x) returned, cos(x) in pcos
Vec2d r_sin0, r_sin1, r_cos0, r_cos1;
r_sin0 = sincos(&r_cos0, x.get_low());
r_sin1 = sincos(&r_cos1, x.get_high());
*pcos = Vec4d(r_cos0, r_cos1);
return Vec4d(r_sin0, r_sin1);
}
static inline Vec8f tan (Vec8f const & x) { // tangent
return Vec8f(tan(x.get_low()), tan(x.get_high()));
}
static inline Vec4d tan (Vec4d const & x) { // tangent
return Vec4d(tan(x.get_low()), tan(x.get_high()));
}
#endif // VECTORMATH_COMMON_H
#endif // VECTORF256_H == 1
/*****************************************************************************
*
* VECTORMATH = 2. Use Intel SVML library with any compiler
*
*****************************************************************************/
#elif VECTORMATH == 2
extern "C" {
extern __m128 __svml_expf4 (__m128);
extern __m128d __svml_exp2 (__m128d);
extern __m128 __svml_expm1f4 (__m128);
extern __m128d __svml_expm12 (__m128d);
extern __m128 __svml_exp2f4 (__m128);
extern __m128d __svml_exp22 (__m128d);
extern __m128 __svml_exp10f4 (__m128);
extern __m128d __svml_exp102 (__m128d);
extern __m128 __svml_powf4 (__m128, __m128);
extern __m128d __svml_pow2 (__m128d, __m128d);
extern __m128 __svml_cbrtf4 (__m128);
extern __m128d __svml_cbrt2 (__m128d);
extern __m128 __svml_invsqrtf4 (__m128);
extern __m128d __svml_invsqrt2 (__m128d);
extern __m128 __svml_logf4 (__m128);
extern __m128d __svml_log2 (__m128d);
extern __m128 __svml_log1pf4 (__m128);
extern __m128d __svml_log1p2 (__m128d);
extern __m128 __svml_log2f4 (__m128);
extern __m128d __svml_log22 (__m128d);
extern __m128 __svml_log10f4 (__m128);
extern __m128d __svml_log102 (__m128d);
extern __m128 __svml_sinf4 (__m128);
extern __m128d __svml_sin2 (__m128d);
extern __m128 __svml_cosf4 (__m128);
extern __m128d __svml_cos2 (__m128d);
extern __m128 __svml_sincosf4 (__m128); // cos returned in xmm1
extern __m128d __svml_sincos2 (__m128d); // cos returned in xmm1
extern __m128 __svml_tanf4 (__m128);
extern __m128d __svml_tan2 (__m128d);
extern __m128 __svml_asinf4 (__m128);
extern __m128d __svml_asin2 (__m128d);
extern __m128 __svml_acosf4 (__m128);
extern __m128d __svml_acos2 (__m128d);
extern __m128 __svml_atanf4 (__m128);
extern __m128d __svml_atan2 (__m128d);
extern __m128 __svml_atan2f4 (__m128, __m128);
extern __m128d __svml_atan22 (__m128d, __m128d);
extern __m128 __svml_sinhf4 (__m128);
extern __m128d __svml_sinh2 (__m128d);
extern __m128 __svml_coshf4 (__m128);
extern __m128d __svml_cosh2 (__m128d);
extern __m128 __svml_tanhf4 (__m128);
extern __m128d __svml_tanh2 (__m128d);
extern __m128 __svml_asinhf4 (__m128);
extern __m128d __svml_asinh2 (__m128d);
extern __m128 __svml_acoshf4 (__m128);
extern __m128d __svml_acosh2 (__m128d);
extern __m128 __svml_atanhf4 (__m128);
extern __m128d __svml_atanh2 (__m128d);
extern __m128 __svml_erff4 (__m128);
extern __m128d __svml_erf2 (__m128d);
extern __m128 __svml_erfcf4 (__m128);
extern __m128d __svml_erfc2 (__m128d);
extern __m128 __svml_erfinvf4 (__m128);
extern __m128d __svml_erfinv2 (__m128d);
extern __m128 __svml_cdfnorminvf4(__m128);
extern __m128d __svml_cdfnorminv2 (__m128d);
extern __m128 __svml_cdfnormf4 (__m128);
extern __m128d __svml_cdfnorm2 (__m128d);
extern __m128 __svml_cexpf4 (__m128);
extern __m128d __svml_cexp2 (__m128d);
}
#ifndef VECTORMATH_COMMON_H
// exponential and power functions
static inline Vec4f exp (Vec4f const & x) { // exponential function
return __svml_expf4(x);
}
static inline Vec2d exp (Vec2d const & x) { // exponential function
return __svml_exp2(x);
}
static inline Vec4f expm1 (Vec4f const & x) { // exp(x)-1. Avoids loss of precision if x is close to 1
return __svml_expm1f4(x);
}
static inline Vec2d expm1 (Vec2d const & x) { // exp(x)-1. Avoids loss of precision if x is close to 1
return __svml_expm12(x);
}
static inline Vec4f exp2 (Vec4f const & x) { // pow(2,x)
return __svml_exp2f4(x);
}
static inline Vec2d exp2 (Vec2d const & x) { // pow(2,x)
return __svml_exp22(x);
}
static inline Vec4f exp10 (Vec4f const & x) { // pow(10,x)
return __svml_exp10f4(x);
}
static inline Vec2d exp10 (Vec2d const & x) { // pow(10,x)
return __svml_exp102(x);
}
static inline Vec4f pow (Vec4f const & a, Vec4f const & b) { // pow(a,b) = a to the power of b
return __svml_powf4(a,b);
}
static inline Vec2d pow (Vec2d const & a, Vec2d const & b) { // pow(a,b) = a to the power of b
return __svml_pow2(a,b);
}
static inline Vec4f cbrt (Vec4f const & x) { // pow(x,1/3)
return __svml_cbrtf4(x);
}
static inline Vec2d cbrt (Vec2d const & x) { // pow(x,1/3)
return __svml_cbrt2(x);
}
// logarithms
static inline Vec4f log (Vec4f const & x) { // natural logarithm
return __svml_logf4(x);
}
static inline Vec2d log (Vec2d const & x) { // natural logarithm
return __svml_log2(x);
}
static inline Vec4f log1p (Vec4f const & x) { // log(1+x). Avoids loss of precision if 1+x is close to 1
return __svml_log1pf4(x);
}
static inline Vec2d log1p (Vec2d const & x) { // log(1+x). Avoids loss of precision if 1+x is close to 1
return __svml_log1p2(x);
}
static inline Vec4f log2 (Vec4f const & x) { // logarithm base 2
return __svml_log2f4(x);
}
static inline Vec2d log2 (Vec2d const & x) { // logarithm base 2
return __svml_log22(x);
}
static inline Vec4f log10 (Vec4f const & x) { // logarithm base 10
return __svml_log10f4(x);
}
static inline Vec2d log10 (Vec2d const & x) { // logarithm base 10
return __svml_log102(x);
}
// trigonometric functions (angles in radians)
static inline Vec4f sin (Vec4f const & x) { // sine
return __svml_sinf4(x);
}
static inline Vec2d sin (Vec2d const & x) { // sine
return __svml_sin2(x);
}
static inline Vec4f cos (Vec4f const & x) { // cosine
return __svml_cosf4(x);
}
static inline Vec2d cos (Vec2d const & x) { // cosine
return __svml_cos2(x);
}
#if defined(__unix__) || defined(__INTEL_COMPILER) || !defined(__x86_64__) || !defined(_MSC_VER)
// no inline assembly in 64 bit MS compiler
static inline Vec4f sincos (Vec4f * pcos, Vec4f const & x) { // sine and cosine. sin(x) returned, cos(x) in pcos
__m128 r_sin, r_cos;
r_sin = __svml_sincosf4(x);
#if defined(__unix__) || defined(__GNUC__)
// __asm__ ( "call __svml_sincosf4 \n movaps %%xmm0, %0 \n movaps %%xmm1, %1" : "=m"(r_sin), "=m"(r_cos) : "xmm0"(x) );
__asm__ __volatile__ ( "movaps %%xmm1, %0":"=m"(r_cos));
#else // Windows
_asm movaps r_cos, xmm1;
#endif
*pcos = r_cos;
return r_sin;
}
static inline Vec2d sincos (Vec2d * pcos, Vec2d const & x) { // sine and cosine. sin(x) returned, cos(x) in pcos
__m128d r_sin, r_cos;
r_sin = __svml_sincos2(x);
#if defined(__unix__) || defined(__GNUC__)
__asm__ __volatile__ ( "movaps %%xmm1, %0":"=m"(r_cos));
#else // Windows
_asm movapd r_cos, xmm1;
#endif
*pcos = r_cos;
return r_sin;
}
#endif // inline assembly available
static inline Vec4f tan (Vec4f const & x) { // tangent
return __svml_tanf4(x);
}
static inline Vec2d tan (Vec2d const & x) { // tangent
return __svml_tan2(x);
}
// inverse trigonometric functions
static inline Vec4f asin (Vec4f const & x) { // inverse sine
return __svml_asinf4(x);
}
static inline Vec2d asin (Vec2d const & x) { // inverse sine
return __svml_asin2(x);
}
static inline Vec4f acos (Vec4f const & x) { // inverse cosine
return __svml_acosf4(x);
}
static inline Vec2d acos (Vec2d const & x) { // inverse cosine
return __svml_acos2(x);
}
static inline Vec4f atan (Vec4f const & x) { // inverse tangent
return __svml_atanf4(x);
}
static inline Vec2d atan (Vec2d const & x) { // inverse tangent
return __svml_atan2(x);
}
static inline Vec4f atan2 (Vec4f const & a, Vec4f const & b) { // inverse tangent of a/b
return __svml_atan2f4(a,b);
}
static inline Vec2d atan2 (Vec2d const & a, Vec2d const & b) { // inverse tangent of a/b
return __svml_atan22(a,b);
}
#endif // VECTORMATH_COMMON_H
// hyperbolic functions and inverse hyperbolic functions
static inline Vec4f sinh (Vec4f const & x) { // hyperbolic sine
return __svml_sinhf4(x);
}
static inline Vec2d sinh (Vec2d const & x) { // hyperbolic sine
return __svml_sinh2(x);
}
static inline Vec4f cosh (Vec4f const & x) { // hyperbolic cosine
return __svml_coshf4(x);
}
static inline Vec2d cosh (Vec2d const & x) { // hyperbolic cosine
return __svml_cosh2(x);
}
static inline Vec4f tanh (Vec4f const & x) { // hyperbolic tangent
return __svml_tanhf4(x);
}
static inline Vec2d tanh (Vec2d const & x) { // hyperbolic tangent
return __svml_tanh2(x);
}
static inline Vec4f asinh (Vec4f const & x) { // inverse hyperbolic sine
return __svml_asinhf4(x);
}
static inline Vec2d asinh (Vec2d const & x) { // inverse hyperbolic sine
return __svml_asinh2(x);
}
static inline Vec4f acosh (Vec4f const & x) { // inverse hyperbolic cosine
return __svml_acoshf4(x);
}
static inline Vec2d acosh (Vec2d const & x) { // inverse hyperbolic cosine
return __svml_acosh2(x);
}
static inline Vec4f atanh (Vec4f const & x) { // inverse hyperbolic tangent
return __svml_atanhf4(x);
}
static inline Vec2d atanh (Vec2d const & x) { // inverse hyperbolic tangent
return __svml_atanh2(x);
}
// error function
static inline Vec4f erf (Vec4f const & x) { // error function
return __svml_erff4(x);
}
static inline Vec2d erf (Vec2d const & x) { // error function
return __svml_erf2(x);
}
static inline Vec4f erfc (Vec4f const & x) { // error function complement
return __svml_erfcf4(x);
}
static inline Vec2d erfc (Vec2d const & x) { // error function complement
return __svml_erfc2(x);
}
static inline Vec4f erfinv (Vec4f const & x) { // inverse error function
return __svml_erfinvf4(x);
}
static inline Vec2d erfinv (Vec2d const & x) { // inverse error function
return __svml_erfinv2(x);
}
static inline Vec4f cdfnorm (Vec4f const & x) { // cumulative normal distribution function
return __svml_cdfnormf4(x);
}
static inline Vec2d cdfnorm (Vec2d const & x) { // cumulative normal distribution function
return __svml_cdfnorm2(x);
}
static inline Vec4f cdfnorminv (Vec4f const & x) { // inverse cumulative normal distribution function
return __svml_cdfnorminvf4(x);
}
static inline Vec2d cdfnorminv (Vec2d const & x) { // inverse cumulative normal distribution function
return __svml_cdfnorminv2(x);
}
// complex exponential function (real part in even numbered elements, imaginary part in odd numbered elements)
static inline Vec4f cexp (Vec4f const & x) { // complex exponential function
return __svml_cexpf4(x);
}
static inline Vec2d cexp (Vec2d const & x) { // complex exponential function
return __svml_cexp2(x);
}
#if defined (VECTORF256_H) && VECTORF256_H >= 2
// AVX gives 256 bit vectors
extern "C" {
extern __m256 __svml_expf8 (__m256);
extern __m256d __svml_exp4 (__m256d);
extern __m256 __svml_expm1f8 (__m256);
extern __m256d __svml_expm14 (__m256d);
extern __m256 __svml_exp2f8 (__m256);
extern __m256d __svml_exp24 (__m256d);
extern __m256 __svml_exp10f8 (__m256);
extern __m256d __svml_exp104 (__m256d);
extern __m256 __svml_powf8 (__m256, __m256);
extern __m256d __svml_pow4 (__m256d, __m256d);
extern __m256 __svml_cbrtf8 (__m256);
extern __m256d __svml_cbrt4 (__m256d);
extern __m256 __svml_invsqrtf8 (__m256);
extern __m256d __svml_invsqrt4 (__m256d);
extern __m256 __svml_logf8 (__m256);
extern __m256d __svml_log4 (__m256d);
extern __m256 __svml_log1pf8 (__m256);
extern __m256d __svml_log1p4 (__m256d);
extern __m256 __svml_log2f8 (__m256);
extern __m256d __svml_log24 (__m256d);
extern __m256 __svml_log10f8 (__m256);
extern __m256d __svml_log104 (__m256d);
extern __m256 __svml_sinf8 (__m256);
extern __m256d __svml_sin4 (__m256d);
extern __m256 __svml_cosf8 (__m256);
extern __m256d __svml_cos4 (__m256d);
extern __m256 __svml_sincosf8 (__m256); // cos returned in ymm1
extern __m256d __svml_sincos4 (__m256d); // cos returned in ymm1
extern __m256 __svml_tanf8 (__m256);
extern __m256d __svml_tan4 (__m256d);
extern __m256 __svml_asinf8 (__m256);
extern __m256d __svml_asin4 (__m256d);
extern __m256 __svml_acosf8 (__m256);
extern __m256d __svml_acos4 (__m256d);
extern __m256 __svml_atanf8 (__m256);
extern __m256d __svml_atan4 (__m256d);
extern __m256 __svml_atan2f8 (__m256, __m256);
extern __m256d __svml_atan24 (__m256d, __m256d);
extern __m256 __svml_sinhf8 (__m256);
extern __m256d __svml_sinh4 (__m256d);
extern __m256 __svml_coshf8 (__m256);
extern __m256d __svml_cosh4 (__m256d);
extern __m256 __svml_tanhf8 (__m256);
extern __m256d __svml_tanh4 (__m256d);
extern __m256 __svml_asinhf8 (__m256);
extern __m256d __svml_asinh4 (__m256d);
extern __m256 __svml_acoshf8 (__m256);
extern __m256d __svml_acosh4 (__m256d);
extern __m256 __svml_atanhf8 (__m256);
extern __m256d __svml_atanh4 (__m256d);
extern __m256 __svml_erff8 (__m256);
extern __m256d __svml_erf4 (__m256d);
extern __m256 __svml_erfcf8 (__m256);
extern __m256d __svml_erfc4 (__m256d);
extern __m256 __svml_erfinvf8 (__m256);
extern __m256d __svml_erfinv4 (__m256d);
extern __m256 __svml_cdfnorminvf8(__m256);
extern __m256d __svml_cdfnorminv4 (__m256d);
extern __m256 __svml_cdfnormf8 (__m256);
extern __m256d __svml_cdfnorm4 (__m256d);
//extern __m256 __svml_cexpf8 (__m256); // missing in current version of SVML (jan 2012)
//extern __m256d __svml_cexp4 (__m256d);
}
#ifndef VECTORMATH_COMMON_H
// exponential and power functions
static inline Vec8f exp (Vec8f const & x) { // exponential function
return __svml_expf8(x);
}
static inline Vec4d exp (Vec4d const & x) { // exponential function
return __svml_exp4(x);
}
static inline Vec8f expm1 (Vec8f const & x) { // exp(x)-1. Avoids loss of precision if x is close to 1
return __svml_expm1f8(x);
}
static inline Vec4d expm1 (Vec4d const & x) { // exp(x)-1. Avoids loss of precision if x is close to 1
return __svml_expm14(x);
}
static inline Vec8f exp2 (Vec8f const & x) { // pow(2,x)
return __svml_exp2f8(x);
}
static inline Vec4d exp2 (Vec4d const & x) { // pow(2,x)
return __svml_exp24(x);
}
static inline Vec8f exp10 (Vec8f const & x) { // pow(10,x)
return __svml_exp10f8(x);
}
static inline Vec4d exp10 (Vec4d const & x) { // pow(10,x)
return __svml_exp104(x);
}
static inline Vec8f pow (Vec8f const & a, Vec8f const & b) { // pow(a,b) = a to the power of b
return __svml_powf8(a,b);
}
static inline Vec4d pow (Vec4d const & a, Vec4d const & b) { // pow(a,b) = a to the power of b
return __svml_pow4(a,b);
}
static inline Vec8f cbrt (Vec8f const & x) { // pow(x,1/3)
return __svml_cbrtf8(x);
}
static inline Vec4d cbrt (Vec4d const & x) { // pow(x,1/3)
return __svml_cbrt4(x);
}
// logarithms
static inline Vec8f log (Vec8f const & x) { // natural logarithm
return __svml_logf8(x);
}
static inline Vec4d log (Vec4d const & x) { // natural logarithm
return __svml_log4(x);
}
static inline Vec8f log1p (Vec8f const & x) { // log(1+x). Avoids loss of precision if 1+x is close to 1
return __svml_log1pf8(x);
}
static inline Vec4d log1p (Vec4d const & x) { // log(1+x). Avoids loss of precision if 1+x is close to 1
return __svml_log1p4(x);
}
static inline Vec8f log2 (Vec8f const & x) { // logarithm base 2
return __svml_log2f8(x);
}
static inline Vec4d log2 (Vec4d const & x) { // logarithm base 2
return __svml_log24(x);
}
static inline Vec8f log10 (Vec8f const & x) { // logarithm base 10
return __svml_log10f8(x);
}
static inline Vec4d log10 (Vec4d const & x) { // logarithm base 10
return __svml_log104(x);
}
// trigonometric functions (angles in radians)
static inline Vec8f sin (Vec8f const & x) { // sine
return __svml_sinf8(x);
}
static inline Vec4d sin (Vec4d const & x) { // sine
return __svml_sin4(x);
}
static inline Vec8f cos (Vec8f const & x) { // cosine
return __svml_cosf8(x);
}
static inline Vec4d cos (Vec4d const & x) { // cosine
return __svml_cos4(x);
}
#if defined(__unix__) || defined(__INTEL_COMPILER) || !defined(__x86_64__) || !defined(_MSC_VER)
// no inline assembly in 64 bit MS compiler
static inline Vec8f sincos (Vec8f * pcos, Vec8f const & x) { // sine and cosine. sin(x) returned, cos(x) in pcos
__m256 r_sin, r_cos;
r_sin = __svml_sincosf8(x);
#if defined(__unix__) || defined(__GNUC__)
__asm__ __volatile__ ( "vmovaps %%ymm1, %0":"=m"(r_cos));
#else // Windows
_asm vmovaps r_cos, ymm1;
#endif
*pcos = r_cos;
return r_sin;
}
static inline Vec4d sincos (Vec4d * pcos, Vec4d const & x) { // sine and cosine. sin(x) returned, cos(x) in pcos
__m256d r_sin, r_cos;
r_sin = __svml_sincos4(x);
#if defined(__unix__) || defined(__GNUC__)
__asm__ __volatile__ ( "vmovaps %%ymm1, %0":"=m"(r_cos));
#else // Windows
_asm vmovapd r_cos, ymm1;
#endif
*pcos = r_cos;
return r_sin;
}
#endif // inline assembly available
static inline Vec8f tan (Vec8f const & x) { // tangent
return __svml_tanf8(x);
}
static inline Vec4d tan (Vec4d const & x) { // tangent
return __svml_tan4(x);
}
// inverse trigonometric functions
static inline Vec8f asin (Vec8f const & x) { // inverse sine
return __svml_asinf8(x);
}
static inline Vec4d asin (Vec4d const & x) { // inverse sine
return __svml_asin4(x);
}
static inline Vec8f acos (Vec8f const & x) { // inverse cosine
return __svml_acosf8(x);
}
static inline Vec4d acos (Vec4d const & x) { // inverse cosine
return __svml_acos4(x);
}
static inline Vec8f atan (Vec8f const & x) { // inverse tangent
return __svml_atanf8(x);
}
static inline Vec4d atan (Vec4d const & x) { // inverse tangent
return __svml_atan4(x);
}
static inline Vec8f atan2 (Vec8f const & a, Vec8f const & b) { // inverse tangent of a/b
return __svml_atan2f8(a,b);
}
static inline Vec4d atan2 (Vec4d const & a, Vec4d const & b) { // inverse tangent of a/b
return __svml_atan24(a,b);
}
#endif // VECTORMATH_COMMON_H
// hyperbolic functions and inverse hyperbolic functions
static inline Vec8f sinh (Vec8f const & x) { // hyperbolic sine
return __svml_sinhf8(x);
}
static inline Vec4d sinh (Vec4d const & x) { // hyperbolic sine
return __svml_sinh4(x);
}
static inline Vec8f cosh (Vec8f const & x) { // hyperbolic cosine
return __svml_coshf8(x);
}
static inline Vec4d cosh (Vec4d const & x) { // hyperbolic cosine
return __svml_cosh4(x);
}
static inline Vec8f tanh (Vec8f const & x) { // hyperbolic tangent
return __svml_tanhf8(x);
}
static inline Vec4d tanh (Vec4d const & x) { // hyperbolic tangent
return __svml_tanh4(x);
}
static inline Vec8f asinh (Vec8f const & x) { // inverse hyperbolic sine
return __svml_asinhf8(x);
}
static inline Vec4d asinh (Vec4d const & x) { // inverse hyperbolic sine
return __svml_asinh4(x);
}
static inline Vec8f acosh (Vec8f const & x) { // inverse hyperbolic cosine
return __svml_acoshf8(x);
}
static inline Vec4d acosh (Vec4d const & x) { // inverse hyperbolic cosine
return __svml_acosh4(x);
}
static inline Vec8f atanh (Vec8f const & x) { // inverse hyperbolic tangent
return __svml_atanhf8(x);
}
static inline Vec4d atanh (Vec4d const & x) { // inverse hyperbolic tangent
return __svml_atanh4(x);
}
// error function
static inline Vec8f erf (Vec8f const & x) { // error function
return __svml_erff8(x);
}
static inline Vec4d erf (Vec4d const & x) { // error function
return __svml_erf4(x);
}
static inline Vec8f erfc (Vec8f const & x) { // error function complement
return __svml_erfcf8(x);
}
static inline Vec4d erfc (Vec4d const & x) { // error function complement
return __svml_erfc4(x);
}
static inline Vec8f erfinv (Vec8f const & x) { // inverse error function
return __svml_erfinvf8(x);
}
static inline Vec4d erfinv (Vec4d const & x) { // inverse error function
return __svml_erfinv4(x);
}
static inline Vec8f cdfnorm (Vec8f const & x) { // cumulative normal distribution function
return __svml_cdfnormf8(x);
}
static inline Vec4d cdfnorm (Vec4d const & x) { // cumulative normal distribution function
return __svml_cdfnorm4(x);
}
static inline Vec8f cdfnorminv (Vec8f const & x) { // inverse cumulative normal distribution function
return __svml_cdfnorminvf8(x);
}
static inline Vec4d cdfnorminv (Vec4d const & x) { // inverse cumulative normal distribution function
return __svml_cdfnorminv4(x);
}
// complex exponential function (real part in even numbered elements, imaginary part in odd numbered elements)
// 256-bit version missing in current version of SVML (jan 2012). Use 128 bit version
static inline Vec8f cexp (Vec8f const & x) { // complex exponential function
return Vec8f(cexp(x.get_low()), cexp(x.get_high()));
}
static inline Vec4d cexp (Vec4d const & x) { // complex exponential function
return Vec4d(cexp(x.get_low()), cexp(x.get_high()));
}
#endif // VECTORF256_H == 2
/*****************************************************************************
*
* VECTORMATH = 3. Use Intel SVML library with Intel compiler
*
*****************************************************************************/
#elif VECTORMATH == 3
#include <ia32intrin.h> // intel svml functions defined in Intel version of immintrin.h
// 128 bit vectors
#ifndef VECTORMATH_COMMON_H
// exponential and power functions
static inline Vec4f exp (Vec4f const & x) { // exponential function
return _mm_exp_ps(x);
}
static inline Vec2d exp (Vec2d const & x) { // exponential function
return _mm_exp_pd(x);
}
static inline Vec4f expm1 (Vec4f const & x) { // exp(x)-1. Avoids loss of precision if x is close to 1
return _mm_expm1_ps(x);
}
static inline Vec2d expm1 (Vec2d const & x) { // exp(x)-1. Avoids loss of precision if x is close to 1
return _mm_expm1_pd(x);
}
static inline Vec4f exp2 (Vec4f const & x) { // pow(2,x)
return _mm_exp2_ps(x);
}
static inline Vec2d exp2 (Vec2d const & x) { // pow(2,x)
return _mm_exp2_pd(x);
}
static inline Vec4f exp10 (Vec4f const & x) { // pow(10,x)
return _mm_exp10_ps(x);
}
static inline Vec2d exp10 (Vec2d const & x) { // pow(10,x)
return _mm_exp10_pd(x);
}
static inline Vec4f pow (Vec4f const & a, Vec4f const & b) { // pow(a,b) = a to the power of b
return _mm_pow_ps(a,b);
}
static inline Vec2d pow (Vec2d const & a, Vec2d const & b) { // pow(a,b) = a to the power of b
return _mm_pow_pd(a,b);
}
static inline Vec4f cbrt (Vec4f const & x) { // pow(x,1/3)
return _mm_cbrt_ps(x);
}
static inline Vec2d cbrt (Vec2d const & x) { // pow(x,1/3)
return _mm_cbrt_pd(x);
}
// logarithms
static inline Vec4f log (Vec4f const & x) { // natural logarithm
return _mm_log_ps(x);
}
static inline Vec2d log (Vec2d const & x) { // natural logarithm
return _mm_log_pd(x);
}
static inline Vec4f log1p (Vec4f const & x) { // log(1+x). Avoids loss of precision if 1+x is close to 1
return _mm_log1p_ps(x);
}
static inline Vec2d log1p (Vec2d const & x) { // log(1+x). Avoids loss of precision if 1+x is close to 1
return _mm_log1p_pd(x);
}
static inline Vec4f log2 (Vec4f const & x) { // logarithm base 2
return _mm_log2_ps(x);
}
static inline Vec2d log2 (Vec2d const & x) { // logarithm base 2
return _mm_log2_pd(x);
}
static inline Vec4f log10 (Vec4f const & x) { // logarithm base 10
return _mm_log10_ps(x);
}
static inline Vec2d log10 (Vec2d const & x) { // logarithm base 10
return _mm_log10_pd(x);
}
// trigonometric functions
static inline Vec4f sin (Vec4f const & x) { // sine
return _mm_sin_ps(x);
}
static inline Vec2d sin (Vec2d const & x) { // sine
return _mm_sin_pd(x);
}
static inline Vec4f cos (Vec4f const & x) { // cosine
return _mm_cos_ps(x);
}
static inline Vec2d cos (Vec2d const & x) { // cosine
return _mm_cos_pd(x);
}
static inline Vec4f sincos (Vec4f * pcos, Vec4f const & x) { // sine and cosine. sin(x) returned, cos(x) in pcos
__m128 r_sin, r_cos;
r_sin = _mm_sincos_ps(&r_cos, x);
*pcos = r_cos;
return r_sin;
}
static inline Vec2d sincos (Vec2d * pcos, Vec2d const & x) { // sine and cosine. sin(x) returned, cos(x) in pcos
__m128d r_sin, r_cos;
r_sin = _mm_sincos_pd(&r_cos, x);
*pcos = r_cos;
return r_sin;
}
static inline Vec4f tan (Vec4f const & x) { // tangent
return _mm_tan_ps(x);
}
static inline Vec2d tan (Vec2d const & x) { // tangent
return _mm_tan_pd(x);
}
// inverse trigonometric functions
static inline Vec4f asin (Vec4f const & x) { // inverse sine
return _mm_asin_ps(x);
}
static inline Vec2d asin (Vec2d const & x) { // inverse sine
return _mm_asin_pd(x);
}
static inline Vec4f acos (Vec4f const & x) { // inverse cosine
return _mm_acos_ps(x);
}
static inline Vec2d acos (Vec2d const & x) { // inverse cosine
return _mm_acos_pd(x);
}
static inline Vec4f atan (Vec4f const & x) { // inverse tangent
return _mm_atan_ps(x);
}
static inline Vec2d atan (Vec2d const & x) { // inverse tangent
return _mm_atan_pd(x);
}
static inline Vec4f atan2 (Vec4f const & a, Vec4f const & b) { // inverse tangent of a/b
return _mm_atan2_ps(a,b);
}
static inline Vec2d atan2 (Vec2d const & a, Vec2d const & b) { // inverse tangent of a/b
return _mm_atan2_pd(a,b);
}
#endif // VECTORMATH_COMMON_H
// hyperbolic functions and inverse hyperbolic functions
static inline Vec4f sinh (Vec4f const & x) { // hyperbolic sine
return _mm_sinh_ps(x);
}
static inline Vec2d sinh (Vec2d const & x) { // hyperbolic sine
return _mm_sinh_pd(x);
}
static inline Vec4f cosh (Vec4f const & x) { // hyperbolic cosine
return _mm_cosh_ps(x);
}
static inline Vec2d cosh (Vec2d const & x) { // hyperbolic cosine
return _mm_cosh_pd(x);
}
static inline Vec4f tanh (Vec4f const & x) { // hyperbolic tangent
return _mm_tanh_ps(x);
}
static inline Vec2d tanh (Vec2d const & x) { // hyperbolic tangent
return _mm_tanh_pd(x);
}
static inline Vec4f asinh (Vec4f const & x) { // inverse hyperbolic sine
return _mm_asinh_ps(x);
}
static inline Vec2d asinh (Vec2d const & x) { // inverse hyperbolic sine
return _mm_asinh_pd(x);
}
static inline Vec4f acosh (Vec4f const & x) { // inverse hyperbolic cosine
return _mm_acosh_ps(x);
}
static inline Vec2d acosh (Vec2d const & x) { // inverse hyperbolic cosine
return _mm_acosh_pd(x);
}
static inline Vec4f atanh (Vec4f const & x) { // inverse hyperbolic tangent
return _mm_atanh_ps(x);
}
static inline Vec2d atanh (Vec2d const & x) { // inverse hyperbolic tangent
return _mm_atanh_pd(x);
}
// error function
static inline Vec4f erf (Vec4f const & x) { // error function
return _mm_erf_ps(x);
}
static inline Vec2d erf (Vec2d const & x) { // error function
return _mm_erf_pd(x);
}
static inline Vec4f erfc (Vec4f const & x) { // error function complement
return _mm_erfc_ps(x);
}
static inline Vec2d erfc (Vec2d const & x) { // error function complement
return _mm_erfc_pd(x);
}
static inline Vec4f erfinv (Vec4f const & x) { // inverse error function
return _mm_erfinv_ps(x);
}
static inline Vec2d erfinv (Vec2d const & x) { // inverse error function
return _mm_erfinv_pd(x);
}
extern "C" {
extern __m128 __svml_cdfnormf4(__m128); // not in immintrin.h
extern __m128d __svml_cdfnorm2(__m128d); // not in immintrin.h
}
static inline Vec4f cdfnorm (Vec4f const & x) { // cumulative normal distribution function
return __svml_cdfnormf4(x);
}
static inline Vec2d cdfnorm (Vec2d const & x) { // cumulative normal distribution function
return __svml_cdfnorm2(x);
}
static inline Vec4f cdfnorminv (Vec4f const & x) { // inverse cumulative normal distribution function
return _mm_cdfnorminv_ps(x);
}
static inline Vec2d cdfnorminv (Vec2d const & x) { // inverse cumulative normal distribution function
return _mm_cdfnorminv_pd(x);
}
// complex functions
extern "C" {
extern __m128 __svml_cexpf2(__m128); // not in immintrin.h
extern __m128 __svml_cexpf4(__m128); // not in immintrin.h
extern __m128d __svml_cexp2(__m128d); // not in immintrin.h
}
static inline Vec4f cexp (Vec4f const & x) { // complex exponential function
return __svml_cexpf4(x);
}
static inline Vec2d cexp (Vec2d const & x) { // complex exponential function
return __svml_cexp2(x);
}
#if defined (VECTORF256_H) && VECTORF256_H >= 2
// 256 bit vectors
#ifndef VECTORMATH_COMMON_H
// exponential and power functions
static inline Vec8f exp (Vec8f const & x) { // exponential function
return _mm256_exp_ps(x);
}
static inline Vec4d exp (Vec4d const & x) { // exponential function
return _mm256_exp_pd(x);
}
static inline Vec8f expm1 (Vec8f const & x) { // exp(x)-1. Avoids loss of precision if x is close to 1
return _mm256_expm1_ps(x);
}
static inline Vec4d expm1 (Vec4d const & x) { // exp(x)-1. Avoids loss of precision if x is close to 1
return _mm256_expm1_pd(x);
}
static inline Vec8f exp2 (Vec8f const & x) { // pow(2,x)
return _mm256_exp2_ps(x);
}
static inline Vec4d exp2 (Vec4d const & x) { // pow(2,x)
return _mm256_exp2_pd(x);
}
static inline Vec8f exp10 (Vec8f const & x) { // pow(10,x)
return _mm256_exp10_ps(x);
}
static inline Vec4d exp10 (Vec4d const & x) { // pow(10,x)
return _mm256_exp10_pd(x);
}
static inline Vec8f pow (Vec8f const & a, Vec8f const & b) { // pow(a,b) = a to the power of b
return _mm256_pow_ps(a,b);
}
static inline Vec4d pow (Vec4d const & a, Vec4d const & b) { // pow(a,b) = a to the power of b
return _mm256_pow_pd(a,b);
}
static inline Vec8f cbrt (Vec8f const & x) { // pow(x,1/3)
return _mm256_cbrt_ps(x);
}
static inline Vec4d cbrt (Vec4d const & x) { // pow(x,1/3)
return _mm256_cbrt_pd(x);
}
// logarithms
static inline Vec8f log (Vec8f const & x) { // natural logarithm
return _mm256_log_ps(x);
}
static inline Vec4d log (Vec4d const & x) { // natural logarithm
return _mm256_log_pd(x);
}
static inline Vec8f log1p (Vec8f const & x) { // log(1+x). Avoids loss of precision if 1+x is close to 1
return _mm256_log1p_ps(x);
}
static inline Vec4d log1p (Vec4d const & x) { // log(1+x). Avoids loss of precision if 1+x is close to 1
return _mm256_log1p_pd(x);
}
static inline Vec8f log2 (Vec8f const & x) { // logarithm base 2
return _mm256_log2_ps(x);
}
static inline Vec4d log2 (Vec4d const & x) { // logarithm base 2
return _mm256_log2_pd(x);
}
static inline Vec8f log10 (Vec8f const & x) { // logarithm base 10
return _mm256_log10_ps(x);
}
static inline Vec4d log10 (Vec4d const & x) { // logarithm base 10
return _mm256_log10_pd(x);
}
// trigonometric functions
static inline Vec8f sin (Vec8f const & x) { // sine
return _mm256_sin_ps(x);
}
static inline Vec4d sin (Vec4d const & x) { // sine
return _mm256_sin_pd(x);
}
static inline Vec8f cos (Vec8f const & x) { // cosine
return _mm256_cos_ps(x);
}
static inline Vec4d cos (Vec4d const & x) { // cosine
return _mm256_cos_pd(x);
}
static inline Vec8f sincos (Vec8f * pcos, Vec8f const & x) { // sine and cosine. sin(x) returned, cos(x) in pcos
__m256 r_sin, r_cos;
r_sin = _mm256_sincos_ps(&r_cos, x);
*pcos = r_cos;
return r_sin;
}
static inline Vec4d sincos (Vec4d * pcos, Vec4d const & x) { // sine and cosine. sin(x) returned, cos(x) in pcos
__m256d r_sin, r_cos;
r_sin = _mm256_sincos_pd(&r_cos, x);
*pcos = r_cos;
return r_sin;
}
static inline Vec8f tan (Vec8f const & x) { // tangent
return _mm256_tan_ps(x);
}
static inline Vec4d tan (Vec4d const & x) { // tangent
return _mm256_tan_pd(x);
}
// inverse trigonometric functions
static inline Vec8f asin (Vec8f const & x) { // inverse sine
return _mm256_asin_ps(x);
}
static inline Vec4d asin (Vec4d const & x) { // inverse sine
return _mm256_asin_pd(x);
}
static inline Vec8f acos (Vec8f const & x) { // inverse cosine
return _mm256_acos_ps(x);
}
static inline Vec4d acos (Vec4d const & x) { // inverse cosine
return _mm256_acos_pd(x);
}
static inline Vec8f atan (Vec8f const & x) { // inverse tangent
return _mm256_atan_ps(x);
}
static inline Vec4d atan (Vec4d const & x) { // inverse tangent
return _mm256_atan_pd(x);
}
static inline Vec8f atan2 (Vec8f const & a, Vec8f const & b) { // inverse tangent of a/b
return _mm256_atan2_ps(a,b);
}
static inline Vec4d atan2 (Vec4d const & a, Vec4d const & b) { // inverse tangent of a/b
return _mm256_atan2_pd(a,b);
}
#endif // VECTORMATH_COMMON_H
// hyperbolic functions and inverse hyperbolic functions
static inline Vec8f sinh (Vec8f const & x) { // hyperbolic sine
return _mm256_sinh_ps(x);
}
static inline Vec4d sinh (Vec4d const & x) { // hyperbolic sine
return _mm256_sinh_pd(x);
}
static inline Vec8f cosh (Vec8f const & x) { // hyperbolic cosine
return _mm256_cosh_ps(x);
}
static inline Vec4d cosh (Vec4d const & x) { // hyperbolic cosine
return _mm256_cosh_pd(x);
}
static inline Vec8f tanh (Vec8f const & x) { // hyperbolic tangent
return _mm256_tanh_ps(x);
}
static inline Vec4d tanh (Vec4d const & x) { // hyperbolic tangent
return _mm256_tanh_pd(x);
}
static inline Vec8f asinh (Vec8f const & x) { // inverse hyperbolic sine
return _mm256_asinh_ps(x);
}
static inline Vec4d asinh (Vec4d const & x) { // inverse hyperbolic sine
return _mm256_asinh_pd(x);
}
static inline Vec8f acosh (Vec8f const & x) { // inverse hyperbolic cosine
return _mm256_acosh_ps(x);
}
static inline Vec4d acosh (Vec4d const & x) { // inverse hyperbolic cosine
return _mm256_acosh_pd(x);
}
static inline Vec8f atanh (Vec8f const & x) { // inverse hyperbolic tangent
return _mm256_atanh_ps(x);
}
static inline Vec4d atanh (Vec4d const & x) { // inverse hyperbolic tangent
return _mm256_atanh_pd(x);
}
// error function
static inline Vec8f erf (Vec8f const & x) { // error function
return _mm256_erf_ps(x);
}
static inline Vec4d erf (Vec4d const & x) { // error function
return _mm256_erf_pd(x);
}
static inline Vec8f erfc (Vec8f const & x) { // error function complement
return _mm256_erfc_ps(x);
}
static inline Vec4d erfc (Vec4d const & x) { // error function complement
return _mm256_erfc_pd(x);
}
static inline Vec8f erfinv (Vec8f const & x) { // inverse error function
return _mm256_erfinv_ps(x);
}
static inline Vec4d erfinv (Vec4d const & x) { // inverse error function
return _mm256_erfinv_pd(x);
}
extern "C" {
extern __m256 __svml_cdfnormf8(__m256); // not in immintrin.h
extern __m256d __svml_cdfnorm4(__m256d); // not in immintrin.h
}
static inline Vec8f cdfnorm (Vec8f const & x) { // cumulative normal distribution function
return __svml_cdfnormf8(x);
}
static inline Vec4d cdfnorm (Vec4d const & x) { // cumulative normal distribution function
return __svml_cdfnorm4(x);
}
static inline Vec8f cdfnorminv (Vec8f const & x) { // inverse cumulative normal distribution function
return _mm256_cdfnorminv_ps(x);
}
static inline Vec4d cdfnorminv (Vec4d const & x) { // inverse cumulative normal distribution function
return _mm256_cdfnorminv_pd(x);
}
// complex exponential function (real part in even numbered elements, imaginary part in odd numbered elements)
static inline Vec8f cexp (Vec8f const & x) { // complex exponential function
return Vec8f(cexp(x.get_low()), cexp(x.get_high()));
}
static inline Vec4d cexp (Vec4d const & x) { // complex exponential function
return Vec4d(cexp(x.get_low()), cexp(x.get_high()));
}
#endif // VECTORF256_H >= 2
#else
#error unknown value of VECTORMATH
#endif // VECTORMATH
#if defined (VECTORF256_H) && VECTORF256_H == 1 && (VECTORMATH == 2 || VECTORMATH == 3)
/*****************************************************************************
*
* VECTORF256_H == 1. 256 bit vectors emulated as two 128-bit vectors,
* SVML library
*
*****************************************************************************/
#ifndef VECTORMATH_COMMON_H
// exponential and power functions
static inline Vec8f exp (Vec8f const & x) { // exponential function
return Vec8f(exp(x.get_low()), exp(x.get_high()));
}
static inline Vec4d exp (Vec4d const & x) { // exponential function
return Vec4d(exp(x.get_low()), exp(x.get_high()));
}
static inline Vec8f expm1 (Vec8f const & x) { // exp(x)-1. Avoids loss of precision if x is close to 1
return Vec8f(expm1(x.get_low()), expm1(x.get_high()));
}
static inline Vec4d expm1 (Vec4d const & x) { // exp(x)-1. Avoids loss of precision if x is close to 1
return Vec4d(expm1(x.get_low()), expm1(x.get_high()));
}
static inline Vec8f exp2 (Vec8f const & x) { // pow(2,x)
return Vec8f(exp2(x.get_low()), exp2(x.get_high()));
}
static inline Vec4d exp2 (Vec4d const & x) { // pow(2,x)
return Vec4d(exp2(x.get_low()), exp2(x.get_high()));
}
static inline Vec8f exp10 (Vec8f const & x) { // pow(10,x)
return Vec8f(exp10(x.get_low()), exp10(x.get_high()));
}
static inline Vec4d exp10 (Vec4d const & x) { // pow(10,x)
return Vec4d(exp10(x.get_low()), exp10(x.get_high()));
}
static inline Vec8f pow (Vec8f const & a, Vec8f const & b) { // pow(a,b) = a to the power of b
return Vec8f(pow(a.get_low(),b.get_low()), pow(a.get_high(),b.get_high()));
}
static inline Vec4d pow (Vec4d const & a, Vec4d const & b) { // pow(a,b) = a to the power of b
return Vec4d(pow(a.get_low(),b.get_low()), pow(a.get_high(),b.get_high()));
}
static inline Vec8f cbrt (Vec8f const & x) { // pow(x,1/3)
return Vec8f(cbrt(x.get_low()), cbrt(x.get_high()));
}
static inline Vec4d cbrt (Vec4d const & x) { // pow(x,1/3)
return Vec4d(cbrt(x.get_low()), cbrt(x.get_high()));
}
// logarithms
static inline Vec8f log (Vec8f const & x) { // natural logarithm
return Vec8f(log(x.get_low()), log(x.get_high()));
}
static inline Vec4d log (Vec4d const & x) { // natural logarithm
return Vec4d(log(x.get_low()), log(x.get_high()));
}
static inline Vec8f log1p (Vec8f const & x) { // log(1+x). Avoids loss of precision if 1+x is close to 1
return Vec8f(log1p(x.get_low()), log1p(x.get_high()));
}
static inline Vec4d log1p (Vec4d const & x) { // log(1+x). Avoids loss of precision if 1+x is close to 1
return Vec4d(log1p(x.get_low()), log1p(x.get_high()));
}
static inline Vec8f log2 (Vec8f const & x) { // logarithm base 2
return Vec8f(log2(x.get_low()), log2(x.get_high()));
}
static inline Vec4d log2 (Vec4d const & x) { // logarithm base 2
return Vec4d(log2(x.get_low()), log2(x.get_high()));
}
static inline Vec8f log10 (Vec8f const & x) { // logarithm base 10
return Vec8f(log10(x.get_low()), log10(x.get_high()));
}
static inline Vec4d log10 (Vec4d const & x) { // logarithm base 10
return Vec4d(log10(x.get_low()), log10(x.get_high()));
}
// trigonometric functions (angles in radians)
static inline Vec8f sin (Vec8f const & x) { // sine
return Vec8f(sin(x.get_low()), sin(x.get_high()));
}
static inline Vec4d sin (Vec4d const & x) { // sine
return Vec4d(sin(x.get_low()), sin(x.get_high()));
}
static inline Vec8f cos (Vec8f const & x) { // cosine
return Vec8f(cos(x.get_low()), cos(x.get_high()));
}
static inline Vec4d cos (Vec4d const & x) { // cosine
return Vec4d(cos(x.get_low()), cos(x.get_high()));
}
#if defined(__unix__) || defined(__INTEL_COMPILER) || !defined(__x86_64__) || !defined(_MSC_VER)
// no inline assembly in 64 bit MS compiler
static inline Vec8f sincos (Vec8f * pcos, Vec8f const & x) { // sine and cosine. sin(x) returned, cos(x) in pcos
Vec4f r_sin0, r_sin1, r_cos0, r_cos1;
r_sin0 = sincos(&r_cos0, x.get_low());
r_sin1 = sincos(&r_cos1, x.get_high());
*pcos = Vec8f(r_cos0, r_cos1);
return Vec8f(r_sin0, r_sin1);
}
static inline Vec4d sincos (Vec4d * pcos, Vec4d const & x) { // sine and cosine. sin(x) returned, cos(x) in pcos
Vec2d r_sin0, r_sin1, r_cos0, r_cos1;
r_sin0 = sincos(&r_cos0, x.get_low());
r_sin1 = sincos(&r_cos1, x.get_high());
*pcos = Vec4d(r_cos0, r_cos1);
return Vec4d(r_sin0, r_sin1);
}
#endif // inline assembly available
static inline Vec8f tan (Vec8f const & x) { // tangent
return Vec8f(tan(x.get_low()), tan(x.get_high()));
}
static inline Vec4d tan (Vec4d const & x) { // tangent
return Vec4d(tan(x.get_low()), tan(x.get_high()));
}
// inverse trigonometric functions
static inline Vec8f asin (Vec8f const & x) { // inverse sine
return Vec8f(asin(x.get_low()), asin(x.get_high()));
}
static inline Vec4d asin (Vec4d const & x) { // inverse sine
return Vec4d(asin(x.get_low()), asin(x.get_high()));
}
static inline Vec8f acos (Vec8f const & x) { // inverse cosine
return Vec8f(acos(x.get_low()), acos(x.get_high()));
}
static inline Vec4d acos (Vec4d const & x) { // inverse cosine
return Vec4d(acos(x.get_low()), acos(x.get_high()));
}
static inline Vec8f atan (Vec8f const & x) { // inverse tangent
return Vec8f(atan(x.get_low()), atan(x.get_high()));
}
static inline Vec4d atan (Vec4d const & x) { // inverse tangent
return Vec4d(atan(x.get_low()), atan(x.get_high()));
}
static inline Vec8f atan2 (Vec8f const & a, Vec8f const & b) { // inverse tangent of a/b
return Vec8f(atan2(a.get_low(),b.get_low()), atan2(a.get_high(),b.get_high()));
}
static inline Vec4d atan2 (Vec4d const & a, Vec4d const & b) { // inverse tangent of a/b
return Vec4d(atan2(a.get_low(),b.get_low()), atan2(a.get_high(),b.get_high()));
}
#endif // VECTORMATH_COMMON_H
// hyperbolic functions and inverse hyperbolic functions
static inline Vec8f sinh (Vec8f const & x) { // hyperbolic sine
return Vec8f(sinh(x.get_low()), sinh(x.get_high()));
}
static inline Vec4d sinh (Vec4d const & x) { // hyperbolic sine
return Vec4d(sinh(x.get_low()), sinh(x.get_high()));
}
static inline Vec8f cosh (Vec8f const & x) { // hyperbolic cosine
return Vec8f(cosh(x.get_low()), cosh(x.get_high()));
}
static inline Vec4d cosh (Vec4d const & x) { // hyperbolic cosine
return Vec4d(cosh(x.get_low()), cosh(x.get_high()));
}
static inline Vec8f tanh (Vec8f const & x) { // hyperbolic tangent
return Vec8f(tanh(x.get_low()), tanh(x.get_high()));
}
static inline Vec4d tanh (Vec4d const & x) { // hyperbolic tangent
return Vec4d(tanh(x.get_low()), tanh(x.get_high()));
}
static inline Vec8f asinh (Vec8f const & x) { // inverse hyperbolic sine
return Vec8f(asinh(x.get_low()), asinh(x.get_high()));
}
static inline Vec4d asinh (Vec4d const & x) { // inverse hyperbolic sine
return Vec4d(asinh(x.get_low()), asinh(x.get_high()));
}
static inline Vec8f acosh (Vec8f const & x) { // inverse hyperbolic cosine
return Vec8f(acosh(x.get_low()), acosh(x.get_high()));
}
static inline Vec4d acosh (Vec4d const & x) { // inverse hyperbolic cosine
return Vec4d(acosh(x.get_low()), acosh(x.get_high()));
}
static inline Vec8f atanh (Vec8f const & x) { // inverse hyperbolic tangent
return Vec8f(atanh(x.get_low()), atanh(x.get_high()));
}
static inline Vec4d atanh (Vec4d const & x) { // inverse hyperbolic tangent
return Vec4d(atanh(x.get_low()), atanh(x.get_high()));
}
// error function
static inline Vec8f erf (Vec8f const & x) { // error function
return Vec8f(erf(x.get_low()), erf(x.get_high()));
}
static inline Vec4d erf (Vec4d const & x) { // error function
return Vec4d(erf(x.get_low()), erf(x.get_high()));
}
static inline Vec8f erfc (Vec8f const & x) { // error function complement
return Vec8f(erfc(x.get_low()), erfc(x.get_high()));
}
static inline Vec4d erfc (Vec4d const & x) { // error function complement
return Vec4d(erfc(x.get_low()), erfc(x.get_high()));
}
static inline Vec8f erfinv (Vec8f const & x) { // inverse error function
return Vec8f(erfinv(x.get_low()), erfinv(x.get_high()));
}
static inline Vec4d erfinv (Vec4d const & x) { // inverse error function
return Vec4d(erfinv(x.get_low()), erfinv(x.get_high()));
}
static inline Vec8f cdfnorm (Vec8f const & x) { // cumulative normal distribution function
return Vec8f(cdfnorm(x.get_low()), cdfnorm(x.get_high()));
}
static inline Vec4d cdfnorm (Vec4d const & x) { // cumulative normal distribution function
return Vec4d(cdfnorm(x.get_low()), cdfnorm(x.get_high()));
}
static inline Vec8f cdfnorminv (Vec8f const & x) { // inverse cumulative normal distribution function
return Vec8f(cdfnorminv(x.get_low()), cdfnorminv(x.get_high()));
}
static inline Vec4d cdfnorminv (Vec4d const & x) { // inverse cumulative normal distribution function
return Vec4d(cdfnorminv(x.get_low()), cdfnorminv(x.get_high()));
}
// complex exponential function (real part in even numbered elements, imaginary part in odd numbered elements)
static inline Vec8f cexp (Vec8f const & x) { // complex exponential function
return Vec8f(cexp(x.get_low()), cexp(x.get_high()));
}
static inline Vec4d cexp (Vec4d const & x) { // complex exponential function
return Vec4d(cexp(x.get_low()), cexp(x.get_high()));
}
#endif // VECTORF256_H == 1
#ifdef VCL_NAMESPACE
}
#endif
#endif // VECTORMATH_LIB_H
|