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 float64
float64_exp(float64 Fm
);
27 float64
float64_ln(float64 Fm
);
28 float64
float64_sin(float64 rFm
);
29 float64
float64_cos(float64 rFm
);
30 float64
float64_arcsin(float64 rFm
);
31 float64
float64_arctan(float64 rFm
);
32 float64
float64_log(float64 rFm
);
33 float64
float64_tan(float64 rFm
);
34 float64
float64_arccos(float64 rFm
);
35 float64
float64_pow(float64 rFn
,float64 rFm
);
36 float64
float64_pol(float64 rFn
,float64 rFm
);
38 unsigned int DoubleCPDO(const unsigned int opcode
)
40 FPA11
*fpa11
= GET_FPA11();
41 float64 rFm
, rFn
= 0; //FIXME - should be zero?
42 unsigned int Fd
, Fm
, Fn
, nRc
= 1;
44 //printk("DoubleCPDO(0x%08x)\n",opcode);
47 if (CONSTANT_FM(opcode
))
49 rFm
= getDoubleConstant(Fm
);
53 switch (fpa11
->fType
[Fm
])
56 rFm
= float32_to_float64(fpa11
->fpreg
[Fm
].fSingle
);
60 rFm
= fpa11
->fpreg
[Fm
].fDouble
;
65 //printk("not implemented! why not?\n");
67 // should never get here, if extended involved
68 // then other operand should be promoted then
69 // ExtendedCPDO called.
76 if (!MONADIC_INSTRUCTION(opcode
))
79 switch (fpa11
->fType
[Fn
])
82 rFn
= float32_to_float64(fpa11
->fpreg
[Fn
].fSingle
);
86 rFn
= fpa11
->fpreg
[Fn
].fDouble
;
94 /* !! this switch isn't optimized; better (opcode & MASK_ARITHMETIC_OPCODE)>>24, sort of */
95 switch (opcode
& MASK_ARITHMETIC_OPCODE
)
99 fpa11
->fpreg
[Fd
].fDouble
= float64_add(rFn
,rFm
);
104 fpa11
->fpreg
[Fd
].fDouble
= float64_mul(rFn
,rFm
);
108 fpa11
->fpreg
[Fd
].fDouble
= float64_sub(rFn
,rFm
);
112 fpa11
->fpreg
[Fd
].fDouble
= float64_sub(rFm
,rFn
);
117 fpa11
->fpreg
[Fd
].fDouble
= float64_div(rFn
,rFm
);
122 fpa11
->fpreg
[Fd
].fDouble
= float64_div(rFm
,rFn
);
127 fpa11
->fpreg
[Fd
].fDouble
= float64_pow(rFn
,rFm
);
131 fpa11
->fpreg
[Fd
].fDouble
= float64_pow(rFm
,rFn
);
136 fpa11
->fpreg
[Fd
].fDouble
= float64_rem(rFn
,rFm
);
141 fpa11
->fpreg
[Fd
].fDouble
= float64_pol(rFn
,rFm
);
145 /* monadic opcodes */
147 fpa11
->fpreg
[Fd
].fDouble
= rFm
;
152 unsigned int *p
= (unsigned int*)&rFm
;
154 fpa11
->fpreg
[Fd
].fDouble
= rFm
;
160 unsigned int *p
= (unsigned int*)&rFm
;
162 fpa11
->fpreg
[Fd
].fDouble
= rFm
;
168 fpa11
->fpreg
[Fd
].fDouble
= float64_round_to_int(rFm
);
172 fpa11
->fpreg
[Fd
].fDouble
= float64_sqrt(rFm
);
177 fpa11
->fpreg
[Fd
].fDouble
= float64_log(rFm
);
181 fpa11
->fpreg
[Fd
].fDouble
= float64_ln(rFm
);
185 fpa11
->fpreg
[Fd
].fDouble
= float64_exp(rFm
);
189 fpa11
->fpreg
[Fd
].fDouble
= float64_sin(rFm
);
193 fpa11
->fpreg
[Fd
].fDouble
= float64_cos(rFm
);
197 fpa11
->fpreg
[Fd
].fDouble
= float64_tan(rFm
);
201 fpa11
->fpreg
[Fd
].fDouble
= float64_arcsin(rFm
);
205 fpa11
->fpreg
[Fd
].fDouble
= float64_arccos(rFm
);
209 fpa11
->fpreg
[Fd
].fDouble
= float64_arctan(rFm
);
222 if (0 != nRc
) fpa11
->fType
[Fd
] = typeDouble
;
227 float64
float64_exp(float64 rFm
)
233 float64
float64_ln(float64 rFm
)
239 float64
float64_sin(float64 rFm
)
245 float64
float64_cos(float64 rFm
)
252 float64
float64_arcsin(float64 rFm
)
257 float64
float64_arctan(float64 rFm
)
263 float64
float64_log(float64 rFm
)
265 return float64_div(float64_ln(rFm
),getDoubleConstant(7));
268 float64
float64_tan(float64 rFm
)
270 return float64_div(float64_sin(rFm
),float64_cos(rFm
));
273 float64
float64_arccos(float64 rFm
)
276 //return float64_sub(halfPi,float64_arcsin(rFm));
279 float64
float64_pow(float64 rFn
,float64 rFm
)
281 return float64_exp(float64_mul(rFm
,float64_ln(rFn
)));
284 float64
float64_pol(float64 rFn
,float64 rFm
)
286 return float64_arctan(float64_div(rFn
,rFm
));