* add p cc
[mascara-docs.git] / i386 / linux / linux-2.3.21 / arch / arm / nwfpe / fpopcode.c
blob0d12f72693e1d2b818546a234a3ff87997bf5e60
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 "fpsr.h"
26 #include "fpa11.h"
27 #include "fpmodule.h"
28 #include "fpmodule.inl"
30 static floatx80 floatx80Constant[] = {
31 { 0x0000, 0x0000000000000000ULL}, /* extended 0.0 */
32 { 0x3fff, 0x8000000000000000ULL}, /* extended 1.0 */
33 { 0x4000, 0x8000000000000000ULL}, /* extended 2.0 */
34 { 0x4000, 0xc000000000000000ULL}, /* extended 3.0 */
35 { 0x4001, 0x8000000000000000ULL}, /* extended 4.0 */
36 { 0x4001, 0xa000000000000000ULL}, /* extended 5.0 */
37 { 0x3ffe, 0x8000000000000000ULL}, /* extended 0.5 */
38 { 0x4002, 0xa000000000000000ULL} /* extended 10.0 */
39 };
41 static float64 float64Constant[] = {
42 0x0000000000000000ULL, /* double 0.0 */
43 0x3ff0000000000000ULL, /* double 1.0 */
44 0x4000000000000000ULL, /* double 2.0 */
45 0x4008000000000000ULL, /* double 3.0 */
46 0x4010000000000000ULL, /* double 4.0 */
47 0x4014000000000000ULL, /* double 5.0 */
48 0x3fe0000000000000ULL, /* double 0.5 */
49 0x4024000000000000ULL /* double 10.0 */
50 };
52 static float32 float32Constant[] = {
53 0x00000000, /* single 0.0 */
54 0x3f800000, /* single 1.0 */
55 0x40000000, /* single 2.0 */
56 0x40400000, /* single 3.0 */
57 0x40800000, /* single 4.0 */
58 0x40a00000, /* single 5.0 */
59 0x3f000000, /* single 0.5 */
60 0x41200000 /* single 10.0 */
61 };
63 floatx80 getExtendedConstant(const unsigned int nIndex)
65 return floatx80Constant[nIndex];
68 float64 getDoubleConstant(const unsigned int nIndex)
70 return float64Constant[nIndex];
73 float32 getSingleConstant(const unsigned int nIndex)
75 return float32Constant[nIndex];
78 unsigned int getTransferLength(const unsigned int opcode)
80 unsigned int nRc;
82 switch (opcode & MASK_TRANSFER_LENGTH)
84 case 0x00000000: nRc = 1; break; /* single precision */
85 case 0x00008000: nRc = 2; break; /* double precision */
86 case 0x00400000: nRc = 3; break; /* extended precision */
87 default: nRc = 0;
90 return(nRc);
93 unsigned int getRegisterCount(const unsigned int opcode)
95 unsigned int nRc;
97 switch (opcode & MASK_REGISTER_COUNT)
99 case 0x00000000: nRc = 4; break;
100 case 0x00008000: nRc = 1; break;
101 case 0x00400000: nRc = 2; break;
102 case 0x00408000: nRc = 3; break;
103 default: nRc = 0;
106 return(nRc);
109 unsigned int getRoundingPrecision(const unsigned int opcode)
111 unsigned int nRc;
113 switch (opcode & MASK_ROUNDING_PRECISION)
115 case 0x00000000: nRc = 1; break;
116 case 0x00000080: nRc = 2; break;
117 case 0x00080000: nRc = 3; break;
118 default: nRc = 0;
121 return(nRc);
124 unsigned int getDestinationSize(const unsigned int opcode)
126 unsigned int nRc;
128 switch (opcode & MASK_DESTINATION_SIZE)
130 case 0x00000000: nRc = typeSingle; break;
131 case 0x00000080: nRc = typeDouble; break;
132 case 0x00080000: nRc = typeExtended; break;
133 default: nRc = typeNone;
136 return(nRc);
139 /* contition code lookup table
140 index into the table is test code: EQ, NE, ... LT, GT, AL, NV
141 bit position in short is condition code: NZCV */
142 unsigned short aCC[16] = {
143 0xF0F0, // EQ == Z set
144 0x0F0F, // NE
145 0xCCCC, // CS == C set
146 0x3333, // CC
147 0xFF00, // MI == N set
148 0x00FF, // PL
149 0xAAAA, // VS == V set
150 0x5555, // VC
151 0x0C0C, // HI == C set && Z clear
152 0xF3F3, // LS == C clear || Z set
153 0xAA55, // GE == (N==V)
154 0x55AA, // LT == (N!=V)
155 0x0A05, // GT == (!Z && (N==V))
156 0xF5FA, // LE == (Z || (N!=V))
157 0xFFFF, // AL always
158 0 // NV
161 unsigned int checkCondition(const unsigned int opcode, const unsigned int ccodes)
163 return (aCC[opcode>>28] >> (ccodes>>28)) & 1;