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"
26 float32
float32_exp(float32 Fm
);
27 float32
float32_ln(float32 Fm
);
28 float32
float32_sin(float32 rFm
);
29 float32
float32_cos(float32 rFm
);
30 float32
float32_arcsin(float32 rFm
);
31 float32
float32_arctan(float32 rFm
);
32 float32
float32_log(float32 rFm
);
33 float32
float32_tan(float32 rFm
);
34 float32
float32_arccos(float32 rFm
);
35 float32
float32_pow(float32 rFn
,float32 rFm
);
36 float32
float32_pol(float32 rFn
,float32 rFm
);
38 unsigned int SingleCPDO(const unsigned int opcode
)
40 FPA11
*fpa11
= GET_FPA11();
41 float32 rFm
, rFn
= 0; //FIXME - should be zero?
42 unsigned int Fd
, Fm
, Fn
, nRc
= 1;
45 if (CONSTANT_FM(opcode
))
47 rFm
= getSingleConstant(Fm
);
51 switch (fpa11
->fType
[Fm
])
54 rFm
= fpa11
->fpreg
[Fm
].fSingle
;
61 if (!MONADIC_INSTRUCTION(opcode
))
64 switch (fpa11
->fType
[Fn
])
67 rFn
= fpa11
->fpreg
[Fn
].fSingle
;
75 switch (opcode
& MASK_ARITHMETIC_OPCODE
)
79 fpa11
->fpreg
[Fd
].fSingle
= float32_add(rFn
,rFm
);
84 fpa11
->fpreg
[Fd
].fSingle
= float32_mul(rFn
,rFm
);
88 fpa11
->fpreg
[Fd
].fSingle
= float32_sub(rFn
,rFm
);
92 fpa11
->fpreg
[Fd
].fSingle
= float32_sub(rFm
,rFn
);
97 fpa11
->fpreg
[Fd
].fSingle
= float32_div(rFn
,rFm
);
102 fpa11
->fpreg
[Fd
].fSingle
= float32_div(rFm
,rFn
);
107 fpa11
->fpreg
[Fd
].fSingle
= float32_pow(rFn
,rFm
);
111 fpa11
->fpreg
[Fd
].fSingle
= float32_pow(rFm
,rFn
);
116 fpa11
->fpreg
[Fd
].fSingle
= float32_rem(rFn
,rFm
);
121 fpa11
->fpreg
[Fd
].fSingle
= float32_pol(rFn
,rFm
);
125 /* monadic opcodes */
127 fpa11
->fpreg
[Fd
].fSingle
= rFm
;
132 fpa11
->fpreg
[Fd
].fSingle
= rFm
;
137 fpa11
->fpreg
[Fd
].fSingle
= rFm
;
142 fpa11
->fpreg
[Fd
].fSingle
= float32_round_to_int(rFm
);
146 fpa11
->fpreg
[Fd
].fSingle
= float32_sqrt(rFm
);
151 fpa11
->fpreg
[Fd
].fSingle
= float32_log(rFm
);
155 fpa11
->fpreg
[Fd
].fSingle
= float32_ln(rFm
);
159 fpa11
->fpreg
[Fd
].fSingle
= float32_exp(rFm
);
163 fpa11
->fpreg
[Fd
].fSingle
= float32_sin(rFm
);
167 fpa11
->fpreg
[Fd
].fSingle
= float32_cos(rFm
);
171 fpa11
->fpreg
[Fd
].fSingle
= float32_tan(rFm
);
175 fpa11
->fpreg
[Fd
].fSingle
= float32_arcsin(rFm
);
179 fpa11
->fpreg
[Fd
].fSingle
= float32_arccos(rFm
);
183 fpa11
->fpreg
[Fd
].fSingle
= float32_arctan(rFm
);
196 if (0 != nRc
) fpa11
->fType
[Fd
] = typeSingle
;
201 float32
float32_exp(float32 Fm
)
206 float32
float32_ln(float32 Fm
)
211 float32
float32_sin(float32 rFm
)
216 float32
float32_cos(float32 rFm
)
221 float32
float32_arcsin(float32 rFm
)
226 float32
float32_arctan(float32 rFm
)
231 float32
float32_arccos(float32 rFm
)
233 //return float32_sub(halfPi,float32_arcsin(rFm));
236 float32
float32_log(float32 rFm
)
238 return float32_div(float32_ln(rFm
),getSingleConstant(7));
241 float32
float32_tan(float32 rFm
)
243 return float32_div(float32_sin(rFm
),float32_cos(rFm
));
246 float32
float32_pow(float32 rFn
,float32 rFm
)
248 return float32_exp(float32_mul(rFm
,float32_ln(rFn
)));
251 float32
float32_pol(float32 rFn
,float32 rFm
)
253 return float32_arctan(float32_div(rFn
,rFm
));