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

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libm/common/m9x/llroundl.c
          +++ new/usr/src/lib/libm/common/m9x/llroundl.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 __llroundl = llroundl
  31   32  #if defined(__sparcv9) || defined(__amd64)
  32   33  #pragma weak lroundl = llroundl
  33   34  #pragma weak __lroundl = llroundl
  34   35  #endif
  35   36  
  36   37  #include "libm.h"
  37   38  
  38   39  #if defined(__sparc)
  39   40  long long
  40      -llroundl(long double x) {
       41 +llroundl(long double x)
       42 +{
  41   43          union {
  42   44                  unsigned i[4];
  43   45                  long double q;
  44   46          } xx;
  45   47          union {
  46   48                  unsigned i[2];
  47   49                  long long l;
  48   50          } zz;
  49   51          union {
  50   52                  unsigned i;
  51   53                  float f;
  52   54          } tt;
       55 +
  53   56          unsigned hx, sx, frac;
  54   57          int j;
  55   58  
  56   59          xx.q = x;
  57   60          sx = xx.i[0] & 0x80000000;
  58   61          hx = xx.i[0] & ~0x80000000;
  59   62  
  60   63          /* handle trivial cases */
  61      -        if (hx > 0x403e0000) { /* |x| > 2^63 + ... or x is nan */
       64 +        if (hx > 0x403e0000) {          /* |x| > 2^63 + ... or x is nan */
  62   65                  /* convert an out-of-range float */
  63   66                  tt.i = sx | 0x7f000000;
  64      -                return ((long long) tt.f);
       67 +                return ((long long)tt.f);
  65   68          }
  66   69  
  67   70          /* handle |x| < 1 */
  68   71          if (hx < 0x3fff0000) {
  69   72                  if (hx >= 0x3ffe0000)
  70   73                          return (sx ? -1LL : 1LL);
       74 +
  71   75                  return (0LL);
  72   76          }
  73   77  
  74   78          /* extract the integer and fractional parts of x */
  75   79          j = 0x406f - (hx >> 16);
  76   80          xx.i[0] = 0x10000 | (xx.i[0] & 0xffff);
       81 +
  77   82          if (j >= 96) {
  78   83                  zz.i[0] = 0;
  79   84                  zz.i[1] = xx.i[0] >> (j - 96);
  80   85                  frac = ((xx.i[0] << 1) << (127 - j)) | (xx.i[1] >> (j - 96));
       86 +
  81   87                  if (((xx.i[1] << 1) << (127 - j)) | xx.i[2] | xx.i[3])
  82   88                          frac |= 1;
  83   89          } else if (j >= 64) {
  84   90                  zz.i[0] = xx.i[0] >> (j - 64);
  85   91                  zz.i[1] = ((xx.i[0] << 1) << (95 - j)) | (xx.i[1] >> (j - 64));
  86   92                  frac = ((xx.i[1] << 1) << (95 - j)) | (xx.i[2] >> (j - 64));
       93 +
  87   94                  if (((xx.i[2] << 1) << (95 - j)) | xx.i[3])
  88   95                          frac |= 1;
  89   96          } else {
  90   97                  zz.i[0] = ((xx.i[0] << 1) << (63 - j)) | (xx.i[1] >> (j - 32));
  91   98                  zz.i[1] = ((xx.i[1] << 1) << (63 - j)) | (xx.i[2] >> (j - 32));
  92   99                  frac = ((xx.i[2] << 1) << (63 - j)) | (xx.i[3] >> (j - 32));
      100 +
  93  101                  if ((xx.i[3] << 1) << (63 - j))
  94  102                          frac |= 1;
  95  103          }
  96  104  
  97  105          /* round */
  98  106          if (frac >= 0x80000000u) {
  99  107                  if (++zz.i[1] == 0)
 100  108                          zz.i[0]++;
 101  109          }
 102  110  
 103  111          /* check for result out of range (note that z is |x| at this point) */
 104  112          if (zz.i[0] > 0x80000000u || (zz.i[0] == 0x80000000 && (zz.i[1] ||
 105      -                !sx))) {
      113 +            !sx))) {
 106  114                  tt.i = sx | 0x7f000000;
 107      -                return ((long long) tt.f);
      115 +                return ((long long)tt.f);
 108  116          }
 109  117  
 110  118          /* negate result if need be */
 111  119          if (sx) {
 112  120                  zz.i[0] = ~zz.i[0];
 113  121                  zz.i[1] = -zz.i[1];
      122 +
 114  123                  if (zz.i[1] == 0)
 115  124                          zz.i[0]++;
 116  125          }
 117  126  
 118  127          return (zz.l);
 119  128  }
 120  129  #elif defined(__x86)
 121  130  long long
 122      -llroundl(long double x) {
      131 +llroundl(long double x)
      132 +{
 123  133          union {
 124  134                  unsigned i[3];
 125  135                  long double e;
 126  136          } xx;
      137 +
 127  138          int ex, sx, i;
 128  139  
 129  140          xx.e = x;
 130  141          ex = xx.i[2] & 0x7fff;
 131  142          sx = xx.i[2] & 0x8000;
 132  143  
 133      -        if (ex < 0x403e) { /* |x| < 2^63 */
      144 +        if (ex < 0x403e) {              /* |x| < 2^63 */
 134  145                  /* handle |x| < 1 */
 135  146                  if (ex < 0x3fff) {
 136  147                          if (ex >= 0x3ffe)
 137  148                                  return (sx ? -1LL : 1LL);
      149 +
 138  150                          return (0LL);
 139  151                  }
 140  152  
 141  153                  /* round x at the integer bit */
 142  154                  if (ex < 0x401e) {
 143  155                          i = 1 << (0x401d - ex);
 144  156                          xx.i[1] = (xx.i[1] + i) & ~(i | (i - 1));
 145  157                          xx.i[0] = 0;
 146  158                  } else {
 147  159                          i = 1 << (0x403d - ex);
 148  160                          xx.i[0] += i;
      161 +
 149  162                          if (xx.i[0] < i)
 150  163                                  xx.i[1]++;
      164 +
 151  165                          xx.i[0] &= ~(i | (i - 1));
 152  166                  }
      167 +
 153  168                  if (xx.i[1] == 0) {
 154  169                          xx.i[2] = sx | ++ex;
 155  170                          xx.i[1] = 0x80000000U;
 156  171                  }
 157  172          }
 158  173  
 159  174          /* now x is nan, inf, or integral */
 160      -        return ((long long) xx.e);
      175 +        return ((long long)xx.e);
 161  176  }
 162  177  #else
 163  178  #error Unknown architecture
 164  179  #endif
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX