* add p cc
[mascara-docs.git] / i386 / linux / linux-2.3.21 / arch / arm / nwfpe / double_cpdo.c
blob3db9e7066fb2055a54e432d603a563ada5baa544
1 /*
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.
22 #include "config.h"
23 #include "softfloat.h"
24 #include "fpopcode.h"
25 #include "fpa11.h"
27 extern FPA11 *fpa11;
29 float64 getDoubleConstant(unsigned int);
31 float64 float64_exp(float64 Fm);
32 float64 float64_ln(float64 Fm);
33 float64 float64_sin(float64 rFm);
34 float64 float64_cos(float64 rFm);
35 float64 float64_arcsin(float64 rFm);
36 float64 float64_arctan(float64 rFm);
37 float64 float64_log(float64 rFm);
38 float64 float64_tan(float64 rFm);
39 float64 float64_arccos(float64 rFm);
40 float64 float64_pow(float64 rFn,float64 rFm);
41 float64 float64_pol(float64 rFn,float64 rFm);
43 unsigned int DoubleCPDO(const unsigned int opcode)
45 float64 rFm, rFn;
46 unsigned int Fd, Fm, Fn, nRc = 1;
48 //fp_printk("DoubleCPDO(0x%08x)\n",opcode);
50 Fm = getFm(opcode);
51 if (CONSTANT_FM(opcode))
53 rFm = getDoubleConstant(Fm);
55 else
57 switch (fpa11->fpreg[Fm].fType)
59 case typeSingle:
60 rFm = float32_to_float64(fpa11->fpreg[Fm].fValue.fSingle);
61 break;
63 case typeDouble:
64 rFm = fpa11->fpreg[Fm].fValue.fDouble;
65 break;
67 case typeExtended:
68 // !! patb
69 //fp_printk("not implemented! why not?\n");
70 //!! ScottB
71 // should never get here, if extended involved
72 // then other operand should be promoted then
73 // ExtendedCPDO called.
74 break;
76 default: return 0;
80 if (!MONADIC_INSTRUCTION(opcode))
82 Fn = getFn(opcode);
83 switch (fpa11->fpreg[Fn].fType)
85 case typeSingle:
86 rFn = float32_to_float64(fpa11->fpreg[Fn].fValue.fSingle);
87 break;
89 case typeDouble:
90 rFn = fpa11->fpreg[Fn].fValue.fDouble;
91 break;
93 default: return 0;
97 Fd = getFd(opcode);
98 /* !! this switch isn't optimized; better (opcode & MASK_ARITHMETIC_OPCODE)>>24, sort of */
99 switch (opcode & MASK_ARITHMETIC_OPCODE)
101 /* dyadic opcodes */
102 case ADF_CODE:
103 fpa11->fpreg[Fd].fValue.fDouble = float64_add(rFn,rFm);
104 break;
106 case MUF_CODE:
107 case FML_CODE:
108 fpa11->fpreg[Fd].fValue.fDouble = float64_mul(rFn,rFm);
109 break;
111 case SUF_CODE:
112 fpa11->fpreg[Fd].fValue.fDouble = float64_sub(rFn,rFm);
113 break;
115 case RSF_CODE:
116 fpa11->fpreg[Fd].fValue.fDouble = float64_sub(rFm,rFn);
117 break;
119 case DVF_CODE:
120 case FDV_CODE:
121 fpa11->fpreg[Fd].fValue.fDouble = float64_div(rFn,rFm);
122 break;
124 case RDF_CODE:
125 case FRD_CODE:
126 fpa11->fpreg[Fd].fValue.fDouble = float64_div(rFm,rFn);
127 break;
129 #if 0
130 case POW_CODE:
131 fpa11->fpreg[Fd].fValue.fDouble = float64_pow(rFn,rFm);
132 break;
134 case RPW_CODE:
135 fpa11->fpreg[Fd].fValue.fDouble = float64_pow(rFm,rFn);
136 break;
137 #endif
139 case RMF_CODE:
140 fpa11->fpreg[Fd].fValue.fDouble = float64_rem(rFn,rFm);
141 break;
143 #if 0
144 case POL_CODE:
145 fpa11->fpreg[Fd].fValue.fDouble = float64_pol(rFn,rFm);
146 break;
147 #endif
149 /* monadic opcodes */
150 case MVF_CODE:
151 fpa11->fpreg[Fd].fValue.fDouble = rFm;
152 break;
154 case MNF_CODE:
156 unsigned int *p = (unsigned int*)&rFm;
157 p[1] ^= 0x80000000;
158 fpa11->fpreg[Fd].fValue.fDouble = rFm;
160 break;
162 case ABS_CODE:
164 unsigned int *p = (unsigned int*)&rFm;
165 p[1] &= 0x7fffffff;
166 fpa11->fpreg[Fd].fValue.fDouble = rFm;
168 break;
170 case RND_CODE:
171 case URD_CODE:
172 fpa11->fpreg[Fd].fValue.fDouble =
173 int32_to_float64(float64_to_int32(rFm));
174 break;
176 case SQT_CODE:
177 fpa11->fpreg[Fd].fValue.fDouble = float64_sqrt(rFm);
178 break;
180 #if 0
181 case LOG_CODE:
182 fpa11->fpreg[Fd].fValue.fDouble = float64_log(rFm);
183 break;
185 case LGN_CODE:
186 fpa11->fpreg[Fd].fValue.fDouble = float64_ln(rFm);
187 break;
189 case EXP_CODE:
190 fpa11->fpreg[Fd].fValue.fDouble = float64_exp(rFm);
191 break;
193 case SIN_CODE:
194 fpa11->fpreg[Fd].fValue.fDouble = float64_sin(rFm);
195 break;
197 case COS_CODE:
198 fpa11->fpreg[Fd].fValue.fDouble = float64_cos(rFm);
199 break;
201 case TAN_CODE:
202 fpa11->fpreg[Fd].fValue.fDouble = float64_tan(rFm);
203 break;
205 case ASN_CODE:
206 fpa11->fpreg[Fd].fValue.fDouble = float64_arcsin(rFm);
207 break;
209 case ACS_CODE:
210 fpa11->fpreg[Fd].fValue.fDouble = float64_arccos(rFm);
211 break;
213 case ATN_CODE:
214 fpa11->fpreg[Fd].fValue.fDouble = float64_arctan(rFm);
215 break;
216 #endif
218 case NRM_CODE:
219 break;
221 default:
223 nRc = 0;
227 if (0 != nRc) fpa11->fpreg[Fd].fType = typeDouble;
228 return nRc;
231 #if 0
232 float64 float64_exp(float64 rFm)
234 return rFm;
235 //series
238 float64 float64_ln(float64 rFm)
240 return rFm;
241 //series
244 float64 float64_sin(float64 rFm)
246 return rFm;
247 //series
250 float64 float64_cos(float64 rFm)
252 return rFm;
253 //series
256 #if 0
257 float64 float64_arcsin(float64 rFm)
259 //series
262 float64 float64_arctan(float64 rFm)
264 //series
266 #endif
268 float64 float64_log(float64 rFm)
270 return float64_div(float64_ln(rFm),getDoubleConstant(7));
273 float64 float64_tan(float64 rFm)
275 return float64_div(float64_sin(rFm),float64_cos(rFm));
278 float64 float64_arccos(float64 rFm)
280 return rFm;
281 //return float64_sub(halfPi,float64_arcsin(rFm));
284 float64 float64_pow(float64 rFn,float64 rFm)
286 return float64_exp(float64_mul(rFm,float64_ln(rFn)));
289 float64 float64_pol(float64 rFn,float64 rFm)
291 return float64_arctan(float64_div(rFn,rFm));
293 #endif