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

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libm/common/m9x/nearbyintl.c
          +++ new/usr/src/lib/libm/common/m9x/nearbyintl.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 nearbyintl = __nearbyintl
  31   32  
  32   33  #include "libm.h"
  33   34  #include "fma.h"
  34   35  #include "fenv_inlines.h"
  35   36  
  36   37  #if defined(__sparc)
  37      -
  38   38  static union {
  39   39          unsigned i;
  40   40          float f;
  41   41  } snan = { 0x7f800001 };
  42      -
  43   42  long double
  44      -__nearbyintl(long double x) {
       43 +__nearbyintl(long double x)
       44 +{
  45   45          union {
  46   46                  unsigned i[4];
  47   47                  long double q;
  48   48          } xx;
       49 +
  49   50          unsigned hx, sx, i, frac;
  50   51          unsigned int fsr;
  51   52          int rm, j;
  52      -        volatile float  dummy;
       53 +        volatile float dummy;
  53   54  
  54   55          xx.q = x;
  55   56          sx = xx.i[0] & 0x80000000;
  56   57          hx = xx.i[0] & ~0x80000000;
  57   58  
  58   59          /* handle trivial cases */
  59      -        if (hx >= 0x406f0000) { /* x is nan, inf, or already integral */
       60 +        if (hx >= 0x406f0000) {         /* x is nan, inf, or already integral */
  60   61                  /* check for signaling nan */
  61      -                if ((hx > 0x7fff0000 || (hx == 0x7fff0000 &&
  62      -                        (xx.i[1] | xx.i[2] | xx.i[3]))) && !(hx & 0x8000)) {
       62 +                if ((hx > 0x7fff0000 || (hx == 0x7fff0000 && (xx.i[1] |
       63 +                    xx.i[2] | xx.i[3]))) && !(hx & 0x8000)) {
  63   64                          dummy = snan.f;
  64   65                          dummy += snan.f;
  65   66                          xx.i[0] = sx | hx | 0x8000;
  66   67                  }
       68 +
  67   69                  return (xx.q);
  68      -        } else if ((hx | xx.i[1] | xx.i[2] | xx.i[3]) == 0)     /* x is zero */
       70 +        } else if ((hx | xx.i[1] | xx.i[2] | xx.i[3]) == 0) {   /* x is zero */
  69   71                  return (x);
       72 +        }
  70   73  
  71   74          /* get the rounding mode */
  72   75          __fenv_getfsr32(&fsr);
  73   76          rm = fsr >> 30;
  74   77  
  75   78          /* flip the sense of directed roundings if x is negative */
  76   79          if (sx)
  77   80                  rm ^= rm >> 1;
  78   81  
  79   82          /* handle |x| < 1 */
  80   83          if (hx < 0x3fff0000) {
  81      -                if (rm == FSR_RP || (rm == FSR_RN && (hx >= 0x3ffe0000 &&
  82      -                        ((hx & 0xffff) | xx.i[1] | xx.i[2] | xx.i[3]))))
       84 +                if (rm == FSR_RP || (rm == FSR_RN && (hx >= 0x3ffe0000 && ((hx &
       85 +                    0xffff) | xx.i[1] | xx.i[2] | xx.i[3]))))
  83   86                          xx.i[0] = sx | 0x3fff0000;
  84   87                  else
  85   88                          xx.i[0] = sx;
       89 +
  86   90                  xx.i[1] = xx.i[2] = xx.i[3] = 0;
  87   91                  return (xx.q);
  88   92          }
  89   93  
  90   94          /* round x at the integer bit */
  91   95          j = 0x406f - (hx >> 16);
       96 +
  92   97          if (j >= 96) {
  93   98                  i = 1 << (j - 96);
  94   99                  frac = ((xx.i[0] << 1) << (127 - j)) | (xx.i[1] >> (j - 96));
      100 +
  95  101                  if ((xx.i[1] & (i - 1)) | xx.i[2] | xx.i[3])
  96  102                          frac |= 1;
      103 +
  97  104                  if (!frac)
  98  105                          return (x);
      106 +
  99  107                  xx.i[1] = xx.i[2] = xx.i[3] = 0;
 100  108                  xx.i[0] &= ~(i - 1);
      109 +
 101  110                  if (rm == FSR_RP || (rm == FSR_RN && (frac > 0x80000000u ||
 102      -                        (frac == 0x80000000 && (xx.i[0] & i)))))
      111 +                    (frac == 0x80000000 && (xx.i[0] & i)))))
 103  112                          xx.i[0] += i;
 104  113          } else if (j >= 64) {
 105  114                  i = 1 << (j - 64);
 106  115                  frac = ((xx.i[1] << 1) << (95 - j)) | (xx.i[2] >> (j - 64));
      116 +
 107  117                  if ((xx.i[2] & (i - 1)) | xx.i[3])
 108  118                          frac |= 1;
      119 +
 109  120                  if (!frac)
 110  121                          return (x);
      122 +
 111  123                  xx.i[2] = xx.i[3] = 0;
 112  124                  xx.i[1] &= ~(i - 1);
      125 +
 113  126                  if (rm == FSR_RP || (rm == FSR_RN && (frac > 0x80000000u ||
 114      -                        (frac == 0x80000000 && (xx.i[1] & i))))) {
      127 +                    (frac == 0x80000000 && (xx.i[1] & i))))) {
 115  128                          xx.i[1] += i;
      129 +
 116  130                          if (xx.i[1] == 0)
 117  131                                  xx.i[0]++;
 118  132                  }
 119  133          } else if (j >= 32) {
 120  134                  i = 1 << (j - 32);
 121  135                  frac = ((xx.i[2] << 1) << (63 - j)) | (xx.i[3] >> (j - 32));
      136 +
 122  137                  if (xx.i[3] & (i - 1))
 123  138                          frac |= 1;
      139 +
 124  140                  if (!frac)
 125  141                          return (x);
      142 +
 126  143                  xx.i[3] = 0;
 127  144                  xx.i[2] &= ~(i - 1);
      145 +
 128  146                  if (rm == FSR_RP || (rm == FSR_RN && (frac > 0x80000000u ||
 129      -                        (frac == 0x80000000 && (xx.i[2] & i))))) {
      147 +                    (frac == 0x80000000 && (xx.i[2] & i))))) {
 130  148                          xx.i[2] += i;
      149 +
 131  150                          if (xx.i[2] == 0)
 132  151                                  if (++xx.i[1] == 0)
 133  152                                          xx.i[0]++;
 134  153                  }
 135  154          } else {
 136  155                  i = 1 << j;
 137  156                  frac = (xx.i[3] << 1) << (31 - j);
      157 +
 138  158                  if (!frac)
 139  159                          return (x);
      160 +
 140  161                  xx.i[3] &= ~(i - 1);
      162 +
 141  163                  if (rm == FSR_RP || (rm == FSR_RN && (frac > 0x80000000u ||
 142      -                        (frac == 0x80000000 && (xx.i[3] & i))))) {
      164 +                    (frac == 0x80000000 && (xx.i[3] & i))))) {
 143  165                          xx.i[3] += i;
      166 +
 144  167                          if (xx.i[3] == 0)
 145  168                                  if (++xx.i[2] == 0)
 146  169                                          if (++xx.i[1] == 0)
 147  170                                                  xx.i[0]++;
 148  171                  }
 149  172          }
 150  173  
 151  174          return (xx.q);
 152  175  }
 153      -
 154  176  #elif defined(__x86)
 155      -
 156  177  /* inline template */
 157  178  extern long double frndint(long double);
 158      -
 159  179  long double
 160      -__nearbyintl(long double x) {
      180 +__nearbyintl(long double x)
      181 +{
 161  182          long double z;
 162  183          unsigned oldcwsw, cwsw;
 163  184  
 164  185          /* save the control and status words, mask the inexact exception */
 165  186          __fenv_getcwsw(&oldcwsw);
 166  187          cwsw = oldcwsw | 0x00200000;
 167  188          __fenv_setcwsw(&cwsw);
 168  189  
 169  190          z = frndint(x);
 170  191  
 171  192          /*
 172  193           * restore the control and status words, preserving all but the
 173  194           * inexact flag
 174  195           */
 175  196          __fenv_getcwsw(&cwsw);
 176  197          oldcwsw |= (cwsw & 0x1f);
 177  198          __fenv_setcwsw(&oldcwsw);
 178  199  
 179  200          return (z);
 180  201  }
 181      -
 182  202  #else
 183  203  #error Unknown architecture
 184  204  #endif
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX