Back to home page

OSCL-LXR

 
 

    


0001 /* Software floating-point emulation.
0002    Basic eight-word fraction declaration and manipulation.
0003    Copyright (C) 1997,1998,1999 Free Software Foundation, Inc.
0004    This file is part of the GNU C Library.
0005    Contributed by Richard Henderson (rth@cygnus.com),
0006           Jakub Jelinek (jj@ultra.linux.cz) and
0007           Peter Maydell (pmaydell@chiark.greenend.org.uk).
0008                                                          
0009    The GNU C Library is free software; you can redistribute it and/or
0010    modify it under the terms of the GNU Library General Public License as
0011    published by the Free Software Foundation; either version 2 of the
0012    License, or (at your option) any later version.
0013 
0014    The GNU C Library is distributed in the hope that it will be useful,
0015    but WITHOUT ANY WARRANTY; without even the implied warranty of
0016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0017    Library General Public License for more details.
0018 
0019    You should have received a copy of the GNU Library General Public
0020    License along with the GNU C Library; see the file COPYING.LIB.  If
0021    not, write to the Free Software Foundation, Inc.,
0022    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
0023 
0024 #ifndef __MATH_EMU_OP_8_H__
0025 #define __MATH_EMU_OP_8_H__
0026 
0027 /* We need just a few things from here for op-4, if we ever need some
0028    other macros, they can be added. */
0029 #define _FP_FRAC_DECL_8(X)  _FP_W_TYPE X##_f[8]
0030 #define _FP_FRAC_HIGH_8(X)  (X##_f[7])
0031 #define _FP_FRAC_LOW_8(X)   (X##_f[0])
0032 #define _FP_FRAC_WORD_8(X,w)    (X##_f[w])
0033 
0034 #define _FP_FRAC_SLL_8(X,N)                     \
0035   do {                                  \
0036     _FP_I_TYPE _up, _down, _skip, _i;                   \
0037     _skip = (N) / _FP_W_TYPE_SIZE;                  \
0038     _up = (N) % _FP_W_TYPE_SIZE;                    \
0039     _down = _FP_W_TYPE_SIZE - _up;                  \
0040     if (!_up)                               \
0041       for (_i = 7; _i >= _skip; --_i)                   \
0042     X##_f[_i] = X##_f[_i-_skip];                    \
0043     else                                \
0044       {                                 \
0045     for (_i = 7; _i > _skip; --_i)                  \
0046       X##_f[_i] = X##_f[_i-_skip] << _up                \
0047               | X##_f[_i-_skip-1] >> _down;         \
0048     X##_f[_i--] = X##_f[0] << _up;                  \
0049       }                                 \
0050     for (; _i >= 0; --_i)                       \
0051       X##_f[_i] = 0;                            \
0052   } while (0)
0053 
0054 #define _FP_FRAC_SRL_8(X,N)                     \
0055   do {                                  \
0056     _FP_I_TYPE _up, _down, _skip, _i;                   \
0057     _skip = (N) / _FP_W_TYPE_SIZE;                  \
0058     _down = (N) % _FP_W_TYPE_SIZE;                  \
0059     _up = _FP_W_TYPE_SIZE - _down;                  \
0060     if (!_down)                             \
0061       for (_i = 0; _i <= 7-_skip; ++_i)                 \
0062     X##_f[_i] = X##_f[_i+_skip];                    \
0063     else                                \
0064       {                                 \
0065     for (_i = 0; _i < 7-_skip; ++_i)                \
0066       X##_f[_i] = X##_f[_i+_skip] >> _down              \
0067               | X##_f[_i+_skip+1] << _up;           \
0068     X##_f[_i++] = X##_f[7] >> _down;                \
0069       }                                 \
0070     for (; _i < 8; ++_i)                        \
0071       X##_f[_i] = 0;                            \
0072   } while (0)
0073 
0074 
0075 /* Right shift with sticky-lsb. 
0076  * What this actually means is that we do a standard right-shift,
0077  * but that if any of the bits that fall off the right hand side
0078  * were one then we always set the LSbit.
0079  */
0080 #define _FP_FRAC_SRS_8(X,N,size)                    \
0081   do {                                  \
0082     _FP_I_TYPE _up, _down, _skip, _i;                   \
0083     _FP_W_TYPE _s;                          \
0084     _skip = (N) / _FP_W_TYPE_SIZE;                  \
0085     _down = (N) % _FP_W_TYPE_SIZE;                  \
0086     _up = _FP_W_TYPE_SIZE - _down;                  \
0087     for (_s = _i = 0; _i < _skip; ++_i)                 \
0088       _s |= X##_f[_i];                          \
0089     _s |= X##_f[_i] << _up;                     \
0090 /* s is now != 0 if we want to set the LSbit */             \
0091     if (!_down)                             \
0092       for (_i = 0; _i <= 7-_skip; ++_i)                 \
0093     X##_f[_i] = X##_f[_i+_skip];                    \
0094     else                                \
0095       {                                 \
0096     for (_i = 0; _i < 7-_skip; ++_i)                \
0097       X##_f[_i] = X##_f[_i+_skip] >> _down              \
0098               | X##_f[_i+_skip+1] << _up;           \
0099     X##_f[_i++] = X##_f[7] >> _down;                \
0100       }                                 \
0101     for (; _i < 8; ++_i)                        \
0102       X##_f[_i] = 0;                            \
0103     /* don't fix the LSB until the very end when we're sure f[0] is stable */   \
0104     X##_f[0] |= (_s != 0);                      \
0105   } while (0)
0106 
0107 #endif