Print this page
10881 more C99 math macros should be compiler builtins

Split Close
Expand all
Collapse all
          --- old/usr/src/head/iso/math_c99.h
          +++ new/usr/src/head/iso/math_c99.h
↓ open down ↓ 28 lines elided ↑ open up ↑
  29   29  #ifndef _ISO_MATH_C99_H
  30   30  #define _ISO_MATH_C99_H
  31   31  
  32   32  #include <sys/isa_defs.h>
  33   33  #include <sys/feature_tests.h>
  34   34  
  35   35  #ifdef __cplusplus
  36   36  extern "C" {
  37   37  #endif
  38   38  
       39 +#undef  FP_ZERO
       40 +#define FP_ZERO         0
       41 +#undef  FP_SUBNORMAL
       42 +#define FP_SUBNORMAL    1
       43 +#undef  FP_NORMAL
       44 +#define FP_NORMAL       2
       45 +#undef  FP_INFINITE
       46 +#define FP_INFINITE     3
       47 +#undef  FP_NAN
       48 +#define FP_NAN          4
       49 +
  39   50  #if defined(_STDC_C99) || _XOPEN_SOURCE - 0 >= 600 || defined(__C99FEATURES__)
  40   51  #if defined(__GNUC__)
  41   52  #undef  HUGE_VAL
  42   53  #define HUGE_VAL        (__builtin_huge_val())
  43   54  #undef  HUGE_VALF
  44   55  #define HUGE_VALF       (__builtin_huge_valf())
  45   56  #undef  HUGE_VALL
  46   57  #define HUGE_VALL       (__builtin_huge_vall())
  47   58  #undef  INFINITY
  48   59  #define INFINITY        (__builtin_inff())
↓ open down ↓ 1 lines elided ↑ open up ↑
  50   61  #define NAN             (__builtin_nanf(""))
  51   62  
  52   63  /*
  53   64   * C99 7.12.3 classification macros
  54   65   */
  55   66  #undef  isnan
  56   67  #undef  isinf
  57   68  #if __GNUC__ >= 4
  58   69  #define isnan(x)        __builtin_isnan(x)
  59   70  #define isinf(x)        __builtin_isinf(x)
  60      -#else
       71 +#define fpclassify(x)   __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, \
       72 +    FP_SUBNORMAL, FP_ZERO, x)
       73 +#define isfinite(x)     __builtin_isfinite(x)
       74 +#define isnormal(x)     __builtin_isnormal(x)
       75 +#define signbit(x)      __builtin_signbit(x)
       76 +#else  /* __GNUC__ >= 4 */
  61   77  #define isnan(x)        __extension__( \
  62   78                          { __typeof(x) __x_n = (x); \
  63   79                          __builtin_isunordered(__x_n, __x_n); })
  64   80  #define isinf(x)        __extension__( \
  65   81                          { __typeof(x) __x_i = (x); \
  66   82                          __x_i == (__typeof(__x_i)) INFINITY || \
  67   83                          __x_i == (__typeof(__x_i)) (-INFINITY); })
  68      -#endif
  69   84  #undef  isfinite
  70   85  #define isfinite(x)     __extension__( \
  71   86                          { __typeof(x) __x_f = (x); \
  72   87                          !isnan(__x_f) && !isinf(__x_f); })
  73   88  #undef  isnormal
  74   89  #define isnormal(x)     __extension__( \
  75   90                          { __typeof(x) __x_r = (x); isfinite(__x_r) && \
  76   91                          (sizeof (__x_r) == sizeof (float) ? \
  77   92                          __builtin_fabsf(__x_r) >= __FLT_MIN__ : \
  78   93                          sizeof (__x_r) == sizeof (double) ? \
↓ open down ↓ 13 lines elided ↑ open up ↑
  92  107                          { __typeof(x) __x_s = (x); \
  93  108                          (int)(*(unsigned *)&__x_s >> 31); })
  94  109  #elif defined(_LITTLE_ENDIAN)
  95  110  #define signbit(x)      __extension__( \
  96  111                          { __typeof(x) __x_s = (x); \
  97  112                          (sizeof (__x_s) == sizeof (float) ? \
  98  113                          (int)(*(unsigned *)&__x_s >> 31) : \
  99  114                          sizeof (__x_s) == sizeof (double) ? \
 100  115                          (int)(((unsigned *)&__x_s)[1] >> 31) : \
 101  116                          (int)(((unsigned short *)&__x_s)[4] >> 15)); })
 102      -#endif
      117 +#endif  /* defined(_BIG_ENDIAN) */
      118 +#endif  /* __GNUC__ >= 4 */
 103  119  
 104  120  /*
 105  121   * C99 7.12.14 comparison macros
 106  122   */
 107  123  #undef  isgreater
 108  124  #define isgreater(x, y)         __builtin_isgreater(x, y)
 109  125  #undef  isgreaterequal
 110  126  #define isgreaterequal(x, y)    __builtin_isgreaterequal(x, y)
 111  127  #undef  isless
 112  128  #define isless(x, y)            __builtin_isless(x, y)
↓ open down ↓ 61 lines elided ↑ open up ↑
 174  190  #elif __FLT_EVAL_METHOD__ - 0 == 2
 175  191  typedef long double float_t;
 176  192  typedef long double double_t;
 177  193  #elif defined(__sparc) || defined(__amd64)
 178  194  typedef float float_t;
 179  195  typedef double double_t;
 180  196  #elif defined(__i386)
 181  197  typedef long double float_t;
 182  198  typedef long double double_t;
 183  199  #endif
 184      -
 185      -#undef  FP_ZERO
 186      -#define FP_ZERO         0
 187      -#undef  FP_SUBNORMAL
 188      -#define FP_SUBNORMAL    1
 189      -#undef  FP_NORMAL
 190      -#define FP_NORMAL       2
 191      -#undef  FP_INFINITE
 192      -#define FP_INFINITE     3
 193      -#undef  FP_NAN
 194      -#define FP_NAN          4
 195  200  
 196  201  #undef  FP_ILOGB0
 197  202  #define FP_ILOGB0       (-2147483647)
 198  203  #undef  FP_ILOGBNAN
 199  204  #define FP_ILOGBNAN     2147483647
 200  205  
 201  206  #undef  MATH_ERRNO
 202  207  #define MATH_ERRNO      1
 203  208  #undef  MATH_ERREXCEPT
 204  209  #define MATH_ERREXCEPT  2
↓ open down ↓ 318 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX