@@ -896,7 +896,9 @@ namespace xsimd
896
896
batch_type k = reducer_t::reduce (self, x);
897
897
x = reducer_t::approx (x);
898
898
x = select (self <= reducer_t::minlog (), batch_type (0 .), ldexp (x, to_int (k)));
899
+ #ifndef __FAST_MATH__
899
900
x = select (self >= reducer_t::maxlog (), constants::infinity<batch_type>(), x);
901
+ #endif
900
902
return x;
901
903
}
902
904
@@ -910,7 +912,9 @@ namespace xsimd
910
912
batch_type c = reducer_t::approx (x);
911
913
c = reducer_t::finalize (x, c, hi, lo);
912
914
c = select (self <= reducer_t::minlog (), batch_type (0 .), ldexp (c, to_int (k)));
915
+ #ifndef __FAST_MATH__
913
916
c = select (self >= reducer_t::maxlog (), constants::infinity<batch_type>(), c);
917
+ #endif
914
918
return c;
915
919
}
916
920
}
@@ -1014,11 +1018,11 @@ namespace xsimd
1014
1018
XSIMD_INLINE batch<T, A> expm1 (batch<T, A> const & self, requires_arch<common>) noexcept
1015
1019
{
1016
1020
using batch_type = batch<T, A>;
1017
- return select (self < constants::logeps<batch_type>(),
1018
- batch_type (- 1 .),
1019
- select (self > constants::maxlog<batch_type>(),
1020
- constants::infinity<batch_type>(),
1021
- detail::expm1 (self)) );
1021
+ auto x = detail::expm1 (self);
1022
+ # ifndef __FAST_MATH__
1023
+ x = select (self > constants::maxlog<batch_type>(), constants::infinity<batch_type>(), x);
1024
+ # endif
1025
+ return select (self < constants::logeps<batch_type>(), batch_type (- 1 .), x );
1022
1026
}
1023
1027
1024
1028
template <class A , class T >
@@ -1245,12 +1249,20 @@ namespace xsimd
1245
1249
batch_type r1 = other (q);
1246
1250
if (any (ltza))
1247
1251
{
1252
+ #ifdef __FAST_MATH__
1253
+ r = negative (q, r1);
1254
+ #else
1248
1255
r = select (inf_result, constants::infinity<batch_type>(), negative (q, r1));
1256
+ #endif
1249
1257
if (all (ltza))
1250
1258
return r;
1251
1259
}
1252
1260
batch_type r2 = select (ltza, r, r1);
1261
+ #ifdef __FAST_MATH__
1262
+ return r2;
1263
+ #else
1253
1264
return select (a == constants::minusinfinity<batch_type>(), constants::nan<batch_type>(), select (inf_result, constants::infinity<batch_type>(), r2));
1265
+ #endif
1254
1266
}
1255
1267
1256
1268
private:
@@ -1371,7 +1383,11 @@ namespace xsimd
1371
1383
}
1372
1384
batch_type r1 = other (a);
1373
1385
batch_type r2 = select (test, r, r1);
1386
+ #ifdef __FAST_MATH__
1387
+ return r2;
1388
+ #else
1374
1389
return select (a == constants::minusinfinity<batch_type>(), constants::nan<batch_type>(), select (inf_result, constants::infinity<batch_type>(), r2));
1390
+ #endif
1375
1391
}
1376
1392
1377
1393
private:
@@ -1479,12 +1495,12 @@ namespace xsimd
1479
1495
batch_type hfsq = batch_type (0.5 ) * f * f;
1480
1496
batch_type dk = to_float (k);
1481
1497
batch_type r = fma (dk, constants::log_2hi<batch_type>(), fma (s, (hfsq + R), dk * constants::log_2lo<batch_type>()) - hfsq + f);
1482
- #ifndef XSIMD_NO_INFINITIES
1483
- batch_type zz = select (isnez, select (self == constants::infinity<batch_type>(), constants::infinity<batch_type>(), r), constants::minusinfinity<batch_type>()) ;
1498
+ #ifdef __FAST_MATH__
1499
+ return r ;
1484
1500
#else
1485
- batch_type zz = select (isnez, r, constants::minusinfinity<batch_type>());
1486
- #endif
1501
+ batch_type zz = select (isnez, select (self == constants::infinity<batch_type>(), constants::infinity<batch_type>(), r), constants::minusinfinity<batch_type>());
1487
1502
return select (!(self >= batch_type (0 .)), constants::nan<batch_type>(), zz);
1503
+ #endif
1488
1504
}
1489
1505
1490
1506
template <class A >
@@ -1522,12 +1538,12 @@ namespace xsimd
1522
1538
batch_type t2 = z * detail::horner<batch_type, 0x3fe5555555555593ll , 0x3fd2492494229359ll , 0x3fc7466496cb03dell , 0x3fc2f112df3e5244ll >(w);
1523
1539
batch_type R = t2 + t1;
1524
1540
batch_type r = fma (dk, constants::log_2hi<batch_type>(), fma (s, (hfsq + R), dk * constants::log_2lo<batch_type>()) - hfsq + f);
1525
- #ifndef XSIMD_NO_INFINITIES
1526
- batch_type zz = select (isnez, select (self == constants::infinity<batch_type>(), constants::infinity<batch_type>(), r), constants::minusinfinity<batch_type>()) ;
1541
+ #ifdef __FAST_MATH__
1542
+ return r ;
1527
1543
#else
1528
- batch_type zz = select (isnez, r, constants::minusinfinity<batch_type>());
1529
- #endif
1544
+ batch_type zz = select (isnez, select (self == constants::infinity<batch_type>(), constants::infinity<batch_type>(), r), constants::minusinfinity<batch_type>());
1530
1545
return select (!(self >= batch_type (0 .)), constants::nan<batch_type>(), zz);
1546
+ #endif
1531
1547
}
1532
1548
1533
1549
template <class A , class T >
@@ -1569,12 +1585,12 @@ namespace xsimd
1569
1585
batch_type hfsq = batch_type (0.5 ) * f * f;
1570
1586
batch_type dk = to_float (k);
1571
1587
batch_type r = fma (fms (s, hfsq + R, hfsq) + f, constants::invlog_2<batch_type>(), dk);
1572
- #ifndef XSIMD_NO_INFINITIES
1573
- batch_type zz = select (isnez, select (self == constants::infinity<batch_type>(), constants::infinity<batch_type>(), r), constants::minusinfinity<batch_type>()) ;
1588
+ #ifdef __FAST_MATH__
1589
+ return r ;
1574
1590
#else
1575
- batch_type zz = select (isnez, r, constants::minusinfinity<batch_type>());
1576
- #endif
1591
+ batch_type zz = select (isnez, select (self == constants::infinity<batch_type>(), constants::infinity<batch_type>(), r), constants::minusinfinity<batch_type>());
1577
1592
return select (!(self >= batch_type (0 .)), constants::nan<batch_type>(), zz);
1593
+ #endif
1578
1594
}
1579
1595
1580
1596
template <class A >
@@ -1617,12 +1633,12 @@ namespace xsimd
1617
1633
val_lo += (dk - w1) + val_hi;
1618
1634
val_hi = w1;
1619
1635
batch_type r = val_lo + val_hi;
1620
- #ifndef XSIMD_NO_INFINITIES
1621
- batch_type zz = select (isnez, select (self == constants::infinity<batch_type>(), constants::infinity<batch_type>(), r), constants::minusinfinity<batch_type>()) ;
1636
+ #ifdef __FAST_MATH__
1637
+ return r ;
1622
1638
#else
1623
- batch_type zz = select (isnez, r, constants::minusinfinity<batch_type>());
1624
- #endif
1639
+ batch_type zz = select (isnez, select (self == constants::infinity<batch_type>(), constants::infinity<batch_type>(), r), constants::minusinfinity<batch_type>());
1625
1640
return select (!(self >= batch_type (0 .)), constants::nan<batch_type>(), zz);
1641
+ #endif
1626
1642
}
1627
1643
1628
1644
namespace detail
@@ -1757,12 +1773,12 @@ namespace xsimd
1757
1773
val_lo += (y - w1) + val_hi;
1758
1774
val_hi = w1;
1759
1775
batch_type r = val_lo + val_hi;
1760
- #ifndef XSIMD_NO_INFINITIES
1761
- batch_type zz = select (isnez, select (self == constants::infinity<batch_type>(), constants::infinity<batch_type>(), r), constants::minusinfinity<batch_type>()) ;
1776
+ #ifdef __FAST_MATH__
1777
+ return r ;
1762
1778
#else
1763
- batch_type zz = select (isnez, r, constants::minusinfinity<batch_type>());
1764
- #endif
1779
+ batch_type zz = select (isnez, select (self == constants::infinity<batch_type>(), constants::infinity<batch_type>(), r), constants::minusinfinity<batch_type>());
1765
1780
return select (!(self >= batch_type (0 .)), constants::nan<batch_type>(), zz);
1781
+ #endif
1766
1782
}
1767
1783
1768
1784
template <class A , class T >
@@ -1805,12 +1821,12 @@ namespace xsimd
1805
1821
/* correction term ~ log(1+x)-log(u), avoid underflow in c/u */
1806
1822
batch_type c = select (batch_bool_cast<float >(k >= i_type (2 )), batch_type (1 .) - (uf - self), self - (uf - batch_type (1 .))) / uf;
1807
1823
batch_type r = fma (dk, constants::log_2hi<batch_type>(), fma (s, (hfsq + R), dk * constants::log_2lo<batch_type>() + c) - hfsq + f);
1808
- #ifndef XSIMD_NO_INFINITIES
1809
- batch_type zz = select (isnez, select (self == constants::infinity<batch_type>(), constants::infinity<batch_type>(), r), constants::minusinfinity<batch_type>()) ;
1824
+ #ifdef __FAST_MATH__
1825
+ return r ;
1810
1826
#else
1811
- batch_type zz = select (isnez, r, constants::minusinfinity<batch_type>());
1812
- #endif
1827
+ batch_type zz = select (isnez, select (self == constants::infinity<batch_type>(), constants::infinity<batch_type>(), r), constants::minusinfinity<batch_type>());
1813
1828
return select (!(uf >= batch_type (0 .)), constants::nan<batch_type>(), zz);
1829
+ #endif
1814
1830
}
1815
1831
1816
1832
template <class A >
@@ -1838,12 +1854,12 @@ namespace xsimd
1838
1854
batch_type R = t2 + t1;
1839
1855
batch_type dk = to_float (k);
1840
1856
batch_type r = fma (dk, constants::log_2hi<batch_type>(), fma (s, hfsq + R, dk * constants::log_2lo<batch_type>() + c) - hfsq + f);
1841
- #ifndef XSIMD_NO_INFINITIES
1842
- batch_type zz = select (isnez, select (self == constants::infinity<batch_type>(), constants::infinity<batch_type>(), r), constants::minusinfinity<batch_type>()) ;
1857
+ #ifdef __FAST_MATH__
1858
+ return r ;
1843
1859
#else
1844
- batch_type zz = select (isnez, r, constants::minusinfinity<batch_type>());
1845
- #endif
1860
+ batch_type zz = select (isnez, select (self == constants::infinity<batch_type>(), constants::infinity<batch_type>(), r), constants::minusinfinity<batch_type>());
1846
1861
return select (!(uf >= batch_type (0 .)), constants::nan<batch_type>(), zz);
1862
+ #endif
1847
1863
}
1848
1864
1849
1865
template <class A , class T >
@@ -1980,13 +1996,21 @@ namespace xsimd
1980
1996
static XSIMD_INLINE batch_type next (const batch_type& b) noexcept
1981
1997
{
1982
1998
batch_type n = ::xsimd::bitwise_cast<T>(::xsimd::bitwise_cast<int_type>(b) + int_type (1 ));
1999
+ #ifdef __FAST_MATH__
2000
+ return n;
2001
+ #else
1983
2002
return select (b == constants::infinity<batch_type>(), b, n);
2003
+ #endif
1984
2004
}
1985
2005
1986
2006
static XSIMD_INLINE batch_type prev (const batch_type& b) noexcept
1987
2007
{
1988
2008
batch_type p = ::xsimd::bitwise_cast<T>(::xsimd::bitwise_cast<int_type>(b) - int_type (1 ));
2009
+ #ifdef __FAST_MATH__
2010
+ return p;
2011
+ #else
1989
2012
return select (b == constants::minusinfinity<batch_type>(), b, p);
2013
+ #endif
1990
2014
}
1991
2015
};
1992
2016
}
@@ -2355,10 +2379,12 @@ namespace xsimd
2355
2379
y *= v;
2356
2380
y = select (test, y, y * v);
2357
2381
y *= constants::sqrt_2pi<batch_type>() * w;
2358
- #ifndef XSIMD_NO_INFINITIES
2382
+ #ifdef __FAST_MATH__
2383
+ return y;
2384
+ #else
2359
2385
y = select (isinf (x), x, y);
2360
- #endif
2361
2386
return select (x > stirlinglargelim, constants::infinity<batch_type>(), y);
2387
+ #endif
2362
2388
}
2363
2389
2364
2390
/* origin: boost/simd/arch/common/detail/common/gamma_kernel.hpp */
@@ -2501,7 +2527,11 @@ namespace xsimd
2501
2527
}
2502
2528
batch_type r1 = detail::tgamma_other (self, test);
2503
2529
batch_type r2 = select (test, r, r1);
2530
+ #ifdef __FAST_MATH__
2531
+ return r2;
2532
+ #else
2504
2533
return select (self == batch_type (0 .), copysign (constants::infinity<batch_type>(), self), select (nan_result, constants::nan<batch_type>(), r2));
2534
+ #endif
2505
2535
}
2506
2536
2507
2537
}
0 commit comments