.
[kopensolaris-gnu/glibc.git] / soft-fp / op-1.h
index 48bf4ce..35cd0ba 100644 (file)
@@ -1,6 +1,6 @@
 /* Software floating-point emulation.
    Basic one-word fraction declaration and manipulation.
-   Copyright (C) 1997,1998,1999 Free Software Foundation, Inc.
+   Copyright (C) 1997,1998,1999,2006 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Richard Henderson (rth@cygnus.com),
                  Jakub Jelinek (jj@ultra.linux.cz),
@@ -8,19 +8,28 @@
                  Peter Maydell (pmaydell@chiark.greenend.org.uk).
 
    The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Library General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   In addition to the permissions in the GNU Lesser General Public
+   License, the Free Software Foundation gives you unlimited
+   permission to link the compiled version of this file into
+   combinations with other programs, and to distribute those
+   combinations without any restriction coming from the use of this
+   file.  (The Lesser General Public License restrictions do apply in
+   other respects; for example, they cover modification of the file,
+   and distribution when not linked into a combine executable.)
 
    The GNU C Library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Library General Public License for more details.
+   Lesser General Public License for more details.
 
-   You should have received a copy of the GNU Library General Public
-   License along with the GNU C Library; see the file COPYING.LIB.  If
-   not, write to the Free Software Foundation, Inc.,
-   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
+   MA 02110-1301, USA.  */
 
 #define _FP_FRAC_DECL_1(X)     _FP_W_TYPE X##_f
 #define _FP_FRAC_COPY_1(D,S)   (D##_f = S##_f)
 #define _FP_FRAC_SRL_1(X,N)    (X##_f >>= N)
 
 /* Right shift with sticky-lsb.  */
+#define _FP_FRAC_SRST_1(X,S,N,sz)      __FP_FRAC_SRST_1(X##_f, S, N, sz)
 #define _FP_FRAC_SRS_1(X,N,sz) __FP_FRAC_SRS_1(X##_f, N, sz)
 
+#define __FP_FRAC_SRST_1(X,S,N,sz)                     \
+do {                                                   \
+  S = (__builtin_constant_p(N) && (N) == 1             \
+       ? X & 1 : (X << (_FP_W_TYPE_SIZE - (N))) != 0); \
+  X = X >> (N);                                                \
+} while (0)
+
 #define __FP_FRAC_SRS_1(X,N,sz)                                                \
    (X = (X >> (N) | (__builtin_constant_p(N) && (N) == 1               \
                     ? X & 1 : (X << (_FP_W_TYPE_SIZE - (N))) != 0)))
@@ -55,6 +72,7 @@
 #define _FP_FRAC_NEGP_1(X)     ((_FP_WS_TYPE)X##_f < 0)
 #define _FP_FRAC_ZEROP_1(X)    (X##_f == 0)
 #define _FP_FRAC_OVERP_1(fs,X) (X##_f & _FP_OVERFLOW_##fs)
+#define _FP_FRAC_CLEAR_OVERP_1(fs,X)   (X##_f &= ~_FP_OVERFLOW_##fs)
 #define _FP_FRAC_EQ_1(X, Y)    (X##_f == Y##_f)
 #define _FP_FRAC_GE_1(X, Y)    (X##_f >= Y##_f)
 #define _FP_FRAC_GT_1(X, Y)    (X##_f > Y##_f)
 
 #define _FP_DIV_MEAT_1_udiv_norm(fs, R, X, Y)                          \
   do {                                                                 \
-    _FP_W_TYPE _nh, _nl, _q, _r;                                       \
+    _FP_W_TYPE _nh, _nl, _q, _r, _y;                                   \
                                                                        \
     /* Normalize Y -- i.e. make the most significant bit set.  */      \
-    Y##_f <<= _FP_WFRACXBITS_##fs - 1;                                 \
+    _y = Y##_f << _FP_WFRACXBITS_##fs;                                 \
                                                                        \
     /* Shift X op correspondingly high, that is, up one full word.  */ \
-    if (X##_f <= Y##_f)                                                        \
+    if (X##_f < Y##_f)                                                 \
       {                                                                        \
+       R##_e--;                                                        \
        _nl = 0;                                                        \
        _nh = X##_f;                                                    \
       }                                                                        \
     else                                                               \
       {                                                                        \
-       R##_e++;                                                        \
-       _nl = X##_f << (_FP_W_TYPE_SIZE-1);                             \
+       _nl = X##_f << (_FP_W_TYPE_SIZE - 1);                           \
        _nh = X##_f >> 1;                                               \
       }                                                                        \
                                                                        \
-    udiv_qrnnd(_q, _r, _nh, _nl, Y##_f);                               \
+    udiv_qrnnd(_q, _r, _nh, _nl, _y);                                  \
     R##_f = _q | (_r != 0);                                            \
   } while (0)
 
  * Convert FP values between word sizes
  */
 
-#define _FP_FRAC_CONV_1_1(dfs, sfs, D, S)                              \
-  do {                                                                 \
-    D##_f = S##_f;                                                     \
-    if (_FP_WFRACBITS_##sfs > _FP_WFRACBITS_##dfs)                     \
-      {                                                                        \
-       if (S##_c != FP_CLS_NAN)                                        \
-         _FP_FRAC_SRS_1(D, (_FP_WFRACBITS_##sfs-_FP_WFRACBITS_##dfs),  \
-                        _FP_WFRACBITS_##sfs);                          \
-       else                                                            \
-         _FP_FRAC_SRL_1(D, (_FP_WFRACBITS_##sfs-_FP_WFRACBITS_##dfs)); \
-      }                                                                        \
-    else                                                               \
-      D##_f <<= _FP_WFRACBITS_##dfs - _FP_WFRACBITS_##sfs;             \
-  } while (0)
+#define _FP_FRAC_COPY_1_1(D, S)                (D##_f = S##_f)