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.
25 unsigned int SingleCPDO(const unsigned int opcode
);
26 unsigned int DoubleCPDO(const unsigned int opcode
);
27 unsigned int ExtendedCPDO(const unsigned int opcode
);
29 unsigned int EmulateCPDO(const unsigned int opcode
)
31 FPA11
*fpa11
= GET_FPA11();
32 unsigned int Fd
, nType
, nDest
, nRc
= 1;
34 //printk("EmulateCPDO(0x%08x)\n",opcode);
36 /* Get the destination size. If not valid let Linux perform
37 an invalid instruction trap. */
38 nDest
= getDestinationSize(opcode
);
39 if (typeNone
== nDest
) return 0;
41 SetRoundingMode(opcode
);
43 /* Compare the size of the operands in Fn and Fm.
44 Choose the largest size and perform operations in that size,
45 in order to make use of all the precision of the operands.
46 If Fm is a constant, we just grab a constant of a size
47 matching the size of the operand in Fn. */
48 if (MONADIC_INSTRUCTION(opcode
))
51 nType
= fpa11
->fType
[getFn(opcode
)];
53 if (!CONSTANT_FM(opcode
))
55 register unsigned int Fm
= getFm(opcode
);
56 if (nType
< fpa11
->fType
[Fm
])
58 nType
= fpa11
->fType
[Fm
];
64 case typeSingle
: nRc
= SingleCPDO(opcode
); break;
65 case typeDouble
: nRc
= DoubleCPDO(opcode
); break;
66 case typeExtended
: nRc
= ExtendedCPDO(opcode
); break;
70 /* If the operation succeeded, check to see if the result in the
71 destination register is the correct size. If not force it
74 nType
= fpa11
->fType
[Fd
];
75 if ((0 != nRc
) && (nDest
!= nType
))
81 if (typeDouble
== nType
)
82 fpa11
->fpreg
[Fd
].fSingle
=
83 float64_to_float32(fpa11
->fpreg
[Fd
].fDouble
, &fpa11
->fp_status
);
85 fpa11
->fpreg
[Fd
].fSingle
=
86 floatx80_to_float32(fpa11
->fpreg
[Fd
].fExtended
, &fpa11
->fp_status
);
92 if (typeSingle
== nType
)
93 fpa11
->fpreg
[Fd
].fDouble
=
94 float32_to_float64(fpa11
->fpreg
[Fd
].fSingle
, &fpa11
->fp_status
);
96 fpa11
->fpreg
[Fd
].fDouble
=
97 floatx80_to_float64(fpa11
->fpreg
[Fd
].fExtended
, &fpa11
->fp_status
);
103 if (typeSingle
== nType
)
104 fpa11
->fpreg
[Fd
].fExtended
=
105 float32_to_floatx80(fpa11
->fpreg
[Fd
].fSingle
, &fpa11
->fp_status
);
107 fpa11
->fpreg
[Fd
].fExtended
=
108 float64_to_floatx80(fpa11
->fpreg
[Fd
].fDouble
, &fpa11
->fp_status
);
113 fpa11
->fType
[Fd
] = nDest
;