This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: bits/mathdef.h cleanup, revisited


How about the following idea instead?  It switches based on
__FLT_EVAL_METHOD__, not on __GNUC__, which gives GCC (and other compilers)
a way to communicate to glibc how floating-point computation works.
(I have not tested this.)

2012-01-31  Joseph Myers  <joseph@codesourcery.com>
	    Paul Eggert  <eggert@cs.ucla.edu>

	* bits/mathdef.h (float_t, double_t): Define based on
	__FLT_EVAL_METHOD__, defaulting to float and double respectively.
	* sysdeps/i386/bits/mathdef.h (float_t, double_t): Define both
	to double if __FLT_EVAL_METHOD__ is 1.
	* sysdeps/x86_64/bits/mathdef.h (float_t, double_t): Likewise.
	* sysdeps/powerpc/bits/mathdef.h (float_t, double_t): Define based
	on __FLT_EVAL_METHOD__ not __GNUC__, with the same default as before.
	* sysdeps/sh/sh4/bits/mathdef.h (float_t, double_t): Likewise.
	* sysdeps/sparc/bits/mathdef.h (float_t, double_t): Likewise.
	* sysdeps/s390/bits/mathdef.h (float_t, double_t): Define based on
	__FLT_EVAL_METHOD__, with the same default as before.

diff --git a/bits/mathdef.h b/bits/mathdef.h
index 3cea584..0f41e45 100644
--- a/bits/mathdef.h
+++ b/bits/mathdef.h
@@ -23,12 +23,24 @@
 #if defined  __USE_ISOC99 && defined _MATH_H && !defined _MATH_H_MATHDEF
 # define _MATH_H_MATHDEF	1
 
-/* Normally, there is no long double type and the `float' and `double'
-   expressions are evaluated as `double'.  */
-typedef double float_t;		/* `float' expressions are evaluated as
-				   `double'.  */
-typedef double double_t;	/* `double' expressions are evaluated as
-				   `double'.  */
+# if __FLT_EVAL_METHOD__ == 1
+
+typedef double float_t;
+typedef double double_t;
+
+# elif __FLT_EVAL_METHOD__ == 2
+
+typedef long double float_t;
+typedef long double double_t;
+
+# else
+
+/* Either __FLT_EVAL_METHOD__ is 0, or the evaluation method is unknown
+   and we make a wild guess that it acts like __FLT_EVAL_METHOD__ is 0.  */
+typedef float float_t;
+typedef double double_t;
+
+# endif
 
 /* The values returned by `ilogb' for 0 and NaN respectively.  */
 # define FP_ILOGB0	(-2147483647)
diff --git a/sysdeps/i386/bits/mathdef.h b/sysdeps/i386/bits/mathdef.h
index 479eb96..a85fd61 100644
--- a/sysdeps/i386/bits/mathdef.h
+++ b/sysdeps/i386/bits/mathdef.h
@@ -29,8 +29,17 @@
 typedef float float_t;		/* `float' expressions are evaluated as `float'.  */
 typedef double double_t;	/* `double' expressions are evaluated as
 				   `double'.  */
+
+# elif __FLT_EVAL_METHOD__ == 1
+
+typedef double float_t;
+typedef double double_t;
+
 # else
-/* The ix87 FPUs evaluate all values in the 80 bit floating-point format
+
+/* Either __FLT_EVAL_METHOD__ is 2, or the evaluation method is unknown
+   and we make a wild guess that it acts like __FLT_EVAL_METHOD__ is 2.
+   The ix87 FPUs evaluate all values in the 80 bit floating-point format
    which is also available for the user as `long double'.  Therefore we
    define:  */
 typedef long double float_t;	/* `float' expressions are evaluated as
diff --git a/sysdeps/powerpc/bits/mathdef.h b/sysdeps/powerpc/bits/mathdef.h
index 3a9b1b0..186478a 100644
--- a/sysdeps/powerpc/bits/mathdef.h
+++ b/sysdeps/powerpc/bits/mathdef.h
@@ -31,20 +31,25 @@
 #if defined __USE_ISOC99 && defined _MATH_H && !defined _MATH_H_MATHDEF
 # define _MATH_H_MATHDEF	1
 
-# ifdef __GNUC__
+# if __FLT_EVAL_METHOD__ == 1
 
-/* gcc leaves `float' expressions as-is.  */
+typedef double float_t;
+typedef double double_t;
+
+# elif __FLT_EVAL_METHOD__ == 2
+
+typedef long double float_t;
+typedef long double double_t;
+
+# else
+
+/* Either __FLT_EVAL_METHOD__ is 0, or the evaluation method is unknown
+   and we make a wild guess that it acts like __FLT_EVAL_METHOD__ is 0.  */
 typedef float float_t;		/* `float' expressions are evaluated as
 				   `float'.  */
 typedef double double_t;	/* `double' expressions are evaluated as
 				   `double'.  */
 
-# else
-
-/* Wild guess at types for float_t and double_t. */
-typedef double float_t;
-typedef double double_t;
-
 # endif
 
 /* The values returned by `ilogb' for 0 and NaN respectively.  */
