Print this page
11210 libm should be cstyle(1ONBLD) clean

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libm/common/m9x/lrintl.c
          +++ new/usr/src/lib/libm/common/m9x/lrintl.c
↓ open down ↓ 14 lines elided ↑ open up ↑
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  24   24   */
       25 +
  25   26  /*
  26   27   * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  27   28   * Use is subject to license terms.
  28   29   */
  29   30  
  30   31  #pragma weak __lrintl = lrintl
  31   32  
  32      -#include <sys/isa_defs.h>       /* _ILP32 */
       33 +#include <sys/isa_defs.h>               /* _ILP32 */
  33   34  #include "libm.h"
  34   35  
  35   36  #if defined(_ILP32)
  36   37  #if defined(__sparc)
  37      -
  38   38  #include "fma.h"
  39   39  #include "fenv_inlines.h"
  40   40  
  41   41  long
  42      -lrintl(long double x) {
       42 +lrintl(long double x)
       43 +{
  43   44          union {
  44   45                  unsigned int i[4];
  45   46                  long double q;
  46   47          } xx;
  47   48          union {
  48   49                  unsigned int i;
  49   50                  float f;
  50   51          } tt;
       52 +
  51   53          unsigned int hx, sx, frac, l, fsr;
  52   54          int rm, j;
  53   55          volatile float dummy;
  54   56  
  55   57          xx.q = x;
  56   58          sx = xx.i[0] & 0x80000000;
  57   59          hx = xx.i[0] & ~0x80000000;
  58   60  
  59   61          /* handle trivial cases */
  60      -        if (hx > 0x401e0000) { /* |x| > 2^31 + ... or x is nan */
       62 +        if (hx > 0x401e0000) {          /* |x| > 2^31 + ... or x is nan */
  61   63                  /* convert an out-of-range float */
  62   64                  tt.i = sx | 0x7f000000;
  63      -                return ((long) tt.f);
  64      -        } else if ((hx | xx.i[1] | xx.i[2] | xx.i[3]) == 0) /* x is zero */
       65 +                return ((long)tt.f);
       66 +        } else if ((hx | xx.i[1] | xx.i[2] | xx.i[3]) == 0) {   /* x is zero */
  65   67                  return (0L);
       68 +        }
  66   69  
  67   70          /* get the rounding mode */
  68   71          __fenv_getfsr32(&fsr);
  69   72          rm = fsr >> 30;
  70   73  
  71   74          /* flip the sense of directed roundings if x is negative */
  72   75          if (sx)
  73   76                  rm ^= rm >> 1;
  74   77  
  75   78          /* handle |x| < 1 */
  76   79          if (hx < 0x3fff0000) {
  77      -                dummy = 1.0e30F; /* x is nonzero, so raise inexact */
       80 +                dummy = 1.0e30F;        /* x is nonzero, so raise inexact */
  78   81                  dummy += 1.0e-30F;
  79      -                if (rm == FSR_RP || (rm == FSR_RN && (hx >= 0x3ffe0000 &&
  80      -                        ((hx & 0xffff) | xx.i[1] | xx.i[2] | xx.i[3]))))
       82 +
       83 +                if (rm == FSR_RP || (rm == FSR_RN && (hx >= 0x3ffe0000 && ((hx &
       84 +                    0xffff) | xx.i[1] | xx.i[2] | xx.i[3]))))
  81   85                          return (sx ? -1L : 1L);
       86 +
  82   87                  return (0L);
  83   88          }
  84   89  
  85   90          /* extract the integer and fractional parts of x */
  86      -        j = 0x406f - (hx >> 16);                /* 91 <= j <= 112 */
       91 +        j = 0x406f - (hx >> 16);        /* 91 <= j <= 112 */
  87   92          xx.i[0] = 0x10000 | (xx.i[0] & 0xffff);
  88      -        if (j >= 96) {                          /* 96 <= j <= 112 */
       93 +
       94 +        if (j >= 96) {                  /* 96 <= j <= 112 */
  89   95                  l = xx.i[0] >> (j - 96);
  90   96                  frac = ((xx.i[0] << 1) << (127 - j)) | (xx.i[1] >> (j - 96));
       97 +
  91   98                  if (((xx.i[1] << 1) << (127 - j)) | xx.i[2] | xx.i[3])
  92   99                          frac |= 1;
  93      -        } else {                                /* 91 <= j <= 95 */
      100 +        } else {                        /* 91 <= j <= 95 */
  94  101                  l = (xx.i[0] << (96 - j)) | (xx.i[1] >> (j - 64));
  95  102                  frac = (xx.i[1] << (96 - j)) | (xx.i[2] >> (j - 64));
      103 +
  96  104                  if ((xx.i[2] << (96 - j)) | xx.i[3])
  97  105                          frac |= 1;
  98  106          }
  99  107  
 100  108          /* round */
 101  109          if (frac && (rm == FSR_RP || (rm == FSR_RN && (frac > 0x80000000U ||
 102      -                (frac == 0x80000000 && (l & 1))))))
      110 +            (frac == 0x80000000 && (l & 1))))))
 103  111                  l++;
 104  112  
 105  113          /* check for result out of range (note that z is |x| at this point) */
 106  114          if (l > 0x80000000U || (l == 0x80000000U && !sx)) {
 107  115                  tt.i = sx | 0x7f000000;
 108      -                return ((long) tt.f);
      116 +                return ((long)tt.f);
 109  117          }
 110  118  
 111  119          /* raise inexact if need be */
 112  120          if (frac) {
 113  121                  dummy = 1.0e30F;
 114  122                  dummy += 1.0e-30F;
 115  123          }
 116  124  
 117  125          /* negate result if need be */
 118  126          if (sx)
 119  127                  l = -l;
 120      -        return ((long) l);
      128 +
      129 +        return ((long)l);
 121  130  }
 122  131  #elif defined(__x86)
 123  132  long
 124      -lrintl(long double x) {
      133 +lrintl(long double x)
      134 +{
 125  135          /*
 126  136           * Note: The following code works on x86 (in the default rounding
 127  137           * precision mode), but one ought to just use the fistpl instruction
 128  138           * instead.
 129  139           */
 130  140          union {
 131  141                  unsigned i[3];
 132  142                  long double e;
 133  143          } xx, yy;
      144 +
 134  145          int ex;
 135  146  
 136  147          xx.e = x;
 137  148          ex = xx.i[2] & 0x7fff;
 138      -        if (ex < 0x403e) {      /* |x| < 2^63 */
      149 +
      150 +        if (ex < 0x403e) {              /* |x| < 2^63 */
 139  151                  /* add and subtract a power of two to round x to an integer */
 140  152                  yy.i[2] = (xx.i[2] & 0x8000) | 0x403e;
 141  153                  yy.i[1] = 0x80000000;
 142  154                  yy.i[0] = 0;
 143  155                  x = (x + yy.e) - yy.e;
 144  156          }
 145  157  
 146  158          /* now x is nan, inf, or integral */
 147      -        return ((long) x);
      159 +        return ((long)x);
 148  160  }
 149  161  #else
 150  162  #error Unknown architecture
 151      -#endif  /* defined(__sparc) || defined(__x86) */
      163 +#endif /* defined(__sparc) || defined(__x86) */
 152  164  #else
 153  165  #error Unsupported architecture
 154      -#endif  /* defined(_ILP32) */
      166 +#endif /* defined(_ILP32) */
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX