summaryrefslogtreecommitdiff
path: root/sysdeps/generic
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2015-09-18 20:00:48 +0000
committerJoseph Myers <joseph@codesourcery.com>2015-09-18 20:00:48 +0000
commitc8235dda728c4452f57c4c0d1bccc4e9a67da80c (patch)
treeae521c94b4648e089ee442cf8991963e7ffd97fe /sysdeps/generic
parentfe8c2b33aed067282ecac0cc3fdff1feef88548b (diff)
downloadglibc-c8235dda728c4452f57c4c0d1bccc4e9a67da80c.tar.gz
Avoid excess range overflowing results from cosh, sinh, lgamma (bug 18980).
Various i386 libm functions return values with excess range and precision; Wilco Dijkstra's patches to make isfinite etc. expand inline cause this pre-existing issue to result in test failures (when e.g. a result that overflows float but not long double gets counted as overflowing for some purposes but not others). This patch addresses those cases arising from functions defined in C, adding a math_narrow_eval macro that forces values to memory to eliminate excess precision if FLT_EVAL_METHOD indicates this is needed, and is a no-op otherwise. I'll convert existing uses of volatile and asm for this purpose to use the new macro later, once i386 has clean test results again (which requires fixes for .S files as well). Tested for x86_64 and x86. Committed. [BZ #18980] * sysdeps/generic/math_private.h: Include <float.h>. (math_narrow_eval): New macro. [FLT_EVAL_METHOD != 0] (excess_precision): Likewise. * sysdeps/ieee754/dbl-64/e_cosh.c (__ieee754_cosh): Use math_narrow_eval on overflowing return value. * sysdeps/ieee754/dbl-64/e_lgamma_r.c (__ieee754_lgamma_r): Likewise. * sysdeps/ieee754/dbl-64/e_sinh.c (__ieee754_sinh): Likewise. * sysdeps/ieee754/flt-32/e_coshf.c (__ieee754_coshf): Likewise. * sysdeps/ieee754/flt-32/e_lgammaf_r.c (__ieee754_lgammaf_r): Likewise. * sysdeps/ieee754/flt-32/e_sinhf.c (__ieee754_sinhf): Likewise.
Diffstat (limited to 'sysdeps/generic')
-rw-r--r--sysdeps/generic/math_private.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/sysdeps/generic/math_private.h b/sysdeps/generic/math_private.h
index 6aea8643da..35591eed15 100644
--- a/sysdeps/generic/math_private.h
+++ b/sysdeps/generic/math_private.h
@@ -20,6 +20,7 @@
#include <stdint.h>
#include <sys/types.h>
#include <fenv.h>
+#include <float.h>
#include <get-rounding-mode.h>
/* The original fdlibm code used statements like:
@@ -405,6 +406,29 @@ extern long double __lgamma_productl (long double t, long double x,
({ __typeof (x) __x = (x); __asm __volatile__ ("" : : "m" (__x)); })
#endif
+/* math_narrow_eval reduces its floating-point argument to the range
+ and precision of its semantic type. (The original evaluation may
+ still occur with excess range and precision, so the result may be
+ affected by double rounding.) */
+#if FLT_EVAL_METHOD == 0
+# define math_narrow_eval(x) (x)
+#else
+# if FLT_EVAL_METHOD == 1
+# define excess_precision(type) __builtin_types_compatible_p (type, float)
+# else
+# define excess_precision(type) (__builtin_types_compatible_p (type, float) \
+ || __builtin_types_compatible_p (type, \
+ double))
+# endif
+# define math_narrow_eval(x) \
+ ({ \
+ __typeof (x) math_narrow_eval_tmp = (x); \
+ if (excess_precision (__typeof (math_narrow_eval_tmp))) \
+ __asm__ ("" : "+m" (math_narrow_eval_tmp)); \
+ math_narrow_eval_tmp; \
+ })
+#endif
+
/* The standards only specify one variant of the fenv.h interfaces.
But at least for some architectures we can be more efficient if we