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