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