Home | History | Annotate | Line # | Download | only in soft-fp
op-8.h revision 1.1
      1  1.1  mrg /* Software floating-point emulation.
      2  1.1  mrg    Basic eight-word fraction declaration and manipulation.
      3  1.1  mrg    Copyright (C) 1997,1998,1999,2006 Free Software Foundation, Inc.
      4  1.1  mrg    This file is part of the GNU C Library.
      5  1.1  mrg    Contributed by Richard Henderson (rth (at) cygnus.com),
      6  1.1  mrg 		  Jakub Jelinek (jj (at) ultra.linux.cz) and
      7  1.1  mrg 		  Peter Maydell (pmaydell (at) chiark.greenend.org.uk).
      8  1.1  mrg 
      9  1.1  mrg    The GNU C Library is free software; you can redistribute it and/or
     10  1.1  mrg    modify it under the terms of the GNU Lesser General Public
     11  1.1  mrg    License as published by the Free Software Foundation; either
     12  1.1  mrg    version 2.1 of the License, or (at your option) any later version.
     13  1.1  mrg 
     14  1.1  mrg    In addition to the permissions in the GNU Lesser General Public
     15  1.1  mrg    License, the Free Software Foundation gives you unlimited
     16  1.1  mrg    permission to link the compiled version of this file into
     17  1.1  mrg    combinations with other programs, and to distribute those
     18  1.1  mrg    combinations without any restriction coming from the use of this
     19  1.1  mrg    file.  (The Lesser General Public License restrictions do apply in
     20  1.1  mrg    other respects; for example, they cover modification of the file,
     21  1.1  mrg    and distribution when not linked into a combine executable.)
     22  1.1  mrg 
     23  1.1  mrg    The GNU C Library is distributed in the hope that it will be useful,
     24  1.1  mrg    but WITHOUT ANY WARRANTY; without even the implied warranty of
     25  1.1  mrg    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     26  1.1  mrg    Lesser General Public License for more details.
     27  1.1  mrg 
     28  1.1  mrg    You should have received a copy of the GNU Lesser General Public
     29  1.1  mrg    License along with the GNU C Library; if not, see
     30  1.1  mrg    <http://www.gnu.org/licenses/>.  */
     31  1.1  mrg 
     32  1.1  mrg /* We need just a few things from here for op-4, if we ever need some
     33  1.1  mrg    other macros, they can be added. */
     34  1.1  mrg #define _FP_FRAC_DECL_8(X)	_FP_W_TYPE X##_f[8]
     35  1.1  mrg #define _FP_FRAC_HIGH_8(X)	(X##_f[7])
     36  1.1  mrg #define _FP_FRAC_LOW_8(X)	(X##_f[0])
     37  1.1  mrg #define _FP_FRAC_WORD_8(X,w)	(X##_f[w])
     38  1.1  mrg 
     39  1.1  mrg #define _FP_FRAC_SLL_8(X,N)						\
     40  1.1  mrg   do {									\
     41  1.1  mrg     _FP_I_TYPE _up, _down, _skip, _i;					\
     42  1.1  mrg     _skip = (N) / _FP_W_TYPE_SIZE;					\
     43  1.1  mrg     _up = (N) % _FP_W_TYPE_SIZE;					\
     44  1.1  mrg     _down = _FP_W_TYPE_SIZE - _up;					\
     45  1.1  mrg     if (!_up)								\
     46  1.1  mrg       for (_i = 7; _i >= _skip; --_i)					\
     47  1.1  mrg 	X##_f[_i] = X##_f[_i-_skip];					\
     48  1.1  mrg     else								\
     49  1.1  mrg       {									\
     50  1.1  mrg 	for (_i = 7; _i > _skip; --_i)					\
     51  1.1  mrg 	  X##_f[_i] = X##_f[_i-_skip] << _up				\
     52  1.1  mrg 		      | X##_f[_i-_skip-1] >> _down;			\
     53  1.1  mrg 	X##_f[_i--] = X##_f[0] << _up; 					\
     54  1.1  mrg       }									\
     55  1.1  mrg     for (; _i >= 0; --_i)						\
     56  1.1  mrg       X##_f[_i] = 0;							\
     57  1.1  mrg   } while (0)
     58  1.1  mrg 
     59  1.1  mrg #define _FP_FRAC_SRL_8(X,N)						\
     60  1.1  mrg   do {									\
     61  1.1  mrg     _FP_I_TYPE _up, _down, _skip, _i;					\
     62  1.1  mrg     _skip = (N) / _FP_W_TYPE_SIZE;					\
     63  1.1  mrg     _down = (N) % _FP_W_TYPE_SIZE;					\
     64  1.1  mrg     _up = _FP_W_TYPE_SIZE - _down;					\
     65  1.1  mrg     if (!_down)								\
     66  1.1  mrg       for (_i = 0; _i <= 7-_skip; ++_i)					\
     67  1.1  mrg 	X##_f[_i] = X##_f[_i+_skip];					\
     68  1.1  mrg     else								\
     69  1.1  mrg       {									\
     70  1.1  mrg 	for (_i = 0; _i < 7-_skip; ++_i)				\
     71  1.1  mrg 	  X##_f[_i] = X##_f[_i+_skip] >> _down				\
     72  1.1  mrg 		      | X##_f[_i+_skip+1] << _up;			\
     73  1.1  mrg 	X##_f[_i++] = X##_f[7] >> _down;				\
     74  1.1  mrg       }									\
     75  1.1  mrg     for (; _i < 8; ++_i)						\
     76  1.1  mrg       X##_f[_i] = 0;							\
     77  1.1  mrg   } while (0)
     78  1.1  mrg 
     79  1.1  mrg 
     80  1.1  mrg /* Right shift with sticky-lsb.
     81  1.1  mrg  * What this actually means is that we do a standard right-shift,
     82  1.1  mrg  * but that if any of the bits that fall off the right hand side
     83  1.1  mrg  * were one then we always set the LSbit.
     84  1.1  mrg  */
     85  1.1  mrg #define _FP_FRAC_SRS_8(X,N,size)					\
     86  1.1  mrg   do {									\
     87  1.1  mrg     _FP_I_TYPE _up, _down, _skip, _i;					\
     88  1.1  mrg     _FP_W_TYPE _s;							\
     89  1.1  mrg     _skip = (N) / _FP_W_TYPE_SIZE;					\
     90  1.1  mrg     _down = (N) % _FP_W_TYPE_SIZE;					\
     91  1.1  mrg     _up = _FP_W_TYPE_SIZE - _down;					\
     92  1.1  mrg     for (_s = _i = 0; _i < _skip; ++_i)					\
     93  1.1  mrg       _s |= X##_f[_i];							\
     94  1.1  mrg     if (!_down)								\
     95  1.1  mrg       for (_i = 0; _i <= 7-_skip; ++_i)					\
     96  1.1  mrg 	X##_f[_i] = X##_f[_i+_skip];					\
     97  1.1  mrg     else								\
     98  1.1  mrg       {									\
     99  1.1  mrg 	_s |= X##_f[_i] << _up;						\
    100  1.1  mrg 	for (_i = 0; _i < 7-_skip; ++_i)				\
    101  1.1  mrg 	  X##_f[_i] = X##_f[_i+_skip] >> _down				\
    102  1.1  mrg 		      | X##_f[_i+_skip+1] << _up;			\
    103  1.1  mrg 	X##_f[_i++] = X##_f[7] >> _down;				\
    104  1.1  mrg       }									\
    105  1.1  mrg     for (; _i < 8; ++_i)						\
    106  1.1  mrg       X##_f[_i] = 0;							\
    107  1.1  mrg     /* don't fix the LSB until the very end when we're sure f[0] is stable */	\
    108  1.1  mrg     X##_f[0] |= (_s != 0);						\
    109  1.1  mrg   } while (0)
    110