2 NetWinder Floating Point Emulator
3 (c) Rebel.COM, 1998,1999
5 Direct questions, comments to Scott Bambrough <scottb@netwinder.org>
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 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "qemu/osdep.h"
23 #include "fpu/softfloat.h"
26 floatx80
floatx80_exp(floatx80 Fm
);
27 floatx80
floatx80_ln(floatx80 Fm
);
28 floatx80
floatx80_sin(floatx80 rFm
);
29 floatx80
floatx80_cos(floatx80 rFm
);
30 floatx80
floatx80_arcsin(floatx80 rFm
);
31 floatx80
floatx80_arctan(floatx80 rFm
);
32 floatx80
floatx80_log(floatx80 rFm
);
33 floatx80
floatx80_tan(floatx80 rFm
);
34 floatx80
floatx80_arccos(floatx80 rFm
);
35 floatx80
floatx80_pow(floatx80 rFn
,floatx80 rFm
);
36 floatx80
floatx80_pol(floatx80 rFn
,floatx80 rFm
);
38 unsigned int ExtendedCPDO(const unsigned int opcode
)
40 FPA11
*fpa11
= GET_FPA11();
42 unsigned int Fd
, Fm
, Fn
, nRc
= 1;
44 //printk("ExtendedCPDO(0x%08x)\n",opcode);
47 if (CONSTANT_FM(opcode
))
49 rFm
= getExtendedConstant(Fm
);
53 switch (fpa11
->fType
[Fm
])
56 rFm
= float32_to_floatx80(fpa11
->fpreg
[Fm
].fSingle
, &fpa11
->fp_status
);
60 rFm
= float64_to_floatx80(fpa11
->fpreg
[Fm
].fDouble
, &fpa11
->fp_status
);
64 rFm
= fpa11
->fpreg
[Fm
].fExtended
;
71 if (!MONADIC_INSTRUCTION(opcode
))
74 switch (fpa11
->fType
[Fn
])
77 rFn
= float32_to_floatx80(fpa11
->fpreg
[Fn
].fSingle
, &fpa11
->fp_status
);
81 rFn
= float64_to_floatx80(fpa11
->fpreg
[Fn
].fDouble
, &fpa11
->fp_status
);
85 rFn
= fpa11
->fpreg
[Fn
].fExtended
;
93 switch (opcode
& MASK_ARITHMETIC_OPCODE
)
97 fpa11
->fpreg
[Fd
].fExtended
= floatx80_add(rFn
,rFm
, &fpa11
->fp_status
);
102 fpa11
->fpreg
[Fd
].fExtended
= floatx80_mul(rFn
,rFm
, &fpa11
->fp_status
);
106 fpa11
->fpreg
[Fd
].fExtended
= floatx80_sub(rFn
,rFm
, &fpa11
->fp_status
);
110 fpa11
->fpreg
[Fd
].fExtended
= floatx80_sub(rFm
,rFn
, &fpa11
->fp_status
);
115 fpa11
->fpreg
[Fd
].fExtended
= floatx80_div(rFn
,rFm
, &fpa11
->fp_status
);
120 fpa11
->fpreg
[Fd
].fExtended
= floatx80_div(rFm
,rFn
, &fpa11
->fp_status
);
125 fpa11
->fpreg
[Fd
].fExtended
= floatx80_pow(rFn
,rFm
);
129 fpa11
->fpreg
[Fd
].fExtended
= floatx80_pow(rFm
,rFn
);
134 fpa11
->fpreg
[Fd
].fExtended
= floatx80_rem(rFn
,rFm
, &fpa11
->fp_status
);
139 fpa11
->fpreg
[Fd
].fExtended
= floatx80_pol(rFn
,rFm
);
143 /* monadic opcodes */
145 fpa11
->fpreg
[Fd
].fExtended
= rFm
;
150 fpa11
->fpreg
[Fd
].fExtended
= rFm
;
155 fpa11
->fpreg
[Fd
].fExtended
= rFm
;
160 fpa11
->fpreg
[Fd
].fExtended
= floatx80_round_to_int(rFm
, &fpa11
->fp_status
);
164 fpa11
->fpreg
[Fd
].fExtended
= floatx80_sqrt(rFm
, &fpa11
->fp_status
);
169 fpa11
->fpreg
[Fd
].fExtended
= floatx80_log(rFm
);
173 fpa11
->fpreg
[Fd
].fExtended
= floatx80_ln(rFm
);
177 fpa11
->fpreg
[Fd
].fExtended
= floatx80_exp(rFm
);
181 fpa11
->fpreg
[Fd
].fExtended
= floatx80_sin(rFm
);
185 fpa11
->fpreg
[Fd
].fExtended
= floatx80_cos(rFm
);
189 fpa11
->fpreg
[Fd
].fExtended
= floatx80_tan(rFm
);
193 fpa11
->fpreg
[Fd
].fExtended
= floatx80_arcsin(rFm
);
197 fpa11
->fpreg
[Fd
].fExtended
= floatx80_arccos(rFm
);
201 fpa11
->fpreg
[Fd
].fExtended
= floatx80_arctan(rFm
);
214 if (0 != nRc
) fpa11
->fType
[Fd
] = typeExtended
;
219 floatx80
floatx80_exp(floatx80 Fm
)
224 floatx80
floatx80_ln(floatx80 Fm
)
229 floatx80
floatx80_sin(floatx80 rFm
)
234 floatx80
floatx80_cos(floatx80 rFm
)
239 floatx80
floatx80_arcsin(floatx80 rFm
)
244 floatx80
floatx80_arctan(floatx80 rFm
)
249 floatx80
floatx80_log(floatx80 rFm
)
251 return floatx80_div(floatx80_ln(rFm
),getExtendedConstant(7));
254 floatx80
floatx80_tan(floatx80 rFm
)
256 return floatx80_div(floatx80_sin(rFm
),floatx80_cos(rFm
));
259 floatx80
floatx80_arccos(floatx80 rFm
)
261 //return floatx80_sub(halfPi,floatx80_arcsin(rFm));
264 floatx80
floatx80_pow(floatx80 rFn
,floatx80 rFm
)
266 return floatx80_exp(floatx80_mul(rFm
,floatx80_ln(rFn
)));
269 floatx80
floatx80_pol(floatx80 rFn
,floatx80 rFm
)
271 return floatx80_arctan(floatx80_div(rFn
,rFm
));