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.
24 #include "softfloat.h"
28 float32
getSingleConstant(unsigned int);
30 float32
float32_exp(float32 Fm
);
31 float32
float32_ln(float32 Fm
);
32 float32
float32_sin(float32 rFm
);
33 float32
float32_cos(float32 rFm
);
34 float32
float32_arcsin(float32 rFm
);
35 float32
float32_arctan(float32 rFm
);
36 float32
float32_log(float32 rFm
);
37 float32
float32_tan(float32 rFm
);
38 float32
float32_arccos(float32 rFm
);
39 float32
float32_pow(float32 rFn
,float32 rFm
);
40 float32
float32_pol(float32 rFn
,float32 rFm
);
42 unsigned int SingleCPDO(const unsigned int opcode
)
45 unsigned int Fd
, Fm
, Fn
, nRc
= 1;
48 if (CONSTANT_FM(opcode
))
50 rFm
= getSingleConstant(Fm
);
54 switch (fpa11
->fpreg
[Fm
].fType
)
57 rFm
= fpa11
->fpreg
[Fm
].fValue
.fSingle
;
64 if (!MONADIC_INSTRUCTION(opcode
))
67 switch (fpa11
->fpreg
[Fn
].fType
)
70 rFn
= fpa11
->fpreg
[Fn
].fValue
.fSingle
;
78 switch (opcode
& MASK_ARITHMETIC_OPCODE
)
82 fpa11
->fpreg
[Fd
].fValue
.fSingle
= float32_add(rFn
,rFm
);
87 fpa11
->fpreg
[Fd
].fValue
.fSingle
= float32_mul(rFn
,rFm
);
91 fpa11
->fpreg
[Fd
].fValue
.fSingle
= float32_sub(rFn
,rFm
);
95 fpa11
->fpreg
[Fd
].fValue
.fSingle
= float32_sub(rFm
,rFn
);
100 fpa11
->fpreg
[Fd
].fValue
.fSingle
= float32_div(rFn
,rFm
);
105 fpa11
->fpreg
[Fd
].fValue
.fSingle
= float32_div(rFm
,rFn
);
110 fpa11
->fpreg
[Fd
].fValue
.fSingle
= float32_pow(rFn
,rFm
);
114 fpa11
->fpreg
[Fd
].fValue
.fSingle
= float32_pow(rFm
,rFn
);
119 fpa11
->fpreg
[Fd
].fValue
.fSingle
= float32_rem(rFn
,rFm
);
124 fpa11
->fpreg
[Fd
].fValue
.fSingle
= float32_pol(rFn
,rFm
);
128 /* monadic opcodes */
130 fpa11
->fpreg
[Fd
].fValue
.fSingle
= rFm
;
135 fpa11
->fpreg
[Fd
].fValue
.fSingle
= rFm
;
140 fpa11
->fpreg
[Fd
].fValue
.fSingle
= rFm
;
145 fpa11
->fpreg
[Fd
].fValue
.fSingle
=
146 int32_to_float32(float32_to_int32(rFm
));
150 fpa11
->fpreg
[Fd
].fValue
.fSingle
= float32_sqrt(rFm
);
155 fpa11
->fpreg
[Fd
].fValue
.fSingle
= float32_log(rFm
);
159 fpa11
->fpreg
[Fd
].fValue
.fSingle
= float32_ln(rFm
);
163 fpa11
->fpreg
[Fd
].fValue
.fSingle
= float32_exp(rFm
);
167 fpa11
->fpreg
[Fd
].fValue
.fSingle
= float32_sin(rFm
);
171 fpa11
->fpreg
[Fd
].fValue
.fSingle
= float32_cos(rFm
);
175 fpa11
->fpreg
[Fd
].fValue
.fSingle
= float32_tan(rFm
);
179 fpa11
->fpreg
[Fd
].fValue
.fSingle
= float32_arcsin(rFm
);
183 fpa11
->fpreg
[Fd
].fValue
.fSingle
= float32_arccos(rFm
);
187 fpa11
->fpreg
[Fd
].fValue
.fSingle
= float32_arctan(rFm
);
200 if (0 != nRc
) fpa11
->fpreg
[Fd
].fType
= typeSingle
;
205 float32
float32_exp(float32 Fm
)
210 float32
float32_ln(float32 Fm
)
215 float32
float32_sin(float32 rFm
)
220 float32
float32_cos(float32 rFm
)
225 float32
float32_arcsin(float32 rFm
)
230 float32
float32_arctan(float32 rFm
)
235 float32
float32_arccos(float32 rFm
)
237 //return float32_sub(halfPi,float32_arcsin(rFm));
240 float32
float32_log(float32 rFm
)
242 return float32_div(float32_ln(rFm
),getSingleConstant(7));
245 float32
float32_tan(float32 rFm
)
247 return float32_div(float32_sin(rFm
),float32_cos(rFm
));
250 float32
float32_pow(float32 rFn
,float32 rFm
)
252 return float32_exp(float32_mul(rFm
,float32_ln(rFn
)));
255 float32
float32_pol(float32 rFn
,float32 rFm
)
257 return float32_arctan(float32_div(rFn
,rFm
));