root / target-arm / nwfpe / double_cpdo.c @ 1d6e34fd
History | View | Annotate | Download (6.2 kB)
1 | 00406dff | bellard | /*
|
---|---|---|---|
2 | 00406dff | bellard | NetWinder Floating Point Emulator
|
3 | 00406dff | bellard | (c) Rebel.COM, 1998,1999
|
4 | 00406dff | bellard | |
5 | 00406dff | bellard | Direct questions, comments to Scott Bambrough <scottb@netwinder.org>
|
6 | 00406dff | bellard | |
7 | 00406dff | bellard | This program is free software; you can redistribute it and/or modify
|
8 | 00406dff | bellard | it under the terms of the GNU General Public License as published by
|
9 | 00406dff | bellard | the Free Software Foundation; either version 2 of the License, or
|
10 | 00406dff | bellard | (at your option) any later version.
|
11 | 00406dff | bellard | |
12 | 00406dff | bellard | This program is distributed in the hope that it will be useful,
|
13 | 00406dff | bellard | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 | 00406dff | bellard | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 | 00406dff | bellard | GNU General Public License for more details.
|
16 | 00406dff | bellard | |
17 | 00406dff | bellard | You should have received a copy of the GNU General Public License
|
18 | 00406dff | bellard | along with this program; if not, write to the Free Software
|
19 | 00406dff | bellard | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
20 | 00406dff | bellard | */
|
21 | 00406dff | bellard | |
22 | 00406dff | bellard | #include "fpa11.h" |
23 | 00406dff | bellard | #include "softfloat.h" |
24 | 00406dff | bellard | #include "fpopcode.h" |
25 | 00406dff | bellard | |
26 | 00406dff | bellard | float64 float64_exp(float64 Fm); |
27 | 00406dff | bellard | float64 float64_ln(float64 Fm); |
28 | 00406dff | bellard | float64 float64_sin(float64 rFm); |
29 | 00406dff | bellard | float64 float64_cos(float64 rFm); |
30 | 00406dff | bellard | float64 float64_arcsin(float64 rFm); |
31 | 00406dff | bellard | float64 float64_arctan(float64 rFm); |
32 | 00406dff | bellard | float64 float64_log(float64 rFm); |
33 | 00406dff | bellard | float64 float64_tan(float64 rFm); |
34 | 00406dff | bellard | float64 float64_arccos(float64 rFm); |
35 | 00406dff | bellard | float64 float64_pow(float64 rFn,float64 rFm); |
36 | 00406dff | bellard | float64 float64_pol(float64 rFn,float64 rFm); |
37 | 00406dff | bellard | |
38 | 00406dff | bellard | unsigned int DoubleCPDO(const unsigned int opcode) |
39 | 00406dff | bellard | { |
40 | 00406dff | bellard | FPA11 *fpa11 = GET_FPA11(); |
41 | 526ff7de | bellard | float64 rFm, rFn = 0;
|
42 | 00406dff | bellard | unsigned int Fd, Fm, Fn, nRc = 1; |
43 | 00406dff | bellard | |
44 | 00406dff | bellard | //printk("DoubleCPDO(0x%08x)\n",opcode);
|
45 | 00406dff | bellard | |
46 | 00406dff | bellard | Fm = getFm(opcode); |
47 | 00406dff | bellard | if (CONSTANT_FM(opcode))
|
48 | 00406dff | bellard | { |
49 | 00406dff | bellard | rFm = getDoubleConstant(Fm); |
50 | 00406dff | bellard | } |
51 | 00406dff | bellard | else
|
52 | 00406dff | bellard | { |
53 | 00406dff | bellard | switch (fpa11->fType[Fm])
|
54 | 00406dff | bellard | { |
55 | 00406dff | bellard | case typeSingle:
|
56 | 00406dff | bellard | rFm = float32_to_float64(fpa11->fpreg[Fm].fSingle); |
57 | 00406dff | bellard | break;
|
58 | 00406dff | bellard | |
59 | 00406dff | bellard | case typeDouble:
|
60 | 00406dff | bellard | rFm = fpa11->fpreg[Fm].fDouble; |
61 | 00406dff | bellard | break;
|
62 | 00406dff | bellard | |
63 | 00406dff | bellard | case typeExtended:
|
64 | 00406dff | bellard | // !! patb
|
65 | 00406dff | bellard | //printk("not implemented! why not?\n");
|
66 | 00406dff | bellard | //!! ScottB
|
67 | 00406dff | bellard | // should never get here, if extended involved
|
68 | 00406dff | bellard | // then other operand should be promoted then
|
69 | 00406dff | bellard | // ExtendedCPDO called.
|
70 | 00406dff | bellard | break;
|
71 | 00406dff | bellard | |
72 | 00406dff | bellard | default: return 0; |
73 | 00406dff | bellard | } |
74 | 00406dff | bellard | } |
75 | 00406dff | bellard | |
76 | 00406dff | bellard | if (!MONADIC_INSTRUCTION(opcode))
|
77 | 00406dff | bellard | { |
78 | 00406dff | bellard | Fn = getFn(opcode); |
79 | 00406dff | bellard | switch (fpa11->fType[Fn])
|
80 | 00406dff | bellard | { |
81 | 00406dff | bellard | case typeSingle:
|
82 | 00406dff | bellard | rFn = float32_to_float64(fpa11->fpreg[Fn].fSingle); |
83 | 00406dff | bellard | break;
|
84 | 00406dff | bellard | |
85 | 00406dff | bellard | case typeDouble:
|
86 | 00406dff | bellard | rFn = fpa11->fpreg[Fn].fDouble; |
87 | 00406dff | bellard | break;
|
88 | 00406dff | bellard | |
89 | 00406dff | bellard | default: return 0; |
90 | 00406dff | bellard | } |
91 | 00406dff | bellard | } |
92 | 00406dff | bellard | |
93 | 00406dff | bellard | Fd = getFd(opcode); |
94 | 00406dff | bellard | /* !! this switch isn't optimized; better (opcode & MASK_ARITHMETIC_OPCODE)>>24, sort of */
|
95 | 00406dff | bellard | switch (opcode & MASK_ARITHMETIC_OPCODE)
|
96 | 00406dff | bellard | { |
97 | 00406dff | bellard | /* dyadic opcodes */
|
98 | 00406dff | bellard | case ADF_CODE:
|
99 | 00406dff | bellard | fpa11->fpreg[Fd].fDouble = float64_add(rFn,rFm); |
100 | 00406dff | bellard | break;
|
101 | 00406dff | bellard | |
102 | 00406dff | bellard | case MUF_CODE:
|
103 | 00406dff | bellard | case FML_CODE:
|
104 | 00406dff | bellard | fpa11->fpreg[Fd].fDouble = float64_mul(rFn,rFm); |
105 | 00406dff | bellard | break;
|
106 | 00406dff | bellard | |
107 | 00406dff | bellard | case SUF_CODE:
|
108 | 00406dff | bellard | fpa11->fpreg[Fd].fDouble = float64_sub(rFn,rFm); |
109 | 00406dff | bellard | break;
|
110 | 00406dff | bellard | |
111 | 00406dff | bellard | case RSF_CODE:
|
112 | 00406dff | bellard | fpa11->fpreg[Fd].fDouble = float64_sub(rFm,rFn); |
113 | 00406dff | bellard | break;
|
114 | 00406dff | bellard | |
115 | 00406dff | bellard | case DVF_CODE:
|
116 | 00406dff | bellard | case FDV_CODE:
|
117 | 00406dff | bellard | fpa11->fpreg[Fd].fDouble = float64_div(rFn,rFm); |
118 | 00406dff | bellard | break;
|
119 | 00406dff | bellard | |
120 | 00406dff | bellard | case RDF_CODE:
|
121 | 00406dff | bellard | case FRD_CODE:
|
122 | 00406dff | bellard | fpa11->fpreg[Fd].fDouble = float64_div(rFm,rFn); |
123 | 00406dff | bellard | break;
|
124 | 00406dff | bellard | |
125 | 00406dff | bellard | #if 0
|
126 | 00406dff | bellard | case POW_CODE:
|
127 | 00406dff | bellard | fpa11->fpreg[Fd].fDouble = float64_pow(rFn,rFm);
|
128 | 00406dff | bellard | break;
|
129 | 00406dff | bellard | |
130 | 00406dff | bellard | case RPW_CODE:
|
131 | 00406dff | bellard | fpa11->fpreg[Fd].fDouble = float64_pow(rFm,rFn);
|
132 | 00406dff | bellard | break;
|
133 | 00406dff | bellard | #endif
|
134 | 00406dff | bellard | |
135 | 00406dff | bellard | case RMF_CODE:
|
136 | 00406dff | bellard | fpa11->fpreg[Fd].fDouble = float64_rem(rFn,rFm); |
137 | 00406dff | bellard | break;
|
138 | 00406dff | bellard | |
139 | 00406dff | bellard | #if 0
|
140 | 00406dff | bellard | case POL_CODE:
|
141 | 00406dff | bellard | fpa11->fpreg[Fd].fDouble = float64_pol(rFn,rFm);
|
142 | 00406dff | bellard | break;
|
143 | 00406dff | bellard | #endif
|
144 | 00406dff | bellard | |
145 | 00406dff | bellard | /* monadic opcodes */
|
146 | 00406dff | bellard | case MVF_CODE:
|
147 | 00406dff | bellard | fpa11->fpreg[Fd].fDouble = rFm; |
148 | 00406dff | bellard | break;
|
149 | 00406dff | bellard | |
150 | 00406dff | bellard | case MNF_CODE:
|
151 | 00406dff | bellard | { |
152 | 00406dff | bellard | unsigned int *p = (unsigned int*)&rFm; |
153 | a8d3431a | bellard | #ifdef WORDS_BIGENDIAN
|
154 | a8d3431a | bellard | p[0] ^= 0x80000000; |
155 | a8d3431a | bellard | #else
|
156 | 00406dff | bellard | p[1] ^= 0x80000000; |
157 | a8d3431a | bellard | #endif
|
158 | 00406dff | bellard | fpa11->fpreg[Fd].fDouble = rFm; |
159 | 00406dff | bellard | } |
160 | 00406dff | bellard | break;
|
161 | 00406dff | bellard | |
162 | 00406dff | bellard | case ABS_CODE:
|
163 | 00406dff | bellard | { |
164 | 00406dff | bellard | unsigned int *p = (unsigned int*)&rFm; |
165 | a8d3431a | bellard | #ifdef WORDS_BIGENDIAN
|
166 | a8d3431a | bellard | p[0] &= 0x7fffffff; |
167 | a8d3431a | bellard | #else
|
168 | 00406dff | bellard | p[1] &= 0x7fffffff; |
169 | a8d3431a | bellard | #endif
|
170 | 00406dff | bellard | fpa11->fpreg[Fd].fDouble = rFm; |
171 | 00406dff | bellard | } |
172 | 00406dff | bellard | break;
|
173 | 00406dff | bellard | |
174 | 00406dff | bellard | case RND_CODE:
|
175 | 00406dff | bellard | case URD_CODE:
|
176 | 00406dff | bellard | fpa11->fpreg[Fd].fDouble = float64_round_to_int(rFm); |
177 | 00406dff | bellard | break;
|
178 | 00406dff | bellard | |
179 | 00406dff | bellard | case SQT_CODE:
|
180 | 00406dff | bellard | fpa11->fpreg[Fd].fDouble = float64_sqrt(rFm); |
181 | 00406dff | bellard | break;
|
182 | 00406dff | bellard | |
183 | 00406dff | bellard | #if 0
|
184 | 00406dff | bellard | case LOG_CODE:
|
185 | 00406dff | bellard | fpa11->fpreg[Fd].fDouble = float64_log(rFm);
|
186 | 00406dff | bellard | break;
|
187 | 00406dff | bellard | |
188 | 00406dff | bellard | case LGN_CODE:
|
189 | 00406dff | bellard | fpa11->fpreg[Fd].fDouble = float64_ln(rFm);
|
190 | 00406dff | bellard | break;
|
191 | 00406dff | bellard | |
192 | 00406dff | bellard | case EXP_CODE:
|
193 | 00406dff | bellard | fpa11->fpreg[Fd].fDouble = float64_exp(rFm);
|
194 | 00406dff | bellard | break;
|
195 | 00406dff | bellard | |
196 | 00406dff | bellard | case SIN_CODE:
|
197 | 00406dff | bellard | fpa11->fpreg[Fd].fDouble = float64_sin(rFm);
|
198 | 00406dff | bellard | break;
|
199 | 00406dff | bellard | |
200 | 00406dff | bellard | case COS_CODE:
|
201 | 00406dff | bellard | fpa11->fpreg[Fd].fDouble = float64_cos(rFm);
|
202 | 00406dff | bellard | break;
|
203 | 00406dff | bellard | |
204 | 00406dff | bellard | case TAN_CODE:
|
205 | 00406dff | bellard | fpa11->fpreg[Fd].fDouble = float64_tan(rFm);
|
206 | 00406dff | bellard | break;
|
207 | 00406dff | bellard | |
208 | 00406dff | bellard | case ASN_CODE:
|
209 | 00406dff | bellard | fpa11->fpreg[Fd].fDouble = float64_arcsin(rFm);
|
210 | 00406dff | bellard | break;
|
211 | 00406dff | bellard | |
212 | 00406dff | bellard | case ACS_CODE:
|
213 | 00406dff | bellard | fpa11->fpreg[Fd].fDouble = float64_arccos(rFm);
|
214 | 00406dff | bellard | break;
|
215 | 00406dff | bellard | |
216 | 00406dff | bellard | case ATN_CODE:
|
217 | 00406dff | bellard | fpa11->fpreg[Fd].fDouble = float64_arctan(rFm);
|
218 | 00406dff | bellard | break;
|
219 | 00406dff | bellard | #endif
|
220 | 00406dff | bellard | |
221 | 00406dff | bellard | case NRM_CODE:
|
222 | 00406dff | bellard | break;
|
223 | 00406dff | bellard | |
224 | 00406dff | bellard | default:
|
225 | 00406dff | bellard | { |
226 | 00406dff | bellard | nRc = 0;
|
227 | 00406dff | bellard | } |
228 | 00406dff | bellard | } |
229 | 00406dff | bellard | |
230 | 00406dff | bellard | if (0 != nRc) fpa11->fType[Fd] = typeDouble; |
231 | 00406dff | bellard | return nRc;
|
232 | 00406dff | bellard | } |
233 | 00406dff | bellard | |
234 | 00406dff | bellard | #if 0
|
235 | 00406dff | bellard | float64 float64_exp(float64 rFm)
|
236 | 00406dff | bellard | {
|
237 | 00406dff | bellard | return rFm;
|
238 | 00406dff | bellard | //series
|
239 | 00406dff | bellard | }
|
240 | 00406dff | bellard | |
241 | 00406dff | bellard | float64 float64_ln(float64 rFm)
|
242 | 00406dff | bellard | {
|
243 | 00406dff | bellard | return rFm;
|
244 | 00406dff | bellard | //series
|
245 | 00406dff | bellard | }
|
246 | 00406dff | bellard | |
247 | 00406dff | bellard | float64 float64_sin(float64 rFm)
|
248 | 00406dff | bellard | {
|
249 | 00406dff | bellard | return rFm;
|
250 | 00406dff | bellard | //series
|
251 | 00406dff | bellard | }
|
252 | 00406dff | bellard | |
253 | 00406dff | bellard | float64 float64_cos(float64 rFm)
|
254 | 00406dff | bellard | {
|
255 | 00406dff | bellard | return rFm;
|
256 | 00406dff | bellard | //series
|
257 | 00406dff | bellard | }
|
258 | 00406dff | bellard | |
259 | 00406dff | bellard | #if 0
|
260 | 00406dff | bellard | float64 float64_arcsin(float64 rFm)
|
261 | 00406dff | bellard | {
|
262 | 00406dff | bellard | //series
|
263 | 00406dff | bellard | }
|
264 | 00406dff | bellard | |
265 | 00406dff | bellard | float64 float64_arctan(float64 rFm)
|
266 | 00406dff | bellard | {
|
267 | 00406dff | bellard | //series
|
268 | 00406dff | bellard | }
|
269 | 00406dff | bellard | #endif
|
270 | 00406dff | bellard | |
271 | 00406dff | bellard | float64 float64_log(float64 rFm) |
272 | 00406dff | bellard | { |
273 | 00406dff | bellard | return float64_div(float64_ln(rFm),getDoubleConstant(7)); |
274 | 00406dff | bellard | } |
275 | 00406dff | bellard | |
276 | 00406dff | bellard | float64 float64_tan(float64 rFm) |
277 | 00406dff | bellard | { |
278 | 00406dff | bellard | return float64_div(float64_sin(rFm),float64_cos(rFm));
|
279 | 00406dff | bellard | } |
280 | 00406dff | bellard | |
281 | 00406dff | bellard | float64 float64_arccos(float64 rFm) |
282 | 00406dff | bellard | { |
283 | 00406dff | bellard | return rFm;
|
284 | 00406dff | bellard | //return float64_sub(halfPi,float64_arcsin(rFm));
|
285 | 00406dff | bellard | } |
286 | 00406dff | bellard | |
287 | 00406dff | bellard | float64 float64_pow(float64 rFn,float64 rFm) |
288 | 00406dff | bellard | { |
289 | 00406dff | bellard | return float64_exp(float64_mul(rFm,float64_ln(rFn)));
|
290 | 00406dff | bellard | } |
291 | 00406dff | bellard | |
292 | 00406dff | bellard | float64 float64_pol(float64 rFn,float64 rFm) |
293 | 00406dff | bellard | { |
294 | 00406dff | bellard | return float64_arctan(float64_div(rFn,rFm));
|
295 | 00406dff | bellard | } |
296 | 00406dff | bellard | #endif |