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

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