Commit | Line | Data |
---|---|---|
3971886a AC |
1 | /* Simulator Floating-point support. |
2 | Copyright (C) 1997 Free Software Foundation, Inc. | |
3 | Contributed by Cygnus Support. | |
4 | ||
5 | This file is part of GDB, the GNU debugger. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License along | |
18 | with this program; if not, write to the Free Software Foundation, Inc., | |
19 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
20 | ||
21 | ||
22 | ||
23 | #ifndef _SIM_FPU_C_ | |
24 | #define _SIM_FPU_C_ | |
25 | ||
26 | #include "sim-main.h" | |
27 | #include "sim-fpu.h" | |
28 | ||
29 | #include <math.h> | |
30 | ||
31 | ||
32 | INLINE_SIM_FPU (sim_fpu) | |
33 | sim_fpu_add (sim_fpu l, | |
34 | sim_fpu r) | |
35 | { | |
36 | sim_fpu ans; | |
37 | ans.val = l.val + r.val; | |
38 | return ans; | |
39 | } | |
40 | ||
41 | ||
42 | INLINE_SIM_FPU (sim_fpu) | |
43 | sim_fpu_sub (sim_fpu l, | |
44 | sim_fpu r) | |
45 | { | |
46 | sim_fpu ans; | |
47 | ans.val = l.val - r.val; | |
48 | return ans; | |
49 | } | |
50 | ||
51 | ||
52 | INLINE_SIM_FPU (sim_fpu) | |
53 | sim_fpu_mul (sim_fpu l, | |
54 | sim_fpu r) | |
55 | { | |
56 | sim_fpu ans; | |
57 | ans.val = l.val * r.val; | |
58 | return ans; | |
59 | } | |
60 | ||
61 | ||
62 | INLINE_SIM_FPU (sim_fpu) | |
63 | sim_fpu_div (sim_fpu l, | |
64 | sim_fpu r) | |
65 | { | |
66 | sim_fpu ans; | |
67 | ans.val = l.val / r.val; | |
68 | return ans; | |
69 | } | |
70 | ||
71 | ||
72 | INLINE_SIM_FPU (sim_fpu) | |
73 | sim_fpu_inv (sim_fpu r) | |
74 | { | |
75 | sim_fpu ans; | |
76 | ans.val = 1 / r.val; | |
77 | return ans; | |
78 | } | |
79 | ||
80 | ||
81 | INLINE_SIM_FPU (sim_fpu) | |
82 | sim_fpu_sqrt (sim_fpu r) | |
83 | { | |
84 | sim_fpu ans; | |
85 | ans.val = sqrt (r.val); | |
86 | return ans; | |
87 | } | |
88 | ||
89 | ||
90 | INLINE_SIM_FPU (sim_fpu) | |
91 | sim_fpu_32to (unsigned32 s) | |
92 | { | |
93 | sim_fpu ans; | |
94 | ans.val = *(float*) &s; | |
95 | return ans; | |
96 | } | |
97 | ||
98 | ||
99 | INLINE_SIM_FPU (sim_fpu) | |
100 | sim_fpu_64to (unsigned64 s) | |
101 | { | |
102 | sim_fpu ans; | |
103 | ans.val = *(double*) &s; | |
104 | return ans; | |
105 | } | |
106 | ||
107 | ||
108 | INLINE_SIM_FPU (unsigned32) | |
109 | sim_fpu_to32 (sim_fpu l) | |
110 | { | |
111 | float s = l.val; | |
112 | return *(unsigned32*) &s; | |
113 | } | |
114 | ||
115 | ||
116 | INLINE_SIM_FPU (unsigned64) | |
117 | sim_fpu_to64 (sim_fpu s) | |
118 | { | |
119 | return *(unsigned64*) &s.val; | |
120 | } | |
121 | ||
122 | ||
123 | INLINE_SIM_FPU (float) | |
124 | sim_fpu_2f (sim_fpu f) | |
125 | { | |
126 | return f.val; | |
127 | } | |
128 | ||
129 | ||
130 | INLINE_SIM_FPU (double) | |
131 | sim_fpu_2d (sim_fpu s) | |
132 | { | |
133 | return s.val; | |
134 | } | |
135 | ||
136 | ||
137 | INLINE_SIM_FPU (sim_fpu) | |
138 | sim_fpu_f2 (float f) | |
139 | { | |
140 | sim_fpu ans; | |
141 | ans.val = f; | |
142 | return ans; | |
143 | } | |
144 | ||
145 | ||
146 | INLINE_SIM_FPU (sim_fpu) | |
147 | sim_fpu_d2 (double d) | |
148 | { | |
149 | sim_fpu ans; | |
150 | ans.val = d; | |
151 | return ans; | |
152 | } | |
153 | ||
154 | ||
155 | INLINE_SIM_FPU (int) | |
156 | sim_fpu_is_nan (sim_fpu d) | |
157 | { | |
158 | return 0; /* FIXME - detect NaN */ | |
159 | } | |
160 | ||
161 | ||
162 | INLINE_SIM_FPU (int) | |
163 | sim_fpu_cmp (sim_fpu l, | |
164 | sim_fpu r) | |
165 | { | |
166 | return l.val - r.val; | |
167 | } | |
168 | ||
169 | #endif |