Linux 2.6.13-rc4
[linux-2.6/next.git] / arch / arm / nwfpe / fpa11_cpdo.c
blob1bea67437b6f2bc5ed859b7aa0db2237e84a7c6e
1 /*
2 NetWinder Floating Point Emulator
3 (c) Rebel.COM, 1998,1999
4 (c) Philip Blundell, 2001
6 Direct questions, comments to Scott Bambrough <scottb@netwinder.org>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <linux/config.h>
24 #include "fpa11.h"
25 #include "fpopcode.h"
27 unsigned int SingleCPDO(const unsigned int opcode, FPREG * rFd);
28 unsigned int DoubleCPDO(const unsigned int opcode, FPREG * rFd);
29 unsigned int ExtendedCPDO(const unsigned int opcode, FPREG * rFd);
31 unsigned int EmulateCPDO(const unsigned int opcode)
33 FPA11 *fpa11 = GET_FPA11();
34 FPREG *rFd;
35 unsigned int nType, nDest, nRc;
37 /* Get the destination size. If not valid let Linux perform
38 an invalid instruction trap. */
39 nDest = getDestinationSize(opcode);
40 if (typeNone == nDest)
41 return 0;
43 SetRoundingMode(opcode);
45 /* Compare the size of the operands in Fn and Fm.
46 Choose the largest size and perform operations in that size,
47 in order to make use of all the precision of the operands.
48 If Fm is a constant, we just grab a constant of a size
49 matching the size of the operand in Fn. */
50 if (MONADIC_INSTRUCTION(opcode))
51 nType = nDest;
52 else
53 nType = fpa11->fType[getFn(opcode)];
55 if (!CONSTANT_FM(opcode)) {
56 register unsigned int Fm = getFm(opcode);
57 if (nType < fpa11->fType[Fm]) {
58 nType = fpa11->fType[Fm];
62 rFd = &fpa11->fpreg[getFd(opcode)];
64 switch (nType) {
65 case typeSingle:
66 nRc = SingleCPDO(opcode, rFd);
67 break;
68 case typeDouble:
69 nRc = DoubleCPDO(opcode, rFd);
70 break;
71 #ifdef CONFIG_FPE_NWFPE_XP
72 case typeExtended:
73 nRc = ExtendedCPDO(opcode, rFd);
74 break;
75 #endif
76 default:
77 nRc = 0;
80 /* The CPDO functions used to always set the destination type
81 to be the same as their working size. */
83 if (nRc != 0) {
84 /* If the operation succeeded, check to see if the result in the
85 destination register is the correct size. If not force it
86 to be. */
88 fpa11->fType[getFd(opcode)] = nDest;
90 #ifdef CONFIG_FPE_NWFPE_XP
91 if (nDest != nType) {
92 switch (nDest) {
93 case typeSingle:
95 if (typeDouble == nType)
96 rFd->fSingle = float64_to_float32(rFd->fDouble);
97 else
98 rFd->fSingle = floatx80_to_float32(rFd->fExtended);
100 break;
102 case typeDouble:
104 if (typeSingle == nType)
105 rFd->fDouble = float32_to_float64(rFd->fSingle);
106 else
107 rFd->fDouble = floatx80_to_float64(rFd->fExtended);
109 break;
111 case typeExtended:
113 if (typeSingle == nType)
114 rFd->fExtended = float32_to_floatx80(rFd->fSingle);
115 else
116 rFd->fExtended = float64_to_floatx80(rFd->fDouble);
118 break;
121 #else
122 if (nDest != nType) {
123 if (nDest == typeSingle)
124 rFd->fSingle = float64_to_float32(rFd->fDouble);
125 else
126 rFd->fDouble = float32_to_float64(rFd->fSingle);
128 #endif
131 return nRc;