This is the mail archive of the libc-alpha@sources.redhat.com 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]

common code for unordered compare builtins


After I discovered that (1) Alpha and others weren't using them,
and (2) the backup isunordered definition didn't work for 128-bit
long double.  Of course, the backup will now *never* be used for
128-bit long double now, since that requires a gcc that does 
support the builtins, but hey, it's still a good cleanup.


r~


2004-03-09  Richard Henderson  <rth@redhat.com>

	* math/math.h (isgreater, isgreaterequal, isless, islessequal,
	islessgreater, isunordered): Use builtins if available.
	* sysdeps/i386/fpu/bits/mathinline.h: Don't define via builtins.
	* sysdeps/m68k/fpu/bits/mathinline.h: Likewise.
	* sysdeps/powerpc/fpu/bits/mathinline.h: Likewise.
	* sysdeps/sparc/fpu/bits/mathinline.h: Likewise.
	* sysdeps/x86_64/fpu/bits/mathinline.h: Likewise.
	* sysdeps/alpha/fpu/bits/mathinline.h (isgreater, isgreaterequal,
	isless, islessequal, islessgreater): Remove; use default.
	(isunordered): Convert inputs to double.

Index: math/math.h
===================================================================
RCS file: /cvs/glibc/libc/math/math.h,v
retrieving revision 1.66
diff -u -p -u -r1.66 math.h
--- math/math.h	25 Oct 2002 19:45:22 -0000	1.66
+++ math/math.h	10 Mar 2004 05:17:59 -0000
@@ -357,18 +357,28 @@ extern int matherr (struct exception *__
 # define __NO_MATH_INLINES	1
 #endif
 
+#if __USE_ISOC99 && __GNUC_PREREQ(2,97)
+/* ISO C99 defines some macros to compare number while taking care for
+   unordered numbers.  Many FPUs provide special instructions to support
+   these operations.  Generic support in GCC for these as builtins went
+   in before 3.0.0, but not all cpus added their patterns.  We define
+   versions that use the builtins here, and <bits/mathinline.h> will
+   undef/redefine as appropriate for the specific GCC version in use.  */
+# define isgreater(x, y)	__builtin_isgreater(x, y)
+# define isgreaterequal(x, y)	__builtin_isgreaterequal(x, y)
+# define isless(x, y)		__builtin_isless(x, y)
+# define islessequal(x, y)	__builtin_islessequal(x, y)
+# define islessgreater(x, y)	__builtin_islessgreater(x, y)
+# define isunordered(u, v)	__builtin_isunordered(u, v)
+#endif
+
 /* Get machine-dependent inline versions (if there are any).  */
 #ifdef __USE_EXTERN_INLINES
 # include <bits/mathinline.h>
 #endif
 
-
 #if __USE_ISOC99
-/* ISO C99 defines some macros to compare number while taking care
-   for unordered numbers.  Since many FPUs provide special
-   instructions to support these operations and these tests are
-   defined in <bits/mathinline.h>, we define the generic macros at
-   this late point and only if they are not defined yet.  */
+/* If we've still got undefined comparison macros, provide defaults.  */
 
 /* Return nonzero value if X is greater than Y.  */
 # ifndef isgreater
Index: sysdeps/alpha/fpu/bits/mathinline.h
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/alpha/fpu/bits/mathinline.h,v
retrieving revision 1.11
diff -u -p -u -r1.11 mathinline.h
--- sysdeps/alpha/fpu/bits/mathinline.h	24 Jun 2003 16:33:49 -0000	1.11
+++ sysdeps/alpha/fpu/bits/mathinline.h	10 Mar 2004 05:18:01 -0000
@@ -28,34 +28,19 @@
 # define __MATH_INLINE extern __inline
 #endif
 
-#ifdef __USE_ISOC99
-# define isunordered(x, y)				\
+#if defined __USE_ISOC99 && defined __GNUC__ && !__GNUC_PREREQ(3,0)
+# undef isgreater
+# undef isgreaterequal
+# undef isless
+# undef islessequal
+# undef islessgreater
+# undef isunordered
+# define isunordered(u, v)				\
   (__extension__					\
-   ({ double __r;					\
+   ({ double __r, __u = (u), __v = (v);			\
       __asm ("cmptun/su %1,%2,%0\n\ttrapb"		\
-	     : "=&f" (__r) : "f" (x), "f"(y));		\
+	     : "=&f" (__r) : "f" (__u), "f"(__v));	\
       __r != 0; }))
-
-# define isgreater(x, y)				\
-  (__extension__					\
-   ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y);	\
-      !isunordered(__x, __y) && __x > __y; }))
-# define isgreaterequal(x, y)				\
-  (__extension__					\
-   ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y);	\
-      !isunordered(__x, __y) && __x >= __y; }))
-# define isless(x, y)					\
-  (__extension__					\
-   ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y);	\
-      !isunordered(__x, __y) && __x < __y; }))
-# define islessequal(x, y)				\
-  (__extension__					\
-   ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y);	\
-      !isunordered(__x, __y) && __x <= __y; }))
-# define islessgreater(x, y)				\
-  (__extension__					\
-   ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y);	\
-      !isunordered(__x, __y) && __x != __y; }))
 #endif /* ISO C99 */
 
 #if (!defined __NO_MATH_INLINES || defined __LIBC_INTERNAL_MATH_INLINES) \
