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/>.
22 #include "softfloat.h"
25 floatx80
floatx80_exp(floatx80 Fm
);
26 floatx80
floatx80_ln(floatx80 Fm
);
27 floatx80
floatx80_sin(floatx80 rFm
);
28 floatx80
floatx80_cos(floatx80 rFm
);
29 floatx80
floatx80_arcsin(floatx80 rFm
);
30 floatx80
floatx80_arctan(floatx80 rFm
);
31 floatx80
floatx80_log(floatx80 rFm
);
32 floatx80
floatx80_tan(floatx80 rFm
);
33 floatx80
floatx80_arccos(floatx80 rFm
);
34 floatx80
floatx80_pow(floatx80 rFn
,floatx80 rFm
);
35 floatx80
floatx80_pol(floatx80 rFn
,floatx80 rFm
);
37 unsigned int ExtendedCPDO(const unsigned int opcode
)
39 FPA11
*fpa11
= GET_FPA11();
41 unsigned int Fd
, Fm
, Fn
, nRc
= 1;
43 //printk("ExtendedCPDO(0x%08x)\n",opcode);
46 if (CONSTANT_FM(opcode
))
48 rFm
= getExtendedConstant(Fm
);
52 switch (fpa11
->fType
[Fm
])
55 rFm
= float32_to_floatx80(fpa11
->fpreg
[Fm
].fSingle
, &fpa11
->fp_status
);
59 rFm
= float64_to_floatx80(fpa11
->fpreg
[Fm
].fDouble
, &fpa11
->fp_status
);
63 rFm
= fpa11
->fpreg
[Fm
].fExtended
;
70 if (!MONADIC_INSTRUCTION(opcode
))
73 switch (fpa11
->fType
[Fn
])
76 rFn
= float32_to_floatx80(fpa11
->fpreg
[Fn
].fSingle
, &fpa11
->fp_status
);
80 rFn
= float64_to_floatx80(fpa11
->fpreg
[Fn
].fDouble
, &fpa11
->fp_status
);
84 rFn
= fpa11
->fpreg
[Fn
].fExtended
;
92 switch (opcode
& MASK_ARITHMETIC_OPCODE
)
96 fpa11
->fpreg
[Fd
].fExtended
= floatx80_add(rFn
,rFm
, &fpa11
->fp_status
);
101 fpa11
->fpreg
[Fd
].fExtended
= floatx80_mul(rFn
,rFm
, &fpa11
->fp_status
);
105 fpa11
->fpreg
[Fd
].fExtended
= floatx80_sub(rFn
,rFm
, &fpa11
->fp_status
);
109 fpa11
->fpreg
[Fd
].fExtended
= floatx80_sub(rFm
,rFn
, &fpa11
->fp_status
);
114 fpa11
->fpreg
[Fd
].fExtended
= floatx80_div(rFn
,rFm
, &fpa11
->fp_status
);
119 fpa11
->fpreg
[Fd
].fExtended
= floatx80_div(rFm
,rFn
, &fpa11
->fp_status
);
124 fpa11
->fpreg
[Fd
].fExtended
= floatx80_pow(rFn
,rFm
);
128 fpa11
->fpreg
[Fd
].fExtended
= floatx80_pow(rFm
,rFn
);
133 fpa11
->fpreg
[Fd
].fExtended
= floatx80_rem(rFn
,rFm
, &fpa11
->fp_status
);
138 fpa11
->fpreg
[Fd
].fExtended
= floatx80_pol(rFn
,rFm
);
142 /* monadic opcodes */
144 fpa11
->fpreg
[Fd
].fExtended
= rFm
;
149 fpa11
->fpreg
[Fd
].fExtended
= rFm
;
154 fpa11
->fpreg
[Fd
].fExtended
= rFm
;
159 fpa11
->fpreg
[Fd
].fExtended
= floatx80_round_to_int(rFm
, &fpa11
->fp_status
);
163 fpa11
->fpreg
[Fd
].fExtended
= floatx80_sqrt(rFm
, &fpa11
->fp_status
);
168 fpa11
->fpreg
[Fd
].fExtended
= floatx80_log(rFm
);
172 fpa11
->fpreg
[Fd
].fExtended
= floatx80_ln(rFm
);
176 fpa11
->fpreg
[Fd
].fExtended
= floatx80_exp(rFm
);
180 fpa11
->fpreg
[Fd
].fExtended
= floatx80_sin(rFm
);
184 fpa11
->fpreg
[Fd
].fExtended
= floatx80_cos(rFm
);
188 fpa11
->fpreg
[Fd
].fExtended
= floatx80_tan(rFm
);
192 fpa11
->fpreg
[Fd
].fExtended
= floatx80_arcsin(rFm
);
196 fpa11
->fpreg
[Fd
].fExtended
= floatx80_arccos(rFm
);
200 fpa11
->fpreg
[Fd
].fExtended
= floatx80_arctan(rFm
);
213 if (0 != nRc
) fpa11
->fType
[Fd
] = typeExtended
;
218 floatx80
floatx80_exp(floatx80 Fm
)
223 floatx80
floatx80_ln(floatx80 Fm
)
228 floatx80
floatx80_sin(floatx80 rFm
)
233 floatx80
floatx80_cos(floatx80 rFm
)
238 floatx80
floatx80_arcsin(floatx80 rFm
)
243 floatx80
floatx80_arctan(floatx80 rFm
)
248 floatx80
floatx80_log(floatx80 rFm
)
250 return floatx80_div(floatx80_ln(rFm
),getExtendedConstant(7));
253 floatx80
floatx80_tan(floatx80 rFm
)
255 return floatx80_div(floatx80_sin(rFm
),floatx80_cos(rFm
));
258 floatx80
floatx80_arccos(floatx80 rFm
)
260 //return floatx80_sub(halfPi,floatx80_arcsin(rFm));
263 floatx80
floatx80_pow(floatx80 rFn
,floatx80 rFm
)
265 return floatx80_exp(floatx80_mul(rFm
,floatx80_ln(rFn
)));
268 floatx80
floatx80_pol(floatx80 rFn
,floatx80 rFm
)
270 return floatx80_arctan(floatx80_div(rFn
,rFm
));