diff --git a/sysdeps/s390/bits/mathdef.h b/sysdeps/s390/bits/mathdef.h
index 4dcb612..c3b0fc9 100644
--- a/sysdeps/s390/bits/mathdef.h
+++ b/sysdeps/s390/bits/mathdef.h
@@ -24,12 +24,25 @@
 #if defined  __USE_ISOC99 && defined _MATH_H && !defined _MATH_H_MATHDEF
 # define _MATH_H_MATHDEF	1
 
+# if defined __FLT_EVAL_METHOD__ && __FLT_EVAL_METHOD__ == 0
+
+typedef float float_t;
+typedef double double_t;
+
+# elif __FLT_EVAL_METHOD__ == 2
+
+typedef long double float_t;
+typedef long double double_t;
+
+# else
+
 /* Normally, there is no long double type and the `float' and `double'
    expressions are evaluated as `double'.  */
 typedef double float_t;		/* `float' expressions are evaluated as
 				   `double'.  */
 typedef double double_t;	/* `double' expressions are evaluated as
 				   `double'.  */
+# endif
 
 /* The values returned by `ilogb' for 0 and NaN respectively.  */
 # define FP_ILOGB0	(-2147483647)
diff --git a/sysdeps/sh/sh4/bits/mathdef.h b/sysdeps/sh/sh4/bits/mathdef.h
index 5b92234..a6df2a5 100644
--- a/sysdeps/sh/sh4/bits/mathdef.h
+++ b/sysdeps/sh/sh4/bits/mathdef.h
@@ -31,20 +31,25 @@
 #if defined __USE_ISOC99 && defined _MATH_H && !defined _MATH_H_MATHDEF
 # define _MATH_H_MATHDEF	1
 
-# ifdef __GNUC__
+# if __FLT_EVAL_METHOD__ == 1
 
-/* gcc leaves `float' expressions as-is.  */
+typedef double float_t;
+typedef double double_t;
+
+# elif __FLT_EVAL_METHOD__ == 2
+
+typedef long double float_t;
+typedef long double double_t;
+
+# else
+
+/* Either __FLT_EVAL_METHOD__ is 0, or the evaluation method is unknown
+   and we make a wild guess that it acts like __FLT_EVAL_METHOD__ is 0.  */
 typedef float float_t;		/* `float' expressions are evaluated as
 				   `float'.  */
 typedef double double_t;	/* `double' expressions are evaluated as
 				   `double'.  */
 
-# else
-
-/* Wild guess at types for float_t and double_t. */
-typedef double float_t;
-typedef double double_t;
-
 # endif
 
 /* The values returned by `ilogb' for 0 and NaN respectively.  */
diff --git a/sysdeps/sparc/bits/mathdef.h b/sysdeps/sparc/bits/mathdef.h
index 042c9c8..e9f35b5 100644
--- a/sysdeps/sparc/bits/mathdef.h
+++ b/sysdeps/sparc/bits/mathdef.h
@@ -29,16 +29,21 @@
 #if defined __USE_ISOC99 && defined _MATH_H && !defined _MATH_H_MATHDEF
 # define _MATH_H_MATHDEF	1
 
-# ifdef __GNUC__
+# if __FLT_EVAL_METHOD__ == 1
 
-/* gcc leaves `float' expressions as-is.  */
-typedef float float_t;
+typedef double float_t;
 typedef double double_t;
 
+# elif __FLT_EVAL_METHOD__ == 2
+
+typedef long double float_t;
+typedef long double double_t;
+
 # else
 
-/* Wild guess at types for float_t and double_t. */
-typedef double float_t;
+/* Either __FLT_EVAL_METHOD__ is 0, or the evaluation method is unknown
+   and we make a wild guess that it acts like __FLT_EVAL_METHOD__ is 0.  */
+typedef float float_t;
 typedef double double_t;
 
 # endif
diff --git a/sysdeps/x86_64/bits/mathdef.h b/sysdeps/x86_64/bits/mathdef.h
index 9146392..63a8aa6 100644
--- a/sysdeps/x86_64/bits/mathdef.h
+++ b/sysdeps/x86_64/bits/mathdef.h
@@ -25,14 +25,26 @@
 
 # include <bits/wordsize.h>
 
-# if __WORDSIZE == 64 || (defined __FLT_EVAL_METHOD__ && __FLT_EVAL_METHOD__ == 0)
-/* The x86-64 architecture computes values with the precission of the
+# if ((__WORDSIZE == 64 && __FLT_EVAL_METHOD__ <= 0) \
+      || (defined __FLT_EVAL_METHOD__ && __FLT_EVAL_METHOD__ == 0))
+/* The x86-64 architecture computes values with the precision of the
    used type.  Similarly for -m32 -mfpmath=sse.  */
 typedef float float_t;		/* `float' expressions are evaluated as `float'.  */
 typedef double double_t;	/* `double' expressions are evaluated
 				   as `double'.  */
+
+# elif __FLT_EVAL_METHOD__ == 1
+
+typedef double float_t;
+typedef double double_t;
+
 # else
-/* The ix87 FPUs evaluate all values in the 80 bit floating-point format
+
+/* Either __FLT_EVAL_METHOD__ is 2, or the evaluation method is
+   unknown on a 32-bit target and we make a wild guess that it acts
+   like __FLT_EVAL_METHOD__ is 2.
+
+   The ix87 FPUs evaluate all values in the 80 bit floating-point format
    which is also available for the user as `long double'.  Therefore we
    define:  */
 typedef long double float_t;	/* `float' expressions are evaluated as


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]