Index: sysdeps/i386/fpu/bits/mathinline.h
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/i386/fpu/bits/mathinline.h,v
retrieving revision 1.55
diff -u -p -u -r1.55 mathinline.h
--- sysdeps/i386/fpu/bits/mathinline.h	24 Dec 2003 01:10:09 -0000	1.55
+++ sysdeps/i386/fpu/bits/mathinline.h	10 Mar 2004 05:18:02 -0000
@@ -30,19 +30,18 @@
 
 
 #if defined __USE_ISOC99 && defined __GNUC__ && __GNUC__ >= 2
-# if __GNUC_PREREQ (2,97)
 /* GCC 2.97 and up have builtins that actually can be used.  */
-#  define isgreater(x, y) __builtin_isgreater (x, y)
-#  define isgreaterequal(x, y) __builtin_isgreaterequal (x, y)
-#  define isless(x, y) __builtin_isless (x, y)
-#  define islessequal(x, y) __builtin_islessequal (x, y)
-#  define islessgreater(x, y) __builtin_islessgreater (x, y)
-#  define isunordered(x, y) __builtin_isunordered (x, y)
-# else
+# if !__GNUC_PREREQ (2,97)
 /* ISO C99 defines some macros to perform unordered comparisons.  The
    ix87 FPU supports this with special opcodes and we should use them.
    These must not be inline functions since we have to be able to handle
    all floating-point types.  */
+#  undef isgreater
+#  undef isgreaterequal
+#  undef isless
+#  undef islessequal
+#  undef islessgreater
+#  undef isunordered
 #  ifdef __i686__
 /* For the PentiumPro and more recent processors we can provide
    better code.  */
Index: sysdeps/m68k/fpu/bits/mathinline.h
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/m68k/fpu/bits/mathinline.h,v
retrieving revision 1.19
diff -u -p -u -r1.19 mathinline.h
--- sysdeps/m68k/fpu/bits/mathinline.h	26 Jun 2003 16:18:13 -0000	1.19
+++ sysdeps/m68k/fpu/bits/mathinline.h	10 Mar 2004 05:18:03 -0000
@@ -21,20 +21,18 @@
 #ifdef	__GNUC__
 
 #ifdef __USE_ISOC99
-
-# if __GNUC_PREREQ (3,1)
 /* GCC 3.1 and up have builtins that actually can be used.  */
-#  define isgreater(x, y) __builtin_isgreater (x, y)
-#  define isgreaterequal(x, y) __builtin_isgreaterequal (x, y)
-#  define isless(x, y) __builtin_isless (x, y)
-#  define islessequal(x, y) __builtin_islessequal (x, y)
-#  define islessgreater(x, y) __builtin_islessgreater (x, y)
-#  define isunordered(x, y) __builtin_isunordered (x, y)
-# else
+# if !__GNUC_PREREQ (3,1)
 /* ISO C99 defines some macros to perform unordered comparisons.  The
    m68k FPU supports this with special opcodes and we should use them.
    These must not be inline functions since we have to be able to handle
    all floating-point types.  */
