]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/erc32/float.c
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / sim / erc32 / float.c
CommitLineData
296730a5
MF
1/* This file is part of SIS (SPARC instruction simulator)
2
1d506c26 3 Copyright (C) 1995-2024 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
6df01ab8
MF
29/* This must come before any other includes. */
30#include "defs.h"
31
c906108c 32#include "sis.h"
0172ee3a 33#include <fenv.h>
c906108c 34
0172ee3a 35/* This routine should return the accrued exceptions */
c906108c 36int
81e6e8ae 37get_accex(void)
c906108c 38{
0172ee3a
JG
39 int fexc, accx;
40
41 fexc = fetestexcept (FE_ALL_EXCEPT);
42 accx = 0;
43 if (fexc & FE_INEXACT)
44 accx |= 1;
45 if (fexc & FE_DIVBYZERO)
46 accx |= 2;
47 if (fexc & FE_UNDERFLOW)
48 accx |= 4;
49 if (fexc & FE_OVERFLOW)
50 accx |= 8;
51 if (fexc & FE_INVALID)
52 accx |= 0x10;
5831e29b 53 return accx;
c906108c
SS
54}
55
56/* How to clear the accrued exceptions */
57void
81e6e8ae 58clear_accex(void)
c906108c 59{
0172ee3a 60 feclearexcept (FE_ALL_EXCEPT);
c906108c
SS
61}
62
63/* How to map SPARC FSR onto the host */
64void
4a92dedc 65set_fsr(uint32_t fsr)
c906108c 66{
0172ee3a 67 int fround;
c906108c 68
0172ee3a
JG
69 fsr >>= 30;
70 switch (fsr) {
c906108c 71 case 0:
0172ee3a
JG
72 fround = FE_TONEAREST;
73 break;
40776d19 74 case 1:
0172ee3a
JG
75 fround = FE_TOWARDZERO;
76 break;
77 case 2:
78 fround = FE_UPWARD;
79 break;
40776d19 80 case 3:
0172ee3a
JG
81 fround = FE_DOWNWARD;
82 break;
c906108c 83 }
0172ee3a 84 fesetround (fround);
c906108c 85}