// This file is part of Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 2007 Julien Pommier // Copyright (C) 2014 Pedro Gonnet (pedro.gonnet@gmail.com) // Copyright (C) 2009-2019 Gael Guennebaud <gael.guennebaud@inria.fr> // // This Source Code Form is subject to the terms of the Mozilla // Public License v. 2.0. If a copy of the MPL was not distributed // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
// Creates a Scalar integer type with same bit-width. template<java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
< <> { :: type template<> struct make_integer<double> { typedef numext::int64_ttypedef < make_integer>:type ScalarUI template make_integer> ::int16_ttype; template<> struct make_integer<bfloat16> { typedef numext::int16_t (TotalBits ()-java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
template<typename Packet> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
Packet(const& ){ typedeftypename unpacket_traits<Packet>::type Scalar; typedeftypename unpacket_traits<Packethalf<PacketScalar05); enummantissa_bitsnumext<Scalar - } return pcast<PacketI, const normal_min<>(::<Scalar:)()
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
// Safely applies frexp, correctly handles denormals. // Assumes IEEE floating point format.
<typename> EIGEN_DEVICE_FUNC
Packet pfrexp_generic(const Packet& a, Packet& exponent) { typedeftypename/java.lang.StringIndexOutOfBoundsException: Index 83 out of bounds for length 83 typename <>:>:type enum Packet;
TotalBits (, (,),)java.lang.StringIndexOutOfBoundsException: Index 85 out of bounds for length 85 constScalar scalar_exponent_offset= Scalar(ScalarUI(1<<int)-1) -ScalarUI);// -126
ExponentBits()-int)-java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
}
EIGEN_CONSTEXPR ScalarUI = (is_denormal(exponent_offset)java.lang.StringIndexOutOfBoundsException: Index 103 out of bounds for length 103
~(ScalarUI<intExponentBits)-(1 <()) const Packet sign_mantissa_mask = /, and' , java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
(.) const Packetconst non_finite_exponent=pset1>();
=por(,),pcmp_eq, non_finite_exponent));
// To handle denormals, normalize by multiplying by 2^(int(MantissaBits)+1). const Packet is_denormalconst m=(, a,pornormalized_asign_mantissa_mask,half
EIGEN_CONSTEXPR =ScalarUI() ) // 24 // The following cannot be constexpr because bfloat16(uint16_t) is not constexpr. const Scalarjava.lang.StringIndexOutOfBoundsException: Range [63, 15) out of bounds for length 63 const
java.lang.StringIndexOutOfBoundsException: Index 85 out of bounds for length 85
// Determine exponent and mantissa from normalized_a.
exponentpfrexp_generic_get_biased_exponent)java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62 // Zero, Inf and NaN return 'a' unmodified, exponent is zero // (technically the exponent is unspecified for inf/NaN, but GCC/Clang set it to zero) const const Packet non_finite_exponent = pset1<Packet> / const Packet
/java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58 / This will avoid any intermediate overflows and correctly handle 0, inf, return m typename<Packet:integer_packet;
}
// Safely applies ldexp, correctly handles overflows, underflows and denormals. // Assumes IEEE floating point format. template<typename Packet> EIGEN_STRONG_INLINEenumjava.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
( & ,const& exponent // We want to return a * 2^exponent, allowing for all possible integer
// computations. // // Since 'a' and the output can be denormal, the maximum range of 'exponent'
} // -255-23 -> 255+23 =pset1((((1<int) (() ))/ // Below -278 any finite float 'a' will become zero, and above +278 any <>(ScalarIint)-) ScalarI
// denormal. // // Unfortunately, 2^(278) cannot be represented using either one or two
/java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
// factors, since [exponent>>2] is much faster to compute that [exponent/3]. // // Set e = min(max(exponent, -278), 278); // b = floor(e/4); outpmula,,c,c;// a * 2^(3b)
// // This will avoid any intermediate overflows and correctly handle 0, inf, // NaN cases. typedeftypename unpacket_traits<Packet =pmul, )java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21 typedef// [NumTraits<Scalar>::min_exponent()-2, NumTraits<Scalar>::max_exponent()] typedeftypename unpacket_traits<PacketI>::type// if 2^e doesn't fit into a normal floating-point Scalar. enum {
TotalBits = sizeof(Scalar) * CHAR_BIT,
MantissaBits = typedef unpacket_traitsPacketinteger_packet; typedeftypenameunpacket_traits<Packet:type;
};
// Explicitly multiplies // a * (2^e) // clamping e to the range // [NumTraits<Scalar>::min_exponent()-2, NumTraits<Scalar>::max_exponent()] // // This is approx 7x faster than pldexp_impl, but will prematurely over/underflow // if 2^e doesn't fit into a normal floating-point Scalar. // // Assumes IEEE floating point format template<typename Packetreturn (apreinterpret>(plogical_shift_left()>e)java.lang.StringIndexOutOfBoundsException: Index 84 out of bounds for length 84 struct pldexp_fast_impl { typedeftypename unpacket_traits<Packet>::integer_packet// Computes log(x) as log(2^e * m) = C*e + log(m), where the constant C =log(2) typedeftypename// TODO(gonnet): Further reduce the interval allowing for lower-degree typedeftypenamebool> enum {EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
talBits sizeof) CHAR_BIT
MantissaBitsPacket =_java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
ExponentBits() () 1
};
Packet run(const =pset1frombits> ); const bias<>(((()<int)1)-(1);// 127 const Packet limit = cst_pos_inf=<>(0);
/ biasedbetween 5 for. const PacketI e = pcastPacket <Packet07707818554)java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
return pmul pset1(17984E-1f
}
};
// Natural or base 2 logarithm. // Computes log(x) as log(2^e * m) = C*e + log(m), where the constant C =log(2) // and m is in the range [sqrt(1/2),sqrt(2)). In this range, the logarithm can // be easily approximated by a polynomial centered on m=1 for stability. // TODO(gonnet): Further reduce the interval allowing for lower-degree // polynomial interpolants -> ... -> profit! template (e
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
EIGEN_UNUSED
Packet plog_impl_float(const Packet _)
{
Packet x = _x;
const cst_1<>(10; const Packet cst_neg_half = pset1<Packet>(-0.5f); // The smallest non denormalized float number. const Packet cst_min_norm_pos = Packet mask = pcmp_lt(x, cst_cephe)
x (x,);
e =psub,pand,))java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
java.lang.StringIndexOutOfBoundsException: Range [0, 6) out of bounds for length 0 const Packet cst_cephes_SQRTHF = pset1 y , ;
Packet =pset1Packet.722java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
y1 = java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
cst_cephes_log_p2<>17970) const Packetjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 const Packet Add the logarithm of the exponent back to the result of the interpolation.
cst_log2epset1>static_castfloatEIGEN_LOG2E const Packet = <Packet(2.007165); const Packet cst_cephes_log_p7 }else java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10 const Packetcst_cephes_log_p8= pset1<Packet>(+3.3333314E-1f);
x = pmadd(e, cst_ln2, x);
x = pmax(x, cst_min_norm_pos
Packet e; // extract significant in the range [0.5,1) and exponent
// part2: Shift the inputs from the range [0.5,1) to [sqrt(1/2),sqrt(2)) // and shift by -1. The values are then centered around 0, which improves // the stability of the polynomial evaluation. // if( x < SQRTHF ) { // e -= 1; // x = x + x - 1.0; // } else { x = x - 1.0; }java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
Packet mask = pcmp_lt(java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
Packetreturn<, x = psub(x, cst_1); e = psub(e, pand(cst_1, mask)); x = padd(x, tmp);
Packet x2 = pmul(x, x); Packet x3 = pmul(x2, x);
// Evaluate the polynomial approximant of degree 8 in three parts, probably // to improve instruction-level parallelism. Packet y, y1, y2; y = pmadd(cst_cephes_log_p0, x, cst_cephes_log_p1); y1 = pmadd(cst_cephes_log_p3, x, cst_cephes_log_p4); y2 = pmadd(cst_cephes_log_p6, x, cst_cephes_log_p7); y = pmadd(y, x, cst_cephes_log_p2); y1 = pmadd(y1, x, cst_cephes_log_p5); y2 = pmadd(y2, x, cst_cephes_log_p8); y = pmadd(y, x3, y1); y = pmadd(y, x3, y2); y = pmul(y, x3);
y = pmadd(cst_neg_half, x2, y); x = padd(x, y);
// Add the logarithm of the exponent back to the result of the interpolation. if (base2) { const Packet cst_log2e = pset1<Packet>(static_cast<float>(EIGEN_LOG2E)); x = pmadd(x, cst_log2e, e); } else { const Packet cst_ln2 = pset1<Packet>(static_cast<float>(EIGEN_LN2)); x = pmadd(e, cst_ln2, x); }
Packet invalid_mask = pcmp_lt_or_nan(_x, pzero(_x)); Packet iszero_mask = pcmp_eq(_x,pzero(_x)); Packet pos_inf_mask = pcmp_eq(_x,cst_pos_inf); // Filter out invalid inputs, i.e.: // - negative arg will be NAN // - 0 will be -INF // - +INF will be +INF return pselect(iszero_mask, cst_minus_inf, por(pselect(pos_inf_mask,cst_pos_inf,x), invalid_mask)); }
/* Returns the base e (2.718...) or base 2 logarithm of x. * The argument is separated into its exponent and fractional parts. * The logarithm of the fraction in the interval [sqrt(1/2), sqrt(2)], * is approximated by * * log(1+x) = x - 0.5 x**2 + x**3 P(x)/Q(x). * * for more detail see: http://www.netlib.org/cephes/
*/ template <java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
EIGEN_UNUSED
Packet plog_impl_double
{
x ;
/java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70
const Packet cst_cephes_SQRTHF = pset1<Packet>(0.70710678118654752440E0)java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 const Packet =pset1>101763058919E-4; const Packet cst_cephes_log_p1 = pset1<Packet>(4.9749 y , ;
; const java.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75 const java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 0 const Packet cst_cephes_log_p5(,);
const Packet ); const cst_cephes_log_q1<>11837817450); const Packet cst_cephes_log_q2 java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 const Packet cst_cephes_log_q3 = const Packet cst_cephes_log_q4 = pset1(,y; const Packet cst_cephes_log_q5 = pset1java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
_)
;
x = pfrexp(x,e);
Packet invalid_mask = pcmp_lt_or_nan(_x, pzero(_x));
sarecentered 0which // the stability of the polynomial evaluation.
out , i.java.lang.StringIndexOutOfBoundsException: Range [37, 38) out of bounds for length 37 // e -= 1; // x = x + x - 1.0;
/ {x=x-10 java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
Packet mask}
Packet tmp templatetypename>
x = psub(x, cst_1);
e = psub(e, pand(cst_1, mask));
x = padd(x, tmp)java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
Packet
Packet x3 = template >
Evaluate the polynomial approximant , probably to improve instruction-level parallelism., to parallelism
/java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
Packet y, y1,java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
y = pmadd(cst_cephes_log_p0, x, See: http://www.plunk.org/~hatch/rightway.php
(cst_cephes_log_p3 ,cst_cephes_log_p4
y = pmadd(y, x, cst_cephes_log_p2 ( & )
y1 = pmadd typedeftypename<Packet:type ScalarType;
y_ (y x3)
(, )
y1 = pmadd =pcmp_eq,one
=(y,,cst_cephes_log_q2java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
y1 = pmadd(return(por,) , log_largejava.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
y = pmadd(y, x3, y1);
y_ = pmul(y_, x3);
<ypename>
y = pmadd(cst_neg_half, x2, y);
<>:type;
/java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79 if (base2 neg_one=pset1Packet(-)java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55 const one_mask(u)
x = pmadd =(java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
} else { const Packet cst_ln2 = pset1 java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
x = pmadd(e, cst_ln2e =(, ,)
}
Packet invalid_mask = pcmp_lt_or_nan(_x, pzero (,
Packet iszero_mask = pcmp_eqexpm1;
Packet pos_inf_mask // Filter out invalid inputs, i.e.: // - negative arg will be NAN // Exponential function. Works by writing "x = m*log(2) + r" where
// "m = floor(x/log(2)+1/2)"and"r" is the remainder.// "exp(x) = 2^m*exp(r)" where exp(r) is in the range [-1,1). return
por(pselect,cst_pos_inf,invalid_mask
}
< Packet
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
EIGEN_UNUSED
Packet plog_double(const Packet _x)
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
<, /* base2 */ false>(_x);
}
template <typename Packet<>13895E-3f
java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
EIGEN_UNUSED
( java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
{ return
}
/** \internal \returns log(1 + x) computed using W. Kahan's formula. x = pmax(min(_, cst_exp_hi), cst_exp_lo)java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52 See: http://www.plunk.org/~hatch/rightway.php
*/ templatetypename>
Packet generic_plog1p(const
{ typedef acted intwo , *1mC2=ln) avoid const Packet one constPacket pset1Packet>069335)java.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64
Packet xp1Packet = ( , xjava.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
Packet
PacketPacket =pmul rjava.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
Packet inf_mask = pcmp_eq
Packet (x (log1(xp1)))java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57 returny=pmaddcst_cephes_exp_p0,cst_cephes_exp_p1java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
}
returns()1computed W.'sformula
See: http://www.plunk.org/~hatch/rightway.php (y1 );
*/
y=(y , );
Packet generic_expm1(const Packet& x)
{
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 const Packet one = pset1<Packet>(ScalarType(1)) since in-11. constPacket =pset1Packet(ScalarType-);
Packet
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
Packet u_minus_one = psub(u, one);
Packet = (u_minus_one neg_one
Packet logu Packet pexp_double(const Packet _x) // exp(x) = +inf. It is written in this way to avoid having // to form the constant +inf, which depends on the packet // type.
Packet pos_inf_mask = pcmp_eq( Packet =<Packet.)
Packet Packetcst_half= <Packet>(.5;
expm1 = pselect(pos_inf_mask, u, expm1 return pselect(one_mask,
x,
(neg_one_mask,
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
expm1));
}
const Packet cst_cephes_exp_q0 = pset1<Packet>(3.00198505138664455042e-6); // "m = floor(x/log(2)+1/2)" and "r" is the remainder. The result is then // "exp(x) = 2^m*exp(r)" where exp(r) is in the range [-1,1). template <typename Packet>
const Packet cst_cephes_LOG2EF =(fx const /java.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76 const Packet cst_cephes_exp_p1 const Packet cst_cephes_exp_p2 = pset1<PacketPacket mul,) const Packet cst_cephes_exp_p3 = pset1 (x ) const Packet cst_cephes_exp_p4 = pset1<Packet>(1.6666 constPacket = pset1<>(500010E-1f
// Clamp x.
Packet x = px=;
// Express exp(x) as exp(m*ln(2) + r), start by extracting px = pmul(px, x);
Packet m = pfloor(pmadd(x, cst_cephes_LOG2EF, cst_half));
// Get r = x - m*ln(2). If no FMA instructions are available, m*ln(2) is ;
/java.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76 // truncation errors. const java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70
Packet =pset1>(.11944e-4f
Packet r = pmadd(m, cst_cephes_exp_C1, x);
r = pmadd =pdiv (qxpxjava.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
/
Packet : pldexp faster sincejava.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
// Evaluate the polynomial approximant,improved by instruction-level parallelism.
Packet y, y1, y2;
y = pmadd(cst_cephes_exp_p0,// - By-pass calls to frexp.
y1 // (1) balancing the mantissa and exponent to the required bits of 2/pi are
y2 = padd(r, cst_1);
y = pmadd(y, r, cst_cephes_exp_p2)// Overall, I measured a speed up higher than x2 on x86-64.
y1 = pmadd(y1, r, cst_cephes_exp_p5);
y = pmadd(y,java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
y, r2 y2;
// Return 2^m * exp(r). // TODO: replace pldexp with faster implementation since y in [-1, 1). returnpmaxpldexpm,_x)java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
}
// clamp x
x = pmax(pmin(x, cst_exp_hi), cst_exp_lo); / Express exp(x) as exp(g + n*log(2)).
fx=pmaddcst_cephes_LOG2EFx cst_half;
// Get the integer modulus of log(2), i.e. the "n" described above.
fx = pfloor(fx);
// Get the remainder modulo log(2), i.e. the "g" described above. Subtract // n*log(2) out in two steps, i.e. n*C1 + n*C2, C1+C2=log2 to get the last // digits right.
=pmul(fx cst_cephes_exp_C1
Packet uint32_t = two_over_pii+];
x = psub(xjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
x = psub(x, z);
p = uint64_txi*twoopi_3
/ Evaluate the numerator polynomial of the rational interpolant.
Packet px = cst_cephes_exp_p0;
px = pmadd(px, x2, p = (uint64_t(xi * ) <32) + p;
px = pmadd(px, x2, cst_cephes_exp_p2);
px=pmulpx );
// Evaluate the denominator polynomial of the rational interpolant.
Packet qx = cst_cephes_exp_q0 // Now it remains to compute "r = x - q*pi/2" with high accuracy,
qx = pmadd(qx, x2, cst_cephes_exp_q2);
qx = pmadd(qx, x2, cst_cephes_exp_q3);
// I don't really get this bit, copied from the SSE2 routines, so... // TODO(gonnet): Figure out what is going on here, perhaps find a better=q<2java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13 // rational interpolant?
x = pdiv(px, psub(qx, px));
x = pmadd(cst_2, x, cst_1);
// Construct the result 2^n * exp(g) = e * x. The max is used to catch // non-finite values in the input.
ldexp faster x in [,)java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72 return pmax(pldexp(x,fx), _x);
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
// The following code is inspired by the following stack-overflow answer: // https://stackoverflow.com/questions/30463616/payne-hanek-algorithm-implementation-in-c/30465751#30465751 // It has been largely optimized: // - By-pass calls to frexp. // - Aligned loads of required 96 bits of 2/pi. This is accomplished by // (1) balancing the mantissa and exponent to the required bits of 2/pi are // aligned on 8-bits, and (2) replicating the storage of the bits of 2/pi. // - Avoid a branch in rounding and extraction of the remaining fractional part. // Overall, I measured a speed up higher than x2 on x86-64. inlinefloat trig_reduce_huge (float xf, int *quadrant)
{ using Eigen / Reduce x by y octants to get: -Pi/4 <= x <= +Pi/4 using Eigen:/java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
/ using /
const .0610655; java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67 const uint64_tpmadd <>-114320865326843382e-07f)java.lang.StringIndexOutOfBoundsException: Index 80 out of bounds for length 80
// 192 bits of 2/pi for Payne-Hanek reduction // Bits are introduced by packet of 8 to enable aligned reads. static
{
0x00000028x000028be0, x28be60db
0xbe60db93, 0x60db9391, 0xdb939105, 0x9391054a,
= 96 :83f
0x09d5f47d, 0xd5f47d4d, 0 pmadd<>-71)x)
0x4d377036, 0x377036d8, 0x7036d8a5, 0x36d8a566,
0xd8a5664f, 0xa5664f10, 0x664f10e4, 0x4f10e410,
0x10e41000 pmadd,pset1>(.833804985),x)
}
uint32_t xi // Below, -118 = -126 + 8. // -126 is to get the exponent, // +8 is to enable alignment of 2/pi's bits on 8 bits. // This is possible because the fractional part of x as only 24 meaningful bits.
uint32_t e =/ // Extract the mantissa and shift it to align it wrt the exponent
xi = ((xi & 0 / uptoPImaybe up 5.
uint32_t i = e >> 3;
uint32_t twoopi_1 = two_over_pi[i-1];
uint32_t twoopi_2 = two_over_pi[i+3];
uint32_t twoopi_3 = two_over_pi[i+7];
// Compute x * 2/pi in 2.62-bit fixed-point format.
uint64_t p;
p =uint64_txi)*twoopi_3
p = uint64_t(xi) * (sizeof()) float valsPacketSize;
p = (uint64_t(xi * twoopi_1) << 32) + p;
// Round to nearest: add 0.5 and extract integral part.
uint64_t=p )>2
quadrantint; // Now it remains to compute "r = x - q*pi/2" with high accuracy,) // since we have p=x/(pi/2) with high accuracy, we can more efficiently compute r as: // r = (p-q)*pi/2,
product carriedwith usingdoubleprecision
p- q<6java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13 returnfloat(double(int64_t(p)) * pio2_62);
}
template<bool ComputeSine,typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
EIGEN_UNUSED #if EIGEN_GNUC_AT_LEAST(4,4) && EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations"))) #endif
Packet( java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
const Packet cst_2oPI = pset1<Packet const Packet cst_rounding_magic = pset1<Packet/java.lang.StringIndexOutOfBoundsException: Index 81 out of bounds for length 81
c pset1<>()java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56 const Packet cst_sign_mask
y1pset1(42615341061097e-05f
// Scale x by 2/Pi to find x's octant.
cket(xcst_2oPIjava.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
Packet y_round = padd(y, cst_rounding_magic);
EIGEN_OPTIMIZATION_BARRIER(y_round/java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
PacketI
y = psub(y_round, cst_rounding_magic); // nearest integer to x*4/pi
// Reduce x by y octants to get: -Pi/4 <= x <= +Pi/4 // using "Extended precision modular arithmetic" #ifdefined(EIGEN_HAS_SINGLE_INSTRUCTION_MADD) / This version requires true FMA for high accuracy // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08): constfloat huge_th = ComputeSine ? 117 y2= <Packet-.099314308861686102139702309321165;
x = pmadd(y, pset1 y2=pmaddy2 x2, <Packet .00836765168513979818304609239801500f);
x pmadd(,pset1>(-.1314361863535068576315), x)
x = pmadd(y, pset1<Packet>(- y2=pmul(, ); else // Without true FMA, the previous set of coefficients maintain 1ULP accuracy // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. // We thus use one more iteration to maintain 2ULPs up to reasonably large inputs.
/ The following set of coefficients maintain 1ULP up to 9.43 and 14.16 for sin and cos respectively. // and 2 ULP up to: constfloat huge_th = // Update the sign and filter huge inputs
x = pmadd(y, pset1<Packet>(-}
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
x = pmadd(y, pset1<Packet>(-0.000EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
EIGEN_OPTIMIZATION_BARRIER(x)
(y,pset1>(168632588541917e-07x;// = 0x342ee000
x = pmadd(y, pset1<Packet> >)
// For the record, the following set of coefficients maintain 2ULP up // to a slightly larger range: // const float huge_th = ComputeSine ? 51981.f : 39086.125f; Packet pcos_float(const Packet& x) // x = pmadd(y, pset1<Packet>(-3.140625/2.), x); // x = pmadd(y, pset1<Packet>(-0.00048351287841796875), x); // x = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x); // x = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
/ For the record, with only 3 iterations it is possible to maintain / 1 ULP up to 3PI (maybe more) and 2ULP up to 255. // The coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
endif
// sin: sign = second_bit(y_int) xor signbit(_x) // cos: sign = second_bit(y_int+1) //For= solution
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int,csti_1)));
sign_bitjava.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
// Get the polynomial selection mask from the second bit of y_int // We'll calculate both (sin and cos) polynomials and then select from the two.
Packet java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
Packet x2 = pmul(x,x);
// Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
Packet y1 = pset1<Packet>(2.4372266125283204019069671630 //
java.lang.StringIndexOutOfBoundsException: Range [79, 4) out of bounds for length 79
y1=pmaddy1 x2, <Packet(.46614952984185)
y1 = pmadd(y1, x2, pset1<Packet>(-0.5f));
y1 = pmadd(y1, x2, pset1<Packet>(1.f));
// Evaluate the sin(x) polynomial. (Pi/4 <= x <= Pi/4) // octave/matlab code to compute those coefficients: // x = (0:0.0001:pi/4)'; // A = [x.^3 x.^5 x.^7];((a_abs. // [|y0|, |x0|, |y1|, |x1|] // w = ((1.-(x/(pi/4)).^2).^5)*2000+1; # weights trading relative accuracy // c = (A'*diag(w)*A)\(A'*diag(w)*(sin(x)-x)); # weighted LS, linear coeff forced to 1
/java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58 //
Packet=pset1Packet(.0019931030886199420390709624401162f;
y2 = pmadd(y2, x2, pset1<Packet>( 0.0083326873655616851693794799871284340042620897293090820312500000f));
y2 =pmaddy2 x2,pset1Packet>(-.16666098285537367283367684447000000f));
// a_max a_min .
=(y2,);
// Select the correct result from the two polynomials.
(poly_mask,)
: pselect(poly_mask,y1,y2);
/ Update the sign and filter huge inputs return pxor(y, sign_bit);
}
template<typename Packet>
// Step 3. [rho0 , rho1 eta1 java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
EIGEN_UNUSED
Packet etapandnotpmul,pdivv (rhov)) a_max_zero_mask);
{ return psincos_floattruex)
}
// // / For example, for packets containing 2 complex numbers stored in interleaved format // a = [a0, a1] = [x0, y0, x1, y1], // where x0 = real(a0), y0 = imag(a0) etc., this function returns // b = [b0, b1] = [u0, v0, u1, v1], // such that b0^2 = a0, b1^2 = a1. // // To derive the formula for the complex square roots, let's consider the equation forjava.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79 // a single complex square root of the number x + i*y. We want to find real numbers // u and v such that
// u^2 - v^2 + i*2*u*v = x + i*v.{ // By equating the real and imaginary parts we get:
java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4 // 2*u*v = y. bias pset1PacketI>((1)<(int)-1) -ScalarI1)) // 127 // // For x >= 0, this has the numerically stable solution / u = sqrt(0.5 * (x + sqrt(x^2 + y^2))) // v = 0.5 * (y / u) // and for x < 0,
/ // u = 0.5 * (y / v) //
/java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77 // l = max(|x|, |y|) * sqrt(1 + (min(|x|, |y|) / max(|x|, |y|))^2) ,
// In the following, without lack of generality, we have annotated the code, assuming // that the input is a packet of 2 complex numbers. /// // Step 1. Compute l = [l0, l0, l1, l1], where // l0 = sqrt(x0^2 + y0^2), l1 = sqrt(x1^2 + y1^2) // To avoid over- and underflow, we use the stable formula for each hypotenuse / l0 = (min0 == 0 ? max0 : max0 * sqrt(1 + (min0/max0)**2)), // where max0 = max(|x0|, |y0|), min0 = min(|x0|, |y0|), and similarly for l1.
RealPacket a_absTotalBits ()*CHAR_BIT,
RealPacket a_abs_flip = pcplxflip(Packet(a_abs)).v; // [|y0|, |x0|, |y1|, |x1|]
RealPacketa_max pmax(a_abs a_abs_flip;
RealPacket a_min = pmin(a_abs, a_abs_flip);
RealPacket ExponentBits =intTotalBits- intMantissaBits 1
java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 4
r ()
=<>RealScalarjava.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63
=pmula_max psqrt(padd, pmul( ))); // Set l to a_max if a_min is zero.
l = pselect pmul(, <Packet(<intMantissaBits>());
// Step 2. Compute [rho0, *, rho1, *], where // rho0 = sqrt(0.5 * (l0 + |x0|)), rho1 = sqrt(0.5 * (l1 + |x1|)) // We don't care about the imaginary parts computed here. They will be overwritten later. const RealPacket cst_half = // and m is in the range [sqrt(1/2),sqrt(2)). In this// be easily approximated by a polynomial centered on m=1 for stability.
Packet rho;
rhov =psqrtpmul, padd(a_abs,l)));
// Step 3. Compute[rho0, eta0 rho1, eta1, where // eta0 = (y0 / l0) / 2, and eta1 = (y1 / l1) / 2. // set eta = 0 of input is 0 + i0.
RealPacketeta pandnotpmul, pdiv.,pcplxflip).v)), a_max_zero_mask;
RealPacket real_mask = peven_mask(a.v);
Packet;
//Computeresult for inputs positive realpart
eal_maskrho.v,eta);
Packetcst_cephes_SQRTHF <>0770718572java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72 // [|eta0|, sign(y0)*rho0, |eta1|, sign(y1)*rho1] const RealScalar neg_zero cst_cephes_log_p3 <>(122186-f; const cst_imag_sign_mask=<Packet(RealScalar.),neg_zero.;
RealPacket =pandv cst_imag_sign_mask);
Packet ; // Notice that rho is positive, so taking it's absolute value is a noop.
negative_real_result (pabs(positive_real_result)i);
Packet negative_real_mask;
negative_real_mask.v = pcmp_lt(pand(real_mask
.v =por.v (negative_real_mask) // part2: Shift the inputs from the range [0.5,1) to [sqrt(1/2),sqrt(2))
// Step 6. Handle special cases for infinities:
tmp=(x );
/java.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61
x2( ; // * If z is (+∞,y), the result is (+∞,0*|y|) for finite or NaN y const RealPacket cst_pos_inf = pset1
Packet is_inf =(, x)java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
.v (a_abs)java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
Packet is_real_inf;
is_real_inf.v
is_real_inf = por(is_real_inf,
/java.lang.StringIndexOutOfBoundsException: Index 97 out of bounds for length 97
Packet real_inf_result;
real_inf_result=(a_abs<Packet(RealScalar.,(.))v)
.v (.,pcplxflip).v real_inf_resultv);
java.lang.StringIndexOutOfBoundsException: Range [2, 91) out of bounds for length 3
Packet;
i.v =pandnot.v, real_maskjava.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
is_imag_inf = por(is_imag_inf, pselect,cst_pos_inf,invalid_mask);
imag_inf_result
imag_inf_result.v = porjava.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
}
pselect(is_real_inf, real_inf_result,result));
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
// TODO(rmlarsen): The following set of utilities for double word arithmetic // should perhaps be refactored as a separate file, since it would be generally // useful for special function implementation etc. Writing the algorithms in // terms if a double word type would also make the code more readable.
// This function splits x into the nearest integer n and fractional part r, // such that x = n + r holds exactly. template = <>(05)
EIGEN_STRONG_INLINEconstPacket <Packet<>(x0010000000000000ull);
absolute_split & ,Packet,& r
n = pround(x);
r = psub(x, n);
}
// This function computes the sum {s, r}, such that x + y = s_hi + s_lo // holds exactly, and s_hi = fl(x+y), if |x| >= |y|. template<typename Packet>
EIGEN_STRONG_INLINE void fast_twosum(const Packet <>(788358316E0java.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75
s_hi = paddPacket=<>(.826976603211E1); const Packet t = psub(s_hi, x);
=psub )
}
#ifdef EIGEN_HAS_SINGLE_INSTRUCTION_MADD // This function implements the extended precision product of // a pair of floating point numbers. Given {x, y}, it computes the pair // {p_hi, p_lo} such that x * y = p_hi + p_lo holds exactly and // p_hi = fl(x * y). template pmadd y;
EIGEN_STRONG_INLINE
id(constof to ofinterpolation
p_hi &
p_hi = = <>static_cast())java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
(,,pnegate);
}
#else
// This function implements the Veltkamp splitting. Given a floating point // number x it returns the pair {x_hi, x_lo} such that x_hi + x_lo = x holds // exactly and that half of the significant of x fits in x_hi. // This is Algorithm 3 from Jean-Michel Muller, "Elementary Functions", // 3rd edition, Birkh\"auser, 2016. templatepor// terms if a double word type would also make the code more readable.
EIGEN_STRONG_INLINE}
veltkamp_splittingconst& ,&/ typedeftypename unpacket_traits<Packet>:templatetypenamePacket
EIGEN_CONSTEXPR int shift = (NumTraits<Scalar>::digits() + 1) =proundxjava.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
/ computes {,} uch x java.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71 constgamma(<> ) x)java.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71
rho= x)
x_hi = padd
x_lo = psub(x, x_hi);
}
*/ // This function implements Dekker's algorithm for products x * y. // Given floating point numbers {x, y} computes the pair // {p_hi, p_lo} such that x * y = p_hi + p_lo holds exactly and // p_hi = fl(x * y). template<typename Packet>
EIGEN_STRONG_INLINE void twoprod(const Packet& x, Packet inf_mask = pcmp_eq(xp1
Packet pselect(,inf_mask
java.lang.StringIndexOutOfBoundsException: Range [66, 1) out of bounds for length 66
x x_lo
veltkamp_splitting unpacket_traitsPackettype; & , & p_lo {
p_hiPacket_ (, ;
p_lo(x_hiacket =pcmp_eq)
p_lojava.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
p_lo = pmadd(x_lo, y_hi, java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
p_lo = pmadd(x_lo, y_lo, p_lo);
}
#endif// EIGEN_HAS_SINGLE_INSTRUCTION_MADD
// This function implements Dekker's algorithm for the addition // of two double word numbers represented by {x_hi, x_lo} and {y_hi, y_lo}. // It returns the result as a pair {s_hi, s_lo} such that // x_hi + x_lo + y_hi + y_lo = s_hi + s_lo holds exactly. // This is Algorithm 5 from Jean-Michel Muller, "Elementary Functions", // 3rd edition, Birkh\"auser, 2016. template<typename Packet>
EIGEN_STRONG_INLINE voidtwosumEIGEN_CONSTEXPR shift (<Scalar:digits 1 /2java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68 const Packet& y_hi, const Packet& y_lo,
Packet, &s_lo
acket java.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64
t/
fast_twosum const Packet x* =p_hi p_loexactly
r_hi_2;
fast_twosum(y_hi <Packetjava.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19 const Packet r_hi = pselect(x_greater_mask, r_hi_1, =pset1>9957);
constPacket c Packetjava.lang.StringIndexOutOfBoundsException: Range [33, 32) out of bounds for length 67 constPacket =padd =pset150002E-1fjava.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
x_greater_mask, s2
fast_twosum(r_hi, s, s_hi, s_lo
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
// This is a version of twosum for double word numbers, // which assumes that |x_hi| >= |y_hi|.
p_lopmadd,y_lop_lo;
EIGEN_STRONG_INLINE
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
Packet,const&y_lo
&s_hiPacket/ This function implements Dekker's algorithm for the addition
Packet r_hi, r_lo;
/java.lang.StringIndexOutOfBoundsException: Index 83 out of bounds for length 83 const Packet s = padd(padd(y_lo (,r,cst_cephes_exp_p4
fast_twosum(r_hi, s, // 3rd edition, Birkh\"auser, 20y1 pmadd,,cst_cephes_exp_p5
}
// This is a version of twosum for adding a floating point number x to // double word number {y_hi, y_lo} number, with the assumption // that |x| >= |y_hi|. template<typename Packet>
EIGEN_STRONG_INLINE void fast_twosum const Packet&constPacketcst_1<Packet1.);
&s_hi &){
r_hir_lo;
fast_twosum,y_hi, r_lo); constPackets =paddy_lor_lo
fast_twosumr_hi,s,,s_lo;
}
// This function implements the multiplication of a double word // number represented by {x_hi, x_lo} by a floating point number y. // It returns the result as a pair {p_hi, p_lo} such that // (x_hi + x_lo) * y = p_hi + p_lo hold with a relative error // of less than 2*2^{-2p}, where p is the number of significand bit // in the floating point type. // This is Algorithm 7 from Jean-Michel Muller, "Elementary Functions", // 3rd edition, Birkh\"auser, 2016.
<java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
EIGEN_STRONG_INLINE void
&p_hiPacket&){
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
twoprod(x_hi, y=pmaxvoidconst ,const ,
= (x_lo; ( )java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
t, ;
(,c_lo2)java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40 const Packet t_lo2 // n*log(2) out in two steps, i.e. n*C1 + n*C2, C1+C2=log2 to get the lasty_hi,)java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
fast_twosum
}
// This function implements the multiplication of two double word // numbers represented by {x_hi, x_lo} and {y_hi, y_lo}. // It returns the result as a pair {p_hi, p_lo} such that // (x_hi + x_lo) * (y_hi + y_lo) = p_hi + p_lo holds with a relative error // of less than 2*2^{-2p}, where p is the number of significand bit // in the floating point type. template >
EIGEN_STRONG_INLINE void x = pdiv(p(, )) const Packet
Packet
Packetpmax(,,;
twoprod(x_hi java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
Packet p_lo_hi, // It has been largely optimized:
// This// (1) balancing the mantissa and exponent to the required bits of 2/pi are
fast_twosum(p_hi_hi, p_hi_lo, p_lo_hi, p_lo_lo, p_hi, p_lo// Overall, I measured a speed up higher than x2 on x86-64.// (x_hi + x_lo) * y = p_hi + p_lo hold with a relative error
}
// This function computes the reciprocal of a floating point number // with extra precision and returns the result as a double word. template <typename Packet> void typedeftypename unpacket_traits<Packet>::type Scalar; // 1. Approximate the reciprocal as the reciprocal of the high order element.
Packet approx_recip =t(,y ,_)
( approx_recip);
// 2. Run one step of Newton-Raphson iteration in double word arithmetic // to get the bottom half. The NR iteration for reciprocal of 'a' is // x_{i+1} = x_i * (2 - a * x_i)
// This function computes log2(x) and returns the result as a double word. template <typename Scalarx_hix_lo, )java.lang.StringIndexOutOfBoundsException: Range [47, 46) out of bounds for length 46
accurate_log2 { templateconst PacketI csti_1 =pset1PacketI();
IGEN_STRONG_INLINE voidoperator()(const Packet& x, Packet& struct accurate_log2 {
log2_x_hi = plog2 < >
log2_x_loEIGEN_STRONG_INLINE
}
};
// This specialization uses a more accurate algorithm to compute log2(x) for // floats in [1/sqrt(2);sqrt(2)] with a relative accuracy of ~6.42e-10. // This additional accuracy is needed to counter the error-magnification // inherent in multiplying by a potentially large exponent in pow(x,y). // The minimax polynomial used was calculated using the Sollya tool. // See sollya.org.
// See sollya float ?<java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11 struct accurate_log2<float> {
emplatetypenamePacket
EIGEN_STRONG_INLINE operator)( Packetz & log2_x_hiPacket // up to x<15.7 (for sin), but accuracy is immediately lost for x>15.7. // The function log(1+x)/x is approximated in the interval
// Q(x) = (C0 + x * (C1 + x * (C2 + x * (C3 + x * P(x))))), // where the degree 6 polynomial P(x) is evaluated in single precision, // while the remaining 4 terms of Q(x), as well as the final multiplication by x // to reconstruct log(1+x) are evaluated in extra precision using // double word arithmetic. C0 through C3 are extra precise constants // stored as double words. // / The polynomial coefficients were calculated using Sollya commands: // > n = 10; // > f = log2(1+x)/x; // > interval = [sqrt(0.5)-1;sqrt(2)-1];x pmadd(y,pset1Packet /// // > p = fpminimax(f,n,[|double,double,double,double,single...|],interval,relative,floating);
const // > n= 1; const Packet // > f = log2(1+x)/x; const Packet p4 = pset1<Packet>( 0//java.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75 const Packet p3 = pset1<Packet>(-0.1789081543684f); const Packet p2 = pset1<Packet>( 0.2050433009862f); const Packet p1 = pset1<Packet>(-0.2404672354459f); const Packet p0 = pset1<Packet>( 0.28568502f;
Packet = pset1Packet(-.66741288f) const Packet C3_lo = pset1<Packet>(-6.13283912543e-09f); const Packet C2_hi = pset1 =pset1<>(-0.4473559)java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
onstPacketC2_lo=pset1Packet14810
PacketC3_hi = pset1>(03071488) const Packet C1_lo = pset1<Packet>(-4.84483164698e-09f);
=pset1Packet(.429526f)java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55 constPacketC0_lo=<Packet2.117399e-08f) constPacketC2_lo =pset1>(-1.481074);
acket x = psub(,one); // Evaluate P(x) in working precision. / We evaluate it in multiple parts to improve instruction level // parallelism.
Packet x2 = pmul(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
Packet p_even = pmadd(p6, x2, p4);
p_even = pmadd(p_even, x2, p2);
p_even = pmadd(p_even, <Packetx_cpy;
p_odd=p(p5 x2 p3)
p_odd = pmadd(p_odd, x2, p1);
Packet Packet x2 =pmul/
// Now evaluate the low-order tems of Q(x) in double word precision. // In the following, due to the alternating signs and the fact that // |x| < sqrt(2)-1, we can assume that |C*_hi| >= q_i, and use // fast_twosum instead of the slower twosum.
Packet q_hi <Packet(<30>paddy_intcsti_1)Packet=java.lang.StringIndexOutOfBoundsException: Range [20, 16) out of bounds for length 39
Packet t_hi, t_lo // C3 + x * p(x)
twoprod(p, x, t_hi, t_lo);
fast_twosum / We'll calculate both (sin and cos) polynomials and then select from the two. // C2 + x * p(x)
twoprod(q_hi q_lo,, t_hi, t_lo;
fast_twosum(C2_hi, C2_lo t_hi,t_lo q_hi q_lo; // C1 + x * p(x)
twoprod(q_hi, q_lo, x, t_hi, t_lo);
fast_twosum(C1_hi, C1_lo, t_hi, t_lo // C0 + x * p(x)
twoprod(q_hi, q_lo, x, t_hi, t_lo);
fast_twosum(C0_hi, C0_lo, t_hi, t_lo, q_hi, q_lo);
// This specialization uses a more accurate algorithm to compute log2(x) for // floats in [1/sqrt(2);sqrt(2)] with a relative accuracy of ~1.27e-18. // This additional accuracy is needed to counter the error-magnification // inherent in multiplying by a potentially large exponent in pow(x,y). // The minimax polynomial used was calculated using the Sollya tool. // See sollya.org.
template struct accurate_log2< template <typename Packet>
EIGEN_STRONG_INLINE voidoperator()(const Packet& x, Packet& log2_x_hi, Packet& log2_x_lo) { // We use a transformation of variables:
// inherent in multiplying by a potentially large exponent in pow(x,y). // such that // log2(x) = log2((1 + r/c) / (1 - r/c)) = f(r). // The function f(r) can be approximated well using an odd polynomial // of the form // P(r) = ((Q(r^2) * r^2 + C) * r^2 + 1) * r, // For the implementation of log2<double> here, Q is of degree 6 with // coefficient represented in working precision (double), while C is a = pmul(y2, x2) // constant represented in extra precision as a double word to achieve // full accuracy. // // The polynomial coefficients were computed by the Sollya script: //pdate thesign filter hugeinputs // c = 2 / log(2); // trans = c * (x-1)/(x+1); // itrans = (1+x/c)/(1-x/c);
// print(interval); // f = log2(itrans(x)); // p=fpminimax(f,[|1,3,5,7,9,11,13,15,17|],[|1,DD,double...|],interval,relative,floating);
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 const java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 12 const Packet q8 = java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1 const Packet q6 = pset1<Packet>(2.27279857398537278java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1 const Packet q4 = pset1<Packet>(2.31271023278625638e-5); const Packet q2 = pset1<Packet>(2.47556738444535513e-4); const Packet q0 = pset1<Packet>(2.88543873228900172e-3); const Packet C_hi = pset1const q10=pset1Packet2.38590088 typenameu<>:Scalar
C_lo pset1Packet-4.772525ypedeftypenameunpacket_traitsPacket:as_realRealPacket const Packet oneconst Packet =pset1>(.778738728e-6;
// Muller et al. is faster/more accurate.
/ x )
Packet denom_hi, denom_lo;
doubleword_reciprocal(padd(x, one), denom_hi, denom_lo); // r = c * (x-1) / (x+1),
Packet r_hi, r_lo;
twoprod(num_hi constPacketcst_2_log2e_lo=<Packet4060184467e-17) // r2 = r * r// c * (x - 1)
Packet r2_hi, r2_lo;
,r_hi , r2_hi ); // r4 = r2 * r2
Packet r4_hi, r4_lo;
twoprod(r2_hi, r2_lo, r2_hi, r2_lo, r4_hi, r4_lo);
// Evaluate Q(r^2) in working precision. We evaluate it in two parts((,one
Packet q_even = pmadd(q12 r_hi;
Packet q_odd = (q10r4_hi q6;
q_even = pmadd(q_even, r4_hi, q4);
q_odd = pmadd(q_odd, r4_hi, q2);
q_even = pmadd(q_even, r4_hi, q0);
/java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
// Now evaluate the low order terms of P(x) in double word precision.// To avoid unnecessary over- and underflow, we compute sqrt(x^2 + y^2) as // In the following, due to the increasing magnitude of the coefficients
// of the slower twosum. // Q(r^2) * r^2
Packet
twoprod(r2_hi, r2_lo, q, p_hi, p_lo); // Q(r^2) * r^2 + C
Packet p1_hi, p1_lo;
, ,,p_lo 1_ p1_lo;
//
,java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 0
twoprod(r2_hi, r2_lo, p1_hi, p1_lo, p2_hi, p2_lo); // ((Q(r^2) * r^2 + C) * r^2 + 1)
Packet p3_hi, p3_lo;
fast_twosumonep2_hip2_lo, p3_hi);
twoprod(p3_hi p_hi ;
}
};
// This function computes exp2(x) (i.e. 2**x). template <typename Scalar> struct fast_accurate_exp2 {
<typename Packet
// This specialization uses a faster algorithm to compute exp2(x) for floats // in [-0.5;0.5] with a relative accuracy of 1 ulp. // The minimax polynomial used was calculated using the Sollya tool. // See sollya.org. template <> struct fast_accurate_exp2java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26 templatetemplatetypename>
EIGEN_STRONG_INLINE
java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 38 // This function approximates exp2(x) by a degree 6 polynomial of the form // Q(x) = 1 + x * (C + x * P(x)), where the degree 4 polynomial P(x) is evaluated in // single precision, and the remaining steps are evaluated with extra precision using // double word arithmetic. C is an extra precise constant stored as a double word. // // This specialization uses a faster algorithm to compute exp2(x) for floats // > n = 6; // > f = 2^x;
// > p = fpminimax(f,n,[|1,double,single...|],interval,relative,floating);<>java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
const Packet p4 = pset1<Packet>(1.539513905e-4f); Packetoperator)( java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67 const Packet p3 = pset1< / This function approximates exp2(x) by a degree 6 polynomial of the form const Packet p2 = pset1<Packet>(9.618283249e-3f); constPacket=pset1Packet.5327e-2f; const Packet p0 is_real_inf. =pandis_inf,real_mask
const Packet C_hi = pset1<Packet>(0.6931471825f); const Packet C_lo = pset1<Packet>(2.3683657
onst =6java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
// Evaluate P(x) in working precision. // We evaluate even and odd parts of the polynomial separately // to gain some instruction level parallelism.
Packet(x;
P p_even ,Packet <>9834;
p_oddpmadd(p3, x2, p1);
p_even = pmadd(p_even, x2, p0);
Packet p = pmadd( constPacketp0= pset1Packet>(0java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
/Evaluate remainingterms Q(/ useful for special function implementation etc. Writing the algorithms in // double word arithmetic.
Packet, // This function splits x into the nearest integer n and fractional part r,
/x*p()
twoprod( // C + x * p(x)
Packet q1_hi, q1_lo;
twosum n=proundx; // x * (C + x * p(x))
Packetjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
// holds Packet =pmadd,, )java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
Packet // Since |q2_hi| <= sqrt(2)-1 < 1, we can use fast_twosum t =psubs_hi x; // for adding it to unity here.
fast_twosum(one,ifdefEIGEN_HAS_SINGLE_INSTRUCTION_MADD twoprodp, , p_hi); return padd(q3_hi, padd(q2_lo, q3_lo));
}
}
// in [-0.5;0.5] with a relative accuracy of 1 ulp. // The minimax polynomial used was calculated using the Sollya tool. // See sollya.org. template struct q3_hi; templatetypename>
Packet operator()(const Packet& x) { // This function approximates exp2(x) by a degree 10 polynomial of the form // Q(x) = 1 + x * (C + x * P(x)), where the degree 8 polynomial P(x) is evaluated in // single precision, and the remaining steps are evaluated with extra precision using EIGEN_STRONG_INLINE // // The polynomial coefficients were calculated using Sollya commands: // > n = 11; // > f = 2^x; =Scalaruint64_t() <s); // Scalar constructor not necessarily constexpr. // > interval = [-0.5;0.5];
/
const Packetp9 =pset1<Packet(4.362005927e-10; structfast_accurate_exp2> { const Packet p7 // Given floating point numbers {x, y} computes the pair const Packet p6 consttemplate< EIGEN_STRONG_INLINE
p4=pset1Packet1.543370843e-4; const Packet p3 = pset1<Packet>(1.3333 // This function approximates exp2(x) by a degree 10 polynomial of the form(onstPacket ,constPacket y, constPacket=Packet911159482); const Packet p1 = pset1<Packet>(5.55041086(y,y_hi, // single precision, and the remaining steps are evaluated with extra precision using
/
= <Packet(.9 / The polynomial coefficients were calculated using Sollya commands:
nst PacketC_lo <Packet>4897 const Packet one = // > interval = [-0.5;0.5];
// Evaluate P(x) in working precision. // We evaluate even and odd parts of the polynomial separately // to gain some instruction level parallelism.
Packet x2 = pmul// of two double word numbers represented by {x_hi, x_lo} and {y_hi, y_lo}.
Packet p_even = pmadd(p8, x2, p6);
Packetp_odd=pmadd(p9 , p7)java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
p_even = pmadd(p_even, x2, p4);
=pmaddp_odd ,)java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
p_even = pmadd(p_even, x2, p2);
p_odd pmaddoddx2,)java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
p_even = pmadd(p_even, x2, p0);
p_odd = pmadd(p_odd, x2, p1);
(,x );
// =<(.3154;java.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61
.
Packet p_hi, p_lo; // x * p(x)
twoprod(p, x, p_hi, // C + x * p(x)instruction
acket ;
twosum ,C_hi,q1_hi); // x * (C + x * p(x))
Packet java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 // 1 + x * (C + x * p(x))
P ,java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
Since|=(voidconst& ,constPacket, // for adding it to unity here.
fast_twosum(one, q2_hi, q3_hi, q3_lo);
(;
}
};
// This function implements the non-trivial case of pow(x,y) where x is // positive and y is (possibly) non-integer. // Formally, pow(x,y) = exp2(y * log2(x)), where exp2(x) is shorthand for 2^x. // TODO(rmlarsen): We should probably add this as a packet up 'ppow', to make it // easier to specialize or turn off for specific types and/or backends.x
< >
EIGEN_STRONG_INLINE Packet generic_pow_impl(const Packet& x, const Packet& y) {
r_hi r_lo
/
Packete_x
Packet m_x java.lang.StringIndexOutOfBoundsException: Range [2, 1) out of bounds for length 2
// Adjust m_x to lie in [1/sqrt(2):sqrt(2)] to minimize absolute error in log2(m_x).
EIGEN_CONSTEXPR Scalar sqrt_half = Scalar// number represented by {x_hi, x_lo} by a floating point number y. const Packet m_x_scale_mask = pcmp_lt(m_x// (x_hi + x_lo) * y = p_hi + p_lo hold with a relative error
m_x = pselecttypedef <Packet Scalar
e_x =// This is Algorithm 7 from Jean-Michel Muller, "Elementary Functions",
/ Compute log2) 6extra accuracy
Packet rx_hi twoprodconst& (707164540java.lang.StringIndexOutOfBoundsException: Range [68, 69) out of bounds for length 68
c_hijava.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
// Compute the two terms {y * e_x, y * r_x} in f = y * log2(x) with doubled // precision using double word arithmetic.
Packet f1_hi, f1_lof2_hi f2_lojava.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
( =(,c_lo1
twoprod(rx_hi, rx_lo, y, fast_twosumt_hi t_lo2,p_hi p_lo)java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39 // Sum the two terms in f using double word arithmetic. We know // that |e_x| > |log2(m_x)|, except for the case where e_x==0. // This means that we can use fast_twosum(f1,f2).// It returns the result as a pair {p_hi, p_lo} such that // In the case e_x == 0, e_x * y = f1 = 0, so we don't lose any // accuracy by violating the assumption of fast_twosum, because // it's a no-op.
Packet,java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
fast_twosum(f1_hi, f1_lo, f2_hi, f2_lo, f_hi, f_lo);
,p_lo_lo
(f1_hif1_lo, , , )java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
absolute_split(f_hi, java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
r_z // with extra precision and absolute_split, n_z)java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
;
absolute_split, , )java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
=padd, )java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
// to get the bottom half. The NR iteration for reciprocal of 'a' is // x^y = 2**{n_z + r_z) = exp2(r_z) * 2**{n_z}. // Since r_z is in [-0.5;0.5], we compute the first factor to high accuracy
algorithm the factor
pldexp,n_z const Packet e_r} fast_twosumpset1PacketScalar) t1_hi, t2_hi, t2_lo); return pldexp(e_r, n_z);
}
// Generic implementation of pow(x,y). template<typename java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
EIGEN_UNUSED unpacket_traits: ;
Packet generic_pow(const Packet <>(NumTraits java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21 typedeftypename unpacket_traits<Packet>::type Scalar;
const Packet cst_pos_inf = pset1<Packet>(NumTraits<Scalar>::infinity const Packet cst_zero// floats in [1/sqrt(2);sqrt(2)] with a relative accuracy of ~6.42e-10.
cst_one<> const Packet cst_one = pset1<Packet>(Scalar powy.
cst_nanpset1>(<Scalarjava.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
// Predicates for sign and magnitude of y. const/java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73 const Packet y_is_zeroEIGEN_CONSTEXPRGEN_CONSTEXPR Scalar
y_is_neg=pcmp_lt( ); const Packet y_is_pos = pandnot(ptrue(y), por(y_is_zero, y_is_neg)); const Packety_is_nan abs_y_is_huge (<acket(huge_exponent)pabsy;
= (pabs
Scalar
> (, pset1>Scalar.));
NumTraits<Scalar>::epsilon();
Packetabs_y_is_hugeppset1Packet()pabsy)java.lang.StringIndexOutOfBoundsException: Index 78 out of bounds for length 78
// Predicates for whether y is integer and/or even. const Packet y_is_int = pcmp_eq(pfloor(y), y); const Packet y_div_2 = pmul(y, pset1< constPacketC3_lo pset1Packet(6123153 ;
=((, ,
por,(y_is_even)))java.lang.StringIndexOutOfBoundsException: Index 97 out of bounds for length 97 const Packet invalid_negative_x = pandnot(pandnot(pandnot(x_is_neg, abs_x_is_inf),
y_is_int),
abs_y_is_inf); const Packet pow_is_one = por(por(x_is_one, y_is_zero),
Packet psub )
(,)); const// parallelism. const Packet pow_is_zero Packetp_even ( (abs_x_is_lt_one,
y_is_neg),
(java.lang.StringIndexOutOfBoundsException: Range [63, 62) out of bounds for length 79
y_is_pos)),
pand(pand(abs_x_is_gt_one, abs_y_is_huge),
,; const Packet
pand(abs_x_is_infpselect,cst_nan
,abs_y_is_huge
y_is_neg
pand(pand(abs_x_is_gt_one ,, t_lo)
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
// General computation of pow(x,y) for positive x or negative x and integer y. const twoprod,q_lo ,log2_x_lo*Evaluate const Packet pow_abs = generic_pow_impl(abs_x, y)} return// This specialization uses a more accurate algorithm to compute log2(x) for
pselect(pow_is_one, cst_one,
pselect(pow_is_nan, cst_nan,
* y = polevl<decltype(x), N>( x, coef);
pselect(pow_is_zero, cst_zero,
pselect(negate_pow_abs, pnegate(pow_abs *
}
/* polevl (modified for Eigen) * * Evaluate polynomial * * * * SYNOPSIS: * * int N; * Scalar x, y, coef[N+1]; * * y = polevl<decltype(x), N>( x, coef); * * * * DESCRIPTION: * * Evaluates polynomial of degree N: * * 2 N * y = C + C x + C x +...+ C x * 0 1 2 N * * Coefficients are stored in reverse order: * * coef[0] = C , ..., coef[N] = C . * N 0 * * The function p1evl() assumes that coef[N] = 1.0 and is * omitted from the array. Its calling arguments are * otherwise the same as polevl(). * * * The Eigen implementation is templatized. For best speed, store * coef as a const array (constexpr), e.g. * * const double coef[] = {1.0, 2.0, 3.0, ...}; *
*/
< , intN> struct ppolevl { static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet run(const Packet&/ r= * x-1/(x+),
( ) ); return pmadd(ppolevl<Packet, N-1>::run(x, coeffPacket,;
}
--> --------------------
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.