From 2ce081b770e429fdf14e53cbec975823a44e0564 Mon Sep 17 00:00:00 2001 From: geoffk Date: Sat, 10 Jan 2004 05:47:14 +0000 Subject: * config/rs6000/darwin-ldouble.c: Add big comment explaining exactly what is expected as a 'long double'. (_xlqadd): When a value to be returned is representable as a 'double', just return it directly, do not construct it using a union. Also, correct final fixup. (_xlqmul): Likewise. (_xlqdiv): Likewise. * real.c (encode_ibm_extended): Make consistent with darwin-ldouble.c. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@75629 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/config/rs6000/darwin-ldouble.c | 66 +++++++++++++------------------------- 1 file changed, 23 insertions(+), 43 deletions(-) (limited to 'gcc/config/rs6000/darwin-ldouble.c') diff --git a/gcc/config/rs6000/darwin-ldouble.c b/gcc/config/rs6000/darwin-ldouble.c index 281eb2a7599..c73b24f5270 100644 --- a/gcc/config/rs6000/darwin-ldouble.c +++ b/gcc/config/rs6000/darwin-ldouble.c @@ -37,6 +37,17 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA Floating-Point Computations", by Seppo Linnainmaa, ACM TOMS vol 7 no 3, September 1961, pages 272-283. */ +/* Each long double is made up of two IEEE doubles. The value of the + long double is the sum of the values of the two parts. The most + significant part is required to be the value of the long double + rounded to the nearest double, as specified by IEEE. For Inf + values, the least significant part is required to be one of +0.0 or + -0.0. No other requirements are made; so, for example, 1.0 may be + represented as (1.0, +0.0) or (1.0, -0.0), and the low part of a + NaN is don't-care. + + This code currently assumes big-endian. */ + #define fabs(x) __builtin_fabs(x) #define unlikely(x) __builtin_expect ((x), 0) @@ -68,11 +79,8 @@ _xlqadd (double a, double b, double c, double d) FPR_zero = 0.0; FPR_PosInf = FPKINF; - if (unlikely (a != a) || unlikely (c != c)) { - z.dval[0] = a + c; /* NaN result. */ - z.dval[1] = a + c; /* NaN result. */ - return z.ldval; - } + if (unlikely (a != a) || unlikely (c != c)) + return a + c; /* NaN result. */ /* Ordered operands are arranged in order of their magnitudes. */ @@ -110,18 +118,14 @@ _xlqadd (double a, double b, double c, double d) t = (tau + b) + a; /* Sum values in ascending magnitude order. */ /* Infinite or zero result. */ - if (unlikely (fabs (t) == FPR_PosInf) || unlikely (t == FPR_zero)) - { - z.dval[0] = t; - z.dval[1] = t >= 0.0 ? (fabs (t) >= 0.0 ? t : 0.0) : -0.0; - return z.ldval; - } + if (unlikely (t == FPR_zero) || unlikely (fabs (t) == FPR_PosInf)) + return t; /* Usual case. */ tau = (((a-t) + b) + c) + d; u = t + tau; z.dval[0] = u; /* Final fixup for long double result. */ - z.dval[1] = (u - t) + tau; + z.dval[1] = (t - u) + tau; return z.ldval; } @@ -142,22 +146,10 @@ _xlqmul (double a, double b, double c, double d) t = a * c; /* Highest order double term. */ - if (unlikely (t != t) || unlikely (t == FPR_zero)) - { - /* NaN or zero result. */ - z.dval[0] = t; - z.dval[1] = t; - return z.ldval; - } + if (unlikely (t != t) || unlikely (t == FPR_zero) + || unlikely (fabs (t) == FPR_PosInf)) + return t; - if (unlikely (fabs(t) == FPR_PosInf)) - { - /* Infinite result. */ - z.dval[0] = t; - z.dval[1] = t >= 0 ? 0.0 : -0.0; - return z.ldval; - } - /* Finite nonzero result requires summing of terms of two highest orders. */ @@ -170,7 +162,7 @@ _xlqmul (double a, double b, double c, double d) /* Construct long double result. */ z.dval[0] = u; - z.dval[1] = (u - t) + tau; + z.dval[1] = (t - u) + tau; return z.ldval; } @@ -185,21 +177,9 @@ _xlqdiv (double a, double b, double c, double d) t = a / c; /* highest order double term */ - if (unlikely (t != t) || unlikely (t == FPR_zero)) - { - /* NaN or zero result. */ - z.dval[0] = t; - z.dval[1] = t; - return z.ldval; - } - - if (unlikely (fabs (t) == FPR_PosInf)) - { - /* Infinite result. */ - z.dval[0] = t; - z.dval[1] = t >= 0.0 ? 0.0 : -0.0; - return z.ldval; - } + if (unlikely (t != t) || unlikely (t == FPR_zero) + || unlikely (fabs (t) == FPR_PosInf)) + return t; /* Finite nonzero result requires corrections to the highest order term. */ -- cgit v1.2.1