On Fri, Jul 15, 2005 at 01:39:13AM +0200, Joerg Schilling wrote:

> It seems that there are two basic "reasons":
> 
> -     Sun CC as well as GNU CC heavily use built in functions
>       for floating point support. Of course these builtins are 
>       incompatible :-(

Some of these are for C99 support, and gcc's are just plain missing.
There was a header fix that recently went back that will allow these
functions to work properly with either compiler's builtins.  Since
they're built-in, there should be no need to provide these in libm.

See 6285517 gcc 3.4.x/4.x c99 math intrinsics support needed

Unfortunately all the good stuff is in the evaluation and suggested
fix, which aren't available.  Alex Liu cleverly worked around gcc's
inadequate C99 implementation and anything built with gcc against the
new math.h should support all the required C99 functions.  Here's the
data from that bug:

Evaluation

[zaliu 6/17/2005]
gcc 3.4.3 has partial support for the C99 math intrinsics: none of the six
classification macros (C99 7.12.3) are directly supported as built-ins.

gcc 4.0.0 implements a type-generic built-in for isnan, along with
inlined type-specific built-ins for float and double signbit i.e.
__builtin_signbitf/__builtin_signbit, but no inlined __builtin_signbitl.

In addition, gcc 3.4.x/4.0.0 defines many C99 math intrinsics differently from
how Sun C defines them.  Specifically:

#define HUGE_VAL        (__builtin_huge_val())
#define HUGE_VALF       (__builtin_huge_valf())
#define HUGE_VALL       (__builtin_huge_vall())
#define INFINITY        (__builtin_inff())
#define NAN             (__builtin_nanf(""))

#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)

See  http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19933 for more details.

Suggested Fix

[zaliu 6/17/2005]
We decided against implementing any of the six classification macros with
*new* math library entry points.  Instead, with the gcc extension __typeof
along with *inlined* gcc built-ins __builtin_isunordered, __builtin_fabsf,
__builtin_fabs, __builtin_fabsl, __FLT_MIN__, __DBL_MIN__ and __LDBL_MIN__,
we implemented all six classification macros directly in <iso/math_c99.h>
for gcc 3.4.x and 4.x:

libm/inc/iso/math_c99.h: 1.9 vs. 1.10
***************
*** 1,5 ****
  /*
!  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
   * Use is subject to license terms.
   */
  
--- 1,5 ----
  /*
!  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
   * Use is subject to license terms.
   */
  
***************
*** 23,29 ****
--- 23,108 ----
  #endif        /* !defined(__P) */
  
  #if defined(_STDC_C99) || _XOPEN_SOURCE - 0 >= 600 || defined(__C99FEATURES__)
+ #if defined(__GNUC__)
  #undef        HUGE_VAL
+ #define       HUGE_VAL        (__builtin_huge_val())
+ #undef        HUGE_VALF
+ #define       HUGE_VALF       (__builtin_huge_valf())
+ #undef        HUGE_VALL
+ #define       HUGE_VALL       (__builtin_huge_vall())
+ #undef        INFINITY
+ #define       INFINITY        (__builtin_inff())
+ #undef        NAN
+ #define       NAN             (__builtin_nanf(""))
+ 
+ /*
+  * C99 7.12.3 classification macros
+  */
+ #undef        isnan
+ #if __GNUC__ >= 4
+ #define       isnan(x)        __builtin_isnan(x)
+ #else
+ #define       isnan(x)        __extension__( \
+                       { __typeof(x) __x_n = (x); \
+                       __builtin_isunordered(__x_n, __x_n); })
+ #endif
+ #undef        isinf
+ #define       isinf(x)        __extension__( \
+                       { __typeof(x) __x_i = (x); \
+                       __x_i == (__typeof(__x_i)) INFINITY || \
+                       __x_i == (__typeof(__x_i)) (-INFINITY); })
+ #undef        isfinite
+ #define       isfinite(x)     __extension__( \
+                       { __typeof(x) __x_f = (x); \
+                       !isnan(__x_f) && !isinf(__x_f); })
+ #undef        isnormal
+ #define       isnormal(x)     __extension__( \
+                       { __typeof(x) __x_r = (x); isfinite(__x_r) && \
+                       (sizeof (__x_r) == sizeof (float) ? \
+                       __builtin_fabsf(__x_r) >= __FLT_MIN__ : \
+                       sizeof (__x_r) == sizeof (double) ? \
+                       __builtin_fabs(__x_r) >= __DBL_MIN__ : \
+                       __builtin_fabsl(__x_r) >= __LDBL_MIN__); })
+ #undef        fpclassify
+ #define       fpclassify(x)   __extension__( \
+                       { __typeof(x) __x_c = (x); \
+                       isnan(__x_c) ? FP_NAN : \
+                       isinf(__x_c) ? FP_INFINITE : \
+                       isnormal(__x_c) ? FP_NORMAL : \
+                       __x_c == (__typeof(__x_c)) 0 ? FP_ZERO : \
+                       FP_SUBNORMAL; })
+ #undef        signbit
+ #if defined(__sparc)
+ #define       signbit(x)      __extension__( \
+                       { __typeof(x) __x_s = (x); \
+                       (int) (*(unsigned *) &__x_s >> 31); })
+ #elif defined(__i386) || defined(__amd64)
+ #define       signbit(x)      __extension__( \
+                       { __typeof(x) __x_s = (x); \
+                       (sizeof (__x_s) == sizeof (float) ? \
+                       (int) (*(unsigned *) &__x_s >> 31) : \
+                       sizeof (__x_s) == sizeof (double) ? \
+                       (int) (((unsigned *) &__x_s)[1] >> 31) : \
+                       (int) (((unsigned short *) &__x_s)[4] >> 15)); })
+ #endif
+ 
+ /*
+  * C99 7.12.14 comparison macros
+  */
+ #undef        isgreater
+ #define       isgreater(x, y)         __builtin_isgreater(x, y)
+ #undef        isgreaterequal
+ #define       isgreaterequal(x, y)    __builtin_isgreaterequal(x, y)
+ #undef        isless
+ #define       isless(x, y)            __builtin_isless(x, y)
+ #undef        islessequal
+ #define       islessequal(x, y)       __builtin_islessequal(x, y)
+ #undef        islessgreater
+ #define       islessgreater(x, y)     __builtin_islessgreater(x, y)
+ #undef        isunordered
+ #define       isunordered(x, y)       __builtin_isunordered(x, y)
+ #else /* defined(__GNUC__) */
+ #undef        HUGE_VAL
  #define       HUGE_VAL        __builtin_huge_val
  #undef        HUGE_VALF
  #define       HUGE_VALF       __builtin_huge_valf
***************
*** 65,70 ****
--- 144,150 ----
  #define       islessgreater(x, y)     ((x) __builtin_islessgreater(y))
  #undef        isunordered
  #define       isunordered(x, y)       ((x) __builtin_isunordered(y))
+ #endif        /* defined(__GNUC__) */
  #endif        /* defined(_STDC_C99) || _XOPEN_SOURCE - 0 >= 600 || ... */
  
  #if defined(__EXTENSIONS__) || defined(_STDC_C99) || \

-- 
Keith M Wesolowski              "Sir, we're surrounded!" 
Solaris Kernel Team             "Excellent; we can attack in any direction!" 
_______________________________________________
opensolaris-discuss mailing list
opensolaris-discuss@opensolaris.org

Reply via email to