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

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libm/common/m9x/llrintl.c
          +++ new/usr/src/lib/libm/common/m9x/llrintl.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 __llrintl = llrintl
  31   32  #if defined(__sparcv9) || defined(__amd64)
  32   33  #pragma weak lrintl = llrintl
  33   34  #pragma weak __lrintl = llrintl
  34   35  #endif
  35   36  
  36   37  #include "libm.h"
  37   38  
  38   39  #if defined(__sparc)
  39      -
  40   40  #include "fma.h"
  41   41  #include "fenv_inlines.h"
  42   42  
  43   43  long long
  44      -llrintl(long double x) {
       44 +llrintl(long double x)
       45 +{
  45   46          union {
  46   47                  unsigned i[4];
  47   48                  long double q;
  48   49          } xx;
  49   50          union {
  50   51                  unsigned i[2];
  51   52                  long long l;
  52   53          } zz;
  53   54          union {
  54   55                  unsigned i;
  55   56                  float f;
  56   57          } tt;
       58 +
  57   59          unsigned int hx, sx, frac, fsr;
  58   60          int rm, j;
  59   61          volatile float dummy;
  60   62  
  61   63          xx.q = x;
  62   64          sx = xx.i[0] & 0x80000000;
  63   65          hx = xx.i[0] & ~0x80000000;
  64   66  
  65   67          /* handle trivial cases */
  66      -        if (hx > 0x403e0000) { /* |x| > 2^63 + ... or x is nan */
       68 +        if (hx > 0x403e0000) {          /* |x| > 2^63 + ... or x is nan */
  67   69                  /* convert an out-of-range float */
  68   70                  tt.i = sx | 0x7f000000;
  69      -                return ((long long) tt.f);
  70      -        } else if ((hx | xx.i[1] | xx.i[2] | xx.i[3]) == 0) /* x is zero */
       71 +                return ((long long)tt.f);
       72 +        } else if ((hx | xx.i[1] | xx.i[2] | xx.i[3]) == 0) {   /* x is zero */
  71   73                  return (0LL);
       74 +        }
  72   75  
  73   76          /* get the rounding mode */
  74   77          __fenv_getfsr32(&fsr);
  75   78          rm = fsr >> 30;
  76   79  
  77   80          /* flip the sense of directed roundings if x is negative */
  78   81          if (sx)
  79   82                  rm ^= rm >> 1;
  80   83  
  81   84          /* handle |x| < 1 */
  82   85          if (hx < 0x3fff0000) {
  83      -                dummy = 1.0e30f; /* x is nonzero, so raise inexact */
       86 +                dummy = 1.0e30f;        /* x is nonzero, so raise inexact */
  84   87                  dummy += 1.0e-30f;
  85      -                if (rm == FSR_RP || (rm == FSR_RN && (hx >= 0x3ffe0000 &&
  86      -                        ((hx & 0xffff) | xx.i[1] | xx.i[2] | xx.i[3]))))
       88 +
       89 +                if (rm == FSR_RP || (rm == FSR_RN && (hx >= 0x3ffe0000 && ((hx &
       90 +                    0xffff) | xx.i[1] | xx.i[2] | xx.i[3]))))
  87   91                          return (sx ? -1LL : 1LL);
       92 +
  88   93                  return (0LL);
  89   94          }
  90   95  
  91   96          /* extract the integer and fractional parts of x */
  92   97          j = 0x406f - (hx >> 16);
  93   98          xx.i[0] = 0x10000 | (xx.i[0] & 0xffff);
       99 +
  94  100          if (j >= 96) {
  95  101                  zz.i[0] = 0;
  96  102                  zz.i[1] = xx.i[0] >> (j - 96);
  97  103                  frac = ((xx.i[0] << 1) << (127 - j)) | (xx.i[1] >> (j - 96));
      104 +
  98  105                  if (((xx.i[1] << 1) << (127 - j)) | xx.i[2] | xx.i[3])
  99  106                          frac |= 1;
 100  107          } else if (j >= 64) {
 101  108                  zz.i[0] = xx.i[0] >> (j - 64);
 102  109                  zz.i[1] = ((xx.i[0] << 1) << (95 - j)) | (xx.i[1] >> (j - 64));
 103  110                  frac = ((xx.i[1] << 1) << (95 - j)) | (xx.i[2] >> (j - 64));
      111 +
 104  112                  if (((xx.i[2] << 1) << (95 - j)) | xx.i[3])
 105  113                          frac |= 1;
 106  114          } else {
 107  115                  zz.i[0] = ((xx.i[0] << 1) << (63 - j)) | (xx.i[1] >> (j - 32));
 108  116                  zz.i[1] = ((xx.i[1] << 1) << (63 - j)) | (xx.i[2] >> (j - 32));
 109  117                  frac = ((xx.i[2] << 1) << (63 - j)) | (xx.i[3] >> (j - 32));
      118 +
 110  119                  if ((xx.i[3] << 1) << (63 - j))
 111  120                          frac |= 1;
 112  121          }
 113  122  
 114  123          /* round */
 115  124          if (frac && (rm == FSR_RP || (rm == FSR_RN && (frac > 0x80000000u ||
 116      -                (frac == 0x80000000 && (zz.i[1] & 1)))))) {
      125 +            (frac == 0x80000000 && (zz.i[1] & 1)))))) {
 117  126                  if (++zz.i[1] == 0)
 118  127                          zz.i[0]++;
 119  128          }
 120  129  
 121  130          /* check for result out of range (note that z is |x| at this point) */
 122  131          if (zz.i[0] > 0x80000000u || (zz.i[0] == 0x80000000 && (zz.i[1] ||
 123      -                !sx))) {
      132 +            !sx))) {
 124  133                  tt.i = sx | 0x7f000000;
 125      -                return ((long long) tt.f);
      134 +                return ((long long)tt.f);
 126  135          }
 127  136  
 128  137          /* raise inexact if need be */
 129  138          if (frac) {
 130  139                  dummy = 1.0e30F;
 131  140                  dummy += 1.0e-30F;
 132  141          }
 133  142  
 134  143          /* negate result if need be */
 135  144          if (sx) {
 136  145                  zz.i[0] = ~zz.i[0];
 137  146                  zz.i[1] = -zz.i[1];
      147 +
 138  148                  if (zz.i[1] == 0)
 139  149                          zz.i[0]++;
 140  150          }
      151 +
 141  152          return (zz.l);
 142  153  }
 143  154  #elif defined(__x86)
 144  155  long long
 145      -llrintl(long double x) {
      156 +llrintl(long double x)
      157 +{
 146  158          /*
 147  159           * Note: The following code works on x86 (in the default rounding
 148  160           * precision mode), but one ought to just use the fistpll instruction
 149  161           * instead.
 150  162           */
 151  163          union {
 152  164                  unsigned i[3];
 153  165                  long double e;
 154  166          } xx, yy;
      167 +
 155  168          int ex;
 156  169  
 157  170          xx.e = x;
 158  171          ex = xx.i[2] & 0x7fff;
 159  172  
 160      -        if (ex < 0x403e) { /* |x| < 2^63 */
      173 +        if (ex < 0x403e) {              /* |x| < 2^63 */
 161  174                  /* add and subtract a power of two to round x to an integer */
 162  175                  yy.i[2] = (xx.i[2] & 0x8000) | 0x403e;
 163  176                  yy.i[1] = 0x80000000;
 164  177                  yy.i[0] = 0;
 165  178                  x = (x + yy.e) - yy.e;
 166  179          }
 167  180  
 168  181          /* now x is nan, inf, or integral */
 169      -        return ((long long) x);
      182 +        return ((long long)x);
 170  183  }
 171  184  #else
 172  185  #error Unknown architecture
 173  186  #endif
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX