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.
26 #include "fpmodule.inl"
28 #include <linux/compiler.h>
29 #include <asm/system.h>
31 /* forward declarations */
32 unsigned int EmulateCPDO(const unsigned int);
33 unsigned int EmulateCPDT(const unsigned int);
34 unsigned int EmulateCPRT(const unsigned int);
36 /* Reset the FPA11 chip. Called to initialize and reset the emulator. */
40 FPA11 *fpa11 = GET_FPA11();
42 /* initialize the register type array */
45 fpa11->fType[i] = typeNone;
48 /* FPSR: set system id to FP_EMULATOR, set AC, clear all other bits */
49 fpa11->fpsr = FP_EMULATOR | BIT_AC;
51 /* FPCR: set SB, AB and DA bits, clear all others */
53 fpa11->fpcr = MASK_RESET;
57 void SetRoundingMode(const unsigned int opcode)
60 FPA11 *fpa11 = GET_FPA11();
61 fpa11->fpcr &= ~MASK_ROUNDING_MODE;
63 switch (opcode & MASK_ROUNDING_MODE)
66 case ROUND_TO_NEAREST:
67 float_rounding_mode = float_round_nearest_even;
69 fpa11->fpcr |= ROUND_TO_NEAREST;
73 case ROUND_TO_PLUS_INFINITY:
74 float_rounding_mode = float_round_up;
76 fpa11->fpcr |= ROUND_TO_PLUS_INFINITY;
80 case ROUND_TO_MINUS_INFINITY:
81 float_rounding_mode = float_round_down;
83 fpa11->fpcr |= ROUND_TO_MINUS_INFINITY;
88 float_rounding_mode = float_round_to_zero;
90 fpa11->fpcr |= ROUND_TO_ZERO;
96 void SetRoundingPrecision(const unsigned int opcode)
99 FPA11 *fpa11 = GET_FPA11();
100 fpa11->fpcr &= ~MASK_ROUNDING_PRECISION;
102 switch (opcode & MASK_ROUNDING_PRECISION)
105 floatx80_rounding_precision = 32;
107 fpa11->fpcr |= ROUND_SINGLE;
112 floatx80_rounding_precision = 64;
114 fpa11->fpcr |= ROUND_DOUBLE;
119 floatx80_rounding_precision = 80;
121 fpa11->fpcr |= ROUND_EXTENDED;
125 default: floatx80_rounding_precision = 80;
129 void FPA11_CheckInit(void)
131 FPA11 *fpa11 = GET_FPA11();
132 if (unlikely(fpa11->initflag == 0))
135 SetRoundingMode(ROUND_TO_NEAREST);
136 SetRoundingPrecision(ROUND_EXTENDED);
141 /* Emulate the instruction in the opcode. */
142 unsigned int EmulateAll(unsigned int opcode)
144 unsigned int nRc = 1, code;
146 code = opcode & 0x00000f00;
147 if (code == 0x00000100 || code == 0x00000200)
149 /* For coprocessor 1 or 2 (FPA11) */
150 code = opcode & 0x0e000000;
151 if (code == 0x0e000000)
153 if (opcode & 0x00000010)
155 /* Emulate conversion opcodes. */
156 /* Emulate register transfer opcodes. */
157 /* Emulate comparison opcodes. */
158 nRc = EmulateCPRT(opcode);
162 /* Emulate monadic arithmetic opcodes. */
163 /* Emulate dyadic arithmetic opcodes. */
164 nRc = EmulateCPDO(opcode);
167 else if (code == 0x0c000000)
169 /* Emulate load/store opcodes. */
170 /* Emulate load/store multiple opcodes. */
171 nRc = EmulateCPDT(opcode);
175 /* Invalid instruction detected. Return FALSE. */
184 unsigned int EmulateAll1(unsigned int opcode)
186 switch ((opcode >> 24) & 0xf)
190 if ((opcode >> 20) & 0x1)
192 switch ((opcode >> 8) & 0xf)
194 case 0x1: return PerformLDF(opcode); break;
195 case 0x2: return PerformLFM(opcode); break;
201 switch ((opcode >> 8) & 0xf)
203 case 0x1: return PerformSTF(opcode); break;
204 case 0x2: return PerformSFM(opcode); break;
212 return EmulateCPDO(opcode);
214 return EmulateCPRT(opcode);