]>
Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* |
2 | * This file is part of SIS. | |
3 | * | |
4 | * SIS, SPARC instruction simulator. Copyright (C) 1995 Jiri Gaisler, European | |
5 | * Space Agency | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify it under | |
8 | * the terms of the GNU General Public License as published by the Free | |
3fd725ef | 9 | * Software Foundation; either version 3 of the License, or (at your option) |
c906108c SS |
10 | * any later version. |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
15 | * more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License along with | |
51b318de | 18 | * this program; if not, see <http://www.gnu.org/licenses/>. |
c906108c SS |
19 | * |
20 | * | |
21 | * This file implements the interface between the host and the simulated | |
22 | * FPU. IEEE trap handling is done as follows: | |
23 | * 1. In the host, all IEEE traps are masked | |
24 | * 2. After each simulated FPU instruction, check if any exception occured | |
25 | * by reading the exception bits from the host FPU status register | |
26 | * (get_accex()). | |
27 | * 3. Propagate any exceptions to the simulated FSR. | |
28 | * 4. Clear host exception bits | |
29 | * | |
30 | * | |
c906108c SS |
31 | */ |
32 | ||
5272643f | 33 | #include "config.h" |
c906108c | 34 | #include "sis.h" |
0172ee3a | 35 | #include <fenv.h> |
c906108c | 36 | |
0172ee3a | 37 | /* This routine should return the accrued exceptions */ |
c906108c SS |
38 | int |
39 | get_accex() | |
40 | { | |
0172ee3a JG |
41 | int fexc, accx; |
42 | ||
43 | fexc = fetestexcept (FE_ALL_EXCEPT); | |
44 | accx = 0; | |
45 | if (fexc & FE_INEXACT) | |
46 | accx |= 1; | |
47 | if (fexc & FE_DIVBYZERO) | |
48 | accx |= 2; | |
49 | if (fexc & FE_UNDERFLOW) | |
50 | accx |= 4; | |
51 | if (fexc & FE_OVERFLOW) | |
52 | accx |= 8; | |
53 | if (fexc & FE_INVALID) | |
54 | accx |= 0x10; | |
5831e29b | 55 | return accx; |
c906108c SS |
56 | } |
57 | ||
58 | /* How to clear the accrued exceptions */ | |
59 | void | |
60 | clear_accex() | |
61 | { | |
0172ee3a | 62 | feclearexcept (FE_ALL_EXCEPT); |
c906108c SS |
63 | } |
64 | ||
65 | /* How to map SPARC FSR onto the host */ | |
66 | void | |
67 | set_fsr(fsr) | |
68 | uint32 fsr; | |
69 | { | |
0172ee3a | 70 | int fround; |
c906108c | 71 | |
0172ee3a JG |
72 | fsr >>= 30; |
73 | switch (fsr) { | |
c906108c | 74 | case 0: |
0172ee3a JG |
75 | fround = FE_TONEAREST; |
76 | break; | |
40776d19 | 77 | case 1: |
0172ee3a JG |
78 | fround = FE_TOWARDZERO; |
79 | break; | |
80 | case 2: | |
81 | fround = FE_UPWARD; | |
82 | break; | |
40776d19 | 83 | case 3: |
0172ee3a JG |
84 | fround = FE_DOWNWARD; |
85 | break; | |
c906108c | 86 | } |
0172ee3a | 87 | fesetround (fround); |
c906108c | 88 | } |