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