/* Software floating-point emulation.1Basic eight-word fraction declaration and manipulation.2Copyright (C) 1997,1998,1999 Free Software Foundation, Inc.3This file is part of the GNU C Library.4Contributed by Richard Henderson ([email protected]),5Jakub Jelinek ([email protected]) and6Peter Maydell ([email protected]).78The GNU C Library is free software; you can redistribute it and/or9modify it under the terms of the GNU Library General Public License as10published by the Free Software Foundation; either version 2 of the11License, or (at your option) any later version.1213The GNU C Library is distributed in the hope that it will be useful,14but WITHOUT ANY WARRANTY; without even the implied warranty of15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU16Library General Public License for more details.1718You should have received a copy of the GNU Library General Public19License along with the GNU C Library; see the file COPYING.LIB. If20not, write to the Free Software Foundation, Inc.,2159 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */2223#ifndef __MATH_EMU_OP_8_H__24#define __MATH_EMU_OP_8_H__2526/* We need just a few things from here for op-4, if we ever need some27other macros, they can be added. */28#define _FP_FRAC_DECL_8(X) _FP_W_TYPE X##_f[8]29#define _FP_FRAC_HIGH_8(X) (X##_f[7])30#define _FP_FRAC_LOW_8(X) (X##_f[0])31#define _FP_FRAC_WORD_8(X,w) (X##_f[w])3233#define _FP_FRAC_SLL_8(X,N) \34do { \35_FP_I_TYPE _up, _down, _skip, _i; \36_skip = (N) / _FP_W_TYPE_SIZE; \37_up = (N) % _FP_W_TYPE_SIZE; \38_down = _FP_W_TYPE_SIZE - _up; \39if (!_up) \40for (_i = 7; _i >= _skip; --_i) \41X##_f[_i] = X##_f[_i-_skip]; \42else \43{ \44for (_i = 7; _i > _skip; --_i) \45X##_f[_i] = X##_f[_i-_skip] << _up \46| X##_f[_i-_skip-1] >> _down; \47X##_f[_i--] = X##_f[0] << _up; \48} \49for (; _i >= 0; --_i) \50X##_f[_i] = 0; \51} while (0)5253#define _FP_FRAC_SRL_8(X,N) \54do { \55_FP_I_TYPE _up, _down, _skip, _i; \56_skip = (N) / _FP_W_TYPE_SIZE; \57_down = (N) % _FP_W_TYPE_SIZE; \58_up = _FP_W_TYPE_SIZE - _down; \59if (!_down) \60for (_i = 0; _i <= 7-_skip; ++_i) \61X##_f[_i] = X##_f[_i+_skip]; \62else \63{ \64for (_i = 0; _i < 7-_skip; ++_i) \65X##_f[_i] = X##_f[_i+_skip] >> _down \66| X##_f[_i+_skip+1] << _up; \67X##_f[_i++] = X##_f[7] >> _down; \68} \69for (; _i < 8; ++_i) \70X##_f[_i] = 0; \71} while (0)727374/* Right shift with sticky-lsb.75* What this actually means is that we do a standard right-shift,76* but that if any of the bits that fall off the right hand side77* were one then we always set the LSbit.78*/79#define _FP_FRAC_SRS_8(X,N,size) \80do { \81_FP_I_TYPE _up, _down, _skip, _i; \82_FP_W_TYPE _s; \83_skip = (N) / _FP_W_TYPE_SIZE; \84_down = (N) % _FP_W_TYPE_SIZE; \85_up = _FP_W_TYPE_SIZE - _down; \86for (_s = _i = 0; _i < _skip; ++_i) \87_s |= X##_f[_i]; \88_s |= X##_f[_i] << _up; \89/* s is now != 0 if we want to set the LSbit */ \90if (!_down) \91for (_i = 0; _i <= 7-_skip; ++_i) \92X##_f[_i] = X##_f[_i+_skip]; \93else \94{ \95for (_i = 0; _i < 7-_skip; ++_i) \96X##_f[_i] = X##_f[_i+_skip] >> _down \97| X##_f[_i+_skip+1] << _up; \98X##_f[_i++] = X##_f[7] >> _down; \99} \100for (; _i < 8; ++_i) \101X##_f[_i] = 0; \102/* don't fix the LSB until the very end when we're sure f[0] is stable */ \103X##_f[0] |= (_s != 0); \104} while (0)105106#endif107108109