162306a36Sopenharmony_ci/* Software floating-point emulation. 262306a36Sopenharmony_ci Basic eight-word fraction declaration and manipulation. 362306a36Sopenharmony_ci Copyright (C) 1997,1998,1999 Free Software Foundation, Inc. 462306a36Sopenharmony_ci This file is part of the GNU C Library. 562306a36Sopenharmony_ci Contributed by Richard Henderson (rth@cygnus.com), 662306a36Sopenharmony_ci Jakub Jelinek (jj@ultra.linux.cz) and 762306a36Sopenharmony_ci Peter Maydell (pmaydell@chiark.greenend.org.uk). 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci The GNU C Library is free software; you can redistribute it and/or 1062306a36Sopenharmony_ci modify it under the terms of the GNU Library General Public License as 1162306a36Sopenharmony_ci published by the Free Software Foundation; either version 2 of the 1262306a36Sopenharmony_ci License, or (at your option) any later version. 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci The GNU C Library is distributed in the hope that it will be useful, 1562306a36Sopenharmony_ci but WITHOUT ANY WARRANTY; without even the implied warranty of 1662306a36Sopenharmony_ci MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1762306a36Sopenharmony_ci Library General Public License for more details. 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci You should have received a copy of the GNU Library General Public 2062306a36Sopenharmony_ci License along with the GNU C Library; see the file COPYING.LIB. If 2162306a36Sopenharmony_ci not, write to the Free Software Foundation, Inc., 2262306a36Sopenharmony_ci 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci#ifndef __MATH_EMU_OP_8_H__ 2562306a36Sopenharmony_ci#define __MATH_EMU_OP_8_H__ 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci/* We need just a few things from here for op-4, if we ever need some 2862306a36Sopenharmony_ci other macros, they can be added. */ 2962306a36Sopenharmony_ci#define _FP_FRAC_DECL_8(X) _FP_W_TYPE X##_f[8] 3062306a36Sopenharmony_ci#define _FP_FRAC_HIGH_8(X) (X##_f[7]) 3162306a36Sopenharmony_ci#define _FP_FRAC_LOW_8(X) (X##_f[0]) 3262306a36Sopenharmony_ci#define _FP_FRAC_WORD_8(X,w) (X##_f[w]) 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci#define _FP_FRAC_SLL_8(X,N) \ 3562306a36Sopenharmony_ci do { \ 3662306a36Sopenharmony_ci _FP_I_TYPE _up, _down, _skip, _i; \ 3762306a36Sopenharmony_ci _skip = (N) / _FP_W_TYPE_SIZE; \ 3862306a36Sopenharmony_ci _up = (N) % _FP_W_TYPE_SIZE; \ 3962306a36Sopenharmony_ci _down = _FP_W_TYPE_SIZE - _up; \ 4062306a36Sopenharmony_ci if (!_up) \ 4162306a36Sopenharmony_ci for (_i = 7; _i >= _skip; --_i) \ 4262306a36Sopenharmony_ci X##_f[_i] = X##_f[_i-_skip]; \ 4362306a36Sopenharmony_ci else \ 4462306a36Sopenharmony_ci { \ 4562306a36Sopenharmony_ci for (_i = 7; _i > _skip; --_i) \ 4662306a36Sopenharmony_ci X##_f[_i] = X##_f[_i-_skip] << _up \ 4762306a36Sopenharmony_ci | X##_f[_i-_skip-1] >> _down; \ 4862306a36Sopenharmony_ci X##_f[_i--] = X##_f[0] << _up; \ 4962306a36Sopenharmony_ci } \ 5062306a36Sopenharmony_ci for (; _i >= 0; --_i) \ 5162306a36Sopenharmony_ci X##_f[_i] = 0; \ 5262306a36Sopenharmony_ci } while (0) 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ci#define _FP_FRAC_SRL_8(X,N) \ 5562306a36Sopenharmony_ci do { \ 5662306a36Sopenharmony_ci _FP_I_TYPE _up, _down, _skip, _i; \ 5762306a36Sopenharmony_ci _skip = (N) / _FP_W_TYPE_SIZE; \ 5862306a36Sopenharmony_ci _down = (N) % _FP_W_TYPE_SIZE; \ 5962306a36Sopenharmony_ci _up = _FP_W_TYPE_SIZE - _down; \ 6062306a36Sopenharmony_ci if (!_down) \ 6162306a36Sopenharmony_ci for (_i = 0; _i <= 7-_skip; ++_i) \ 6262306a36Sopenharmony_ci X##_f[_i] = X##_f[_i+_skip]; \ 6362306a36Sopenharmony_ci else \ 6462306a36Sopenharmony_ci { \ 6562306a36Sopenharmony_ci for (_i = 0; _i < 7-_skip; ++_i) \ 6662306a36Sopenharmony_ci X##_f[_i] = X##_f[_i+_skip] >> _down \ 6762306a36Sopenharmony_ci | X##_f[_i+_skip+1] << _up; \ 6862306a36Sopenharmony_ci X##_f[_i++] = X##_f[7] >> _down; \ 6962306a36Sopenharmony_ci } \ 7062306a36Sopenharmony_ci for (; _i < 8; ++_i) \ 7162306a36Sopenharmony_ci X##_f[_i] = 0; \ 7262306a36Sopenharmony_ci } while (0) 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci/* Right shift with sticky-lsb. 7662306a36Sopenharmony_ci * What this actually means is that we do a standard right-shift, 7762306a36Sopenharmony_ci * but that if any of the bits that fall off the right hand side 7862306a36Sopenharmony_ci * were one then we always set the LSbit. 7962306a36Sopenharmony_ci */ 8062306a36Sopenharmony_ci#define _FP_FRAC_SRS_8(X,N,size) \ 8162306a36Sopenharmony_ci do { \ 8262306a36Sopenharmony_ci _FP_I_TYPE _up, _down, _skip, _i; \ 8362306a36Sopenharmony_ci _FP_W_TYPE _s; \ 8462306a36Sopenharmony_ci _skip = (N) / _FP_W_TYPE_SIZE; \ 8562306a36Sopenharmony_ci _down = (N) % _FP_W_TYPE_SIZE; \ 8662306a36Sopenharmony_ci _up = _FP_W_TYPE_SIZE - _down; \ 8762306a36Sopenharmony_ci for (_s = _i = 0; _i < _skip; ++_i) \ 8862306a36Sopenharmony_ci _s |= X##_f[_i]; \ 8962306a36Sopenharmony_ci _s |= X##_f[_i] << _up; \ 9062306a36Sopenharmony_ci/* s is now != 0 if we want to set the LSbit */ \ 9162306a36Sopenharmony_ci if (!_down) \ 9262306a36Sopenharmony_ci for (_i = 0; _i <= 7-_skip; ++_i) \ 9362306a36Sopenharmony_ci X##_f[_i] = X##_f[_i+_skip]; \ 9462306a36Sopenharmony_ci else \ 9562306a36Sopenharmony_ci { \ 9662306a36Sopenharmony_ci for (_i = 0; _i < 7-_skip; ++_i) \ 9762306a36Sopenharmony_ci X##_f[_i] = X##_f[_i+_skip] >> _down \ 9862306a36Sopenharmony_ci | X##_f[_i+_skip+1] << _up; \ 9962306a36Sopenharmony_ci X##_f[_i++] = X##_f[7] >> _down; \ 10062306a36Sopenharmony_ci } \ 10162306a36Sopenharmony_ci for (; _i < 8; ++_i) \ 10262306a36Sopenharmony_ci X##_f[_i] = 0; \ 10362306a36Sopenharmony_ci /* don't fix the LSB until the very end when we're sure f[0] is stable */ \ 10462306a36Sopenharmony_ci X##_f[0] |= (_s != 0); \ 10562306a36Sopenharmony_ci } while (0) 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci#endif 108