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, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "softfloat.h"
27 floatx80
getExtendedConstant(unsigned int);
29 floatx80
floatx80_exp(floatx80 Fm
);
30 floatx80
floatx80_ln(floatx80 Fm
);
31 floatx80
floatx80_sin(floatx80 rFm
);
32 floatx80
floatx80_cos(floatx80 rFm
);
33 floatx80
floatx80_arcsin(floatx80 rFm
);
34 floatx80
floatx80_arctan(floatx80 rFm
);
35 floatx80
floatx80_log(floatx80 rFm
);
36 floatx80
floatx80_tan(floatx80 rFm
);
37 floatx80
floatx80_arccos(floatx80 rFm
);
38 floatx80
floatx80_pow(floatx80 rFn
,floatx80 rFm
);
39 floatx80
floatx80_pol(floatx80 rFn
,floatx80 rFm
);
41 unsigned int ExtendedCPDO(const unsigned int opcode
)
44 unsigned int Fd
, Fm
, Fn
, nRc
= 1;
46 //fp_printk("ExtendedCPDO(0x%08x)\n",opcode);
49 if (CONSTANT_FM(opcode
))
51 rFm
= getExtendedConstant(Fm
);
55 switch (fpa11
->fpreg
[Fm
].fType
)
58 rFm
= float32_to_floatx80(fpa11
->fpreg
[Fm
].fValue
.fSingle
);
62 rFm
= float64_to_floatx80(fpa11
->fpreg
[Fm
].fValue
.fDouble
);
66 rFm
= fpa11
->fpreg
[Fm
].fValue
.fExtended
;
73 if (!MONADIC_INSTRUCTION(opcode
))
76 switch (fpa11
->fpreg
[Fn
].fType
)
79 rFn
= float32_to_floatx80(fpa11
->fpreg
[Fn
].fValue
.fSingle
);
83 rFn
= float64_to_floatx80(fpa11
->fpreg
[Fn
].fValue
.fDouble
);
87 rFn
= fpa11
->fpreg
[Fn
].fValue
.fExtended
;
95 switch (opcode
& MASK_ARITHMETIC_OPCODE
)
99 fpa11
->fpreg
[Fd
].fValue
.fExtended
= floatx80_add(rFn
,rFm
);
104 fpa11
->fpreg
[Fd
].fValue
.fExtended
= floatx80_mul(rFn
,rFm
);
108 fpa11
->fpreg
[Fd
].fValue
.fExtended
= floatx80_sub(rFn
,rFm
);
112 fpa11
->fpreg
[Fd
].fValue
.fExtended
= floatx80_sub(rFm
,rFn
);
117 fpa11
->fpreg
[Fd
].fValue
.fExtended
= floatx80_div(rFn
,rFm
);
122 fpa11
->fpreg
[Fd
].fValue
.fExtended
= floatx80_div(rFm
,rFn
);
127 fpa11
->fpreg
[Fd
].fValue
.fExtended
= floatx80_pow(rFn
,rFm
);
131 fpa11
->fpreg
[Fd
].fValue
.fExtended
= floatx80_pow(rFm
,rFn
);
136 fpa11
->fpreg
[Fd
].fValue
.fExtended
= floatx80_rem(rFn
,rFm
);
141 fpa11
->fpreg
[Fd
].fValue
.fExtended
= floatx80_pol(rFn
,rFm
);
145 /* monadic opcodes */
147 fpa11
->fpreg
[Fd
].fValue
.fExtended
= rFm
;
152 fpa11
->fpreg
[Fd
].fValue
.fExtended
= rFm
;
157 fpa11
->fpreg
[Fd
].fValue
.fExtended
= rFm
;
162 fpa11
->fpreg
[Fd
].fValue
.fExtended
=
163 int32_to_floatx80(floatx80_to_int32(rFm
));
167 fpa11
->fpreg
[Fd
].fValue
.fExtended
= floatx80_sqrt(rFm
);
172 fpa11
->fpreg
[Fd
].fValue
.fExtended
= floatx80_log(rFm
);
176 fpa11
->fpreg
[Fd
].fValue
.fExtended
= floatx80_ln(rFm
);
180 fpa11
->fpreg
[Fd
].fValue
.fExtended
= floatx80_exp(rFm
);
184 fpa11
->fpreg
[Fd
].fValue
.fExtended
= floatx80_sin(rFm
);
188 fpa11
->fpreg
[Fd
].fValue
.fExtended
= floatx80_cos(rFm
);
192 fpa11
->fpreg
[Fd
].fValue
.fExtended
= floatx80_tan(rFm
);
196 fpa11
->fpreg
[Fd
].fValue
.fExtended
= floatx80_arcsin(rFm
);
200 fpa11
->fpreg
[Fd
].fValue
.fExtended
= floatx80_arccos(rFm
);
204 fpa11
->fpreg
[Fd
].fValue
.fExtended
= floatx80_arctan(rFm
);
217 if (0 != nRc
) fpa11
->fpreg
[Fd
].fType
= typeExtended
;
222 floatx80
floatx80_exp(floatx80 Fm
)
227 floatx80
floatx80_ln(floatx80 Fm
)
232 floatx80
floatx80_sin(floatx80 rFm
)
237 floatx80
floatx80_cos(floatx80 rFm
)
242 floatx80
floatx80_arcsin(floatx80 rFm
)
247 floatx80
floatx80_arctan(floatx80 rFm
)
252 floatx80
floatx80_log(floatx80 rFm
)
254 return floatx80_div(floatx80_ln(rFm
),getExtendedConstant(7));
257 floatx80
floatx80_tan(floatx80 rFm
)
259 return floatx80_div(floatx80_sin(rFm
),floatx80_cos(rFm
));
262 floatx80
floatx80_arccos(floatx80 rFm
)
264 //return floatx80_sub(halfPi,floatx80_arcsin(rFm));
267 floatx80
floatx80_pow(floatx80 rFn
,floatx80 rFm
)
269 return floatx80_exp(floatx80_mul(rFm
,floatx80_ln(rFn
)));
272 floatx80
floatx80_pol(floatx80 rFn
,floatx80 rFm
)
274 return floatx80_arctan(floatx80_div(rFn
,rFm
));