sim/erc32: Use fenv.h for host FPU access
[deliverable/binutils-gdb.git] / sim / erc32 / float.c
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
9 * Software Foundation; either version 3 of the License, or (at your option)
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
18 * this program; if not, see <http://www.gnu.org/licenses/>.
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 *
31 */
32
33 #include "config.h"
34 #include "sis.h"
35 #include <fenv.h>
36
37 /* This routine should return the accrued exceptions */
38 int
39 get_accex()
40 {
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;
55 return(accx);
56 }
57
58 /* How to clear the accrued exceptions */
59 void
60 clear_accex()
61 {
62 feclearexcept (FE_ALL_EXCEPT);
63 }
64
65 /* How to map SPARC FSR onto the host */
66 void
67 set_fsr(fsr)
68 uint32 fsr;
69 {
70 int fround;
71
72 fsr >>= 30;
73 switch (fsr) {
74 case 0:
75 fround = FE_TONEAREST;
76 break;
77 case 1:
78 fround = FE_TOWARDZERO;
79 break;
80 case 2:
81 fround = FE_UPWARD;
82 break;
83 case 3:
84 fround = FE_DOWNWARD;
85 break;
86 }
87 fesetround (fround);
88 }
This page took 0.031942 seconds and 5 git commands to generate.