+#  undef isgreater
+#  undef isgreaterequal
+#  undef isless
+#  undef islessequal
+#  undef islessgreater
+#  undef isunordered
 #  define isgreater(x, y)					\
    __extension__					\
    ({ char __result;					\
Index: sysdeps/powerpc/fpu/bits/mathinline.h
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/powerpc/fpu/bits/mathinline.h,v
retrieving revision 1.7
diff -u -p -u -r1.7 mathinline.h
--- sysdeps/powerpc/fpu/bits/mathinline.h	20 Feb 2004 20:17:00 -0000	1.7
+++ sysdeps/powerpc/fpu/bits/mathinline.h	10 Mar 2004 05:18:03 -0000
@@ -21,17 +21,7 @@
 #if defined __GNUC__ && !defined _SOFT_FLOAT
 
 #ifdef __USE_ISOC99
-# if __GNUC_PREREQ (2,96)
-
-#  define isgreater(x, y) __builtin_isgreater (x, y)
-#  define isgreaterequal(x, y) __builtin_isgreaterequal (x, y)
-#  define isless(x, y) __builtin_isless (x, y)
-#  define islessequal(x, y) __builtin_islessequal (x, y)
-#  define islessgreater(x, y) __builtin_islessgreater (x, y)
-#  define isunordered(x, y) __builtin_isunordered (x, y)
-
-# else
-
+# if !__GNUC_PREREQ (2,97)
 #  define __unordered_cmp(x, y) \
   (__extension__							      \
    ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y);			      \
@@ -39,6 +29,13 @@
       __asm__("fcmpu 7,%1,%2 ; mfcr %0" : "=r" (__r) : "f" (__x), "f"(__y)    \
               : "cr7");  \
       __r; }))
+
+#  undef isgreater
+#  undef isgreaterequal
+#  undef isless
+#  undef islessequal
+#  undef islessgreater
+#  undef isunordered
 
 #  define isgreater(x, y) (__unordered_cmp (x, y) >> 2 & 1)
 #  define isgreaterequal(x, y) ((__unordered_cmp (x, y) & 6) != 0)
Index: sysdeps/sparc/fpu/bits/mathinline.h
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/sparc/fpu/bits/mathinline.h,v
retrieving revision 1.11
diff -u -p -u -r1.11 mathinline.h
--- sysdeps/sparc/fpu/bits/mathinline.h	16 May 2002 00:17:30 -0000	1.11
+++ sysdeps/sparc/fpu/bits/mathinline.h	10 Mar 2004 05:18:03 -0000
@@ -24,9 +24,13 @@
 
 #include <bits/wordsize.h>
 
-#ifdef __GNUC__
-
-#ifdef __USE_ISOC99
+#if defined __USE_ISOC99 && defined __GNUC__ && !__GNUC_PREREQ(3,0)
+# undef isgreater
+# undef isgreaterequal
+# undef isless
+# undef islessequal
+# undef islessgreater
+# undef isunordered
 
 # if __WORDSIZE == 32
 
Index: sysdeps/x86_64/fpu/bits/mathinline.h
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/x86_64/fpu/bits/mathinline.h,v
retrieving revision 1.2
diff -u -p -u -r1.2 mathinline.h
--- sysdeps/x86_64/fpu/bits/mathinline.h	28 Aug 2003 00:00:45 -0000	1.2
+++ sysdeps/x86_64/fpu/bits/mathinline.h	10 Mar 2004 05:18:05 -0000
@@ -30,14 +30,6 @@
 
 
 #if defined __USE_ISOC99 && defined __GNUC__ && __GNUC__ >= 2
-/* GCC has builtins that can be used.  */
-# define isgreater(x, y) __builtin_isgreater (x, y)
-# define isgreaterequal(x, y) __builtin_isgreaterequal (x, y)
-# define isless(x, y) __builtin_isless (x, y)
-# define islessequal(x, y) __builtin_islessequal (x, y)
-# define islessgreater(x, y) __builtin_islessgreater (x, y)
-# define isunordered(x, y) __builtin_isunordered (x, y)
-
 
 /* Test for negative number.  Used in the signbit() macro.  */
 __MATH_INLINE int


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