1 /* Software floating-point emulation.
2 Basic eight-word fraction declaration and manipulation.
3 Copyright (C) 1997-2014 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).
9 The GNU C Library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
14 In addition to the permissions in the GNU Lesser General Public
15 License, the Free Software Foundation gives you unlimited
16 permission to link the compiled version of this file into
17 combinations with other programs, and to distribute those
18 combinations without any restriction coming from the use of this
19 file. (The Lesser General Public License restrictions do apply in
20 other respects; for example, they cover modification of the file,
21 and distribution when not linked into a combine executable.)
23 The GNU C Library is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 Lesser General Public License for more details.
28 You should have received a copy of the GNU Lesser General Public
29 License along with the GNU C Library; if not, see
30 <http://www.gnu.org/licenses/>. */
32 /* We need just a few things from here for op-4, if we ever need some
33 other macros, they can be added. */
34 #define _FP_FRAC_DECL_8(X) _FP_W_TYPE X##_f[8]
35 #define _FP_FRAC_HIGH_8(X) (X##_f[7])
36 #define _FP_FRAC_LOW_8(X) (X##_f[0])
37 #define _FP_FRAC_WORD_8(X, w) (X##_f[w])
39 #define _FP_FRAC_SLL_8(X, N) \
42 _FP_I_TYPE _FP_FRAC_SLL_8_up, _FP_FRAC_SLL_8_down; \
43 _FP_I_TYPE _FP_FRAC_SLL_8_skip, _FP_FRAC_SLL_8_i; \
44 _FP_FRAC_SLL_8_skip = (N) / _FP_W_TYPE_SIZE; \
45 _FP_FRAC_SLL_8_up = (N) % _FP_W_TYPE_SIZE; \
46 _FP_FRAC_SLL_8_down = _FP_W_TYPE_SIZE - _FP_FRAC_SLL_8_up; \
47 if (!_FP_FRAC_SLL_8_up) \
48 for (_FP_FRAC_SLL_8_i = 7; \
49 _FP_FRAC_SLL_8_i >= _FP_FRAC_SLL_8_skip; \
51 X##_f[_FP_FRAC_SLL_8_i] \
52 = X##_f[_FP_FRAC_SLL_8_i-_FP_FRAC_SLL_8_skip]; \
55 for (_FP_FRAC_SLL_8_i = 7; \
56 _FP_FRAC_SLL_8_i > _FP_FRAC_SLL_8_skip; \
58 X##_f[_FP_FRAC_SLL_8_i] \
59 = ((X##_f[_FP_FRAC_SLL_8_i-_FP_FRAC_SLL_8_skip] \
60 << _FP_FRAC_SLL_8_up) \
61 | (X##_f[_FP_FRAC_SLL_8_i-_FP_FRAC_SLL_8_skip-1] \
62 >> _FP_FRAC_SLL_8_down)); \
63 X##_f[_FP_FRAC_SLL_8_i--] = X##_f[0] << _FP_FRAC_SLL_8_up; \
65 for (; _FP_FRAC_SLL_8_i >= 0; --_FP_FRAC_SLL_8_i) \
66 X##_f[_FP_FRAC_SLL_8_i] = 0; \
70 #define _FP_FRAC_SRL_8(X, N) \
73 _FP_I_TYPE _FP_FRAC_SRL_8_up, _FP_FRAC_SRL_8_down; \
74 _FP_I_TYPE _FP_FRAC_SRL_8_skip, _FP_FRAC_SRL_8_i; \
75 _FP_FRAC_SRL_8_skip = (N) / _FP_W_TYPE_SIZE; \
76 _FP_FRAC_SRL_8_down = (N) % _FP_W_TYPE_SIZE; \
77 _FP_FRAC_SRL_8_up = _FP_W_TYPE_SIZE - _FP_FRAC_SRL_8_down; \
78 if (!_FP_FRAC_SRL_8_down) \
79 for (_FP_FRAC_SRL_8_i = 0; \
80 _FP_FRAC_SRL_8_i <= 7-_FP_FRAC_SRL_8_skip; \
82 X##_f[_FP_FRAC_SRL_8_i] \
83 = X##_f[_FP_FRAC_SRL_8_i+_FP_FRAC_SRL_8_skip]; \
86 for (_FP_FRAC_SRL_8_i = 0; \
87 _FP_FRAC_SRL_8_i < 7-_FP_FRAC_SRL_8_skip; \
89 X##_f[_FP_FRAC_SRL_8_i] \
90 = ((X##_f[_FP_FRAC_SRL_8_i+_FP_FRAC_SRL_8_skip] \
91 >> _FP_FRAC_SRL_8_down) \
92 | (X##_f[_FP_FRAC_SRL_8_i+_FP_FRAC_SRL_8_skip+1] \
93 << _FP_FRAC_SRL_8_up)); \
94 X##_f[_FP_FRAC_SRL_8_i++] = X##_f[7] >> _FP_FRAC_SRL_8_down; \
96 for (; _FP_FRAC_SRL_8_i < 8; ++_FP_FRAC_SRL_8_i) \
97 X##_f[_FP_FRAC_SRL_8_i] = 0; \
102 /* Right shift with sticky-lsb.
103 What this actually means is that we do a standard right-shift,
104 but that if any of the bits that fall off the right hand side
105 were one then we always set the LSbit. */
106 #define _FP_FRAC_SRS_8(X, N, size) \
109 _FP_I_TYPE _FP_FRAC_SRS_8_up, _FP_FRAC_SRS_8_down; \
110 _FP_I_TYPE _FP_FRAC_SRS_8_skip, _FP_FRAC_SRS_8_i; \
111 _FP_W_TYPE _FP_FRAC_SRS_8_s; \
112 _FP_FRAC_SRS_8_skip = (N) / _FP_W_TYPE_SIZE; \
113 _FP_FRAC_SRS_8_down = (N) % _FP_W_TYPE_SIZE; \
114 _FP_FRAC_SRS_8_up = _FP_W_TYPE_SIZE - _FP_FRAC_SRS_8_down; \
115 for (_FP_FRAC_SRS_8_s = _FP_FRAC_SRS_8_i = 0; \
116 _FP_FRAC_SRS_8_i < _FP_FRAC_SRS_8_skip; \
117 ++_FP_FRAC_SRS_8_i) \
118 _FP_FRAC_SRS_8_s |= X##_f[_FP_FRAC_SRS_8_i]; \
119 if (!_FP_FRAC_SRS_8_down) \
120 for (_FP_FRAC_SRS_8_i = 0; \
121 _FP_FRAC_SRS_8_i <= 7-_FP_FRAC_SRS_8_skip; \
122 ++_FP_FRAC_SRS_8_i) \
123 X##_f[_FP_FRAC_SRS_8_i] \
124 = X##_f[_FP_FRAC_SRS_8_i+_FP_FRAC_SRS_8_skip]; \
128 |= X##_f[_FP_FRAC_SRS_8_i] << _FP_FRAC_SRS_8_up; \
129 for (_FP_FRAC_SRS_8_i = 0; \
130 _FP_FRAC_SRS_8_i < 7-_FP_FRAC_SRS_8_skip; \
131 ++_FP_FRAC_SRS_8_i) \
132 X##_f[_FP_FRAC_SRS_8_i] \
133 = ((X##_f[_FP_FRAC_SRS_8_i+_FP_FRAC_SRS_8_skip] \
134 >> _FP_FRAC_SRS_8_down) \
135 | (X##_f[_FP_FRAC_SRS_8_i+_FP_FRAC_SRS_8_skip+1] \
136 << _FP_FRAC_SRS_8_up)); \
137 X##_f[_FP_FRAC_SRS_8_i++] = X##_f[7] >> _FP_FRAC_SRS_8_down; \
139 for (; _FP_FRAC_SRS_8_i < 8; ++_FP_FRAC_SRS_8_i) \
140 X##_f[_FP_FRAC_SRS_8_i] = 0; \
141 /* Don't fix the LSB until the very end when we're sure f[0] is \
143 X##_f[0] |= (_FP_FRAC_SRS_8_s != 0); \