]>
Commit | Line | Data |
---|---|---|
d876f532 UD |
1 | /* Software floating-point emulation. |
2 | Basic eight-word fraction declaration and manipulation. | |
568035b7 | 3 | Copyright (C) 1997-2013 Free Software Foundation, Inc. |
d876f532 UD |
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). | |
41bdb6e2 | 8 | |
d876f532 | 9 | The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
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. | |
d876f532 | 13 | |
638a783c RM |
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.) | |
22 | ||
d876f532 UD |
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 | |
41bdb6e2 | 26 | Lesser General Public License for more details. |
d876f532 | 27 | |
41bdb6e2 | 28 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
29 | License along with the GNU C Library; if not, see |
30 | <http://www.gnu.org/licenses/>. */ | |
d876f532 UD |
31 | |
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]) | |
38 | ||
39 | #define _FP_FRAC_SLL_8(X,N) \ | |
40 | do { \ | |
41 | _FP_I_TYPE _up, _down, _skip, _i; \ | |
42 | _skip = (N) / _FP_W_TYPE_SIZE; \ | |
43 | _up = (N) % _FP_W_TYPE_SIZE; \ | |
44 | _down = _FP_W_TYPE_SIZE - _up; \ | |
45 | if (!_up) \ | |
46 | for (_i = 7; _i >= _skip; --_i) \ | |
47 | X##_f[_i] = X##_f[_i-_skip]; \ | |
48 | else \ | |
49 | { \ | |
50 | for (_i = 7; _i > _skip; --_i) \ | |
51 | X##_f[_i] = X##_f[_i-_skip] << _up \ | |
52 | | X##_f[_i-_skip-1] >> _down; \ | |
53 | X##_f[_i--] = X##_f[0] << _up; \ | |
54 | } \ | |
55 | for (; _i >= 0; --_i) \ | |
56 | X##_f[_i] = 0; \ | |
57 | } while (0) | |
58 | ||
59 | #define _FP_FRAC_SRL_8(X,N) \ | |
60 | do { \ | |
61 | _FP_I_TYPE _up, _down, _skip, _i; \ | |
62 | _skip = (N) / _FP_W_TYPE_SIZE; \ | |
63 | _down = (N) % _FP_W_TYPE_SIZE; \ | |
64 | _up = _FP_W_TYPE_SIZE - _down; \ | |
65 | if (!_down) \ | |
66 | for (_i = 0; _i <= 7-_skip; ++_i) \ | |
67 | X##_f[_i] = X##_f[_i+_skip]; \ | |
68 | else \ | |
69 | { \ | |
70 | for (_i = 0; _i < 7-_skip; ++_i) \ | |
71 | X##_f[_i] = X##_f[_i+_skip] >> _down \ | |
72 | | X##_f[_i+_skip+1] << _up; \ | |
73 | X##_f[_i++] = X##_f[7] >> _down; \ | |
74 | } \ | |
75 | for (; _i < 8; ++_i) \ | |
76 | X##_f[_i] = 0; \ | |
77 | } while (0) | |
78 | ||
79 | ||
9c84384c | 80 | /* Right shift with sticky-lsb. |
d876f532 UD |
81 | * What this actually means is that we do a standard right-shift, |
82 | * but that if any of the bits that fall off the right hand side | |
83 | * were one then we always set the LSbit. | |
84 | */ | |
85 | #define _FP_FRAC_SRS_8(X,N,size) \ | |
86 | do { \ | |
87 | _FP_I_TYPE _up, _down, _skip, _i; \ | |
88 | _FP_W_TYPE _s; \ | |
89 | _skip = (N) / _FP_W_TYPE_SIZE; \ | |
90 | _down = (N) % _FP_W_TYPE_SIZE; \ | |
91 | _up = _FP_W_TYPE_SIZE - _down; \ | |
92 | for (_s = _i = 0; _i < _skip; ++_i) \ | |
93 | _s |= X##_f[_i]; \ | |
d876f532 UD |
94 | if (!_down) \ |
95 | for (_i = 0; _i <= 7-_skip; ++_i) \ | |
96 | X##_f[_i] = X##_f[_i+_skip]; \ | |
97 | else \ | |
98 | { \ | |
fe0b1e85 | 99 | _s |= X##_f[_i] << _up; \ |
d876f532 UD |
100 | for (_i = 0; _i < 7-_skip; ++_i) \ |
101 | X##_f[_i] = X##_f[_i+_skip] >> _down \ | |
102 | | X##_f[_i+_skip+1] << _up; \ | |
103 | X##_f[_i++] = X##_f[7] >> _down; \ | |
104 | } \ | |
105 | for (; _i < 8; ++_i) \ | |
106 | X##_f[_i] = 0; \ | |
107 | /* don't fix the LSB until the very end when we're sure f[0] is stable */ \ | |
108 | X##_f[0] |= (_s != 0); \ | |
109 | } while (0) |